aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host')
-rw-r--r--drivers/usb/host/Kconfig4
-rw-r--r--drivers/usb/host/ehci-atmel.c19
-rw-r--r--drivers/usb/host/ehci-au1xxx.c87
-rw-r--r--drivers/usb/host/ehci-cns3xxx.c6
-rw-r--r--drivers/usb/host/ehci-dbg.c24
-rw-r--r--drivers/usb/host/ehci-fsl.c42
-rw-r--r--drivers/usb/host/ehci-grlib.c15
-rw-r--r--drivers/usb/host/ehci-hcd.c512
-rw-r--r--drivers/usb/host/ehci-hub.c129
-rw-r--r--drivers/usb/host/ehci-ixp4xx.c6
-rw-r--r--drivers/usb/host/ehci-mem.c25
-rw-r--r--drivers/usb/host/ehci-msm.c27
-rw-r--r--drivers/usb/host/ehci-mv.c36
-rw-r--r--drivers/usb/host/ehci-mxc.c17
-rw-r--r--drivers/usb/host/ehci-octeon.c8
-rw-r--r--drivers/usb/host/ehci-omap.c114
-rw-r--r--drivers/usb/host/ehci-orion.c17
-rw-r--r--drivers/usb/host/ehci-pci.c238
-rw-r--r--drivers/usb/host/ehci-platform.c7
-rw-r--r--drivers/usb/host/ehci-pmcmsp.c17
-rw-r--r--drivers/usb/host/ehci-ppc-of.c25
-rw-r--r--drivers/usb/host/ehci-ps3.c18
-rw-r--r--drivers/usb/host/ehci-q.c311
-rw-r--r--drivers/usb/host/ehci-s5p.c135
-rw-r--r--drivers/usb/host/ehci-sched.c552
-rw-r--r--drivers/usb/host/ehci-sead3.c74
-rw-r--r--drivers/usb/host/ehci-sh.c16
-rw-r--r--drivers/usb/host/ehci-spear.c71
-rw-r--r--drivers/usb/host/ehci-tegra.c36
-rw-r--r--drivers/usb/host/ehci-timer.c401
-rw-r--r--drivers/usb/host/ehci-vt8500.c14
-rw-r--r--drivers/usb/host/ehci-w90x900.c9
-rw-r--r--drivers/usb/host/ehci-xilinx-of.c31
-rw-r--r--drivers/usb/host/ehci-xls.c21
-rw-r--r--drivers/usb/host/ehci.h138
-rw-r--r--drivers/usb/host/fhci-dbg.c12
-rw-r--r--drivers/usb/host/fhci-hcd.c32
-rw-r--r--drivers/usb/host/fhci-hub.c16
-rw-r--r--drivers/usb/host/fhci-sched.c30
-rw-r--r--drivers/usb/host/fhci-tds.c14
-rw-r--r--drivers/usb/host/fhci.h22
-rw-r--r--drivers/usb/host/imx21-hcd.c6
-rw-r--r--drivers/usb/host/ohci-exynos.c46
-rw-r--r--drivers/usb/host/ohci-nxp.c88
-rw-r--r--drivers/usb/host/ohci-omap.c28
-rw-r--r--drivers/usb/host/ohci.h5
-rw-r--r--drivers/usb/host/xhci-hub.c6
-rw-r--r--drivers/usb/host/xhci.c2
48 files changed, 1604 insertions, 1905 deletions
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index dcfaaa91a3fb..075d2eca8108 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -652,7 +652,7 @@ config USB_HCD_BCMA
652 select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD 652 select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD
653 select USB_EHCI_HCD_PLATFORM if USB_EHCI_HCD 653 select USB_EHCI_HCD_PLATFORM if USB_EHCI_HCD
654 help 654 help
655 Enbale support for the EHCI and OCHI host controller on an bcma bus. 655 Enable support for the EHCI and OCHI host controller on an bcma bus.
656 It converts the bcma driver into two platform device drivers 656 It converts the bcma driver into two platform device drivers
657 for ehci and ohci. 657 for ehci and ohci.
658 658
@@ -664,7 +664,7 @@ config USB_HCD_SSB
664 select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD 664 select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD
665 select USB_EHCI_HCD_PLATFORM if USB_EHCI_HCD 665 select USB_EHCI_HCD_PLATFORM if USB_EHCI_HCD
666 help 666 help
667 Enbale support for the EHCI and OCHI host controller on an bcma bus. 667 Enable support for the EHCI and OCHI host controller on an bcma bus.
668 It converts the bcma driver into two platform device drivers 668 It converts the bcma driver into two platform device drivers
669 for ehci and ohci. 669 for ehci and ohci.
670 670
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c
index cf14c95a6700..a47e2cffaaf8 100644
--- a/drivers/usb/host/ehci-atmel.c
+++ b/drivers/usb/host/ehci-atmel.c
@@ -53,30 +53,15 @@ static void atmel_stop_ehci(struct platform_device *pdev)
53static int ehci_atmel_setup(struct usb_hcd *hcd) 53static int ehci_atmel_setup(struct usb_hcd *hcd)
54{ 54{
55 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 55 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
56 int retval = 0; 56 int retval;
57 57
58 /* registers start at offset 0x0 */ 58 /* registers start at offset 0x0 */
59 ehci->caps = hcd->regs; 59 ehci->caps = hcd->regs;
60 ehci->regs = hcd->regs +
61 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
62 dbg_hcs_params(ehci, "reset");
63 dbg_hcc_params(ehci, "reset");
64
65 /* cache this readonly data; minimize chip reads */
66 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
67
68 retval = ehci_halt(ehci);
69 if (retval)
70 return retval;
71 60
72 /* data structure init */ 61 retval = ehci_setup(hcd);
73 retval = ehci_init(hcd);
74 if (retval) 62 if (retval)
75 return retval; 63 return retval;
76 64
77 ehci->sbrn = 0x20;
78
79 ehci_reset(ehci);
80 ehci_port_power(ehci, 0); 65 ehci_port_power(ehci, 0);
81 66
82 return retval; 67 return retval;
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
index bf7441afed16..cba10d625a5d 100644
--- a/drivers/usb/host/ehci-au1xxx.c
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -20,10 +20,12 @@ extern int usb_disabled(void);
20static int au1xxx_ehci_setup(struct usb_hcd *hcd) 20static int au1xxx_ehci_setup(struct usb_hcd *hcd)
21{ 21{
22 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 22 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
23 int ret = ehci_init(hcd); 23 int ret;
24
25 ehci->caps = hcd->regs;
26 ret = ehci_setup(hcd);
24 27
25 ehci->need_io_watchdog = 0; 28 ehci->need_io_watchdog = 0;
26 ehci_reset(ehci);
27 return ret; 29 return ret;
28} 30}
29 31
@@ -78,7 +80,6 @@ static const struct hc_driver ehci_au1xxx_hc_driver = {
78static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev) 80static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
79{ 81{
80 struct usb_hcd *hcd; 82 struct usb_hcd *hcd;
81 struct ehci_hcd *ehci;
82 struct resource *res; 83 struct resource *res;
83 int ret; 84 int ret;
84 85
@@ -116,13 +117,6 @@ static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
116 goto err3; 117 goto err3;
117 } 118 }
118 119
119 ehci = hcd_to_ehci(hcd);
120 ehci->caps = hcd->regs;
121 ehci->regs = hcd->regs +
122 HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
123 /* cache this readonly data; minimize chip reads */
124 ehci->hcs_params = readl(&ehci->caps->hcs_params);
125
126 ret = usb_add_hcd(hcd, pdev->resource[1].start, 120 ret = usb_add_hcd(hcd, pdev->resource[1].start,
127 IRQF_SHARED); 121 IRQF_SHARED);
128 if (ret == 0) { 122 if (ret == 0) {
@@ -158,28 +152,10 @@ static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
158static int ehci_hcd_au1xxx_drv_suspend(struct device *dev) 152static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
159{ 153{
160 struct usb_hcd *hcd = dev_get_drvdata(dev); 154 struct usb_hcd *hcd = dev_get_drvdata(dev);
161 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 155 bool do_wakeup = device_may_wakeup(dev);
162 unsigned long flags; 156 int rc;
163 int rc = 0;
164
165 if (time_before(jiffies, ehci->next_statechange))
166 msleep(10);
167
168 /* Root hub was already suspended. Disable irq emission and
169 * mark HW unaccessible. The PM and USB cores make sure that
170 * the root hub is either suspended or stopped.
171 */
172 ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
173 spin_lock_irqsave(&ehci->lock, flags);
174 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
175 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
176
177 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
178 spin_unlock_irqrestore(&ehci->lock, flags);
179
180 // could save FLADJ in case of Vaux power loss
181 // ... we'd only use it to handle clock skew
182 157
158 rc = ehci_suspend(hcd, do_wakeup);
183 alchemy_usb_control(ALCHEMY_USB_EHCI0, 0); 159 alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
184 160
185 return rc; 161 return rc;
@@ -188,56 +164,9 @@ static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
188static int ehci_hcd_au1xxx_drv_resume(struct device *dev) 164static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
189{ 165{
190 struct usb_hcd *hcd = dev_get_drvdata(dev); 166 struct usb_hcd *hcd = dev_get_drvdata(dev);
191 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
192 167
193 alchemy_usb_control(ALCHEMY_USB_EHCI0, 1); 168 alchemy_usb_control(ALCHEMY_USB_EHCI0, 1);
194 169 ehci_resume(hcd, false);
195 // maybe restore FLADJ
196
197 if (time_before(jiffies, ehci->next_statechange))
198 msleep(100);
199
200 /* Mark hardware accessible again as we are out of D3 state by now */
201 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
202
203 /* If CF is still set, we maintained PCI Vaux power.
204 * Just undo the effect of ehci_pci_suspend().
205 */
206 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
207 int mask = INTR_MASK;
208
209 ehci_prepare_ports_for_controller_resume(ehci);
210 if (!hcd->self.root_hub->do_remote_wakeup)
211 mask &= ~STS_PCD;
212 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
213 ehci_readl(ehci, &ehci->regs->intr_enable);
214 return 0;
215 }
216
217 ehci_dbg(ehci, "lost power, restarting\n");
218 usb_root_hub_lost_power(hcd->self.root_hub);
219
220 /* Else reset, to cope with power loss or flush-to-storage
221 * style "resume" having let BIOS kick in during reboot.
222 */
223 (void) ehci_halt(ehci);
224 (void) ehci_reset(ehci);
225
226 /* emptying the schedule aborts any urbs */
227 spin_lock_irq(&ehci->lock);
228 if (ehci->reclaim)
229 end_unlink_async(ehci);
230 ehci_work(ehci);
231 spin_unlock_irq(&ehci->lock);
232
233 ehci_writel(ehci, ehci->command, &ehci->regs->command);
234 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
235 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
236
237 /* here we "know" root ports should always stay powered */
238 ehci_port_power(ehci, 1);
239
240 ehci->rh_state = EHCI_RH_SUSPENDED;
241 170
242 return 0; 171 return 0;
243} 172}
diff --git a/drivers/usb/host/ehci-cns3xxx.c b/drivers/usb/host/ehci-cns3xxx.c
index 6536abdea6e6..caaa3e5be334 100644
--- a/drivers/usb/host/ehci-cns3xxx.c
+++ b/drivers/usb/host/ehci-cns3xxx.c
@@ -33,14 +33,10 @@ static int cns3xxx_ehci_init(struct usb_hcd *hcd)
33 } 33 }
34 34
35 ehci->caps = hcd->regs; 35 ehci->caps = hcd->regs;
36 ehci->regs = hcd->regs
37 + HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
38 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
39 36
40 hcd->has_tt = 0; 37 hcd->has_tt = 0;
41 ehci_reset(ehci);
42 38
43 retval = ehci_init(hcd); 39 retval = ehci_setup(hcd);
44 if (retval) 40 if (retval)
45 return retval; 41 return retval;
46 42
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 7561966fbdc4..f0c00de035ef 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -404,9 +404,9 @@ struct debug_buffer {
404 404
405#define speed_char(info1) ({ char tmp; \ 405#define speed_char(info1) ({ char tmp; \
406 switch (info1 & (3 << 12)) { \ 406 switch (info1 & (3 << 12)) { \
407 case 0 << 12: tmp = 'f'; break; \ 407 case QH_FULL_SPEED: tmp = 'f'; break; \
408 case 1 << 12: tmp = 'l'; break; \ 408 case QH_LOW_SPEED: tmp = 'l'; break; \
409 case 2 << 12: tmp = 'h'; break; \ 409 case QH_HIGH_SPEED: tmp = 'h'; break; \
410 default: tmp = '?'; break; \ 410 default: tmp = '?'; break; \
411 }; tmp; }) 411 }; tmp; })
412 412
@@ -538,12 +538,13 @@ static ssize_t fill_async_buffer(struct debug_buffer *buf)
538 spin_lock_irqsave (&ehci->lock, flags); 538 spin_lock_irqsave (&ehci->lock, flags);
539 for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh) 539 for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh)
540 qh_lines (ehci, qh, &next, &size); 540 qh_lines (ehci, qh, &next, &size);
541 if (ehci->reclaim && size > 0) { 541 if (ehci->async_unlink && size > 0) {
542 temp = scnprintf (next, size, "\nreclaim =\n"); 542 temp = scnprintf(next, size, "\nunlink =\n");
543 size -= temp; 543 size -= temp;
544 next += temp; 544 next += temp;
545 545
546 for (qh = ehci->reclaim; size > 0 && qh; qh = qh->reclaim) 546 for (qh = ehci->async_unlink; size > 0 && qh;
547 qh = qh->unlink_next)
547 qh_lines (ehci, qh, &next, &size); 548 qh_lines (ehci, qh, &next, &size);
548 } 549 }
549 spin_unlock_irqrestore (&ehci->lock, flags); 550 spin_unlock_irqrestore (&ehci->lock, flags);
@@ -705,6 +706,8 @@ static const char *rh_state_string(struct ehci_hcd *ehci)
705 return "suspended"; 706 return "suspended";
706 case EHCI_RH_RUNNING: 707 case EHCI_RH_RUNNING:
707 return "running"; 708 return "running";
709 case EHCI_RH_STOPPING:
710 return "stopping";
708 } 711 }
709 return "?"; 712 return "?";
710} 713}
@@ -841,16 +844,17 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
841 } 844 }
842 } 845 }
843 846
844 if (ehci->reclaim) { 847 if (ehci->async_unlink) {
845 temp = scnprintf(next, size, "reclaim qh %p\n", ehci->reclaim); 848 temp = scnprintf(next, size, "async unlink qh %p\n",
849 ehci->async_unlink);
846 size -= temp; 850 size -= temp;
847 next += temp; 851 next += temp;
848 } 852 }
849 853
850#ifdef EHCI_STATS 854#ifdef EHCI_STATS
851 temp = scnprintf (next, size, 855 temp = scnprintf (next, size,
852 "irq normal %ld err %ld reclaim %ld (lost %ld)\n", 856 "irq normal %ld err %ld iaa %ld (lost %ld)\n",
853 ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim, 857 ehci->stats.normal, ehci->stats.error, ehci->stats.iaa,
854 ehci->stats.lost_iaa); 858 ehci->stats.lost_iaa);
855 size -= temp; 859 size -= temp;
856 next += temp; 860 next += temp;
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 43362577b54a..b7451b29c5ac 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -27,6 +27,7 @@
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/pm.h> 29#include <linux/pm.h>
30#include <linux/err.h>
30#include <linux/platform_device.h> 31#include <linux/platform_device.h>
31#include <linux/fsl_devices.h> 32#include <linux/fsl_devices.h>
32 33
@@ -142,19 +143,19 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver,
142 if (pdata->operating_mode == FSL_USB2_DR_OTG) { 143 if (pdata->operating_mode == FSL_USB2_DR_OTG) {
143 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 144 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
144 145
145 ehci->transceiver = usb_get_transceiver(); 146 hcd->phy = usb_get_phy(USB_PHY_TYPE_USB2);
146 dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, transceiver=0x%p\n", 147 dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, phy=0x%p\n",
147 hcd, ehci, ehci->transceiver); 148 hcd, ehci, hcd->phy);
148 149
149 if (ehci->transceiver) { 150 if (!IS_ERR_OR_NULL(hcd->phy)) {
150 retval = otg_set_host(ehci->transceiver->otg, 151 retval = otg_set_host(hcd->phy->otg,
151 &ehci_to_hcd(ehci)->self); 152 &ehci_to_hcd(ehci)->self);
152 if (retval) { 153 if (retval) {
153 usb_put_transceiver(ehci->transceiver); 154 usb_put_phy(hcd->phy);
154 goto err4; 155 goto err4;
155 } 156 }
156 } else { 157 } else {
157 dev_err(&pdev->dev, "can't find transceiver\n"); 158 dev_err(&pdev->dev, "can't find phy\n");
158 retval = -ENODEV; 159 retval = -ENODEV;
159 goto err4; 160 goto err4;
160 } 161 }
@@ -190,11 +191,10 @@ static void usb_hcd_fsl_remove(struct usb_hcd *hcd,
190 struct platform_device *pdev) 191 struct platform_device *pdev)
191{ 192{
192 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data; 193 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
193 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
194 194
195 if (ehci->transceiver) { 195 if (!IS_ERR_OR_NULL(hcd->phy)) {
196 otg_set_host(ehci->transceiver->otg, NULL); 196 otg_set_host(hcd->phy->otg, NULL);
197 usb_put_transceiver(ehci->transceiver); 197 usb_put_phy(hcd->phy);
198 } 198 }
199 199
200 usb_remove_hcd(hcd); 200 usb_remove_hcd(hcd);
@@ -313,7 +313,7 @@ static void ehci_fsl_usb_setup(struct ehci_hcd *ehci)
313 } 313 }
314 314
315 if (pdata->have_sysif_regs) { 315 if (pdata->have_sysif_regs) {
316#ifdef CONFIG_PPC_85xx 316#ifdef CONFIG_FSL_SOC_BOOKE
317 out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x00000008); 317 out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x00000008);
318 out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000080); 318 out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000080);
319#else 319#else
@@ -348,29 +348,13 @@ static int ehci_fsl_setup(struct usb_hcd *hcd)
348 348
349 /* EHCI registers start at offset 0x100 */ 349 /* EHCI registers start at offset 0x100 */
350 ehci->caps = hcd->regs + 0x100; 350 ehci->caps = hcd->regs + 0x100;
351 ehci->regs = hcd->regs + 0x100 +
352 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
353 dbg_hcs_params(ehci, "reset");
354 dbg_hcc_params(ehci, "reset");
355
356 /* cache this readonly data; minimize chip reads */
357 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
358 351
359 hcd->has_tt = 1; 352 hcd->has_tt = 1;
360 353
361 retval = ehci_halt(ehci); 354 retval = ehci_setup(hcd);
362 if (retval)
363 return retval;
364
365 /* data structure init */
366 retval = ehci_init(hcd);
367 if (retval) 355 if (retval)
368 return retval; 356 return retval;
369 357
370 ehci->sbrn = 0x20;
371
372 ehci_reset(ehci);
373
374 if (of_device_is_compatible(dev->parent->of_node, 358 if (of_device_is_compatible(dev->parent->of_node,
375 "fsl,mpc5121-usb2-dr")) { 359 "fsl,mpc5121-usb2-dr")) {
376 /* 360 /*
diff --git a/drivers/usb/host/ehci-grlib.c b/drivers/usb/host/ehci-grlib.c
index fdfd8c5b639b..22ca45c079a4 100644
--- a/drivers/usb/host/ehci-grlib.c
+++ b/drivers/usb/host/ehci-grlib.c
@@ -40,18 +40,13 @@ static int ehci_grlib_setup(struct usb_hcd *hcd)
40 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 40 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
41 int retval; 41 int retval;
42 42
43 retval = ehci_halt(ehci); 43 retval = ehci_setup(hcd);
44 if (retval) 44 if (retval)
45 return retval; 45 return retval;
46 46
47 retval = ehci_init(hcd);
48 if (retval)
49 return retval;
50
51 ehci->sbrn = 0x20;
52 ehci_port_power(ehci, 1); 47 ehci_port_power(ehci, 1);
53 48
54 return ehci_reset(ehci); 49 return retval;
55} 50}
56 51
57 52
@@ -164,12 +159,6 @@ static int __devinit ehci_hcd_grlib_probe(struct platform_device *op)
164 ehci->big_endian_capbase = 1; 159 ehci->big_endian_capbase = 1;
165 } 160 }
166 161
167 ehci->regs = hcd->regs +
168 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
169
170 /* cache this readonly data; minimize chip reads */
171 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
172
173 rv = usb_add_hcd(hcd, irq, 0); 162 rv = usb_add_hcd(hcd, irq, 0);
174 if (rv) 163 if (rv)
175 goto err_ehci; 164 goto err_ehci;
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 1d9401e0990a..b05c6865b610 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -30,8 +30,7 @@
30#include <linux/vmalloc.h> 30#include <linux/vmalloc.h>
31#include <linux/errno.h> 31#include <linux/errno.h>
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/timer.h> 33#include <linux/hrtimer.h>
34#include <linux/ktime.h>
35#include <linux/list.h> 34#include <linux/list.h>
36#include <linux/interrupt.h> 35#include <linux/interrupt.h>
37#include <linux/usb.h> 36#include <linux/usb.h>
@@ -94,12 +93,6 @@ static const char hcd_name [] = "ehci_hcd";
94 */ 93 */
95#define EHCI_TUNE_FLS 1 /* (medium) 512-frame schedule */ 94#define EHCI_TUNE_FLS 1 /* (medium) 512-frame schedule */
96 95
97#define EHCI_IAA_MSECS 10 /* arbitrary */
98#define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */
99#define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */
100#define EHCI_SHRINK_JIFFIES (DIV_ROUND_UP(HZ, 200) + 1)
101 /* 5-ms async qh unlink delay */
102
103/* Initial IRQ latency: faster than hw default */ 96/* Initial IRQ latency: faster than hw default */
104static int log2_irq_thresh = 0; // 0 to 6 97static int log2_irq_thresh = 0; // 0 to 6
105module_param (log2_irq_thresh, int, S_IRUGO); 98module_param (log2_irq_thresh, int, S_IRUGO);
@@ -130,41 +123,6 @@ MODULE_PARM_DESC(hird, "host initiated resume duration, +1 for each 75us");
130 123
131/*-------------------------------------------------------------------------*/ 124/*-------------------------------------------------------------------------*/
132 125
133static void
134timer_action(struct ehci_hcd *ehci, enum ehci_timer_action action)
135{
136 /* Don't override timeouts which shrink or (later) disable
137 * the async ring; just the I/O watchdog. Note that if a
138 * SHRINK were pending, OFF would never be requested.
139 */
140 if (timer_pending(&ehci->watchdog)
141 && ((BIT(TIMER_ASYNC_SHRINK) | BIT(TIMER_ASYNC_OFF))
142 & ehci->actions))
143 return;
144
145 if (!test_and_set_bit(action, &ehci->actions)) {
146 unsigned long t;
147
148 switch (action) {
149 case TIMER_IO_WATCHDOG:
150 if (!ehci->need_io_watchdog)
151 return;
152 t = EHCI_IO_JIFFIES;
153 break;
154 case TIMER_ASYNC_OFF:
155 t = EHCI_ASYNC_JIFFIES;
156 break;
157 /* case TIMER_ASYNC_SHRINK: */
158 default:
159 t = EHCI_SHRINK_JIFFIES;
160 break;
161 }
162 mod_timer(&ehci->watchdog, t + jiffies);
163 }
164}
165
166/*-------------------------------------------------------------------------*/
167
168/* 126/*
169 * handshake - spin reading hc until handshake completes or fails 127 * handshake - spin reading hc until handshake completes or fails
170 * @ptr: address of hc register to be read 128 * @ptr: address of hc register to be read
@@ -203,29 +161,30 @@ static int handshake (struct ehci_hcd *ehci, void __iomem *ptr,
203/* check TDI/ARC silicon is in host mode */ 161/* check TDI/ARC silicon is in host mode */
204static int tdi_in_host_mode (struct ehci_hcd *ehci) 162static int tdi_in_host_mode (struct ehci_hcd *ehci)
205{ 163{
206 u32 __iomem *reg_ptr;
207 u32 tmp; 164 u32 tmp;
208 165
209 reg_ptr = (u32 __iomem *)(((u8 __iomem *)ehci->regs) + USBMODE); 166 tmp = ehci_readl(ehci, &ehci->regs->usbmode);
210 tmp = ehci_readl(ehci, reg_ptr);
211 return (tmp & 3) == USBMODE_CM_HC; 167 return (tmp & 3) == USBMODE_CM_HC;
212} 168}
213 169
214/* force HC to halt state from unknown (EHCI spec section 2.3) */ 170/*
171 * Force HC to halt state from unknown (EHCI spec section 2.3).
172 * Must be called with interrupts enabled and the lock not held.
173 */
215static int ehci_halt (struct ehci_hcd *ehci) 174static int ehci_halt (struct ehci_hcd *ehci)
216{ 175{
217 u32 temp = ehci_readl(ehci, &ehci->regs->status); 176 u32 temp;
177
178 spin_lock_irq(&ehci->lock);
218 179
219 /* disable any irqs left enabled by previous code */ 180 /* disable any irqs left enabled by previous code */
220 ehci_writel(ehci, 0, &ehci->regs->intr_enable); 181 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
221 182
222 if (ehci_is_TDI(ehci) && tdi_in_host_mode(ehci) == 0) { 183 if (ehci_is_TDI(ehci) && !tdi_in_host_mode(ehci)) {
184 spin_unlock_irq(&ehci->lock);
223 return 0; 185 return 0;
224 } 186 }
225 187
226 if ((temp & STS_HALT) != 0)
227 return 0;
228
229 /* 188 /*
230 * This routine gets called during probe before ehci->command 189 * This routine gets called during probe before ehci->command
231 * has been initialized, so we can't rely on its value. 190 * has been initialized, so we can't rely on its value.
@@ -234,80 +193,20 @@ static int ehci_halt (struct ehci_hcd *ehci)
234 temp = ehci_readl(ehci, &ehci->regs->command); 193 temp = ehci_readl(ehci, &ehci->regs->command);
235 temp &= ~(CMD_RUN | CMD_IAAD); 194 temp &= ~(CMD_RUN | CMD_IAAD);
236 ehci_writel(ehci, temp, &ehci->regs->command); 195 ehci_writel(ehci, temp, &ehci->regs->command);
237 return handshake (ehci, &ehci->regs->status,
238 STS_HALT, STS_HALT, 16 * 125);
239}
240
241#if defined(CONFIG_USB_SUSPEND) && defined(CONFIG_PPC_PS3)
242
243/*
244 * The EHCI controller of the Cell Super Companion Chip used in the
245 * PS3 will stop the root hub after all root hub ports are suspended.
246 * When in this condition handshake will return -ETIMEDOUT. The
247 * STS_HLT bit will not be set, so inspection of the frame index is
248 * used here to test for the condition. If the condition is found
249 * return success to allow the USB suspend to complete.
250 */
251
252static int handshake_for_broken_root_hub(struct ehci_hcd *ehci,
253 void __iomem *ptr, u32 mask, u32 done,
254 int usec)
255{
256 unsigned int old_index;
257 int error;
258
259 if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
260 return -ETIMEDOUT;
261
262 old_index = ehci_read_frame_index(ehci);
263
264 error = handshake(ehci, ptr, mask, done, usec);
265
266 if (error == -ETIMEDOUT && ehci_read_frame_index(ehci) == old_index)
267 return 0;
268
269 return error;
270}
271
272#else
273
274static int handshake_for_broken_root_hub(struct ehci_hcd *ehci,
275 void __iomem *ptr, u32 mask, u32 done,
276 int usec)
277{
278 return -ETIMEDOUT;
279}
280
281#endif
282 196
283static int handshake_on_error_set_halt(struct ehci_hcd *ehci, void __iomem *ptr, 197 spin_unlock_irq(&ehci->lock);
284 u32 mask, u32 done, int usec) 198 synchronize_irq(ehci_to_hcd(ehci)->irq);
285{
286 int error;
287
288 error = handshake(ehci, ptr, mask, done, usec);
289 if (error == -ETIMEDOUT)
290 error = handshake_for_broken_root_hub(ehci, ptr, mask, done,
291 usec);
292
293 if (error) {
294 ehci_halt(ehci);
295 ehci->rh_state = EHCI_RH_HALTED;
296 ehci_err(ehci, "force halt; handshake %p %08x %08x -> %d\n",
297 ptr, mask, done, error);
298 }
299 199
300 return error; 200 return handshake(ehci, &ehci->regs->status,
201 STS_HALT, STS_HALT, 16 * 125);
301} 202}
302 203
303/* put TDI/ARC silicon into EHCI mode */ 204/* put TDI/ARC silicon into EHCI mode */
304static void tdi_reset (struct ehci_hcd *ehci) 205static void tdi_reset (struct ehci_hcd *ehci)
305{ 206{
306 u32 __iomem *reg_ptr;
307 u32 tmp; 207 u32 tmp;
308 208
309 reg_ptr = (u32 __iomem *)(((u8 __iomem *)ehci->regs) + USBMODE); 209 tmp = ehci_readl(ehci, &ehci->regs->usbmode);
310 tmp = ehci_readl(ehci, reg_ptr);
311 tmp |= USBMODE_CM_HC; 210 tmp |= USBMODE_CM_HC;
312 /* The default byte access to MMR space is LE after 211 /* The default byte access to MMR space is LE after
313 * controller reset. Set the required endian mode 212 * controller reset. Set the required endian mode
@@ -315,10 +214,13 @@ static void tdi_reset (struct ehci_hcd *ehci)
315 */ 214 */
316 if (ehci_big_endian_mmio(ehci)) 215 if (ehci_big_endian_mmio(ehci))
317 tmp |= USBMODE_BE; 216 tmp |= USBMODE_BE;
318 ehci_writel(ehci, tmp, reg_ptr); 217 ehci_writel(ehci, tmp, &ehci->regs->usbmode);
319} 218}
320 219
321/* reset a non-running (STS_HALT == 1) controller */ 220/*
221 * Reset a non-running (STS_HALT == 1) controller.
222 * Must be called with interrupts enabled and the lock not held.
223 */
322static int ehci_reset (struct ehci_hcd *ehci) 224static int ehci_reset (struct ehci_hcd *ehci)
323{ 225{
324 int retval; 226 int retval;
@@ -339,9 +241,8 @@ static int ehci_reset (struct ehci_hcd *ehci)
339 241
340 if (ehci->has_hostpc) { 242 if (ehci->has_hostpc) {
341 ehci_writel(ehci, USBMODE_EX_HC | USBMODE_EX_VBPS, 243 ehci_writel(ehci, USBMODE_EX_HC | USBMODE_EX_VBPS,
342 (u32 __iomem *)(((u8 *)ehci->regs) + USBMODE_EX)); 244 &ehci->regs->usbmode_ex);
343 ehci_writel(ehci, TXFIFO_DEFAULT, 245 ehci_writel(ehci, TXFIFO_DEFAULT, &ehci->regs->txfill_tuning);
344 (u32 __iomem *)(((u8 *)ehci->regs) + TXFILLTUNING));
345 } 246 }
346 if (retval) 247 if (retval)
347 return retval; 248 return retval;
@@ -357,36 +258,40 @@ static int ehci_reset (struct ehci_hcd *ehci)
357 return retval; 258 return retval;
358} 259}
359 260
360/* idle the controller (from running) */ 261/*
262 * Idle the controller (turn off the schedules).
263 * Must be called with interrupts enabled and the lock not held.
264 */
361static void ehci_quiesce (struct ehci_hcd *ehci) 265static void ehci_quiesce (struct ehci_hcd *ehci)
362{ 266{
363 u32 temp; 267 u32 temp;
364 268
365#ifdef DEBUG
366 if (ehci->rh_state != EHCI_RH_RUNNING) 269 if (ehci->rh_state != EHCI_RH_RUNNING)
367 BUG (); 270 return;
368#endif
369 271
370 /* wait for any schedule enables/disables to take effect */ 272 /* wait for any schedule enables/disables to take effect */
371 temp = (ehci->command << 10) & (STS_ASS | STS_PSS); 273 temp = (ehci->command << 10) & (STS_ASS | STS_PSS);
372 if (handshake_on_error_set_halt(ehci, &ehci->regs->status, 274 handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, temp, 16 * 125);
373 STS_ASS | STS_PSS, temp, 16 * 125))
374 return;
375 275
376 /* then disable anything that's still active */ 276 /* then disable anything that's still active */
277 spin_lock_irq(&ehci->lock);
377 ehci->command &= ~(CMD_ASE | CMD_PSE); 278 ehci->command &= ~(CMD_ASE | CMD_PSE);
378 ehci_writel(ehci, ehci->command, &ehci->regs->command); 279 ehci_writel(ehci, ehci->command, &ehci->regs->command);
280 spin_unlock_irq(&ehci->lock);
379 281
380 /* hardware can take 16 microframes to turn off ... */ 282 /* hardware can take 16 microframes to turn off ... */
381 handshake_on_error_set_halt(ehci, &ehci->regs->status, 283 handshake(ehci, &ehci->regs->status, STS_ASS | STS_PSS, 0, 16 * 125);
382 STS_ASS | STS_PSS, 0, 16 * 125);
383} 284}
384 285
385/*-------------------------------------------------------------------------*/ 286/*-------------------------------------------------------------------------*/
386 287
387static void end_unlink_async(struct ehci_hcd *ehci); 288static void end_unlink_async(struct ehci_hcd *ehci);
289static void unlink_empty_async(struct ehci_hcd *ehci);
388static void ehci_work(struct ehci_hcd *ehci); 290static void ehci_work(struct ehci_hcd *ehci);
291static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
292static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
389 293
294#include "ehci-timer.c"
390#include "ehci-hub.c" 295#include "ehci-hub.c"
391#include "ehci-lpm.c" 296#include "ehci-lpm.c"
392#include "ehci-mem.c" 297#include "ehci-mem.c"
@@ -396,68 +301,6 @@ static void ehci_work(struct ehci_hcd *ehci);
396 301
397/*-------------------------------------------------------------------------*/ 302/*-------------------------------------------------------------------------*/
398 303
399static void ehci_iaa_watchdog(unsigned long param)
400{
401 struct ehci_hcd *ehci = (struct ehci_hcd *) param;
402 unsigned long flags;
403
404 spin_lock_irqsave (&ehci->lock, flags);
405
406 /* Lost IAA irqs wedge things badly; seen first with a vt8235.
407 * So we need this watchdog, but must protect it against both
408 * (a) SMP races against real IAA firing and retriggering, and
409 * (b) clean HC shutdown, when IAA watchdog was pending.
410 */
411 if (ehci->reclaim
412 && !timer_pending(&ehci->iaa_watchdog)
413 && ehci->rh_state == EHCI_RH_RUNNING) {
414 u32 cmd, status;
415
416 /* If we get here, IAA is *REALLY* late. It's barely
417 * conceivable that the system is so busy that CMD_IAAD
418 * is still legitimately set, so let's be sure it's
419 * clear before we read STS_IAA. (The HC should clear
420 * CMD_IAAD when it sets STS_IAA.)
421 */
422 cmd = ehci_readl(ehci, &ehci->regs->command);
423
424 /* If IAA is set here it either legitimately triggered
425 * before we cleared IAAD above (but _way_ late, so we'll
426 * still count it as lost) ... or a silicon erratum:
427 * - VIA seems to set IAA without triggering the IRQ;
428 * - IAAD potentially cleared without setting IAA.
429 */
430 status = ehci_readl(ehci, &ehci->regs->status);
431 if ((status & STS_IAA) || !(cmd & CMD_IAAD)) {
432 COUNT (ehci->stats.lost_iaa);
433 ehci_writel(ehci, STS_IAA, &ehci->regs->status);
434 }
435
436 ehci_vdbg(ehci, "IAA watchdog: status %x cmd %x\n",
437 status, cmd);
438 end_unlink_async(ehci);
439 }
440
441 spin_unlock_irqrestore(&ehci->lock, flags);
442}
443
444static void ehci_watchdog(unsigned long param)
445{
446 struct ehci_hcd *ehci = (struct ehci_hcd *) param;
447 unsigned long flags;
448
449 spin_lock_irqsave(&ehci->lock, flags);
450
451 /* stop async processing after it's idled a bit */
452 if (test_bit (TIMER_ASYNC_OFF, &ehci->actions))
453 start_unlink_async (ehci, ehci->async);
454
455 /* ehci could run by timer, without IRQs ... */
456 ehci_work (ehci);
457
458 spin_unlock_irqrestore (&ehci->lock, flags);
459}
460
461/* On some systems, leaving remote wakeup enabled prevents system shutdown. 304/* On some systems, leaving remote wakeup enabled prevents system shutdown.
462 * The firmware seems to think that powering off is a wakeup event! 305 * The firmware seems to think that powering off is a wakeup event!
463 * This routine turns off remote wakeup and everything else, on all ports. 306 * This routine turns off remote wakeup and everything else, on all ports.
@@ -473,11 +316,14 @@ static void ehci_turn_off_all_ports(struct ehci_hcd *ehci)
473 316
474/* 317/*
475 * Halt HC, turn off all ports, and let the BIOS use the companion controllers. 318 * Halt HC, turn off all ports, and let the BIOS use the companion controllers.
476 * Should be called with ehci->lock held. 319 * Must be called with interrupts enabled and the lock not held.
477 */ 320 */
478static void ehci_silence_controller(struct ehci_hcd *ehci) 321static void ehci_silence_controller(struct ehci_hcd *ehci)
479{ 322{
480 ehci_halt(ehci); 323 ehci_halt(ehci);
324
325 spin_lock_irq(&ehci->lock);
326 ehci->rh_state = EHCI_RH_HALTED;
481 ehci_turn_off_all_ports(ehci); 327 ehci_turn_off_all_ports(ehci);
482 328
483 /* make BIOS/etc use companion controller during reboot */ 329 /* make BIOS/etc use companion controller during reboot */
@@ -485,6 +331,7 @@ static void ehci_silence_controller(struct ehci_hcd *ehci)
485 331
486 /* unblock posted writes */ 332 /* unblock posted writes */
487 ehci_readl(ehci, &ehci->regs->configured_flag); 333 ehci_readl(ehci, &ehci->regs->configured_flag);
334 spin_unlock_irq(&ehci->lock);
488} 335}
489 336
490/* ehci_shutdown kick in for silicon on any bus (not just pci, etc). 337/* ehci_shutdown kick in for silicon on any bus (not just pci, etc).
@@ -495,12 +342,15 @@ static void ehci_shutdown(struct usb_hcd *hcd)
495{ 342{
496 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 343 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
497 344
498 del_timer_sync(&ehci->watchdog);
499 del_timer_sync(&ehci->iaa_watchdog);
500
501 spin_lock_irq(&ehci->lock); 345 spin_lock_irq(&ehci->lock);
502 ehci_silence_controller(ehci); 346 ehci->shutdown = true;
347 ehci->rh_state = EHCI_RH_STOPPING;
348 ehci->enabled_hrtimer_events = 0;
503 spin_unlock_irq(&ehci->lock); 349 spin_unlock_irq(&ehci->lock);
350
351 ehci_silence_controller(ehci);
352
353 hrtimer_cancel(&ehci->hrtimer);
504} 354}
505 355
506static void ehci_port_power (struct ehci_hcd *ehci, int is_on) 356static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
@@ -529,28 +379,33 @@ static void ehci_port_power (struct ehci_hcd *ehci, int is_on)
529 */ 379 */
530static void ehci_work (struct ehci_hcd *ehci) 380static void ehci_work (struct ehci_hcd *ehci)
531{ 381{
532 timer_action_done (ehci, TIMER_IO_WATCHDOG);
533
534 /* another CPU may drop ehci->lock during a schedule scan while 382 /* another CPU may drop ehci->lock during a schedule scan while
535 * it reports urb completions. this flag guards against bogus 383 * it reports urb completions. this flag guards against bogus
536 * attempts at re-entrant schedule scanning. 384 * attempts at re-entrant schedule scanning.
537 */ 385 */
538 if (ehci->scanning) 386 if (ehci->scanning) {
387 ehci->need_rescan = true;
539 return; 388 return;
540 ehci->scanning = 1; 389 }
541 scan_async (ehci); 390 ehci->scanning = true;
542 if (ehci->next_uframe != -1) 391
543 scan_periodic (ehci); 392 rescan:
544 ehci->scanning = 0; 393 ehci->need_rescan = false;
394 if (ehci->async_count)
395 scan_async(ehci);
396 if (ehci->intr_count > 0)
397 scan_intr(ehci);
398 if (ehci->isoc_count > 0)
399 scan_isoc(ehci);
400 if (ehci->need_rescan)
401 goto rescan;
402 ehci->scanning = false;
545 403
546 /* the IO watchdog guards against hardware or driver bugs that 404 /* the IO watchdog guards against hardware or driver bugs that
547 * misplace IRQs, and should let us run completely without IRQs. 405 * misplace IRQs, and should let us run completely without IRQs.
548 * such lossage has been observed on both VT6202 and VT8235. 406 * such lossage has been observed on both VT6202 and VT8235.
549 */ 407 */
550 if (ehci->rh_state == EHCI_RH_RUNNING && 408 turn_on_io_watchdog(ehci);
551 (ehci->async->qh_next.ptr != NULL ||
552 ehci->periodic_sched != 0))
553 timer_action (ehci, TIMER_IO_WATCHDOG);
554} 409}
555 410
556/* 411/*
@@ -563,24 +418,22 @@ static void ehci_stop (struct usb_hcd *hcd)
563 ehci_dbg (ehci, "stop\n"); 418 ehci_dbg (ehci, "stop\n");
564 419
565 /* no more interrupts ... */ 420 /* no more interrupts ... */
566 del_timer_sync (&ehci->watchdog);
567 del_timer_sync(&ehci->iaa_watchdog);
568 421
569 spin_lock_irq(&ehci->lock); 422 spin_lock_irq(&ehci->lock);
570 if (ehci->rh_state == EHCI_RH_RUNNING) 423 ehci->enabled_hrtimer_events = 0;
571 ehci_quiesce (ehci); 424 spin_unlock_irq(&ehci->lock);
572 425
426 ehci_quiesce(ehci);
573 ehci_silence_controller(ehci); 427 ehci_silence_controller(ehci);
574 ehci_reset (ehci); 428 ehci_reset (ehci);
575 spin_unlock_irq(&ehci->lock);
576 429
430 hrtimer_cancel(&ehci->hrtimer);
577 remove_sysfs_files(ehci); 431 remove_sysfs_files(ehci);
578 remove_debug_files (ehci); 432 remove_debug_files (ehci);
579 433
580 /* root hub is shut down separately (first, when possible) */ 434 /* root hub is shut down separately (first, when possible) */
581 spin_lock_irq (&ehci->lock); 435 spin_lock_irq (&ehci->lock);
582 if (ehci->async) 436 end_free_itds(ehci);
583 ehci_work (ehci);
584 spin_unlock_irq (&ehci->lock); 437 spin_unlock_irq (&ehci->lock);
585 ehci_mem_cleanup (ehci); 438 ehci_mem_cleanup (ehci);
586 439
@@ -588,8 +441,8 @@ static void ehci_stop (struct usb_hcd *hcd)
588 usb_amd_dev_put(); 441 usb_amd_dev_put();
589 442
590#ifdef EHCI_STATS 443#ifdef EHCI_STATS
591 ehci_dbg (ehci, "irq normal %ld err %ld reclaim %ld (lost %ld)\n", 444 ehci_dbg(ehci, "irq normal %ld err %ld iaa %ld (lost %ld)\n",
592 ehci->stats.normal, ehci->stats.error, ehci->stats.reclaim, 445 ehci->stats.normal, ehci->stats.error, ehci->stats.iaa,
593 ehci->stats.lost_iaa); 446 ehci->stats.lost_iaa);
594 ehci_dbg (ehci, "complete %ld unlink %ld\n", 447 ehci_dbg (ehci, "complete %ld unlink %ld\n",
595 ehci->stats.complete, ehci->stats.unlink); 448 ehci->stats.complete, ehci->stats.unlink);
@@ -614,13 +467,10 @@ static int ehci_init(struct usb_hcd *hcd)
614 * keep io watchdog by default, those good HCDs could turn off it later 467 * keep io watchdog by default, those good HCDs could turn off it later
615 */ 468 */
616 ehci->need_io_watchdog = 1; 469 ehci->need_io_watchdog = 1;
617 init_timer(&ehci->watchdog);
618 ehci->watchdog.function = ehci_watchdog;
619 ehci->watchdog.data = (unsigned long) ehci;
620 470
621 init_timer(&ehci->iaa_watchdog); 471 hrtimer_init(&ehci->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
622 ehci->iaa_watchdog.function = ehci_iaa_watchdog; 472 ehci->hrtimer.function = ehci_hrtimer_func;
623 ehci->iaa_watchdog.data = (unsigned long) ehci; 473 ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
624 474
625 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params); 475 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
626 476
@@ -635,6 +485,7 @@ static int ehci_init(struct usb_hcd *hcd)
635 * periodic_size can shrink by USBCMD update if hcc_params allows. 485 * periodic_size can shrink by USBCMD update if hcc_params allows.
636 */ 486 */
637 ehci->periodic_size = DEFAULT_I_TDPS; 487 ehci->periodic_size = DEFAULT_I_TDPS;
488 INIT_LIST_HEAD(&ehci->intr_qh_list);
638 INIT_LIST_HEAD(&ehci->cached_itd_list); 489 INIT_LIST_HEAD(&ehci->cached_itd_list);
639 INIT_LIST_HEAD(&ehci->cached_sitd_list); 490 INIT_LIST_HEAD(&ehci->cached_sitd_list);
640 491
@@ -656,10 +507,6 @@ static int ehci_init(struct usb_hcd *hcd)
656 else // N microframes cached 507 else // N microframes cached
657 ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params); 508 ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
658 509
659 ehci->reclaim = NULL;
660 ehci->next_uframe = -1;
661 ehci->clock_frame = -1;
662
663 /* 510 /*
664 * dedicate a qh for the async ring head, since we couldn't unlink 511 * dedicate a qh for the async ring head, since we couldn't unlink
665 * a 'real' qh without stopping the async schedule [4.8]. use it 512 * a 'real' qh without stopping the async schedule [4.8]. use it
@@ -672,7 +519,7 @@ static int ehci_init(struct usb_hcd *hcd)
672 hw->hw_next = QH_NEXT(ehci, ehci->async->qh_dma); 519 hw->hw_next = QH_NEXT(ehci, ehci->async->qh_dma);
673 hw->hw_info1 = cpu_to_hc32(ehci, QH_HEAD); 520 hw->hw_info1 = cpu_to_hc32(ehci, QH_HEAD);
674#if defined(CONFIG_PPC_PS3) 521#if defined(CONFIG_PPC_PS3)
675 hw->hw_info1 |= cpu_to_hc32(ehci, (1 << 7)); /* I = 1 */ 522 hw->hw_info1 |= cpu_to_hc32(ehci, QH_INACTIVATE);
676#endif 523#endif
677 hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT); 524 hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT);
678 hw->hw_qtd_next = EHCI_LIST_END(ehci); 525 hw->hw_qtd_next = EHCI_LIST_END(ehci);
@@ -813,7 +660,7 @@ static int ehci_run (struct usb_hcd *hcd)
813 return 0; 660 return 0;
814} 661}
815 662
816static int __maybe_unused ehci_setup (struct usb_hcd *hcd) 663static int ehci_setup(struct usb_hcd *hcd)
817{ 664{
818 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 665 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
819 int retval; 666 int retval;
@@ -828,15 +675,18 @@ static int __maybe_unused ehci_setup (struct usb_hcd *hcd)
828 675
829 ehci->sbrn = HCD_USB2; 676 ehci->sbrn = HCD_USB2;
830 677
831 retval = ehci_halt(ehci); 678 /* data structure init */
679 retval = ehci_init(hcd);
832 if (retval) 680 if (retval)
833 return retval; 681 return retval;
834 682
835 /* data structure init */ 683 retval = ehci_halt(ehci);
836 retval = ehci_init(hcd);
837 if (retval) 684 if (retval)
838 return retval; 685 return retval;
839 686
687 if (ehci_is_TDI(ehci))
688 tdi_reset(ehci);
689
840 ehci_reset(ehci); 690 ehci_reset(ehci);
841 691
842 return 0; 692 return 0;
@@ -895,14 +745,28 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
895 745
896 /* complete the unlinking of some qh [4.15.2.3] */ 746 /* complete the unlinking of some qh [4.15.2.3] */
897 if (status & STS_IAA) { 747 if (status & STS_IAA) {
748
749 /* Turn off the IAA watchdog */
750 ehci->enabled_hrtimer_events &= ~BIT(EHCI_HRTIMER_IAA_WATCHDOG);
751
752 /*
753 * Mild optimization: Allow another IAAD to reset the
754 * hrtimer, if one occurs before the next expiration.
755 * In theory we could always cancel the hrtimer, but
756 * tests show that about half the time it will be reset
757 * for some other event anyway.
758 */
759 if (ehci->next_hrtimer_event == EHCI_HRTIMER_IAA_WATCHDOG)
760 ++ehci->next_hrtimer_event;
761
898 /* guard against (alleged) silicon errata */ 762 /* guard against (alleged) silicon errata */
899 if (cmd & CMD_IAAD) 763 if (cmd & CMD_IAAD)
900 ehci_dbg(ehci, "IAA with IAAD still set?\n"); 764 ehci_dbg(ehci, "IAA with IAAD still set?\n");
901 if (ehci->reclaim) { 765 if (ehci->async_iaa) {
902 COUNT(ehci->stats.reclaim); 766 COUNT(ehci->stats.iaa);
903 end_unlink_async(ehci); 767 end_unlink_async(ehci);
904 } else 768 } else
905 ehci_dbg(ehci, "IAA with nothing to reclaim?\n"); 769 ehci_dbg(ehci, "IAA with nothing unlinked?\n");
906 } 770 }
907 771
908 /* remote wakeup [4.3.1] */ 772 /* remote wakeup [4.3.1] */
@@ -956,15 +820,19 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
956 ehci_err(ehci, "fatal error\n"); 820 ehci_err(ehci, "fatal error\n");
957 dbg_cmd(ehci, "fatal", cmd); 821 dbg_cmd(ehci, "fatal", cmd);
958 dbg_status(ehci, "fatal", status); 822 dbg_status(ehci, "fatal", status);
959 ehci_halt(ehci);
960dead: 823dead:
961 ehci_reset(ehci);
962 ehci_writel(ehci, 0, &ehci->regs->configured_flag);
963 usb_hc_died(hcd); 824 usb_hc_died(hcd);
964 /* generic layer kills/unlinks all urbs, then 825
965 * uses ehci_stop to clean up the rest 826 /* Don't let the controller do anything more */
966 */ 827 ehci->shutdown = true;
967 bh = 1; 828 ehci->rh_state = EHCI_RH_STOPPING;
829 ehci->command &= ~(CMD_RUN | CMD_ASE | CMD_PSE);
830 ehci_writel(ehci, ehci->command, &ehci->regs->command);
831 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
832 ehci_handle_controller_death(ehci);
833
834 /* Handle completions when the controller stops */
835 bh = 0;
968 } 836 }
969 837
970 if (bh) 838 if (bh)
@@ -1026,38 +894,6 @@ static int ehci_urb_enqueue (
1026 } 894 }
1027} 895}
1028 896
1029static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
1030{
1031 /* failfast */
1032 if (ehci->rh_state != EHCI_RH_RUNNING && ehci->reclaim)
1033 end_unlink_async(ehci);
1034
1035 /* If the QH isn't linked then there's nothing we can do
1036 * unless we were called during a giveback, in which case
1037 * qh_completions() has to deal with it.
1038 */
1039 if (qh->qh_state != QH_STATE_LINKED) {
1040 if (qh->qh_state == QH_STATE_COMPLETING)
1041 qh->needs_rescan = 1;
1042 return;
1043 }
1044
1045 /* defer till later if busy */
1046 if (ehci->reclaim) {
1047 struct ehci_qh *last;
1048
1049 for (last = ehci->reclaim;
1050 last->reclaim;
1051 last = last->reclaim)
1052 continue;
1053 qh->qh_state = QH_STATE_UNLINK_WAIT;
1054 last->reclaim = qh;
1055
1056 /* start IAA cycle */
1057 } else
1058 start_unlink_async (ehci, qh);
1059}
1060
1061/* remove from hardware lists 897/* remove from hardware lists
1062 * completions normally happen asynchronously 898 * completions normally happen asynchronously
1063 */ 899 */
@@ -1084,7 +920,7 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1084 switch (qh->qh_state) { 920 switch (qh->qh_state) {
1085 case QH_STATE_LINKED: 921 case QH_STATE_LINKED:
1086 case QH_STATE_COMPLETING: 922 case QH_STATE_COMPLETING:
1087 unlink_async(ehci, qh); 923 start_unlink_async(ehci, qh);
1088 break; 924 break;
1089 case QH_STATE_UNLINK: 925 case QH_STATE_UNLINK:
1090 case QH_STATE_UNLINK_WAIT: 926 case QH_STATE_UNLINK_WAIT:
@@ -1104,7 +940,7 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1104 switch (qh->qh_state) { 940 switch (qh->qh_state) {
1105 case QH_STATE_LINKED: 941 case QH_STATE_LINKED:
1106 case QH_STATE_COMPLETING: 942 case QH_STATE_COMPLETING:
1107 intr_deschedule (ehci, qh); 943 start_unlink_intr(ehci, qh);
1108 break; 944 break;
1109 case QH_STATE_IDLE: 945 case QH_STATE_IDLE:
1110 qh_completions (ehci, qh); 946 qh_completions (ehci, qh);
@@ -1152,11 +988,17 @@ rescan:
1152 * accelerate iso completions ... so spin a while. 988 * accelerate iso completions ... so spin a while.
1153 */ 989 */
1154 if (qh->hw == NULL) { 990 if (qh->hw == NULL) {
1155 ehci_vdbg (ehci, "iso delay\n"); 991 struct ehci_iso_stream *stream = ep->hcpriv;
1156 goto idle_timeout; 992
993 if (!list_empty(&stream->td_list))
994 goto idle_timeout;
995
996 /* BUG_ON(!list_empty(&stream->free_list)); */
997 kfree(stream);
998 goto done;
1157 } 999 }
1158 1000
1159 if (ehci->rh_state != EHCI_RH_RUNNING) 1001 if (ehci->rh_state < EHCI_RH_RUNNING)
1160 qh->qh_state = QH_STATE_IDLE; 1002 qh->qh_state = QH_STATE_IDLE;
1161 switch (qh->qh_state) { 1003 switch (qh->qh_state) {
1162 case QH_STATE_LINKED: 1004 case QH_STATE_LINKED:
@@ -1169,7 +1011,7 @@ rescan:
1169 * may already be unlinked. 1011 * may already be unlinked.
1170 */ 1012 */
1171 if (tmp) 1013 if (tmp)
1172 unlink_async(ehci, qh); 1014 start_unlink_async(ehci, qh);
1173 /* FALL THROUGH */ 1015 /* FALL THROUGH */
1174 case QH_STATE_UNLINK: /* wait for hw to finish? */ 1016 case QH_STATE_UNLINK: /* wait for hw to finish? */
1175 case QH_STATE_UNLINK_WAIT: 1017 case QH_STATE_UNLINK_WAIT:
@@ -1181,7 +1023,7 @@ idle_timeout:
1181 if (qh->clearing_tt) 1023 if (qh->clearing_tt)
1182 goto idle_timeout; 1024 goto idle_timeout;
1183 if (list_empty (&qh->qtd_list)) { 1025 if (list_empty (&qh->qtd_list)) {
1184 qh_put (qh); 1026 qh_destroy(ehci, qh);
1185 break; 1027 break;
1186 } 1028 }
1187 /* else FALL THROUGH */ 1029 /* else FALL THROUGH */
@@ -1194,8 +1036,8 @@ idle_timeout:
1194 list_empty (&qh->qtd_list) ? "" : "(has tds)"); 1036 list_empty (&qh->qtd_list) ? "" : "(has tds)");
1195 break; 1037 break;
1196 } 1038 }
1039 done:
1197 ep->hcpriv = NULL; 1040 ep->hcpriv = NULL;
1198done:
1199 spin_unlock_irqrestore (&ehci->lock, flags); 1041 spin_unlock_irqrestore (&ehci->lock, flags);
1200} 1042}
1201 1043
@@ -1232,9 +1074,9 @@ ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
1232 * re-linking will call qh_refresh(). 1074 * re-linking will call qh_refresh().
1233 */ 1075 */
1234 if (eptype == USB_ENDPOINT_XFER_BULK) 1076 if (eptype == USB_ENDPOINT_XFER_BULK)
1235 unlink_async(ehci, qh); 1077 start_unlink_async(ehci, qh);
1236 else 1078 else
1237 intr_deschedule(ehci, qh); 1079 start_unlink_intr(ehci, qh);
1238 } 1080 }
1239 } 1081 }
1240 spin_unlock_irqrestore(&ehci->lock, flags); 1082 spin_unlock_irqrestore(&ehci->lock, flags);
@@ -1247,6 +1089,104 @@ static int ehci_get_frame (struct usb_hcd *hcd)
1247} 1089}
1248 1090
1249/*-------------------------------------------------------------------------*/ 1091/*-------------------------------------------------------------------------*/
1092
1093#ifdef CONFIG_PM
1094
1095/* suspend/resume, section 4.3 */
1096
1097/* These routines handle the generic parts of controller suspend/resume */
1098
1099static int __maybe_unused ehci_suspend(struct usb_hcd *hcd, bool do_wakeup)
1100{
1101 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1102
1103 if (time_before(jiffies, ehci->next_statechange))
1104 msleep(10);
1105
1106 /*
1107 * Root hub was already suspended. Disable IRQ emission and
1108 * mark HW unaccessible. The PM and USB cores make sure that
1109 * the root hub is either suspended or stopped.
1110 */
1111 ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup);
1112
1113 spin_lock_irq(&ehci->lock);
1114 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
1115 (void) ehci_readl(ehci, &ehci->regs->intr_enable);
1116
1117 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1118 spin_unlock_irq(&ehci->lock);
1119
1120 return 0;
1121}
1122
1123/* Returns 0 if power was preserved, 1 if power was lost */
1124static int __maybe_unused ehci_resume(struct usb_hcd *hcd, bool hibernated)
1125{
1126 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1127
1128 if (time_before(jiffies, ehci->next_statechange))
1129 msleep(100);
1130
1131 /* Mark hardware accessible again as we are back to full power by now */
1132 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
1133
1134 if (ehci->shutdown)
1135 return 0; /* Controller is dead */
1136
1137 /*
1138 * If CF is still set and we aren't resuming from hibernation
1139 * then we maintained suspend power.
1140 * Just undo the effect of ehci_suspend().
1141 */
1142 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF &&
1143 !hibernated) {
1144 int mask = INTR_MASK;
1145
1146 ehci_prepare_ports_for_controller_resume(ehci);
1147
1148 spin_lock_irq(&ehci->lock);
1149 if (ehci->shutdown)
1150 goto skip;
1151
1152 if (!hcd->self.root_hub->do_remote_wakeup)
1153 mask &= ~STS_PCD;
1154 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
1155 ehci_readl(ehci, &ehci->regs->intr_enable);
1156 skip:
1157 spin_unlock_irq(&ehci->lock);
1158 return 0;
1159 }
1160
1161 /*
1162 * Else reset, to cope with power loss or resume from hibernation
1163 * having let the firmware kick in during reboot.
1164 */
1165 usb_root_hub_lost_power(hcd->self.root_hub);
1166 (void) ehci_halt(ehci);
1167 (void) ehci_reset(ehci);
1168
1169 spin_lock_irq(&ehci->lock);
1170 if (ehci->shutdown)
1171 goto skip;
1172
1173 ehci_writel(ehci, ehci->command, &ehci->regs->command);
1174 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
1175 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
1176
1177 ehci->rh_state = EHCI_RH_SUSPENDED;
1178 spin_unlock_irq(&ehci->lock);
1179
1180 /* here we "know" root ports should always stay powered */
1181 ehci_port_power(ehci, 1);
1182
1183 return 1;
1184}
1185
1186#endif
1187
1188/*-------------------------------------------------------------------------*/
1189
1250/* 1190/*
1251 * The EHCI in ChipIdea HDRC cannot be a separate module or device, 1191 * The EHCI in ChipIdea HDRC cannot be a separate module or device,
1252 * because its registers (and irq) are shared between host/gadget/otg 1192 * because its registers (and irq) are shared between host/gadget/otg
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index fc9e7cc6ac9b..c7880223738a 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -59,6 +59,7 @@ static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
59 /* Give the connections some time to appear */ 59 /* Give the connections some time to appear */
60 msleep(20); 60 msleep(20);
61 61
62 spin_lock_irq(&ehci->lock);
62 port = HCS_N_PORTS(ehci->hcs_params); 63 port = HCS_N_PORTS(ehci->hcs_params);
63 while (port--) { 64 while (port--) {
64 if (test_bit(port, &ehci->owned_ports)) { 65 if (test_bit(port, &ehci->owned_ports)) {
@@ -70,23 +71,30 @@ static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
70 clear_bit(port, &ehci->owned_ports); 71 clear_bit(port, &ehci->owned_ports);
71 else if (test_bit(port, &ehci->companion_ports)) 72 else if (test_bit(port, &ehci->companion_ports))
72 ehci_writel(ehci, status & ~PORT_PE, reg); 73 ehci_writel(ehci, status & ~PORT_PE, reg);
73 else 74 else {
75 spin_unlock_irq(&ehci->lock);
74 ehci_hub_control(hcd, SetPortFeature, 76 ehci_hub_control(hcd, SetPortFeature,
75 USB_PORT_FEAT_RESET, port + 1, 77 USB_PORT_FEAT_RESET, port + 1,
76 NULL, 0); 78 NULL, 0);
79 spin_lock_irq(&ehci->lock);
80 }
77 } 81 }
78 } 82 }
83 spin_unlock_irq(&ehci->lock);
79 84
80 if (!ehci->owned_ports) 85 if (!ehci->owned_ports)
81 return; 86 return;
82 msleep(90); /* Wait for resets to complete */ 87 msleep(90); /* Wait for resets to complete */
83 88
89 spin_lock_irq(&ehci->lock);
84 port = HCS_N_PORTS(ehci->hcs_params); 90 port = HCS_N_PORTS(ehci->hcs_params);
85 while (port--) { 91 while (port--) {
86 if (test_bit(port, &ehci->owned_ports)) { 92 if (test_bit(port, &ehci->owned_ports)) {
93 spin_unlock_irq(&ehci->lock);
87 ehci_hub_control(hcd, GetPortStatus, 94 ehci_hub_control(hcd, GetPortStatus,
88 0, port + 1, 95 0, port + 1,
89 (char *) &buf, sizeof(buf)); 96 (char *) &buf, sizeof(buf));
97 spin_lock_irq(&ehci->lock);
90 98
91 /* The companion should now own the port, 99 /* The companion should now own the port,
92 * but if something went wrong the port must not 100 * but if something went wrong the port must not
@@ -105,9 +113,10 @@ static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
105 } 113 }
106 114
107 ehci->owned_ports = 0; 115 ehci->owned_ports = 0;
116 spin_unlock_irq(&ehci->lock);
108} 117}
109 118
110static int __maybe_unused ehci_port_change(struct ehci_hcd *ehci) 119static int ehci_port_change(struct ehci_hcd *ehci)
111{ 120{
112 int i = HCS_N_PORTS(ehci->hcs_params); 121 int i = HCS_N_PORTS(ehci->hcs_params);
113 122
@@ -128,12 +137,11 @@ static int __maybe_unused ehci_port_change(struct ehci_hcd *ehci)
128 return 0; 137 return 0;
129} 138}
130 139
131static __maybe_unused void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci, 140static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
132 bool suspending, bool do_wakeup) 141 bool suspending, bool do_wakeup)
133{ 142{
134 int port; 143 int port;
135 u32 temp; 144 u32 temp;
136 unsigned long flags;
137 145
138 /* If remote wakeup is enabled for the root hub but disabled 146 /* If remote wakeup is enabled for the root hub but disabled
139 * for the controller, we must adjust all the port wakeup flags 147 * for the controller, we must adjust all the port wakeup flags
@@ -143,22 +151,20 @@ static __maybe_unused void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
143 if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || do_wakeup) 151 if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup || do_wakeup)
144 return; 152 return;
145 153
146 spin_lock_irqsave(&ehci->lock, flags); 154 spin_lock_irq(&ehci->lock);
147 155
148 /* clear phy low-power mode before changing wakeup flags */ 156 /* clear phy low-power mode before changing wakeup flags */
149 if (ehci->has_hostpc) { 157 if (ehci->has_hostpc) {
150 port = HCS_N_PORTS(ehci->hcs_params); 158 port = HCS_N_PORTS(ehci->hcs_params);
151 while (port--) { 159 while (port--) {
152 u32 __iomem *hostpc_reg; 160 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
153 161
154 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
155 + HOSTPC0 + 4 * port);
156 temp = ehci_readl(ehci, hostpc_reg); 162 temp = ehci_readl(ehci, hostpc_reg);
157 ehci_writel(ehci, temp & ~HOSTPC_PHCD, hostpc_reg); 163 ehci_writel(ehci, temp & ~HOSTPC_PHCD, hostpc_reg);
158 } 164 }
159 spin_unlock_irqrestore(&ehci->lock, flags); 165 spin_unlock_irq(&ehci->lock);
160 msleep(5); 166 msleep(5);
161 spin_lock_irqsave(&ehci->lock, flags); 167 spin_lock_irq(&ehci->lock);
162 } 168 }
163 169
164 port = HCS_N_PORTS(ehci->hcs_params); 170 port = HCS_N_PORTS(ehci->hcs_params);
@@ -185,10 +191,8 @@ static __maybe_unused void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
185 if (ehci->has_hostpc) { 191 if (ehci->has_hostpc) {
186 port = HCS_N_PORTS(ehci->hcs_params); 192 port = HCS_N_PORTS(ehci->hcs_params);
187 while (port--) { 193 while (port--) {
188 u32 __iomem *hostpc_reg; 194 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
189 195
190 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
191 + HOSTPC0 + 4 * port);
192 temp = ehci_readl(ehci, hostpc_reg); 196 temp = ehci_readl(ehci, hostpc_reg);
193 ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg); 197 ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg);
194 } 198 }
@@ -198,7 +202,7 @@ static __maybe_unused void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
198 if (!suspending && ehci_port_change(ehci)) 202 if (!suspending && ehci_port_change(ehci))
199 usb_hcd_resume_root_hub(ehci_to_hcd(ehci)); 203 usb_hcd_resume_root_hub(ehci_to_hcd(ehci));
200 204
201 spin_unlock_irqrestore(&ehci->lock, flags); 205 spin_unlock_irq(&ehci->lock);
202} 206}
203 207
204static int ehci_bus_suspend (struct usb_hcd *hcd) 208static int ehci_bus_suspend (struct usb_hcd *hcd)
@@ -212,10 +216,13 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
212 216
213 if (time_before (jiffies, ehci->next_statechange)) 217 if (time_before (jiffies, ehci->next_statechange))
214 msleep(5); 218 msleep(5);
215 del_timer_sync(&ehci->watchdog); 219
216 del_timer_sync(&ehci->iaa_watchdog); 220 /* stop the schedules */
221 ehci_quiesce(ehci);
217 222
218 spin_lock_irq (&ehci->lock); 223 spin_lock_irq (&ehci->lock);
224 if (ehci->rh_state < EHCI_RH_RUNNING)
225 goto done;
219 226
220 /* Once the controller is stopped, port resumes that are already 227 /* Once the controller is stopped, port resumes that are already
221 * in progress won't complete. Hence if remote wakeup is enabled 228 * in progress won't complete. Hence if remote wakeup is enabled
@@ -230,11 +237,6 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
230 } 237 }
231 } 238 }
232 239
233 /* stop schedules, clean any completed work */
234 if (ehci->rh_state == EHCI_RH_RUNNING)
235 ehci_quiesce (ehci);
236 ehci_work(ehci);
237
238 /* Unlike other USB host controller types, EHCI doesn't have 240 /* Unlike other USB host controller types, EHCI doesn't have
239 * any notion of "global" or bus-wide suspend. The driver has 241 * any notion of "global" or bus-wide suspend. The driver has
240 * to manually suspend all the active unsuspended ports, and 242 * to manually suspend all the active unsuspended ports, and
@@ -285,11 +287,9 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
285 287
286 port = HCS_N_PORTS(ehci->hcs_params); 288 port = HCS_N_PORTS(ehci->hcs_params);
287 while (port--) { 289 while (port--) {
288 u32 __iomem *hostpc_reg; 290 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[port];
289 u32 t3; 291 u32 t3;
290 292
291 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
292 + HOSTPC0 + 4 * port);
293 t3 = ehci_readl(ehci, hostpc_reg); 293 t3 = ehci_readl(ehci, hostpc_reg);
294 ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg); 294 ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg);
295 t3 = ehci_readl(ehci, hostpc_reg); 295 t3 = ehci_readl(ehci, hostpc_reg);
@@ -298,6 +298,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
298 "succeeded" : "failed"); 298 "succeeded" : "failed");
299 } 299 }
300 } 300 }
301 spin_unlock_irq(&ehci->lock);
301 302
302 /* Apparently some devices need a >= 1-uframe delay here */ 303 /* Apparently some devices need a >= 1-uframe delay here */
303 if (ehci->bus_suspended) 304 if (ehci->bus_suspended)
@@ -305,10 +306,18 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
305 306
306 /* turn off now-idle HC */ 307 /* turn off now-idle HC */
307 ehci_halt (ehci); 308 ehci_halt (ehci);
309
310 spin_lock_irq(&ehci->lock);
311 if (ehci->enabled_hrtimer_events & BIT(EHCI_HRTIMER_POLL_DEAD))
312 ehci_handle_controller_death(ehci);
313 if (ehci->rh_state != EHCI_RH_RUNNING)
314 goto done;
308 ehci->rh_state = EHCI_RH_SUSPENDED; 315 ehci->rh_state = EHCI_RH_SUSPENDED;
309 316
310 if (ehci->reclaim) 317 end_unlink_async(ehci);
311 end_unlink_async(ehci); 318 unlink_empty_async(ehci);
319 ehci_handle_intr_unlinks(ehci);
320 end_free_itds(ehci);
312 321
313 /* allow remote wakeup */ 322 /* allow remote wakeup */
314 mask = INTR_MASK; 323 mask = INTR_MASK;
@@ -317,13 +326,13 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
317 ehci_writel(ehci, mask, &ehci->regs->intr_enable); 326 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
318 ehci_readl(ehci, &ehci->regs->intr_enable); 327 ehci_readl(ehci, &ehci->regs->intr_enable);
319 328
329 done:
320 ehci->next_statechange = jiffies + msecs_to_jiffies(10); 330 ehci->next_statechange = jiffies + msecs_to_jiffies(10);
331 ehci->enabled_hrtimer_events = 0;
332 ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
321 spin_unlock_irq (&ehci->lock); 333 spin_unlock_irq (&ehci->lock);
322 334
323 /* ehci_work() may have re-enabled the watchdog timer, which we do not 335 hrtimer_cancel(&ehci->hrtimer);
324 * want, and so we must delete any pending watchdog timer events.
325 */
326 del_timer_sync(&ehci->watchdog);
327 return 0; 336 return 0;
328} 337}
329 338
@@ -340,10 +349,8 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
340 if (time_before (jiffies, ehci->next_statechange)) 349 if (time_before (jiffies, ehci->next_statechange))
341 msleep(5); 350 msleep(5);
342 spin_lock_irq (&ehci->lock); 351 spin_lock_irq (&ehci->lock);
343 if (!HCD_HW_ACCESSIBLE(hcd)) { 352 if (!HCD_HW_ACCESSIBLE(hcd) || ehci->shutdown)
344 spin_unlock_irq(&ehci->lock); 353 goto shutdown;
345 return -ESHUTDOWN;
346 }
347 354
348 if (unlikely(ehci->debug)) { 355 if (unlikely(ehci->debug)) {
349 if (!dbgp_reset_prep()) 356 if (!dbgp_reset_prep())
@@ -382,16 +389,17 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
382 spin_unlock_irq(&ehci->lock); 389 spin_unlock_irq(&ehci->lock);
383 msleep(8); 390 msleep(8);
384 spin_lock_irq(&ehci->lock); 391 spin_lock_irq(&ehci->lock);
392 if (ehci->shutdown)
393 goto shutdown;
385 394
386 /* clear phy low-power mode before resume */ 395 /* clear phy low-power mode before resume */
387 if (ehci->bus_suspended && ehci->has_hostpc) { 396 if (ehci->bus_suspended && ehci->has_hostpc) {
388 i = HCS_N_PORTS(ehci->hcs_params); 397 i = HCS_N_PORTS(ehci->hcs_params);
389 while (i--) { 398 while (i--) {
390 if (test_bit(i, &ehci->bus_suspended)) { 399 if (test_bit(i, &ehci->bus_suspended)) {
391 u32 __iomem *hostpc_reg; 400 u32 __iomem *hostpc_reg =
401 &ehci->regs->hostpc[i];
392 402
393 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
394 + HOSTPC0 + 4 * i);
395 temp = ehci_readl(ehci, hostpc_reg); 403 temp = ehci_readl(ehci, hostpc_reg);
396 ehci_writel(ehci, temp & ~HOSTPC_PHCD, 404 ehci_writel(ehci, temp & ~HOSTPC_PHCD,
397 hostpc_reg); 405 hostpc_reg);
@@ -400,6 +408,8 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
400 spin_unlock_irq(&ehci->lock); 408 spin_unlock_irq(&ehci->lock);
401 msleep(5); 409 msleep(5);
402 spin_lock_irq(&ehci->lock); 410 spin_lock_irq(&ehci->lock);
411 if (ehci->shutdown)
412 goto shutdown;
403 } 413 }
404 414
405 /* manually resume the ports we suspended during bus_suspend() */ 415 /* manually resume the ports we suspended during bus_suspend() */
@@ -420,6 +430,8 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
420 spin_unlock_irq(&ehci->lock); 430 spin_unlock_irq(&ehci->lock);
421 msleep(20); 431 msleep(20);
422 spin_lock_irq(&ehci->lock); 432 spin_lock_irq(&ehci->lock);
433 if (ehci->shutdown)
434 goto shutdown;
423 } 435 }
424 436
425 i = HCS_N_PORTS (ehci->hcs_params); 437 i = HCS_N_PORTS (ehci->hcs_params);
@@ -431,27 +443,25 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
431 ehci_vdbg (ehci, "resumed port %d\n", i + 1); 443 ehci_vdbg (ehci, "resumed port %d\n", i + 1);
432 } 444 }
433 } 445 }
434 (void) ehci_readl(ehci, &ehci->regs->command);
435
436 /* maybe re-activate the schedule(s) */
437 temp = 0;
438 if (ehci->async->qh_next.qh)
439 temp |= CMD_ASE;
440 if (ehci->periodic_sched)
441 temp |= CMD_PSE;
442 if (temp) {
443 ehci->command |= temp;
444 ehci_writel(ehci, ehci->command, &ehci->regs->command);
445 }
446 446
447 ehci->next_statechange = jiffies + msecs_to_jiffies(5); 447 ehci->next_statechange = jiffies + msecs_to_jiffies(5);
448 spin_unlock_irq(&ehci->lock);
449
450 ehci_handover_companion_ports(ehci);
448 451
449 /* Now we can safely re-enable irqs */ 452 /* Now we can safely re-enable irqs */
453 spin_lock_irq(&ehci->lock);
454 if (ehci->shutdown)
455 goto shutdown;
450 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); 456 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable);
457 (void) ehci_readl(ehci, &ehci->regs->intr_enable);
458 spin_unlock_irq(&ehci->lock);
451 459
452 spin_unlock_irq (&ehci->lock);
453 ehci_handover_companion_ports(ehci);
454 return 0; 460 return 0;
461
462 shutdown:
463 spin_unlock_irq(&ehci->lock);
464 return -ESHUTDOWN;
455} 465}
456 466
457#else 467#else
@@ -667,7 +677,7 @@ static int ehci_hub_control (
667 int ports = HCS_N_PORTS (ehci->hcs_params); 677 int ports = HCS_N_PORTS (ehci->hcs_params);
668 u32 __iomem *status_reg = &ehci->regs->port_status[ 678 u32 __iomem *status_reg = &ehci->regs->port_status[
669 (wIndex & 0xff) - 1]; 679 (wIndex & 0xff) - 1];
670 u32 __iomem *hostpc_reg = NULL; 680 u32 __iomem *hostpc_reg = &ehci->regs->hostpc[(wIndex & 0xff) - 1];
671 u32 temp, temp1, status; 681 u32 temp, temp1, status;
672 unsigned long flags; 682 unsigned long flags;
673 int retval = 0; 683 int retval = 0;
@@ -680,9 +690,6 @@ static int ehci_hub_control (
680 * power, "this is the one", etc. EHCI spec supports this. 690 * power, "this is the one", etc. EHCI spec supports this.
681 */ 691 */
682 692
683 if (ehci->has_hostpc)
684 hostpc_reg = (u32 __iomem *)((u8 *)ehci->regs
685 + HOSTPC0 + 4 * ((wIndex & 0xff) - 1));
686 spin_lock_irqsave (&ehci->lock, flags); 693 spin_lock_irqsave (&ehci->lock, flags);
687 switch (typeReq) { 694 switch (typeReq) {
688 case ClearHubFeature: 695 case ClearHubFeature:
@@ -724,7 +731,7 @@ static int ehci_hub_control (
724#ifdef CONFIG_USB_OTG 731#ifdef CONFIG_USB_OTG
725 if ((hcd->self.otg_port == (wIndex + 1)) 732 if ((hcd->self.otg_port == (wIndex + 1))
726 && hcd->self.b_hnp_enable) { 733 && hcd->self.b_hnp_enable) {
727 otg_start_hnp(ehci->transceiver->otg); 734 otg_start_hnp(hcd->phy->otg);
728 break; 735 break;
729 } 736 }
730#endif 737#endif
@@ -734,7 +741,7 @@ static int ehci_hub_control (
734 goto error; 741 goto error;
735 742
736 /* clear phy low-power mode before resume */ 743 /* clear phy low-power mode before resume */
737 if (hostpc_reg) { 744 if (ehci->has_hostpc) {
738 temp1 = ehci_readl(ehci, hostpc_reg); 745 temp1 = ehci_readl(ehci, hostpc_reg);
739 ehci_writel(ehci, temp1 & ~HOSTPC_PHCD, 746 ehci_writel(ehci, temp1 & ~HOSTPC_PHCD,
740 hostpc_reg); 747 hostpc_reg);
@@ -984,7 +991,7 @@ static int ehci_hub_control (
984 temp &= ~PORT_WKCONN_E; 991 temp &= ~PORT_WKCONN_E;
985 temp |= PORT_WKDISC_E | PORT_WKOC_E; 992 temp |= PORT_WKDISC_E | PORT_WKOC_E;
986 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg); 993 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
987 if (hostpc_reg) { 994 if (ehci->has_hostpc) {
988 spin_unlock_irqrestore(&ehci->lock, flags); 995 spin_unlock_irqrestore(&ehci->lock, flags);
989 msleep(5);/* 5ms for HCD enter low pwr mode */ 996 msleep(5);/* 5ms for HCD enter low pwr mode */
990 spin_lock_irqsave(&ehci->lock, flags); 997 spin_lock_irqsave(&ehci->lock, flags);
@@ -1041,7 +1048,9 @@ static int ehci_hub_control (
1041 case USB_PORT_FEAT_TEST: 1048 case USB_PORT_FEAT_TEST:
1042 if (!selector || selector > 5) 1049 if (!selector || selector > 5)
1043 goto error; 1050 goto error;
1051 spin_unlock_irqrestore(&ehci->lock, flags);
1044 ehci_quiesce(ehci); 1052 ehci_quiesce(ehci);
1053 spin_lock_irqsave(&ehci->lock, flags);
1045 1054
1046 /* Put all enabled ports into suspend */ 1055 /* Put all enabled ports into suspend */
1047 while (ports--) { 1056 while (ports--) {
@@ -1053,7 +1062,11 @@ static int ehci_hub_control (
1053 ehci_writel(ehci, temp | PORT_SUSPEND, 1062 ehci_writel(ehci, temp | PORT_SUSPEND,
1054 sreg); 1063 sreg);
1055 } 1064 }
1065
1066 spin_unlock_irqrestore(&ehci->lock, flags);
1056 ehci_halt(ehci); 1067 ehci_halt(ehci);
1068 spin_lock_irqsave(&ehci->lock, flags);
1069
1057 temp = ehci_readl(ehci, status_reg); 1070 temp = ehci_readl(ehci, status_reg);
1058 temp |= selector << 16; 1071 temp |= selector << 16;
1059 ehci_writel(ehci, temp, status_reg); 1072 ehci_writel(ehci, temp, status_reg);
diff --git a/drivers/usb/host/ehci-ixp4xx.c b/drivers/usb/host/ehci-ixp4xx.c
index c4460f3d009f..488d401942e9 100644
--- a/drivers/usb/host/ehci-ixp4xx.c
+++ b/drivers/usb/host/ehci-ixp4xx.c
@@ -22,14 +22,10 @@ static int ixp4xx_ehci_init(struct usb_hcd *hcd)
22 ehci->big_endian_mmio = 1; 22 ehci->big_endian_mmio = 1;
23 23
24 ehci->caps = hcd->regs + 0x100; 24 ehci->caps = hcd->regs + 0x100;
25 ehci->regs = hcd->regs + 0x100
26 + HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
27 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
28 25
29 hcd->has_tt = 1; 26 hcd->has_tt = 1;
30 ehci_reset(ehci);
31 27
32 retval = ehci_init(hcd); 28 retval = ehci_setup(hcd);
33 if (retval) 29 if (retval)
34 return retval; 30 return retval;
35 31
diff --git a/drivers/usb/host/ehci-mem.c b/drivers/usb/host/ehci-mem.c
index 12f70c302b0b..ef2c3a1eca4b 100644
--- a/drivers/usb/host/ehci-mem.c
+++ b/drivers/usb/host/ehci-mem.c
@@ -64,10 +64,8 @@ static inline void ehci_qtd_free (struct ehci_hcd *ehci, struct ehci_qtd *qtd)
64} 64}
65 65
66 66
67static void qh_destroy(struct ehci_qh *qh) 67static void qh_destroy(struct ehci_hcd *ehci, struct ehci_qh *qh)
68{ 68{
69 struct ehci_hcd *ehci = qh->ehci;
70
71 /* clean qtds first, and know this is not linked */ 69 /* clean qtds first, and know this is not linked */
72 if (!list_empty (&qh->qtd_list) || qh->qh_next.ptr) { 70 if (!list_empty (&qh->qtd_list) || qh->qh_next.ptr) {
73 ehci_dbg (ehci, "unused qh not empty!\n"); 71 ehci_dbg (ehci, "unused qh not empty!\n");
@@ -92,8 +90,6 @@ static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, gfp_t flags)
92 if (!qh->hw) 90 if (!qh->hw)
93 goto fail; 91 goto fail;
94 memset(qh->hw, 0, sizeof *qh->hw); 92 memset(qh->hw, 0, sizeof *qh->hw);
95 qh->refcount = 1;
96 qh->ehci = ehci;
97 qh->qh_dma = dma; 93 qh->qh_dma = dma;
98 // INIT_LIST_HEAD (&qh->qh_list); 94 // INIT_LIST_HEAD (&qh->qh_list);
99 INIT_LIST_HEAD (&qh->qtd_list); 95 INIT_LIST_HEAD (&qh->qtd_list);
@@ -113,20 +109,6 @@ fail:
113 return NULL; 109 return NULL;
114} 110}
115 111
116/* to share a qh (cpu threads, or hc) */
117static inline struct ehci_qh *qh_get (struct ehci_qh *qh)
118{
119 WARN_ON(!qh->refcount);
120 qh->refcount++;
121 return qh;
122}
123
124static inline void qh_put (struct ehci_qh *qh)
125{
126 if (!--qh->refcount)
127 qh_destroy(qh);
128}
129
130/*-------------------------------------------------------------------------*/ 112/*-------------------------------------------------------------------------*/
131 113
132/* The queue heads and transfer descriptors are managed from pools tied 114/* The queue heads and transfer descriptors are managed from pools tied
@@ -136,13 +118,12 @@ static inline void qh_put (struct ehci_qh *qh)
136 118
137static void ehci_mem_cleanup (struct ehci_hcd *ehci) 119static void ehci_mem_cleanup (struct ehci_hcd *ehci)
138{ 120{
139 free_cached_lists(ehci);
140 if (ehci->async) 121 if (ehci->async)
141 qh_put (ehci->async); 122 qh_destroy(ehci, ehci->async);
142 ehci->async = NULL; 123 ehci->async = NULL;
143 124
144 if (ehci->dummy) 125 if (ehci->dummy)
145 qh_put(ehci->dummy); 126 qh_destroy(ehci, ehci->dummy);
146 ehci->dummy = NULL; 127 ehci->dummy = NULL;
147 128
148 /* DMA consistent memory and pools */ 129 /* DMA consistent memory and pools */
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c
index 9803a55fd5f4..17dd9e94001e 100644
--- a/drivers/usb/host/ehci-msm.c
+++ b/drivers/usb/host/ehci-msm.c
@@ -145,8 +145,8 @@ static int ehci_msm_probe(struct platform_device *pdev)
145 * powering up VBUS, mapping of registers address space and power 145 * powering up VBUS, mapping of registers address space and power
146 * management. 146 * management.
147 */ 147 */
148 phy = usb_get_transceiver(); 148 phy = usb_get_phy(USB_PHY_TYPE_USB2);
149 if (!phy) { 149 if (IS_ERR_OR_NULL(phy)) {
150 dev_err(&pdev->dev, "unable to find transceiver\n"); 150 dev_err(&pdev->dev, "unable to find transceiver\n");
151 ret = -ENODEV; 151 ret = -ENODEV;
152 goto unmap; 152 goto unmap;
@@ -169,7 +169,7 @@ static int ehci_msm_probe(struct platform_device *pdev)
169 return 0; 169 return 0;
170 170
171put_transceiver: 171put_transceiver:
172 usb_put_transceiver(phy); 172 usb_put_phy(phy);
173unmap: 173unmap:
174 iounmap(hcd->regs); 174 iounmap(hcd->regs);
175put_hcd: 175put_hcd:
@@ -187,7 +187,7 @@ static int __devexit ehci_msm_remove(struct platform_device *pdev)
187 pm_runtime_set_suspended(&pdev->dev); 187 pm_runtime_set_suspended(&pdev->dev);
188 188
189 otg_set_host(phy->otg, NULL); 189 otg_set_host(phy->otg, NULL);
190 usb_put_transceiver(phy); 190 usb_put_phy(phy);
191 191
192 usb_put_hcd(hcd); 192 usb_put_hcd(hcd);
193 193
@@ -198,24 +198,11 @@ static int __devexit ehci_msm_remove(struct platform_device *pdev)
198static int ehci_msm_pm_suspend(struct device *dev) 198static int ehci_msm_pm_suspend(struct device *dev)
199{ 199{
200 struct usb_hcd *hcd = dev_get_drvdata(dev); 200 struct usb_hcd *hcd = dev_get_drvdata(dev);
201 bool wakeup = device_may_wakeup(dev); 201 bool do_wakeup = device_may_wakeup(dev);
202 202
203 dev_dbg(dev, "ehci-msm PM suspend\n"); 203 dev_dbg(dev, "ehci-msm PM suspend\n");
204 204
205 /* 205 return ehci_suspend(hcd, do_wakeup);
206 * EHCI helper function has also the same check before manipulating
207 * port wakeup flags. We do check here the same condition before
208 * calling the same helper function to avoid bringing hardware
209 * from Low power mode when there is no need for adjusting port
210 * wakeup flags.
211 */
212 if (hcd->self.root_hub->do_remote_wakeup && !wakeup) {
213 pm_runtime_resume(dev);
214 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
215 wakeup);
216 }
217
218 return 0;
219} 206}
220 207
221static int ehci_msm_pm_resume(struct device *dev) 208static int ehci_msm_pm_resume(struct device *dev)
@@ -223,7 +210,7 @@ static int ehci_msm_pm_resume(struct device *dev)
223 struct usb_hcd *hcd = dev_get_drvdata(dev); 210 struct usb_hcd *hcd = dev_get_drvdata(dev);
224 211
225 dev_dbg(dev, "ehci-msm PM resume\n"); 212 dev_dbg(dev, "ehci-msm PM resume\n");
226 ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd)); 213 ehci_resume(hcd, false);
227 214
228 return 0; 215 return 0;
229} 216}
diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c
index a936bbcff8f4..f6df1ccc9617 100644
--- a/drivers/usb/host/ehci-mv.c
+++ b/drivers/usb/host/ehci-mv.c
@@ -13,6 +13,7 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/clk.h> 15#include <linux/clk.h>
16#include <linux/err.h>
16#include <linux/usb/otg.h> 17#include <linux/usb/otg.h>
17#include <linux/platform_data/mv_usb.h> 18#include <linux/platform_data/mv_usb.h>
18 19
@@ -76,7 +77,6 @@ static void mv_ehci_disable(struct ehci_hcd_mv *ehci_mv)
76 77
77static int mv_ehci_reset(struct usb_hcd *hcd) 78static int mv_ehci_reset(struct usb_hcd *hcd)
78{ 79{
79 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
80 struct device *dev = hcd->self.controller; 80 struct device *dev = hcd->self.controller;
81 struct ehci_hcd_mv *ehci_mv = dev_get_drvdata(dev); 81 struct ehci_hcd_mv *ehci_mv = dev_get_drvdata(dev);
82 int retval; 82 int retval;
@@ -86,25 +86,13 @@ static int mv_ehci_reset(struct usb_hcd *hcd)
86 return -ENODEV; 86 return -ENODEV;
87 } 87 }
88 88
89 /*
90 * data structure init
91 */
92 retval = ehci_init(hcd);
93 if (retval) {
94 dev_err(dev, "ehci_init failed %d\n", retval);
95 return retval;
96 }
97
98 hcd->has_tt = 1; 89 hcd->has_tt = 1;
99 ehci->sbrn = 0x20;
100 90
101 retval = ehci_reset(ehci); 91 retval = ehci_setup(hcd);
102 if (retval) { 92 if (retval)
103 dev_err(dev, "ehci_reset failed %d\n", retval); 93 dev_err(dev, "ehci_setup failed %d\n", retval);
104 return retval;
105 }
106 94
107 return 0; 95 return retval;
108} 96}
109 97
110static const struct hc_driver mv_ehci_hc_driver = { 98static const struct hc_driver mv_ehci_hc_driver = {
@@ -247,14 +235,12 @@ static int mv_ehci_probe(struct platform_device *pdev)
247 235
248 ehci = hcd_to_ehci(hcd); 236 ehci = hcd_to_ehci(hcd);
249 ehci->caps = (struct ehci_caps *) ehci_mv->cap_regs; 237 ehci->caps = (struct ehci_caps *) ehci_mv->cap_regs;
250 ehci->regs = (struct ehci_regs *) ehci_mv->op_regs;
251 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
252 238
253 ehci_mv->mode = pdata->mode; 239 ehci_mv->mode = pdata->mode;
254 if (ehci_mv->mode == MV_USB_MODE_OTG) { 240 if (ehci_mv->mode == MV_USB_MODE_OTG) {
255#ifdef CONFIG_USB_OTG_UTILS 241#ifdef CONFIG_USB_OTG_UTILS
256 ehci_mv->otg = usb_get_transceiver(); 242 ehci_mv->otg = usb_get_phy(USB_PHY_TYPE_USB2);
257 if (!ehci_mv->otg) { 243 if (IS_ERR_OR_NULL(ehci_mv->otg)) {
258 dev_err(&pdev->dev, 244 dev_err(&pdev->dev,
259 "unable to find transceiver\n"); 245 "unable to find transceiver\n");
260 retval = -ENODEV; 246 retval = -ENODEV;
@@ -302,8 +288,8 @@ err_set_vbus:
302 pdata->set_vbus(0); 288 pdata->set_vbus(0);
303#ifdef CONFIG_USB_OTG_UTILS 289#ifdef CONFIG_USB_OTG_UTILS
304err_put_transceiver: 290err_put_transceiver:
305 if (ehci_mv->otg) 291 if (!IS_ERR_OR_NULL(ehci_mv->otg))
306 usb_put_transceiver(ehci_mv->otg); 292 usb_put_phy(ehci_mv->otg);
307#endif 293#endif
308err_disable_clk: 294err_disable_clk:
309 mv_ehci_disable(ehci_mv); 295 mv_ehci_disable(ehci_mv);
@@ -331,9 +317,9 @@ static int mv_ehci_remove(struct platform_device *pdev)
331 if (hcd->rh_registered) 317 if (hcd->rh_registered)
332 usb_remove_hcd(hcd); 318 usb_remove_hcd(hcd);
333 319
334 if (ehci_mv->otg) { 320 if (!IS_ERR_OR_NULL(ehci_mv->otg)) {
335 otg_set_host(ehci_mv->otg->otg, NULL); 321 otg_set_host(ehci_mv->otg->otg, NULL);
336 usb_put_transceiver(ehci_mv->otg); 322 usb_put_phy(ehci_mv->otg);
337 } 323 }
338 324
339 if (ehci_mv->mode == MV_USB_MODE_HOST) { 325 if (ehci_mv->mode == MV_USB_MODE_HOST) {
diff --git a/drivers/usb/host/ehci-mxc.c b/drivers/usb/host/ehci-mxc.c
index c778ffe4e4e5..34201372c85f 100644
--- a/drivers/usb/host/ehci-mxc.c
+++ b/drivers/usb/host/ehci-mxc.c
@@ -42,27 +42,12 @@ static int ehci_mxc_setup(struct usb_hcd *hcd)
42 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 42 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
43 int retval; 43 int retval;
44 44
45 dbg_hcs_params(ehci, "reset");
46 dbg_hcc_params(ehci, "reset");
47
48 /* cache this readonly data; minimize chip reads */
49 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
50
51 hcd->has_tt = 1; 45 hcd->has_tt = 1;
52 46
53 retval = ehci_halt(ehci); 47 retval = ehci_setup(hcd);
54 if (retval) 48 if (retval)
55 return retval; 49 return retval;
56 50
57 /* data structure init */
58 retval = ehci_init(hcd);
59 if (retval)
60 return retval;
61
62 ehci->sbrn = 0x20;
63
64 ehci_reset(ehci);
65
66 ehci_port_power(ehci, 0); 51 ehci_port_power(ehci, 0);
67 return 0; 52 return 0;
68} 53}
diff --git a/drivers/usb/host/ehci-octeon.c b/drivers/usb/host/ehci-octeon.c
index c0104882c72d..ba26957abf46 100644
--- a/drivers/usb/host/ehci-octeon.c
+++ b/drivers/usb/host/ehci-octeon.c
@@ -56,7 +56,7 @@ static const struct hc_driver ehci_octeon_hc_driver = {
56 /* 56 /*
57 * basic lifecycle operations 57 * basic lifecycle operations
58 */ 58 */
59 .reset = ehci_init, 59 .reset = ehci_setup,
60 .start = ehci_run, 60 .start = ehci_run,
61 .stop = ehci_stop, 61 .stop = ehci_stop,
62 .shutdown = ehci_shutdown, 62 .shutdown = ehci_shutdown,
@@ -150,12 +150,6 @@ static int ehci_octeon_drv_probe(struct platform_device *pdev)
150#endif 150#endif
151 151
152 ehci->caps = hcd->regs; 152 ehci->caps = hcd->regs;
153 ehci->regs = hcd->regs +
154 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
155 /* cache this readonly data; minimize chip reads */
156 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
157
158 ehci_reset(ehci);
159 153
160 ret = usb_add_hcd(hcd, irq, IRQF_SHARED); 154 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
161 if (ret) { 155 if (ret) {
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index c30435499a02..ec21f4a4a056 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -115,9 +115,8 @@ static void omap_ehci_erratum_i693(struct ehci_hcd *ehci)
115 clk_disable(usbhost_p2_fck); 115 clk_disable(usbhost_p2_fck);
116} 116}
117 117
118static void omap_ehci_soft_phy_reset(struct platform_device *pdev, u8 port) 118static void omap_ehci_soft_phy_reset(struct usb_hcd *hcd, u8 port)
119{ 119{
120 struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
121 unsigned long timeout = jiffies + msecs_to_jiffies(1000); 120 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
122 unsigned reg = 0; 121 unsigned reg = 0;
123 122
@@ -139,12 +138,63 @@ static void omap_ehci_soft_phy_reset(struct platform_device *pdev, u8 port)
139 cpu_relax(); 138 cpu_relax();
140 139
141 if (time_after(jiffies, timeout)) { 140 if (time_after(jiffies, timeout)) {
142 dev_dbg(&pdev->dev, "phy reset operation timed out\n"); 141 dev_dbg(hcd->self.controller,
142 "phy reset operation timed out\n");
143 break; 143 break;
144 } 144 }
145 } 145 }
146} 146}
147 147
148static int omap_ehci_init(struct usb_hcd *hcd)
149{
150 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
151 int rc;
152 struct ehci_hcd_omap_platform_data *pdata;
153
154 pdata = hcd->self.controller->platform_data;
155 if (pdata->phy_reset) {
156 if (gpio_is_valid(pdata->reset_gpio_port[0]))
157 gpio_request_one(pdata->reset_gpio_port[0],
158 GPIOF_OUT_INIT_LOW, "USB1 PHY reset");
159
160 if (gpio_is_valid(pdata->reset_gpio_port[1]))
161 gpio_request_one(pdata->reset_gpio_port[1],
162 GPIOF_OUT_INIT_LOW, "USB2 PHY reset");
163
164 /* Hold the PHY in RESET for enough time till DIR is high */
165 udelay(10);
166 }
167
168 /* Soft reset the PHY using PHY reset command over ULPI */
169 if (pdata->port_mode[0] == OMAP_EHCI_PORT_MODE_PHY)
170 omap_ehci_soft_phy_reset(hcd, 0);
171 if (pdata->port_mode[1] == OMAP_EHCI_PORT_MODE_PHY)
172 omap_ehci_soft_phy_reset(hcd, 1);
173
174 /* we know this is the memory we want, no need to ioremap again */
175 ehci->caps = hcd->regs;
176
177 rc = ehci_setup(hcd);
178
179 if (pdata->phy_reset) {
180 /* Hold the PHY in RESET for enough time till
181 * PHY is settled and ready
182 */
183 udelay(10);
184
185 if (gpio_is_valid(pdata->reset_gpio_port[0]))
186 gpio_set_value_cansleep(pdata->reset_gpio_port[0], 1);
187
188 if (gpio_is_valid(pdata->reset_gpio_port[1]))
189 gpio_set_value_cansleep(pdata->reset_gpio_port[1], 1);
190 }
191
192 /* root ports should always stay powered */
193 ehci_port_power(ehci, 1);
194
195 return rc;
196}
197
148static int omap_ehci_hub_control( 198static int omap_ehci_hub_control(
149 struct usb_hcd *hcd, 199 struct usb_hcd *hcd,
150 u16 typeReq, 200 u16 typeReq,
@@ -219,7 +269,6 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
219 struct resource *res; 269 struct resource *res;
220 struct usb_hcd *hcd; 270 struct usb_hcd *hcd;
221 void __iomem *regs; 271 void __iomem *regs;
222 struct ehci_hcd *omap_ehci;
223 int ret = -ENODEV; 272 int ret = -ENODEV;
224 int irq; 273 int irq;
225 int i; 274 int i;
@@ -281,18 +330,6 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
281 } 330 }
282 } 331 }
283 332
284 /* Hold PHYs in reset while initializing EHCI controller */
285 if (pdata->phy_reset) {
286 if (gpio_is_valid(pdata->reset_gpio_port[0]))
287 gpio_set_value_cansleep(pdata->reset_gpio_port[0], 0);
288
289 if (gpio_is_valid(pdata->reset_gpio_port[1]))
290 gpio_set_value_cansleep(pdata->reset_gpio_port[1], 0);
291
292 /* Hold the PHY in RESET for enough time till DIR is high */
293 udelay(10);
294 }
295
296 pm_runtime_enable(dev); 333 pm_runtime_enable(dev);
297 pm_runtime_get_sync(dev); 334 pm_runtime_get_sync(dev);
298 335
@@ -308,49 +345,12 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
308 ehci_write(regs, EHCI_INSNREG04, 345 ehci_write(regs, EHCI_INSNREG04,
309 EHCI_INSNREG04_DISABLE_UNSUSPEND); 346 EHCI_INSNREG04_DISABLE_UNSUSPEND);
310 347
311 /* Soft reset the PHY using PHY reset command over ULPI */
312 if (pdata->port_mode[0] == OMAP_EHCI_PORT_MODE_PHY)
313 omap_ehci_soft_phy_reset(pdev, 0);
314 if (pdata->port_mode[1] == OMAP_EHCI_PORT_MODE_PHY)
315 omap_ehci_soft_phy_reset(pdev, 1);
316
317 omap_ehci = hcd_to_ehci(hcd);
318 omap_ehci->sbrn = 0x20;
319
320 /* we know this is the memory we want, no need to ioremap again */
321 omap_ehci->caps = hcd->regs;
322 omap_ehci->regs = hcd->regs
323 + HC_LENGTH(ehci, readl(&omap_ehci->caps->hc_capbase));
324
325 dbg_hcs_params(omap_ehci, "reset");
326 dbg_hcc_params(omap_ehci, "reset");
327
328 /* cache this readonly data; minimize chip reads */
329 omap_ehci->hcs_params = readl(&omap_ehci->caps->hcs_params);
330
331 ehci_reset(omap_ehci);
332 ret = usb_add_hcd(hcd, irq, IRQF_SHARED); 348 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
333 if (ret) { 349 if (ret) {
334 dev_err(dev, "failed to add hcd with err %d\n", ret); 350 dev_err(dev, "failed to add hcd with err %d\n", ret);
335 goto err_add_hcd; 351 goto err_pm_runtime;
336 } 352 }
337 353
338 if (pdata->phy_reset) {
339 /* Hold the PHY in RESET for enough time till
340 * PHY is settled and ready
341 */
342 udelay(10);
343
344 if (gpio_is_valid(pdata->reset_gpio_port[0]))
345 gpio_set_value_cansleep(pdata->reset_gpio_port[0], 1);
346
347 if (gpio_is_valid(pdata->reset_gpio_port[1]))
348 gpio_set_value_cansleep(pdata->reset_gpio_port[1], 1);
349 }
350
351 /* root ports should always stay powered */
352 ehci_port_power(omap_ehci, 1);
353
354 /* get clocks */ 354 /* get clocks */
355 utmi_p1_fck = clk_get(dev, "utmi_p1_gfclk"); 355 utmi_p1_fck = clk_get(dev, "utmi_p1_gfclk");
356 if (IS_ERR(utmi_p1_fck)) { 356 if (IS_ERR(utmi_p1_fck)) {
@@ -422,8 +422,12 @@ err_utmi_p1_fck:
422 clk_put(utmi_p1_fck); 422 clk_put(utmi_p1_fck);
423 423
424err_add_hcd: 424err_add_hcd:
425 usb_remove_hcd(hcd);
426
427err_pm_runtime:
425 disable_put_regulator(pdata); 428 disable_put_regulator(pdata);
426 pm_runtime_put_sync(dev); 429 pm_runtime_put_sync(dev);
430 usb_put_hcd(hcd);
427 431
428err_io: 432err_io:
429 iounmap(regs); 433 iounmap(regs);
@@ -506,7 +510,7 @@ static const struct hc_driver ehci_omap_hc_driver = {
506 /* 510 /*
507 * basic lifecycle operations 511 * basic lifecycle operations
508 */ 512 */
509 .reset = ehci_init, 513 .reset = omap_ehci_init,
510 .start = ehci_run, 514 .start = ehci_run,
511 .stop = ehci_stop, 515 .stop = ehci_stop,
512 .shutdown = ehci_shutdown, 516 .shutdown = ehci_shutdown,
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c
index 82de1073aa52..9408da83eaf1 100644
--- a/drivers/usb/host/ehci-orion.c
+++ b/drivers/usb/host/ehci-orion.c
@@ -106,21 +106,10 @@ static int ehci_orion_setup(struct usb_hcd *hcd)
106 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 106 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
107 int retval; 107 int retval;
108 108
109 hcd->has_tt = 1; 109 retval = ehci_setup(hcd);
110
111 retval = ehci_halt(ehci);
112 if (retval)
113 return retval;
114
115 /*
116 * data structure init
117 */
118 retval = ehci_init(hcd);
119 if (retval) 110 if (retval)
120 return retval; 111 return retval;
121 112
122 ehci_reset(ehci);
123
124 ehci_port_power(ehci, 0); 113 ehci_port_power(ehci, 0);
125 114
126 return retval; 115 return retval;
@@ -261,11 +250,7 @@ static int __devinit ehci_orion_drv_probe(struct platform_device *pdev)
261 250
262 ehci = hcd_to_ehci(hcd); 251 ehci = hcd_to_ehci(hcd);
263 ehci->caps = hcd->regs + 0x100; 252 ehci->caps = hcd->regs + 0x100;
264 ehci->regs = hcd->regs + 0x100 +
265 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
266 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
267 hcd->has_tt = 1; 253 hcd->has_tt = 1;
268 ehci->sbrn = 0x20;
269 254
270 /* 255 /*
271 * (Re-)program MBUS remapping windows if we are asked to. 256 * (Re-)program MBUS remapping windows if we are asked to.
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index 123481793a47..2cb7d370c4ef 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -54,6 +54,17 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
54 u32 temp; 54 u32 temp;
55 int retval; 55 int retval;
56 56
57 ehci->caps = hcd->regs;
58
59 /*
60 * ehci_init() causes memory for DMA transfers to be
61 * allocated. Thus, any vendor-specific workarounds based on
62 * limiting the type of memory used for DMA transfers must
63 * happen before ehci_setup() is called.
64 *
65 * Most other workarounds can be done either before or after
66 * init and reset; they are located here too.
67 */
57 switch (pdev->vendor) { 68 switch (pdev->vendor) {
58 case PCI_VENDOR_ID_TOSHIBA_2: 69 case PCI_VENDOR_ID_TOSHIBA_2:
59 /* celleb's companion chip */ 70 /* celleb's companion chip */
@@ -66,20 +77,6 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
66#endif 77#endif
67 } 78 }
68 break; 79 break;
69 }
70
71 ehci->caps = hcd->regs;
72 ehci->regs = hcd->regs +
73 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
74
75 dbg_hcs_params(ehci, "reset");
76 dbg_hcc_params(ehci, "reset");
77
78 /* ehci_init() causes memory for DMA transfers to be
79 * allocated. Thus, any vendor-specific workarounds based on
80 * limiting the type of memory used for DMA transfers must
81 * happen before ehci_init() is called. */
82 switch (pdev->vendor) {
83 case PCI_VENDOR_ID_NVIDIA: 80 case PCI_VENDOR_ID_NVIDIA:
84 /* NVidia reports that certain chips don't handle 81 /* NVidia reports that certain chips don't handle
85 * QH, ITD, or SITD addresses above 2GB. (But TD, 82 * QH, ITD, or SITD addresses above 2GB. (But TD,
@@ -95,61 +92,24 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
95 ehci_warn(ehci, "can't enable NVidia " 92 ehci_warn(ehci, "can't enable NVidia "
96 "workaround for >2GB RAM\n"); 93 "workaround for >2GB RAM\n");
97 break; 94 break;
98 }
99 break;
100 }
101
102 /* cache this readonly data; minimize chip reads */
103 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
104
105 retval = ehci_halt(ehci);
106 if (retval)
107 return retval;
108 95
109 if ((pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x7808) || 96 /* Some NForce2 chips have problems with selective suspend;
110 (pdev->vendor == PCI_VENDOR_ID_ATI && pdev->device == 0x4396)) { 97 * fixed in newer silicon.
111 /* EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
112 * read/write memory space which does not belong to it when
113 * there is NULL pointer with T-bit set to 1 in the frame list
114 * table. To avoid the issue, the frame list link pointer
115 * should always contain a valid pointer to a inactive qh.
116 */ 98 */
117 ehci->use_dummy_qh = 1; 99 case 0x0068:
118 ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI " 100 if (pdev->revision < 0xa4)
119 "dummy qh workaround\n"); 101 ehci->no_selective_suspend = 1;
120 } 102 break;
121 103 }
122 /* data structure init */
123 retval = ehci_init(hcd);
124 if (retval)
125 return retval;
126
127 switch (pdev->vendor) {
128 case PCI_VENDOR_ID_NEC:
129 ehci->need_io_watchdog = 0;
130 break; 104 break;
131 case PCI_VENDOR_ID_INTEL: 105 case PCI_VENDOR_ID_INTEL:
132 ehci->need_io_watchdog = 0;
133 ehci->fs_i_thresh = 1; 106 ehci->fs_i_thresh = 1;
134 if (pdev->device == 0x27cc) { 107 if (pdev->device == PCI_DEVICE_ID_INTEL_CE4100_USB)
135 ehci->broken_periodic = 1;
136 ehci_info(ehci, "using broken periodic workaround\n");
137 }
138 if (pdev->device == 0x0806 || pdev->device == 0x0811
139 || pdev->device == 0x0829) {
140 ehci_info(ehci, "disable lpm for langwell/penwell\n");
141 ehci->has_lpm = 0;
142 }
143 if (pdev->device == PCI_DEVICE_ID_INTEL_CE4100_USB) {
144 hcd->has_tt = 1; 108 hcd->has_tt = 1;
145 tdi_reset(ehci);
146 }
147 break; 109 break;
148 case PCI_VENDOR_ID_TDI: 110 case PCI_VENDOR_ID_TDI:
149 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) { 111 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI)
150 hcd->has_tt = 1; 112 hcd->has_tt = 1;
151 tdi_reset(ehci);
152 }
153 break; 113 break;
154 case PCI_VENDOR_ID_AMD: 114 case PCI_VENDOR_ID_AMD:
155 /* AMD PLL quirk */ 115 /* AMD PLL quirk */
@@ -161,28 +121,17 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
161 retval = -EIO; 121 retval = -EIO;
162 goto done; 122 goto done;
163 } 123 }
164 break;
165 case PCI_VENDOR_ID_NVIDIA:
166 switch (pdev->device) {
167 /* Some NForce2 chips have problems with selective suspend;
168 * fixed in newer silicon.
169 */
170 case 0x0068:
171 if (pdev->revision < 0xa4)
172 ehci->no_selective_suspend = 1;
173 break;
174 124
175 /* MCP89 chips on the MacBookAir3,1 give EPROTO when 125 /*
176 * fetching device descriptors unless LPM is disabled. 126 * EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
177 * There are also intermittent problems enumerating 127 * read/write memory space which does not belong to it when
178 * devices with PPCD enabled. 128 * there is NULL pointer with T-bit set to 1 in the frame list
129 * table. To avoid the issue, the frame list link pointer
130 * should always contain a valid pointer to a inactive qh.
179 */ 131 */
180 case 0x0d9d: 132 if (pdev->device == 0x7808) {
181 ehci_info(ehci, "disable lpm/ppcd for nvidia mcp89"); 133 ehci->use_dummy_qh = 1;
182 ehci->has_lpm = 0; 134 ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI dummy qh workaround\n");
183 ehci->has_ppcd = 0;
184 ehci->command &= ~CMD_PPCEE;
185 break;
186 } 135 }
187 break; 136 break;
188 case PCI_VENDOR_ID_VIA: 137 case PCI_VENDOR_ID_VIA:
@@ -203,6 +152,18 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
203 /* AMD PLL quirk */ 152 /* AMD PLL quirk */
204 if (usb_amd_find_chipset_info()) 153 if (usb_amd_find_chipset_info())
205 ehci->amd_pll_fix = 1; 154 ehci->amd_pll_fix = 1;
155
156 /*
157 * EHCI controller on AMD SB700/SB800/Hudson-2/3 platforms may
158 * read/write memory space which does not belong to it when
159 * there is NULL pointer with T-bit set to 1 in the frame list
160 * table. To avoid the issue, the frame list link pointer
161 * should always contain a valid pointer to a inactive qh.
162 */
163 if (pdev->device == 0x4396) {
164 ehci->use_dummy_qh = 1;
165 ehci_info(ehci, "applying AMD SB700/SB800/Hudson-2/3 EHCI dummy qh workaround\n");
166 }
206 /* SB600 and old version of SB700 have a bug in EHCI controller, 167 /* SB600 and old version of SB700 have a bug in EHCI controller,
207 * which causes usb devices lose response in some cases. 168 * which causes usb devices lose response in some cases.
208 */ 169 */
@@ -231,6 +192,40 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
231 break; 192 break;
232 } 193 }
233 194
195 retval = ehci_setup(hcd);
196 if (retval)
197 return retval;
198
199 /* These workarounds need to be applied after ehci_setup() */
200 switch (pdev->vendor) {
201 case PCI_VENDOR_ID_NEC:
202 ehci->need_io_watchdog = 0;
203 break;
204 case PCI_VENDOR_ID_INTEL:
205 ehci->need_io_watchdog = 0;
206 if (pdev->device == 0x0806 || pdev->device == 0x0811
207 || pdev->device == 0x0829) {
208 ehci_info(ehci, "disable lpm for langwell/penwell\n");
209 ehci->has_lpm = 0;
210 }
211 break;
212 case PCI_VENDOR_ID_NVIDIA:
213 switch (pdev->device) {
214 /* MCP89 chips on the MacBookAir3,1 give EPROTO when
215 * fetching device descriptors unless LPM is disabled.
216 * There are also intermittent problems enumerating
217 * devices with PPCD enabled.
218 */
219 case 0x0d9d:
220 ehci_info(ehci, "disable lpm/ppcd for nvidia mcp89");
221 ehci->has_lpm = 0;
222 ehci->has_ppcd = 0;
223 ehci->command &= ~CMD_PPCEE;
224 break;
225 }
226 break;
227 }
228
234 /* optional debug port, normally in the first BAR */ 229 /* optional debug port, normally in the first BAR */
235 temp = pci_find_capability(pdev, 0x0a); 230 temp = pci_find_capability(pdev, 0x0a);
236 if (temp) { 231 if (temp) {
@@ -238,7 +233,7 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
238 temp >>= 16; 233 temp >>= 16;
239 if ((temp & (3 << 13)) == (1 << 13)) { 234 if ((temp & (3 << 13)) == (1 << 13)) {
240 temp &= 0x1fff; 235 temp &= 0x1fff;
241 ehci->debug = ehci_to_hcd(ehci)->regs + temp; 236 ehci->debug = hcd->regs + temp;
242 temp = ehci_readl(ehci, &ehci->debug->control); 237 temp = ehci_readl(ehci, &ehci->debug->control);
243 ehci_info(ehci, "debug port %d%s\n", 238 ehci_info(ehci, "debug port %d%s\n",
244 HCS_DEBUG_PORT(ehci->hcs_params), 239 HCS_DEBUG_PORT(ehci->hcs_params),
@@ -250,8 +245,6 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
250 } 245 }
251 } 246 }
252 247
253 ehci_reset(ehci);
254
255 /* at least the Genesys GL880S needs fixup here */ 248 /* at least the Genesys GL880S needs fixup here */
256 temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params); 249 temp = HCS_N_CC(ehci->hcs_params) * HCS_N_PCC(ehci->hcs_params);
257 temp &= 0x0f; 250 temp &= 0x0f;
@@ -275,10 +268,11 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
275 } 268 }
276 269
277 /* Serial Bus Release Number is at PCI 0x60 offset */ 270 /* Serial Bus Release Number is at PCI 0x60 offset */
278 pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
279 if (pdev->vendor == PCI_VENDOR_ID_STMICRO 271 if (pdev->vendor == PCI_VENDOR_ID_STMICRO
280 && pdev->device == PCI_DEVICE_ID_STMICRO_USB_HOST) 272 && pdev->device == PCI_DEVICE_ID_STMICRO_USB_HOST)
281 ehci->sbrn = 0x20; /* ConneXT has no sbrn register */ 273 ; /* ConneXT has no sbrn register */
274 else
275 pci_read_config_byte(pdev, 0x60, &ehci->sbrn);
282 276
283 /* Keep this around for a while just in case some EHCI 277 /* Keep this around for a while just in case some EHCI
284 * implementation uses legacy PCI PM support. This test 278 * implementation uses legacy PCI PM support. This test
@@ -331,29 +325,7 @@ done:
331 325
332static int ehci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) 326static int ehci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
333{ 327{
334 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 328 return ehci_suspend(hcd, do_wakeup);
335 unsigned long flags;
336 int rc = 0;
337
338 if (time_before(jiffies, ehci->next_statechange))
339 msleep(10);
340
341 /* Root hub was already suspended. Disable irq emission and
342 * mark HW unaccessible. The PM and USB cores make sure that
343 * the root hub is either suspended or stopped.
344 */
345 ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup);
346 spin_lock_irqsave (&ehci->lock, flags);
347 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
348 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
349
350 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
351 spin_unlock_irqrestore (&ehci->lock, flags);
352
353 // could save FLADJ in case of Vaux power loss
354 // ... we'd only use it to handle clock skew
355
356 return rc;
357} 329}
358 330
359static bool usb_is_intel_switchable_ehci(struct pci_dev *pdev) 331static bool usb_is_intel_switchable_ehci(struct pci_dev *pdev)
@@ -402,54 +374,8 @@ static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
402 if (usb_is_intel_switchable_ehci(pdev)) 374 if (usb_is_intel_switchable_ehci(pdev))
403 ehci_enable_xhci_companion(); 375 ehci_enable_xhci_companion();
404 376
405 // maybe restore FLADJ 377 if (ehci_resume(hcd, hibernated) != 0)
406 378 (void) ehci_pci_reinit(ehci, pdev);
407 if (time_before(jiffies, ehci->next_statechange))
408 msleep(100);
409
410 /* Mark hardware accessible again as we are out of D3 state by now */
411 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
412
413 /* If CF is still set and we aren't resuming from hibernation
414 * then we maintained PCI Vaux power.
415 * Just undo the effect of ehci_pci_suspend().
416 */
417 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF &&
418 !hibernated) {
419 int mask = INTR_MASK;
420
421 ehci_prepare_ports_for_controller_resume(ehci);
422 if (!hcd->self.root_hub->do_remote_wakeup)
423 mask &= ~STS_PCD;
424 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
425 ehci_readl(ehci, &ehci->regs->intr_enable);
426 return 0;
427 }
428
429 usb_root_hub_lost_power(hcd->self.root_hub);
430
431 /* Else reset, to cope with power loss or flush-to-storage
432 * style "resume" having let BIOS kick in during reboot.
433 */
434 (void) ehci_halt(ehci);
435 (void) ehci_reset(ehci);
436 (void) ehci_pci_reinit(ehci, pdev);
437
438 /* emptying the schedule aborts any urbs */
439 spin_lock_irq(&ehci->lock);
440 if (ehci->reclaim)
441 end_unlink_async(ehci);
442 ehci_work(ehci);
443 spin_unlock_irq(&ehci->lock);
444
445 ehci_writel(ehci, ehci->command, &ehci->regs->command);
446 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
447 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
448
449 /* here we "know" root ports should always stay powered */
450 ehci_port_power(ehci, 1);
451
452 ehci->rh_state = EHCI_RH_SUSPENDED;
453 return 0; 379 return 0;
454} 380}
455#endif 381#endif
diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
index dfe881a34ae2..4b1d896d5a22 100644
--- a/drivers/usb/host/ehci-platform.c
+++ b/drivers/usb/host/ehci-platform.c
@@ -153,17 +153,16 @@ static int __devexit ehci_platform_remove(struct platform_device *dev)
153static int ehci_platform_suspend(struct device *dev) 153static int ehci_platform_suspend(struct device *dev)
154{ 154{
155 struct usb_hcd *hcd = dev_get_drvdata(dev); 155 struct usb_hcd *hcd = dev_get_drvdata(dev);
156 bool wakeup = device_may_wakeup(dev); 156 bool do_wakeup = device_may_wakeup(dev);
157 157
158 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd), wakeup); 158 return ehci_suspend(hcd, do_wakeup);
159 return 0;
160} 159}
161 160
162static int ehci_platform_resume(struct device *dev) 161static int ehci_platform_resume(struct device *dev)
163{ 162{
164 struct usb_hcd *hcd = dev_get_drvdata(dev); 163 struct usb_hcd *hcd = dev_get_drvdata(dev);
165 164
166 ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd)); 165 ehci_resume(hcd, false);
167 return 0; 166 return 0;
168} 167}
169 168
diff --git a/drivers/usb/host/ehci-pmcmsp.c b/drivers/usb/host/ehci-pmcmsp.c
index e8d54de44acc..087aee2a904f 100644
--- a/drivers/usb/host/ehci-pmcmsp.c
+++ b/drivers/usb/host/ehci-pmcmsp.c
@@ -78,27 +78,14 @@ static int ehci_msp_setup(struct usb_hcd *hcd)
78{ 78{
79 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 79 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
80 int retval; 80 int retval;
81
81 ehci->big_endian_mmio = 1; 82 ehci->big_endian_mmio = 1;
82 ehci->big_endian_desc = 1; 83 ehci->big_endian_desc = 1;
83 84
84 ehci->caps = hcd->regs; 85 ehci->caps = hcd->regs;
85 ehci->regs = hcd->regs +
86 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
87 dbg_hcs_params(ehci, "reset");
88 dbg_hcc_params(ehci, "reset");
89
90 /* cache this readonly data; minimize chip reads */
91 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
92 hcd->has_tt = 1; 86 hcd->has_tt = 1;
93 87
94 retval = ehci_halt(ehci); 88 retval = ehci_setup(hcd);
95 if (retval)
96 return retval;
97
98 ehci_reset(ehci);
99
100 /* data structure init */
101 retval = ehci_init(hcd);
102 if (retval) 89 if (retval)
103 return retval; 90 return retval;
104 91
diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c
index 41d11fe14252..bbbe89dfd886 100644
--- a/drivers/usb/host/ehci-ppc-of.c
+++ b/drivers/usb/host/ehci-ppc-of.c
@@ -17,24 +17,6 @@
17#include <linux/of.h> 17#include <linux/of.h>
18#include <linux/of_platform.h> 18#include <linux/of_platform.h>
19 19
20/* called during probe() after chip reset completes */
21static int ehci_ppc_of_setup(struct usb_hcd *hcd)
22{
23 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
24 int retval;
25
26 retval = ehci_halt(ehci);
27 if (retval)
28 return retval;
29
30 retval = ehci_init(hcd);
31 if (retval)
32 return retval;
33
34 ehci->sbrn = 0x20;
35 return ehci_reset(ehci);
36}
37
38 20
39static const struct hc_driver ehci_ppc_of_hc_driver = { 21static const struct hc_driver ehci_ppc_of_hc_driver = {
40 .description = hcd_name, 22 .description = hcd_name,
@@ -50,7 +32,7 @@ static const struct hc_driver ehci_ppc_of_hc_driver = {
50 /* 32 /*
51 * basic lifecycle operations 33 * basic lifecycle operations
52 */ 34 */
53 .reset = ehci_ppc_of_setup, 35 .reset = ehci_setup,
54 .start = ehci_run, 36 .start = ehci_run,
55 .stop = ehci_stop, 37 .stop = ehci_stop,
56 .shutdown = ehci_shutdown, 38 .shutdown = ehci_shutdown,
@@ -178,11 +160,6 @@ static int __devinit ehci_hcd_ppc_of_probe(struct platform_device *op)
178 ehci->big_endian_desc = 1; 160 ehci->big_endian_desc = 1;
179 161
180 ehci->caps = hcd->regs; 162 ehci->caps = hcd->regs;
181 ehci->regs = hcd->regs +
182 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
183
184 /* cache this readonly data; minimize chip reads */
185 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
186 163
187 if (of_device_is_compatible(dn, "ibm,usb-ehci-440epx")) { 164 if (of_device_is_compatible(dn, "ibm,usb-ehci-440epx")) {
188 rv = ppc44x_enable_bmt(dn); 165 rv = ppc44x_enable_bmt(dn);
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c
index a20e496eb479..45a356e9f138 100644
--- a/drivers/usb/host/ehci-ps3.c
+++ b/drivers/usb/host/ehci-ps3.c
@@ -55,28 +55,12 @@ static int ps3_ehci_hc_reset(struct usb_hcd *hcd)
55 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 55 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
56 56
57 ehci->big_endian_mmio = 1; 57 ehci->big_endian_mmio = 1;
58
59 ehci->caps = hcd->regs; 58 ehci->caps = hcd->regs;
60 ehci->regs = hcd->regs + HC_LENGTH(ehci, ehci_readl(ehci,
61 &ehci->caps->hc_capbase));
62
63 dbg_hcs_params(ehci, "reset");
64 dbg_hcc_params(ehci, "reset");
65
66 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
67
68 result = ehci_halt(ehci);
69 59
60 result = ehci_setup(hcd);
70 if (result) 61 if (result)
71 return result; 62 return result;
72 63
73 result = ehci_init(hcd);
74
75 if (result)
76 return result;
77
78 ehci_reset(ehci);
79
80 ps3_ehci_setup_insnreg(ehci); 64 ps3_ehci_setup_insnreg(ehci);
81 65
82 return result; 66 return result;
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 4378bf72bbac..9bc39ca460c8 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -100,7 +100,7 @@ qh_update (struct ehci_hcd *ehci, struct ehci_qh *qh, struct ehci_qtd *qtd)
100 * and set the pseudo-toggle in udev. Only usb_clear_halt() will 100 * and set the pseudo-toggle in udev. Only usb_clear_halt() will
101 * ever clear it. 101 * ever clear it.
102 */ 102 */
103 if (!(hw->hw_info1 & cpu_to_hc32(ehci, 1 << 14))) { 103 if (!(hw->hw_info1 & cpu_to_hc32(ehci, QH_TOGGLE_CTL))) {
104 unsigned is_out, epnum; 104 unsigned is_out, epnum;
105 105
106 is_out = qh->is_out; 106 is_out = qh->is_out;
@@ -265,7 +265,6 @@ __acquires(ehci->lock)
265 /* ... update hc-wide periodic stats (for usbfs) */ 265 /* ... update hc-wide periodic stats (for usbfs) */
266 ehci_to_hcd(ehci)->self.bandwidth_int_reqs--; 266 ehci_to_hcd(ehci)->self.bandwidth_int_reqs--;
267 } 267 }
268 qh_put (qh);
269 } 268 }
270 269
271 if (unlikely(urb->unlinked)) { 270 if (unlikely(urb->unlinked)) {
@@ -294,9 +293,6 @@ __acquires(ehci->lock)
294 spin_lock (&ehci->lock); 293 spin_lock (&ehci->lock);
295} 294}
296 295
297static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh);
298static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh);
299
300static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh); 296static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh);
301 297
302/* 298/*
@@ -326,7 +322,7 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
326 * 322 *
327 * It's a bug for qh->qh_state to be anything other than 323 * It's a bug for qh->qh_state to be anything other than
328 * QH_STATE_IDLE, unless our caller is scan_async() or 324 * QH_STATE_IDLE, unless our caller is scan_async() or
329 * scan_periodic(). 325 * scan_intr().
330 */ 326 */
331 state = qh->qh_state; 327 state = qh->qh_state;
332 qh->qh_state = QH_STATE_COMPLETING; 328 qh->qh_state = QH_STATE_COMPLETING;
@@ -434,7 +430,7 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
434 430
435 /* stop scanning when we reach qtds the hc is using */ 431 /* stop scanning when we reach qtds the hc is using */
436 } else if (likely (!stopped 432 } else if (likely (!stopped
437 && ehci->rh_state == EHCI_RH_RUNNING)) { 433 && ehci->rh_state >= EHCI_RH_RUNNING)) {
438 break; 434 break;
439 435
440 /* scan the whole queue for unlinks whenever it stops */ 436 /* scan the whole queue for unlinks whenever it stops */
@@ -442,7 +438,7 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
442 stopped = 1; 438 stopped = 1;
443 439
444 /* cancel everything if we halt, suspend, etc */ 440 /* cancel everything if we halt, suspend, etc */
445 if (ehci->rh_state != EHCI_RH_RUNNING) 441 if (ehci->rh_state < EHCI_RH_RUNNING)
446 last_status = -ESHUTDOWN; 442 last_status = -ESHUTDOWN;
447 443
448 /* this qtd is active; skip it unless a previous qtd 444 /* this qtd is active; skip it unless a previous qtd
@@ -836,7 +832,6 @@ qh_make (
836 is_input, 0, 832 is_input, 0,
837 hb_mult(maxp) * max_packet(maxp))); 833 hb_mult(maxp) * max_packet(maxp)));
838 qh->start = NO_FRAME; 834 qh->start = NO_FRAME;
839 qh->stamp = ehci->periodic_stamp;
840 835
841 if (urb->dev->speed == USB_SPEED_HIGH) { 836 if (urb->dev->speed == USB_SPEED_HIGH) {
842 qh->c_usecs = 0; 837 qh->c_usecs = 0;
@@ -887,7 +882,7 @@ qh_make (
887 /* using TT? */ 882 /* using TT? */
888 switch (urb->dev->speed) { 883 switch (urb->dev->speed) {
889 case USB_SPEED_LOW: 884 case USB_SPEED_LOW:
890 info1 |= (1 << 12); /* EPS "low" */ 885 info1 |= QH_LOW_SPEED;
891 /* FALL THROUGH */ 886 /* FALL THROUGH */
892 887
893 case USB_SPEED_FULL: 888 case USB_SPEED_FULL:
@@ -895,8 +890,8 @@ qh_make (
895 if (type != PIPE_INTERRUPT) 890 if (type != PIPE_INTERRUPT)
896 info1 |= (EHCI_TUNE_RL_TT << 28); 891 info1 |= (EHCI_TUNE_RL_TT << 28);
897 if (type == PIPE_CONTROL) { 892 if (type == PIPE_CONTROL) {
898 info1 |= (1 << 27); /* for TT */ 893 info1 |= QH_CONTROL_EP; /* for TT */
899 info1 |= 1 << 14; /* toggle from qtd */ 894 info1 |= QH_TOGGLE_CTL; /* toggle from qtd */
900 } 895 }
901 info1 |= maxp << 16; 896 info1 |= maxp << 16;
902 897
@@ -921,11 +916,11 @@ qh_make (
921 break; 916 break;
922 917
923 case USB_SPEED_HIGH: /* no TT involved */ 918 case USB_SPEED_HIGH: /* no TT involved */
924 info1 |= (2 << 12); /* EPS "high" */ 919 info1 |= QH_HIGH_SPEED;
925 if (type == PIPE_CONTROL) { 920 if (type == PIPE_CONTROL) {
926 info1 |= (EHCI_TUNE_RL_HS << 28); 921 info1 |= (EHCI_TUNE_RL_HS << 28);
927 info1 |= 64 << 16; /* usb2 fixed maxpacket */ 922 info1 |= 64 << 16; /* usb2 fixed maxpacket */
928 info1 |= 1 << 14; /* toggle from qtd */ 923 info1 |= QH_TOGGLE_CTL; /* toggle from qtd */
929 info2 |= (EHCI_TUNE_MULT_HS << 30); 924 info2 |= (EHCI_TUNE_MULT_HS << 30);
930 } else if (type == PIPE_BULK) { 925 } else if (type == PIPE_BULK) {
931 info1 |= (EHCI_TUNE_RL_HS << 28); 926 info1 |= (EHCI_TUNE_RL_HS << 28);
@@ -946,7 +941,7 @@ qh_make (
946 ehci_dbg(ehci, "bogus dev %p speed %d\n", urb->dev, 941 ehci_dbg(ehci, "bogus dev %p speed %d\n", urb->dev,
947 urb->dev->speed); 942 urb->dev->speed);
948done: 943done:
949 qh_put (qh); 944 qh_destroy(ehci, qh);
950 return NULL; 945 return NULL;
951 } 946 }
952 947
@@ -965,6 +960,31 @@ done:
965 960
966/*-------------------------------------------------------------------------*/ 961/*-------------------------------------------------------------------------*/
967 962
963static void enable_async(struct ehci_hcd *ehci)
964{
965 if (ehci->async_count++)
966 return;
967
968 /* Stop waiting to turn off the async schedule */
969 ehci->enabled_hrtimer_events &= ~BIT(EHCI_HRTIMER_DISABLE_ASYNC);
970
971 /* Don't start the schedule until ASS is 0 */
972 ehci_poll_ASS(ehci);
973 turn_on_io_watchdog(ehci);
974}
975
976static void disable_async(struct ehci_hcd *ehci)
977{
978 if (--ehci->async_count)
979 return;
980
981 /* The async schedule and async_unlink list are supposed to be empty */
982 WARN_ON(ehci->async->qh_next.qh || ehci->async_unlink);
983
984 /* Don't turn off the schedule until ASS is 1 */
985 ehci_poll_ASS(ehci);
986}
987
968/* move qh (and its qtds) onto async queue; maybe enable queue. */ 988/* move qh (and its qtds) onto async queue; maybe enable queue. */
969 989
970static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh) 990static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
@@ -978,24 +998,11 @@ static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
978 998
979 WARN_ON(qh->qh_state != QH_STATE_IDLE); 999 WARN_ON(qh->qh_state != QH_STATE_IDLE);
980 1000
981 /* (re)start the async schedule? */
982 head = ehci->async;
983 timer_action_done (ehci, TIMER_ASYNC_OFF);
984 if (!head->qh_next.qh) {
985 if (!(ehci->command & CMD_ASE)) {
986 /* in case a clear of CMD_ASE didn't take yet */
987 (void)handshake(ehci, &ehci->regs->status,
988 STS_ASS, 0, 150);
989 ehci->command |= CMD_ASE;
990 ehci_writel(ehci, ehci->command, &ehci->regs->command);
991 /* posted write need not be known to HC yet ... */
992 }
993 }
994
995 /* clear halt and/or toggle; and maybe recover from silicon quirk */ 1001 /* clear halt and/or toggle; and maybe recover from silicon quirk */
996 qh_refresh(ehci, qh); 1002 qh_refresh(ehci, qh);
997 1003
998 /* splice right after start */ 1004 /* splice right after start */
1005 head = ehci->async;
999 qh->qh_next = head->qh_next; 1006 qh->qh_next = head->qh_next;
1000 qh->hw->hw_next = head->hw->hw_next; 1007 qh->hw->hw_next = head->hw->hw_next;
1001 wmb (); 1008 wmb ();
@@ -1003,10 +1010,11 @@ static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
1003 head->qh_next.qh = qh; 1010 head->qh_next.qh = qh;
1004 head->hw->hw_next = dma; 1011 head->hw->hw_next = dma;
1005 1012
1006 qh_get(qh);
1007 qh->xacterrs = 0; 1013 qh->xacterrs = 0;
1008 qh->qh_state = QH_STATE_LINKED; 1014 qh->qh_state = QH_STATE_LINKED;
1009 /* qtd completions reported later by interrupt */ 1015 /* qtd completions reported later by interrupt */
1016
1017 enable_async(ehci);
1010} 1018}
1011 1019
1012/*-------------------------------------------------------------------------*/ 1020/*-------------------------------------------------------------------------*/
@@ -1090,7 +1098,7 @@ static struct ehci_qh *qh_append_tds (
1090 wmb (); 1098 wmb ();
1091 dummy->hw_token = token; 1099 dummy->hw_token = token;
1092 1100
1093 urb->hcpriv = qh_get (qh); 1101 urb->hcpriv = qh;
1094 } 1102 }
1095 } 1103 }
1096 return qh; 1104 return qh;
@@ -1155,117 +1163,155 @@ submit_async (
1155 1163
1156/*-------------------------------------------------------------------------*/ 1164/*-------------------------------------------------------------------------*/
1157 1165
1158/* the async qh for the qtds being reclaimed are now unlinked from the HC */ 1166static void single_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh)
1159
1160static void end_unlink_async (struct ehci_hcd *ehci)
1161{ 1167{
1162 struct ehci_qh *qh = ehci->reclaim; 1168 struct ehci_qh *prev;
1163 struct ehci_qh *next;
1164 1169
1165 iaa_watchdog_done(ehci); 1170 /* Add to the end of the list of QHs waiting for the next IAAD */
1171 qh->qh_state = QH_STATE_UNLINK;
1172 if (ehci->async_unlink)
1173 ehci->async_unlink_last->unlink_next = qh;
1174 else
1175 ehci->async_unlink = qh;
1176 ehci->async_unlink_last = qh;
1166 1177
1167 // qh->hw_next = cpu_to_hc32(qh->qh_dma); 1178 /* Unlink it from the schedule */
1168 qh->qh_state = QH_STATE_IDLE; 1179 prev = ehci->async;
1169 qh->qh_next.qh = NULL; 1180 while (prev->qh_next.qh != qh)
1170 qh_put (qh); // refcount from reclaim 1181 prev = prev->qh_next.qh;
1171 1182
1172 /* other unlink(s) may be pending (in QH_STATE_UNLINK_WAIT) */ 1183 prev->hw->hw_next = qh->hw->hw_next;
1173 next = qh->reclaim; 1184 prev->qh_next = qh->qh_next;
1174 ehci->reclaim = next; 1185 if (ehci->qh_scan_next == qh)
1175 qh->reclaim = NULL; 1186 ehci->qh_scan_next = qh->qh_next.qh;
1187}
1176 1188
1177 qh_completions (ehci, qh); 1189static void start_iaa_cycle(struct ehci_hcd *ehci, bool nested)
1190{
1191 /*
1192 * Do nothing if an IAA cycle is already running or
1193 * if one will be started shortly.
1194 */
1195 if (ehci->async_iaa || ehci->async_unlinking)
1196 return;
1178 1197
1179 if (!list_empty(&qh->qtd_list) && ehci->rh_state == EHCI_RH_RUNNING) { 1198 /* Do all the waiting QHs at once */
1180 qh_link_async (ehci, qh); 1199 ehci->async_iaa = ehci->async_unlink;
1181 } else { 1200 ehci->async_unlink = NULL;
1182 /* it's not free to turn the async schedule on/off; leave it
1183 * active but idle for a while once it empties.
1184 */
1185 if (ehci->rh_state == EHCI_RH_RUNNING
1186 && ehci->async->qh_next.qh == NULL)
1187 timer_action (ehci, TIMER_ASYNC_OFF);
1188 }
1189 qh_put(qh); /* refcount from async list */
1190 1201
1191 if (next) { 1202 /* If the controller isn't running, we don't have to wait for it */
1192 ehci->reclaim = NULL; 1203 if (unlikely(ehci->rh_state < EHCI_RH_RUNNING)) {
1193 start_unlink_async (ehci, next); 1204 if (!nested) /* Avoid recursion */
1205 end_unlink_async(ehci);
1206
1207 /* Otherwise start a new IAA cycle */
1208 } else if (likely(ehci->rh_state == EHCI_RH_RUNNING)) {
1209 /* Make sure the unlinks are all visible to the hardware */
1210 wmb();
1211
1212 ehci_writel(ehci, ehci->command | CMD_IAAD,
1213 &ehci->regs->command);
1214 ehci_readl(ehci, &ehci->regs->command);
1215 ehci_enable_event(ehci, EHCI_HRTIMER_IAA_WATCHDOG, true);
1194 } 1216 }
1217}
1218
1219/* the async qh for the qtds being unlinked are now gone from the HC */
1220
1221static void end_unlink_async(struct ehci_hcd *ehci)
1222{
1223 struct ehci_qh *qh;
1195 1224
1196 if (ehci->has_synopsys_hc_bug) 1225 if (ehci->has_synopsys_hc_bug)
1197 ehci_writel(ehci, (u32) ehci->async->qh_dma, 1226 ehci_writel(ehci, (u32) ehci->async->qh_dma,
1198 &ehci->regs->async_next); 1227 &ehci->regs->async_next);
1199}
1200
1201/* makes sure the async qh will become idle */
1202/* caller must own ehci->lock */
1203 1228
1204static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) 1229 /* Process the idle QHs */
1205{ 1230 restart:
1206 struct ehci_qh *prev; 1231 ehci->async_unlinking = true;
1232 while (ehci->async_iaa) {
1233 qh = ehci->async_iaa;
1234 ehci->async_iaa = qh->unlink_next;
1235 qh->unlink_next = NULL;
1236
1237 qh->qh_state = QH_STATE_IDLE;
1238 qh->qh_next.qh = NULL;
1239
1240 qh_completions(ehci, qh);
1241 if (!list_empty(&qh->qtd_list) &&
1242 ehci->rh_state == EHCI_RH_RUNNING)
1243 qh_link_async(ehci, qh);
1244 disable_async(ehci);
1245 }
1246 ehci->async_unlinking = false;
1207 1247
1208#ifdef DEBUG 1248 /* Start a new IAA cycle if any QHs are waiting for it */
1209 assert_spin_locked(&ehci->lock); 1249 if (ehci->async_unlink) {
1210 if (ehci->reclaim 1250 start_iaa_cycle(ehci, true);
1211 || (qh->qh_state != QH_STATE_LINKED 1251 if (unlikely(ehci->rh_state < EHCI_RH_RUNNING))
1212 && qh->qh_state != QH_STATE_UNLINK_WAIT) 1252 goto restart;
1213 ) 1253 }
1214 BUG (); 1254}
1215#endif
1216 1255
1217 /* stop async schedule right now? */ 1256static void unlink_empty_async(struct ehci_hcd *ehci)
1218 if (unlikely (qh == ehci->async)) { 1257{
1219 /* can't get here without STS_ASS set */ 1258 struct ehci_qh *qh, *next;
1220 if (ehci->rh_state != EHCI_RH_HALTED 1259 bool stopped = (ehci->rh_state < EHCI_RH_RUNNING);
1221 && !ehci->reclaim) { 1260 bool check_unlinks_later = false;
1222 /* ... and CMD_IAAD clear */ 1261
1223 ehci->command &= ~CMD_ASE; 1262 /* Unlink all the async QHs that have been empty for a timer cycle */
1224 ehci_writel(ehci, ehci->command, &ehci->regs->command); 1263 next = ehci->async->qh_next.qh;
1225 wmb (); 1264 while (next) {
1226 // handshake later, if we need to 1265 qh = next;
1227 timer_action_done (ehci, TIMER_ASYNC_OFF); 1266 next = qh->qh_next.qh;
1267
1268 if (list_empty(&qh->qtd_list) &&
1269 qh->qh_state == QH_STATE_LINKED) {
1270 if (!stopped && qh->unlink_cycle ==
1271 ehci->async_unlink_cycle)
1272 check_unlinks_later = true;
1273 else
1274 single_unlink_async(ehci, qh);
1228 } 1275 }
1229 return;
1230 } 1276 }
1231 1277
1232 qh->qh_state = QH_STATE_UNLINK; 1278 /* Start a new IAA cycle if any QHs are waiting for it */
1233 ehci->reclaim = qh = qh_get (qh); 1279 if (ehci->async_unlink)
1280 start_iaa_cycle(ehci, false);
1234 1281
1235 prev = ehci->async; 1282 /* QHs that haven't been empty for long enough will be handled later */
1236 while (prev->qh_next.qh != qh) 1283 if (check_unlinks_later) {
1237 prev = prev->qh_next.qh; 1284 ehci_enable_event(ehci, EHCI_HRTIMER_ASYNC_UNLINKS, true);
1285 ++ehci->async_unlink_cycle;
1286 }
1287}
1238 1288
1239 prev->hw->hw_next = qh->hw->hw_next; 1289/* makes sure the async qh will become idle */
1240 prev->qh_next = qh->qh_next; 1290/* caller must own ehci->lock */
1241 if (ehci->qh_scan_next == qh)
1242 ehci->qh_scan_next = qh->qh_next.qh;
1243 wmb ();
1244 1291
1245 /* If the controller isn't running, we don't have to wait for it */ 1292static void start_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh)
1246 if (unlikely(ehci->rh_state != EHCI_RH_RUNNING)) { 1293{
1247 /* if (unlikely (qh->reclaim != 0)) 1294 /*
1248 * this will recurse, probably not much 1295 * If the QH isn't linked then there's nothing we can do
1249 */ 1296 * unless we were called during a giveback, in which case
1250 end_unlink_async (ehci); 1297 * qh_completions() has to deal with it.
1298 */
1299 if (qh->qh_state != QH_STATE_LINKED) {
1300 if (qh->qh_state == QH_STATE_COMPLETING)
1301 qh->needs_rescan = 1;
1251 return; 1302 return;
1252 } 1303 }
1253 1304
1254 ehci_writel(ehci, ehci->command | CMD_IAAD, &ehci->regs->command); 1305 single_unlink_async(ehci, qh);
1255 (void)ehci_readl(ehci, &ehci->regs->command); 1306 start_iaa_cycle(ehci, false);
1256 iaa_watchdog_start(ehci);
1257} 1307}
1258 1308
1259/*-------------------------------------------------------------------------*/ 1309/*-------------------------------------------------------------------------*/
1260 1310
1261static void scan_async (struct ehci_hcd *ehci) 1311static void scan_async (struct ehci_hcd *ehci)
1262{ 1312{
1263 bool stopped;
1264 struct ehci_qh *qh; 1313 struct ehci_qh *qh;
1265 enum ehci_timer_action action = TIMER_IO_WATCHDOG; 1314 bool check_unlinks_later = false;
1266
1267 timer_action_done (ehci, TIMER_ASYNC_SHRINK);
1268 stopped = (ehci->rh_state != EHCI_RH_RUNNING);
1269 1315
1270 ehci->qh_scan_next = ehci->async->qh_next.qh; 1316 ehci->qh_scan_next = ehci->async->qh_next.qh;
1271 while (ehci->qh_scan_next) { 1317 while (ehci->qh_scan_next) {
@@ -1281,33 +1327,30 @@ static void scan_async (struct ehci_hcd *ehci)
1281 * drops the lock. That's why ehci->qh_scan_next 1327 * drops the lock. That's why ehci->qh_scan_next
1282 * always holds the next qh to scan; if the next qh 1328 * always holds the next qh to scan; if the next qh
1283 * gets unlinked then ehci->qh_scan_next is adjusted 1329 * gets unlinked then ehci->qh_scan_next is adjusted
1284 * in start_unlink_async(). 1330 * in single_unlink_async().
1285 */ 1331 */
1286 qh = qh_get(qh);
1287 temp = qh_completions(ehci, qh); 1332 temp = qh_completions(ehci, qh);
1288 if (qh->needs_rescan) 1333 if (qh->needs_rescan) {
1289 unlink_async(ehci, qh); 1334 start_unlink_async(ehci, qh);
1290 qh->unlink_time = jiffies + EHCI_SHRINK_JIFFIES; 1335 } else if (list_empty(&qh->qtd_list)
1291 qh_put(qh); 1336 && qh->qh_state == QH_STATE_LINKED) {
1292 if (temp != 0) 1337 qh->unlink_cycle = ehci->async_unlink_cycle;
1338 check_unlinks_later = true;
1339 } else if (temp != 0)
1293 goto rescan; 1340 goto rescan;
1294 } 1341 }
1342 }
1295 1343
1296 /* unlink idle entries, reducing DMA usage as well 1344 /*
1297 * as HCD schedule-scanning costs. delay for any qh 1345 * Unlink empty entries, reducing DMA usage as well
1298 * we just scanned, there's a not-unusual case that it 1346 * as HCD schedule-scanning costs. Delay for any qh
1299 * doesn't stay idle for long. 1347 * we just scanned, there's a not-unusual case that it
1300 * (plus, avoids some kind of re-activation race.) 1348 * doesn't stay idle for long.
1301 */ 1349 */
1302 if (list_empty(&qh->qtd_list) 1350 if (check_unlinks_later && ehci->rh_state == EHCI_RH_RUNNING &&
1303 && qh->qh_state == QH_STATE_LINKED) { 1351 !(ehci->enabled_hrtimer_events &
1304 if (!ehci->reclaim && (stopped || 1352 BIT(EHCI_HRTIMER_ASYNC_UNLINKS))) {
1305 time_after_eq(jiffies, qh->unlink_time))) 1353 ehci_enable_event(ehci, EHCI_HRTIMER_ASYNC_UNLINKS, true);
1306 start_unlink_async(ehci, qh); 1354 ++ehci->async_unlink_cycle;
1307 else
1308 action = TIMER_ASYNC_SHRINK;
1309 }
1310 } 1355 }
1311 if (action == TIMER_ASYNC_SHRINK)
1312 timer_action (ehci, TIMER_ASYNC_SHRINK);
1313} 1356}
diff --git a/drivers/usb/host/ehci-s5p.c b/drivers/usb/host/ehci-s5p.c
index c474cec064e4..9d8f1dd57cb3 100644
--- a/drivers/usb/host/ehci-s5p.c
+++ b/drivers/usb/host/ehci-s5p.c
@@ -13,7 +13,9 @@
13 */ 13 */
14 14
15#include <linux/clk.h> 15#include <linux/clk.h>
16#include <linux/of.h>
16#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/of_gpio.h>
17#include <plat/ehci.h> 19#include <plat/ehci.h>
18#include <plat/usb-phy.h> 20#include <plat/usb-phy.h>
19 21
@@ -40,7 +42,7 @@ static const struct hc_driver s5p_ehci_hc_driver = {
40 .irq = ehci_irq, 42 .irq = ehci_irq,
41 .flags = HCD_MEMORY | HCD_USB2, 43 .flags = HCD_MEMORY | HCD_USB2,
42 44
43 .reset = ehci_init, 45 .reset = ehci_setup,
44 .start = ehci_run, 46 .start = ehci_run,
45 .stop = ehci_stop, 47 .stop = ehci_stop,
46 .shutdown = ehci_shutdown, 48 .shutdown = ehci_shutdown,
@@ -63,6 +65,26 @@ static const struct hc_driver s5p_ehci_hc_driver = {
63 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 65 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
64}; 66};
65 67
68static void s5p_setup_vbus_gpio(struct platform_device *pdev)
69{
70 int err;
71 int gpio;
72
73 if (!pdev->dev.of_node)
74 return;
75
76 gpio = of_get_named_gpio(pdev->dev.of_node,
77 "samsung,vbus-gpio", 0);
78 if (!gpio_is_valid(gpio))
79 return;
80
81 err = gpio_request_one(gpio, GPIOF_OUT_INIT_HIGH, "ehci_vbus_gpio");
82 if (err)
83 dev_err(&pdev->dev, "can't request ehci vbus gpio %d", gpio);
84}
85
86static u64 ehci_s5p_dma_mask = DMA_BIT_MASK(32);
87
66static int __devinit s5p_ehci_probe(struct platform_device *pdev) 88static int __devinit s5p_ehci_probe(struct platform_device *pdev)
67{ 89{
68 struct s5p_ehci_platdata *pdata; 90 struct s5p_ehci_platdata *pdata;
@@ -79,7 +101,20 @@ static int __devinit s5p_ehci_probe(struct platform_device *pdev)
79 return -EINVAL; 101 return -EINVAL;
80 } 102 }
81 103
82 s5p_ehci = kzalloc(sizeof(struct s5p_ehci_hcd), GFP_KERNEL); 104 /*
105 * Right now device-tree probed devices don't get dma_mask set.
106 * Since shared usb code relies on it, set it here for now.
107 * Once we move to full device tree support this will vanish off.
108 */
109 if (!pdev->dev.dma_mask)
110 pdev->dev.dma_mask = &ehci_s5p_dma_mask;
111 if (!pdev->dev.coherent_dma_mask)
112 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
113
114 s5p_setup_vbus_gpio(pdev);
115
116 s5p_ehci = devm_kzalloc(&pdev->dev, sizeof(struct s5p_ehci_hcd),
117 GFP_KERNEL);
83 if (!s5p_ehci) 118 if (!s5p_ehci)
84 return -ENOMEM; 119 return -ENOMEM;
85 120
@@ -89,8 +124,7 @@ static int __devinit s5p_ehci_probe(struct platform_device *pdev)
89 dev_name(&pdev->dev)); 124 dev_name(&pdev->dev));
90 if (!hcd) { 125 if (!hcd) {
91 dev_err(&pdev->dev, "Unable to create HCD\n"); 126 dev_err(&pdev->dev, "Unable to create HCD\n");
92 err = -ENOMEM; 127 return -ENOMEM;
93 goto fail_hcd;
94 } 128 }
95 129
96 s5p_ehci->hcd = hcd; 130 s5p_ehci->hcd = hcd;
@@ -115,7 +149,7 @@ static int __devinit s5p_ehci_probe(struct platform_device *pdev)
115 149
116 hcd->rsrc_start = res->start; 150 hcd->rsrc_start = res->start;
117 hcd->rsrc_len = resource_size(res); 151 hcd->rsrc_len = resource_size(res);
118 hcd->regs = ioremap(res->start, resource_size(res)); 152 hcd->regs = devm_ioremap(&pdev->dev, res->start, hcd->rsrc_len);
119 if (!hcd->regs) { 153 if (!hcd->regs) {
120 dev_err(&pdev->dev, "Failed to remap I/O memory\n"); 154 dev_err(&pdev->dev, "Failed to remap I/O memory\n");
121 err = -ENOMEM; 155 err = -ENOMEM;
@@ -126,7 +160,7 @@ static int __devinit s5p_ehci_probe(struct platform_device *pdev)
126 if (!irq) { 160 if (!irq) {
127 dev_err(&pdev->dev, "Failed to get IRQ\n"); 161 dev_err(&pdev->dev, "Failed to get IRQ\n");
128 err = -ENODEV; 162 err = -ENODEV;
129 goto fail; 163 goto fail_io;
130 } 164 }
131 165
132 if (pdata->phy_init) 166 if (pdata->phy_init)
@@ -134,40 +168,26 @@ static int __devinit s5p_ehci_probe(struct platform_device *pdev)
134 168
135 ehci = hcd_to_ehci(hcd); 169 ehci = hcd_to_ehci(hcd);
136 ehci->caps = hcd->regs; 170 ehci->caps = hcd->regs;
137 ehci->regs = hcd->regs +
138 HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
139 171
140 /* DMA burst Enable */ 172 /* DMA burst Enable */
141 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); 173 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
142 174
143 dbg_hcs_params(ehci, "reset");
144 dbg_hcc_params(ehci, "reset");
145
146 /* cache this readonly data; minimize chip reads */
147 ehci->hcs_params = readl(&ehci->caps->hcs_params);
148
149 ehci_reset(ehci);
150
151 err = usb_add_hcd(hcd, irq, IRQF_SHARED); 175 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
152 if (err) { 176 if (err) {
153 dev_err(&pdev->dev, "Failed to add USB HCD\n"); 177 dev_err(&pdev->dev, "Failed to add USB HCD\n");
154 goto fail; 178 goto fail_io;
155 } 179 }
156 180
157 platform_set_drvdata(pdev, s5p_ehci); 181 platform_set_drvdata(pdev, s5p_ehci);
158 182
159 return 0; 183 return 0;
160 184
161fail:
162 iounmap(hcd->regs);
163fail_io: 185fail_io:
164 clk_disable(s5p_ehci->clk); 186 clk_disable(s5p_ehci->clk);
165fail_clken: 187fail_clken:
166 clk_put(s5p_ehci->clk); 188 clk_put(s5p_ehci->clk);
167fail_clk: 189fail_clk:
168 usb_put_hcd(hcd); 190 usb_put_hcd(hcd);
169fail_hcd:
170 kfree(s5p_ehci);
171 return err; 191 return err;
172} 192}
173 193
@@ -182,13 +202,10 @@ static int __devexit s5p_ehci_remove(struct platform_device *pdev)
182 if (pdata && pdata->phy_exit) 202 if (pdata && pdata->phy_exit)
183 pdata->phy_exit(pdev, S5P_USB_PHY_HOST); 203 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
184 204
185 iounmap(hcd->regs);
186
187 clk_disable(s5p_ehci->clk); 205 clk_disable(s5p_ehci->clk);
188 clk_put(s5p_ehci->clk); 206 clk_put(s5p_ehci->clk);
189 207
190 usb_put_hcd(hcd); 208 usb_put_hcd(hcd);
191 kfree(s5p_ehci);
192 209
193 return 0; 210 return 0;
194} 211}
@@ -207,27 +224,12 @@ static int s5p_ehci_suspend(struct device *dev)
207{ 224{
208 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev); 225 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
209 struct usb_hcd *hcd = s5p_ehci->hcd; 226 struct usb_hcd *hcd = s5p_ehci->hcd;
210 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 227 bool do_wakeup = device_may_wakeup(dev);
211 struct platform_device *pdev = to_platform_device(dev); 228 struct platform_device *pdev = to_platform_device(dev);
212 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; 229 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
213 unsigned long flags; 230 int rc;
214 int rc = 0;
215
216 if (time_before(jiffies, ehci->next_statechange))
217 msleep(20);
218
219 /*
220 * Root hub was already suspended. Disable irq emission and
221 * mark HW unaccessible. The PM and USB cores make sure that
222 * the root hub is either suspended or stopped.
223 */
224 ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
225 spin_lock_irqsave(&ehci->lock, flags);
226 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
227 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
228 231
229 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 232 rc = ehci_suspend(hcd, do_wakeup);
230 spin_unlock_irqrestore(&ehci->lock, flags);
231 233
232 if (pdata && pdata->phy_exit) 234 if (pdata && pdata->phy_exit)
233 pdata->phy_exit(pdev, S5P_USB_PHY_HOST); 235 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
@@ -241,7 +243,6 @@ static int s5p_ehci_resume(struct device *dev)
241{ 243{
242 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev); 244 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev);
243 struct usb_hcd *hcd = s5p_ehci->hcd; 245 struct usb_hcd *hcd = s5p_ehci->hcd;
244 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
245 struct platform_device *pdev = to_platform_device(dev); 246 struct platform_device *pdev = to_platform_device(dev);
246 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; 247 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
247 248
@@ -253,44 +254,7 @@ static int s5p_ehci_resume(struct device *dev)
253 /* DMA burst Enable */ 254 /* DMA burst Enable */
254 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); 255 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
255 256
256 if (time_before(jiffies, ehci->next_statechange)) 257 ehci_resume(hcd, false);
257 msleep(100);
258
259 /* Mark hardware accessible again as we are out of D3 state by now */
260 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
261
262 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
263 int mask = INTR_MASK;
264
265 ehci_prepare_ports_for_controller_resume(ehci);
266 if (!hcd->self.root_hub->do_remote_wakeup)
267 mask &= ~STS_PCD;
268 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
269 ehci_readl(ehci, &ehci->regs->intr_enable);
270 return 0;
271 }
272
273 usb_root_hub_lost_power(hcd->self.root_hub);
274
275 (void) ehci_halt(ehci);
276 (void) ehci_reset(ehci);
277
278 /* emptying the schedule aborts any urbs */
279 spin_lock_irq(&ehci->lock);
280 if (ehci->reclaim)
281 end_unlink_async(ehci);
282 ehci_work(ehci);
283 spin_unlock_irq(&ehci->lock);
284
285 ehci_writel(ehci, ehci->command, &ehci->regs->command);
286 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
287 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
288
289 /* here we "know" root ports should always stay powered */
290 ehci_port_power(ehci, 1);
291
292 ehci->rh_state = EHCI_RH_SUSPENDED;
293
294 return 0; 258 return 0;
295} 259}
296#else 260#else
@@ -303,6 +267,14 @@ static const struct dev_pm_ops s5p_ehci_pm_ops = {
303 .resume = s5p_ehci_resume, 267 .resume = s5p_ehci_resume,
304}; 268};
305 269
270#ifdef CONFIG_OF
271static const struct of_device_id exynos_ehci_match[] = {
272 { .compatible = "samsung,exynos-ehci" },
273 {},
274};
275MODULE_DEVICE_TABLE(of, exynos_ehci_match);
276#endif
277
306static struct platform_driver s5p_ehci_driver = { 278static struct platform_driver s5p_ehci_driver = {
307 .probe = s5p_ehci_probe, 279 .probe = s5p_ehci_probe,
308 .remove = __devexit_p(s5p_ehci_remove), 280 .remove = __devexit_p(s5p_ehci_remove),
@@ -311,6 +283,7 @@ static struct platform_driver s5p_ehci_driver = {
311 .name = "s5p-ehci", 283 .name = "s5p-ehci",
312 .owner = THIS_MODULE, 284 .owner = THIS_MODULE,
313 .pm = &s5p_ehci_pm_ops, 285 .pm = &s5p_ehci_pm_ops,
286 .of_match_table = of_match_ptr(exynos_ehci_match),
314 } 287 }
315}; 288};
316 289
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 33182c6d1ff9..7cf3da7babf0 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -479,70 +479,26 @@ static int tt_no_collision (
479 479
480/*-------------------------------------------------------------------------*/ 480/*-------------------------------------------------------------------------*/
481 481
482static int enable_periodic (struct ehci_hcd *ehci) 482static void enable_periodic(struct ehci_hcd *ehci)
483{ 483{
484 int status; 484 if (ehci->periodic_count++)
485 485 return;
486 if (ehci->periodic_sched++)
487 return 0;
488
489 /* did clearing PSE did take effect yet?
490 * takes effect only at frame boundaries...
491 */
492 status = handshake_on_error_set_halt(ehci, &ehci->regs->status,
493 STS_PSS, 0, 9 * 125);
494 if (status) {
495 usb_hc_died(ehci_to_hcd(ehci));
496 return status;
497 }
498 486
499 ehci->command |= CMD_PSE; 487 /* Stop waiting to turn off the periodic schedule */
500 ehci_writel(ehci, ehci->command, &ehci->regs->command); 488 ehci->enabled_hrtimer_events &= ~BIT(EHCI_HRTIMER_DISABLE_PERIODIC);
501 /* posted write ... PSS happens later */
502 489
503 /* make sure ehci_work scans these */ 490 /* Don't start the schedule until PSS is 0 */
504 ehci->next_uframe = ehci_read_frame_index(ehci) 491 ehci_poll_PSS(ehci);
505 % (ehci->periodic_size << 3); 492 turn_on_io_watchdog(ehci);
506 if (unlikely(ehci->broken_periodic))
507 ehci->last_periodic_enable = ktime_get_real();
508 return 0;
509} 493}
510 494
511static int disable_periodic (struct ehci_hcd *ehci) 495static void disable_periodic(struct ehci_hcd *ehci)
512{ 496{
513 int status; 497 if (--ehci->periodic_count)
514 498 return;
515 if (--ehci->periodic_sched)
516 return 0;
517
518 if (unlikely(ehci->broken_periodic)) {
519 /* delay experimentally determined */
520 ktime_t safe = ktime_add_us(ehci->last_periodic_enable, 1000);
521 ktime_t now = ktime_get_real();
522 s64 delay = ktime_us_delta(safe, now);
523
524 if (unlikely(delay > 0))
525 udelay(delay);
526 }
527
528 /* did setting PSE not take effect yet?
529 * takes effect only at frame boundaries...
530 */
531 status = handshake_on_error_set_halt(ehci, &ehci->regs->status,
532 STS_PSS, STS_PSS, 9 * 125);
533 if (status) {
534 usb_hc_died(ehci_to_hcd(ehci));
535 return status;
536 }
537
538 ehci->command &= ~CMD_PSE;
539 ehci_writel(ehci, ehci->command, &ehci->regs->command);
540 /* posted write ... */
541
542 free_cached_lists(ehci);
543 499
544 ehci->next_uframe = -1; 500 /* Don't turn off the schedule until PSS is 1 */
545 return 0; 501 ehci_poll_PSS(ehci);
546} 502}
547 503
548/*-------------------------------------------------------------------------*/ 504/*-------------------------------------------------------------------------*/
@@ -553,7 +509,7 @@ static int disable_periodic (struct ehci_hcd *ehci)
553 * this just links in a qh; caller guarantees uframe masks are set right. 509 * this just links in a qh; caller guarantees uframe masks are set right.
554 * no FSTN support (yet; ehci 0.96+) 510 * no FSTN support (yet; ehci 0.96+)
555 */ 511 */
556static int qh_link_periodic (struct ehci_hcd *ehci, struct ehci_qh *qh) 512static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
557{ 513{
558 unsigned i; 514 unsigned i;
559 unsigned period = qh->period; 515 unsigned period = qh->period;
@@ -606,28 +562,38 @@ static int qh_link_periodic (struct ehci_hcd *ehci, struct ehci_qh *qh)
606 } 562 }
607 qh->qh_state = QH_STATE_LINKED; 563 qh->qh_state = QH_STATE_LINKED;
608 qh->xacterrs = 0; 564 qh->xacterrs = 0;
609 qh_get (qh);
610 565
611 /* update per-qh bandwidth for usbfs */ 566 /* update per-qh bandwidth for usbfs */
612 ehci_to_hcd(ehci)->self.bandwidth_allocated += qh->period 567 ehci_to_hcd(ehci)->self.bandwidth_allocated += qh->period
613 ? ((qh->usecs + qh->c_usecs) / qh->period) 568 ? ((qh->usecs + qh->c_usecs) / qh->period)
614 : (qh->usecs * 8); 569 : (qh->usecs * 8);
615 570
571 list_add(&qh->intr_node, &ehci->intr_qh_list);
572
616 /* maybe enable periodic schedule processing */ 573 /* maybe enable periodic schedule processing */
617 return enable_periodic(ehci); 574 ++ehci->intr_count;
575 enable_periodic(ehci);
618} 576}
619 577
620static int qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh) 578static void qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
621{ 579{
622 unsigned i; 580 unsigned i;
623 unsigned period; 581 unsigned period;
624 582
625 // FIXME: 583 /*
626 // IF this isn't high speed 584 * If qh is for a low/full-speed device, simply unlinking it
627 // and this qh is active in the current uframe 585 * could interfere with an ongoing split transaction. To unlink
628 // (and overlay token SplitXstate is false?) 586 * it safely would require setting the QH_INACTIVATE bit and
629 // THEN 587 * waiting at least one frame, as described in EHCI 4.12.2.5.
630 // qh->hw_info1 |= cpu_to_hc32(1 << 7 /* "ignore" */); 588 *
589 * We won't bother with any of this. Instead, we assume that the
590 * only reason for unlinking an interrupt QH while the current URB
591 * is still active is to dequeue all the URBs (flush the whole
592 * endpoint queue).
593 *
594 * If rebalancing the periodic schedule is ever implemented, this
595 * approach will no longer be valid.
596 */
631 597
632 /* high bandwidth, or otherwise part of every microframe */ 598 /* high bandwidth, or otherwise part of every microframe */
633 if ((period = qh->period) == 0) 599 if ((period = qh->period) == 0)
@@ -650,18 +616,15 @@ static int qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
650 /* qh->qh_next still "live" to HC */ 616 /* qh->qh_next still "live" to HC */
651 qh->qh_state = QH_STATE_UNLINK; 617 qh->qh_state = QH_STATE_UNLINK;
652 qh->qh_next.ptr = NULL; 618 qh->qh_next.ptr = NULL;
653 qh_put (qh);
654 619
655 /* maybe turn off periodic schedule */ 620 if (ehci->qh_scan_next == qh)
656 return disable_periodic(ehci); 621 ehci->qh_scan_next = list_entry(qh->intr_node.next,
622 struct ehci_qh, intr_node);
623 list_del(&qh->intr_node);
657} 624}
658 625
659static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh) 626static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
660{ 627{
661 unsigned wait;
662 struct ehci_qh_hw *hw = qh->hw;
663 int rc;
664
665 /* If the QH isn't linked then there's nothing we can do 628 /* If the QH isn't linked then there's nothing we can do
666 * unless we were called during a giveback, in which case 629 * unless we were called during a giveback, in which case
667 * qh_completions() has to deal with it. 630 * qh_completions() has to deal with it.
@@ -674,28 +637,45 @@ static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh)
674 637
675 qh_unlink_periodic (ehci, qh); 638 qh_unlink_periodic (ehci, qh);
676 639
677 /* simple/paranoid: always delay, expecting the HC needs to read 640 /* Make sure the unlinks are visible before starting the timer */
678 * qh->hw_next or finish a writeback after SPLIT/CSPLIT ... and 641 wmb();
679 * expect khubd to clean up after any CSPLITs we won't issue. 642
680 * active high speed queues may need bigger delays... 643 /*
644 * The EHCI spec doesn't say how long it takes the controller to
645 * stop accessing an unlinked interrupt QH. The timer delay is
646 * 9 uframes; presumably that will be long enough.
681 */ 647 */
682 if (list_empty (&qh->qtd_list) 648 qh->unlink_cycle = ehci->intr_unlink_cycle;
683 || (cpu_to_hc32(ehci, QH_CMASK) 649
684 & hw->hw_info2) != 0) 650 /* New entries go at the end of the intr_unlink list */
685 wait = 2; 651 if (ehci->intr_unlink)
652 ehci->intr_unlink_last->unlink_next = qh;
686 else 653 else
687 wait = 55; /* worst case: 3 * 1024 */ 654 ehci->intr_unlink = qh;
655 ehci->intr_unlink_last = qh;
656
657 if (ehci->intr_unlinking)
658 ; /* Avoid recursive calls */
659 else if (ehci->rh_state < EHCI_RH_RUNNING)
660 ehci_handle_intr_unlinks(ehci);
661 else if (ehci->intr_unlink == qh) {
662 ehci_enable_event(ehci, EHCI_HRTIMER_UNLINK_INTR, true);
663 ++ehci->intr_unlink_cycle;
664 }
665}
666
667static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
668{
669 struct ehci_qh_hw *hw = qh->hw;
670 int rc;
688 671
689 udelay (wait);
690 qh->qh_state = QH_STATE_IDLE; 672 qh->qh_state = QH_STATE_IDLE;
691 hw->hw_next = EHCI_LIST_END(ehci); 673 hw->hw_next = EHCI_LIST_END(ehci);
692 wmb ();
693 674
694 qh_completions(ehci, qh); 675 qh_completions(ehci, qh);
695 676
696 /* reschedule QH iff another request is queued */ 677 /* reschedule QH iff another request is queued */
697 if (!list_empty(&qh->qtd_list) && 678 if (!list_empty(&qh->qtd_list) && ehci->rh_state == EHCI_RH_RUNNING) {
698 ehci->rh_state == EHCI_RH_RUNNING) {
699 rc = qh_schedule(ehci, qh); 679 rc = qh_schedule(ehci, qh);
700 680
701 /* An error here likely indicates handshake failure 681 /* An error here likely indicates handshake failure
@@ -708,6 +688,10 @@ static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh)
708 ehci_err(ehci, "can't reschedule qh %p, err %d\n", 688 ehci_err(ehci, "can't reschedule qh %p, err %d\n",
709 qh, rc); 689 qh, rc);
710 } 690 }
691
692 /* maybe turn off periodic schedule */
693 --ehci->intr_count;
694 disable_periodic(ehci);
711} 695}
712 696
713/*-------------------------------------------------------------------------*/ 697/*-------------------------------------------------------------------------*/
@@ -884,7 +868,7 @@ static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh)
884 ehci_dbg (ehci, "reused qh %p schedule\n", qh); 868 ehci_dbg (ehci, "reused qh %p schedule\n", qh);
885 869
886 /* stuff into the periodic schedule */ 870 /* stuff into the periodic schedule */
887 status = qh_link_periodic (ehci, qh); 871 qh_link_periodic(ehci, qh);
888done: 872done:
889 return status; 873 return status;
890} 874}
@@ -944,6 +928,35 @@ done_not_linked:
944 return status; 928 return status;
945} 929}
946 930
931static void scan_intr(struct ehci_hcd *ehci)
932{
933 struct ehci_qh *qh;
934
935 list_for_each_entry_safe(qh, ehci->qh_scan_next, &ehci->intr_qh_list,
936 intr_node) {
937 rescan:
938 /* clean any finished work for this qh */
939 if (!list_empty(&qh->qtd_list)) {
940 int temp;
941
942 /*
943 * Unlinks could happen here; completion reporting
944 * drops the lock. That's why ehci->qh_scan_next
945 * always holds the next qh to scan; if the next qh
946 * gets unlinked then ehci->qh_scan_next is adjusted
947 * in qh_unlink_periodic().
948 */
949 temp = qh_completions(ehci, qh);
950 if (unlikely(qh->needs_rescan ||
951 (list_empty(&qh->qtd_list) &&
952 qh->qh_state == QH_STATE_LINKED)))
953 start_unlink_intr(ehci, qh);
954 else if (temp != 0)
955 goto rescan;
956 }
957 }
958}
959
947/*-------------------------------------------------------------------------*/ 960/*-------------------------------------------------------------------------*/
948 961
949/* ehci_iso_stream ops work with both ITD and SITD */ 962/* ehci_iso_stream ops work with both ITD and SITD */
@@ -958,7 +971,6 @@ iso_stream_alloc (gfp_t mem_flags)
958 INIT_LIST_HEAD(&stream->td_list); 971 INIT_LIST_HEAD(&stream->td_list);
959 INIT_LIST_HEAD(&stream->free_list); 972 INIT_LIST_HEAD(&stream->free_list);
960 stream->next_uframe = -1; 973 stream->next_uframe = -1;
961 stream->refcount = 1;
962 } 974 }
963 return stream; 975 return stream;
964} 976}
@@ -1058,57 +1070,6 @@ iso_stream_init (
1058 stream->maxp = maxp; 1070 stream->maxp = maxp;
1059} 1071}
1060 1072
1061static void
1062iso_stream_put(struct ehci_hcd *ehci, struct ehci_iso_stream *stream)
1063{
1064 stream->refcount--;
1065
1066 /* free whenever just a dev->ep reference remains.
1067 * not like a QH -- no persistent state (toggle, halt)
1068 */
1069 if (stream->refcount == 1) {
1070 // BUG_ON (!list_empty(&stream->td_list));
1071
1072 while (!list_empty (&stream->free_list)) {
1073 struct list_head *entry;
1074
1075 entry = stream->free_list.next;
1076 list_del (entry);
1077
1078 /* knows about ITD vs SITD */
1079 if (stream->highspeed) {
1080 struct ehci_itd *itd;
1081
1082 itd = list_entry (entry, struct ehci_itd,
1083 itd_list);
1084 dma_pool_free (ehci->itd_pool, itd,
1085 itd->itd_dma);
1086 } else {
1087 struct ehci_sitd *sitd;
1088
1089 sitd = list_entry (entry, struct ehci_sitd,
1090 sitd_list);
1091 dma_pool_free (ehci->sitd_pool, sitd,
1092 sitd->sitd_dma);
1093 }
1094 }
1095
1096 stream->bEndpointAddress &= 0x0f;
1097 if (stream->ep)
1098 stream->ep->hcpriv = NULL;
1099
1100 kfree(stream);
1101 }
1102}
1103
1104static inline struct ehci_iso_stream *
1105iso_stream_get (struct ehci_iso_stream *stream)
1106{
1107 if (likely (stream != NULL))
1108 stream->refcount++;
1109 return stream;
1110}
1111
1112static struct ehci_iso_stream * 1073static struct ehci_iso_stream *
1113iso_stream_find (struct ehci_hcd *ehci, struct urb *urb) 1074iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
1114{ 1075{
@@ -1129,7 +1090,6 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
1129 if (unlikely (stream == NULL)) { 1090 if (unlikely (stream == NULL)) {
1130 stream = iso_stream_alloc(GFP_ATOMIC); 1091 stream = iso_stream_alloc(GFP_ATOMIC);
1131 if (likely (stream != NULL)) { 1092 if (likely (stream != NULL)) {
1132 /* dev->ep owns the initial refcount */
1133 ep->hcpriv = stream; 1093 ep->hcpriv = stream;
1134 stream->ep = ep; 1094 stream->ep = ep;
1135 iso_stream_init(ehci, stream, urb->dev, urb->pipe, 1095 iso_stream_init(ehci, stream, urb->dev, urb->pipe,
@@ -1144,9 +1104,6 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
1144 stream = NULL; 1104 stream = NULL;
1145 } 1105 }
1146 1106
1147 /* caller guarantees an eventual matching iso_stream_put */
1148 stream = iso_stream_get (stream);
1149
1150 spin_unlock_irqrestore (&ehci->lock, flags); 1107 spin_unlock_irqrestore (&ehci->lock, flags);
1151 return stream; 1108 return stream;
1152} 1109}
@@ -1254,17 +1211,19 @@ itd_urb_transaction (
1254 spin_lock_irqsave (&ehci->lock, flags); 1211 spin_lock_irqsave (&ehci->lock, flags);
1255 for (i = 0; i < num_itds; i++) { 1212 for (i = 0; i < num_itds; i++) {
1256 1213
1257 /* free_list.next might be cache-hot ... but maybe 1214 /*
1258 * the HC caches it too. avoid that issue for now. 1215 * Use iTDs from the free list, but not iTDs that may
1216 * still be in use by the hardware.
1259 */ 1217 */
1260 1218 if (likely(!list_empty(&stream->free_list))) {
1261 /* prefer previously-allocated itds */ 1219 itd = list_first_entry(&stream->free_list,
1262 if (likely (!list_empty(&stream->free_list))) {
1263 itd = list_entry (stream->free_list.prev,
1264 struct ehci_itd, itd_list); 1220 struct ehci_itd, itd_list);
1221 if (itd->frame == ehci->now_frame)
1222 goto alloc_itd;
1265 list_del (&itd->itd_list); 1223 list_del (&itd->itd_list);
1266 itd_dma = itd->itd_dma; 1224 itd_dma = itd->itd_dma;
1267 } else { 1225 } else {
1226 alloc_itd:
1268 spin_unlock_irqrestore (&ehci->lock, flags); 1227 spin_unlock_irqrestore (&ehci->lock, flags);
1269 itd = dma_pool_alloc (ehci->itd_pool, mem_flags, 1228 itd = dma_pool_alloc (ehci->itd_pool, mem_flags,
1270 &itd_dma); 1229 &itd_dma);
@@ -1528,6 +1487,10 @@ iso_stream_schedule (
1528 urb->start_frame = stream->next_uframe; 1487 urb->start_frame = stream->next_uframe;
1529 if (!stream->highspeed) 1488 if (!stream->highspeed)
1530 urb->start_frame >>= 3; 1489 urb->start_frame >>= 3;
1490
1491 /* Make sure scan_isoc() sees these */
1492 if (ehci->isoc_count == 0)
1493 ehci->next_frame = now >> 3;
1531 return 0; 1494 return 0;
1532 1495
1533 fail: 1496 fail:
@@ -1615,8 +1578,7 @@ itd_link (struct ehci_hcd *ehci, unsigned frame, struct ehci_itd *itd)
1615} 1578}
1616 1579
1617/* fit urb's itds into the selected schedule slot; activate as needed */ 1580/* fit urb's itds into the selected schedule slot; activate as needed */
1618static int 1581static void itd_link_urb(
1619itd_link_urb (
1620 struct ehci_hcd *ehci, 1582 struct ehci_hcd *ehci,
1621 struct urb *urb, 1583 struct urb *urb,
1622 unsigned mod, 1584 unsigned mod,
@@ -1659,7 +1621,7 @@ itd_link_urb (
1659 itd = list_entry (iso_sched->td_list.next, 1621 itd = list_entry (iso_sched->td_list.next,
1660 struct ehci_itd, itd_list); 1622 struct ehci_itd, itd_list);
1661 list_move_tail (&itd->itd_list, &stream->td_list); 1623 list_move_tail (&itd->itd_list, &stream->td_list);
1662 itd->stream = iso_stream_get (stream); 1624 itd->stream = stream;
1663 itd->urb = urb; 1625 itd->urb = urb;
1664 itd_init (ehci, stream, itd); 1626 itd_init (ehci, stream, itd);
1665 } 1627 }
@@ -1686,8 +1648,8 @@ itd_link_urb (
1686 iso_sched_free (stream, iso_sched); 1648 iso_sched_free (stream, iso_sched);
1687 urb->hcpriv = NULL; 1649 urb->hcpriv = NULL;
1688 1650
1689 timer_action (ehci, TIMER_IO_WATCHDOG); 1651 ++ehci->isoc_count;
1690 return enable_periodic(ehci); 1652 enable_periodic(ehci);
1691} 1653}
1692 1654
1693#define ISO_ERRS (EHCI_ISOC_BUF_ERR | EHCI_ISOC_BABBLE | EHCI_ISOC_XACTERR) 1655#define ISO_ERRS (EHCI_ISOC_BUF_ERR | EHCI_ISOC_BABBLE | EHCI_ISOC_XACTERR)
@@ -1702,11 +1664,8 @@ itd_link_urb (
1702 * (b) only this endpoint's completions submit URBs. It seems some silicon 1664 * (b) only this endpoint's completions submit URBs. It seems some silicon
1703 * corrupts things if you reuse completed descriptors very quickly... 1665 * corrupts things if you reuse completed descriptors very quickly...
1704 */ 1666 */
1705static unsigned 1667static bool itd_complete(struct ehci_hcd *ehci, struct ehci_itd *itd)
1706itd_complete ( 1668{
1707 struct ehci_hcd *ehci,
1708 struct ehci_itd *itd
1709) {
1710 struct urb *urb = itd->urb; 1669 struct urb *urb = itd->urb;
1711 struct usb_iso_packet_descriptor *desc; 1670 struct usb_iso_packet_descriptor *desc;
1712 u32 t; 1671 u32 t;
@@ -1714,7 +1673,7 @@ itd_complete (
1714 int urb_index = -1; 1673 int urb_index = -1;
1715 struct ehci_iso_stream *stream = itd->stream; 1674 struct ehci_iso_stream *stream = itd->stream;
1716 struct usb_device *dev; 1675 struct usb_device *dev;
1717 unsigned retval = false; 1676 bool retval = false;
1718 1677
1719 /* for each uframe with a packet */ 1678 /* for each uframe with a packet */
1720 for (uframe = 0; uframe < 8; uframe++) { 1679 for (uframe = 0; uframe < 8; uframe++) {
@@ -1767,9 +1726,11 @@ itd_complete (
1767 ehci_urb_done(ehci, urb, 0); 1726 ehci_urb_done(ehci, urb, 0);
1768 retval = true; 1727 retval = true;
1769 urb = NULL; 1728 urb = NULL;
1770 (void) disable_periodic(ehci);
1771 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--;
1772 1729
1730 --ehci->isoc_count;
1731 disable_periodic(ehci);
1732
1733 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--;
1773 if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { 1734 if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) {
1774 if (ehci->amd_pll_fix == 1) 1735 if (ehci->amd_pll_fix == 1)
1775 usb_amd_quirk_pll_enable(); 1736 usb_amd_quirk_pll_enable();
@@ -1783,28 +1744,20 @@ itd_complete (
1783 dev->devpath, stream->bEndpointAddress & 0x0f, 1744 dev->devpath, stream->bEndpointAddress & 0x0f,
1784 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); 1745 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out");
1785 } 1746 }
1786 iso_stream_put (ehci, stream);
1787 1747
1788done: 1748done:
1789 itd->urb = NULL; 1749 itd->urb = NULL;
1790 if (ehci->clock_frame != itd->frame || itd->index[7] != -1) { 1750
1791 /* OK to recycle this ITD now. */ 1751 /* Add to the end of the free list for later reuse */
1792 itd->stream = NULL; 1752 list_move_tail(&itd->itd_list, &stream->free_list);
1793 list_move(&itd->itd_list, &stream->free_list); 1753
1794 iso_stream_put(ehci, stream); 1754 /* Recycle the iTDs when the pipeline is empty (ep no longer in use) */
1795 } else { 1755 if (list_empty(&stream->td_list)) {
1796 /* HW might remember this ITD, so we can't recycle it yet. 1756 list_splice_tail_init(&stream->free_list,
1797 * Move it to a safe place until a new frame starts. 1757 &ehci->cached_itd_list);
1798 */ 1758 start_free_itds(ehci);
1799 list_move(&itd->itd_list, &ehci->cached_itd_list);
1800 if (stream->refcount == 2) {
1801 /* If iso_stream_put() were called here, stream
1802 * would be freed. Instead, just prevent reuse.
1803 */
1804 stream->ep->hcpriv = NULL;
1805 stream->ep = NULL;
1806 }
1807 } 1759 }
1760
1808 return retval; 1761 return retval;
1809} 1762}
1810 1763
@@ -1861,12 +1814,9 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
1861 itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); 1814 itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
1862 else 1815 else
1863 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb); 1816 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
1864done_not_linked: 1817 done_not_linked:
1865 spin_unlock_irqrestore (&ehci->lock, flags); 1818 spin_unlock_irqrestore (&ehci->lock, flags);
1866 1819 done:
1867done:
1868 if (unlikely (status < 0))
1869 iso_stream_put (ehci, stream);
1870 return status; 1820 return status;
1871} 1821}
1872 1822
@@ -1955,17 +1905,19 @@ sitd_urb_transaction (
1955 * means we never need two sitds for full speed packets. 1905 * means we never need two sitds for full speed packets.
1956 */ 1906 */
1957 1907
1958 /* free_list.next might be cache-hot ... but maybe 1908 /*
1959 * the HC caches it too. avoid that issue for now. 1909 * Use siTDs from the free list, but not siTDs that may
1910 * still be in use by the hardware.
1960 */ 1911 */
1961 1912 if (likely(!list_empty(&stream->free_list))) {
1962 /* prefer previously-allocated sitds */ 1913 sitd = list_first_entry(&stream->free_list,
1963 if (!list_empty(&stream->free_list)) {
1964 sitd = list_entry (stream->free_list.prev,
1965 struct ehci_sitd, sitd_list); 1914 struct ehci_sitd, sitd_list);
1915 if (sitd->frame == ehci->now_frame)
1916 goto alloc_sitd;
1966 list_del (&sitd->sitd_list); 1917 list_del (&sitd->sitd_list);
1967 sitd_dma = sitd->sitd_dma; 1918 sitd_dma = sitd->sitd_dma;
1968 } else { 1919 } else {
1920 alloc_sitd:
1969 spin_unlock_irqrestore (&ehci->lock, flags); 1921 spin_unlock_irqrestore (&ehci->lock, flags);
1970 sitd = dma_pool_alloc (ehci->sitd_pool, mem_flags, 1922 sitd = dma_pool_alloc (ehci->sitd_pool, mem_flags,
1971 &sitd_dma); 1923 &sitd_dma);
@@ -2034,8 +1986,7 @@ sitd_link (struct ehci_hcd *ehci, unsigned frame, struct ehci_sitd *sitd)
2034} 1986}
2035 1987
2036/* fit urb's sitds into the selected schedule slot; activate as needed */ 1988/* fit urb's sitds into the selected schedule slot; activate as needed */
2037static int 1989static void sitd_link_urb(
2038sitd_link_urb (
2039 struct ehci_hcd *ehci, 1990 struct ehci_hcd *ehci,
2040 struct urb *urb, 1991 struct urb *urb,
2041 unsigned mod, 1992 unsigned mod,
@@ -2081,7 +2032,7 @@ sitd_link_urb (
2081 sitd = list_entry (sched->td_list.next, 2032 sitd = list_entry (sched->td_list.next,
2082 struct ehci_sitd, sitd_list); 2033 struct ehci_sitd, sitd_list);
2083 list_move_tail (&sitd->sitd_list, &stream->td_list); 2034 list_move_tail (&sitd->sitd_list, &stream->td_list);
2084 sitd->stream = iso_stream_get (stream); 2035 sitd->stream = stream;
2085 sitd->urb = urb; 2036 sitd->urb = urb;
2086 2037
2087 sitd_patch(ehci, stream, sitd, sched, packet); 2038 sitd_patch(ehci, stream, sitd, sched, packet);
@@ -2096,8 +2047,8 @@ sitd_link_urb (
2096 iso_sched_free (stream, sched); 2047 iso_sched_free (stream, sched);
2097 urb->hcpriv = NULL; 2048 urb->hcpriv = NULL;
2098 2049
2099 timer_action (ehci, TIMER_IO_WATCHDOG); 2050 ++ehci->isoc_count;
2100 return enable_periodic(ehci); 2051 enable_periodic(ehci);
2101} 2052}
2102 2053
2103/*-------------------------------------------------------------------------*/ 2054/*-------------------------------------------------------------------------*/
@@ -2115,18 +2066,15 @@ sitd_link_urb (
2115 * (b) only this endpoint's completions submit URBs. It seems some silicon 2066 * (b) only this endpoint's completions submit URBs. It seems some silicon
2116 * corrupts things if you reuse completed descriptors very quickly... 2067 * corrupts things if you reuse completed descriptors very quickly...
2117 */ 2068 */
2118static unsigned 2069static bool sitd_complete(struct ehci_hcd *ehci, struct ehci_sitd *sitd)
2119sitd_complete ( 2070{
2120 struct ehci_hcd *ehci,
2121 struct ehci_sitd *sitd
2122) {
2123 struct urb *urb = sitd->urb; 2071 struct urb *urb = sitd->urb;
2124 struct usb_iso_packet_descriptor *desc; 2072 struct usb_iso_packet_descriptor *desc;
2125 u32 t; 2073 u32 t;
2126 int urb_index = -1; 2074 int urb_index = -1;
2127 struct ehci_iso_stream *stream = sitd->stream; 2075 struct ehci_iso_stream *stream = sitd->stream;
2128 struct usb_device *dev; 2076 struct usb_device *dev;
2129 unsigned retval = false; 2077 bool retval = false;
2130 2078
2131 urb_index = sitd->index; 2079 urb_index = sitd->index;
2132 desc = &urb->iso_frame_desc [urb_index]; 2080 desc = &urb->iso_frame_desc [urb_index];
@@ -2163,9 +2111,11 @@ sitd_complete (
2163 ehci_urb_done(ehci, urb, 0); 2111 ehci_urb_done(ehci, urb, 0);
2164 retval = true; 2112 retval = true;
2165 urb = NULL; 2113 urb = NULL;
2166 (void) disable_periodic(ehci);
2167 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--;
2168 2114
2115 --ehci->isoc_count;
2116 disable_periodic(ehci);
2117
2118 ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--;
2169 if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) { 2119 if (ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs == 0) {
2170 if (ehci->amd_pll_fix == 1) 2120 if (ehci->amd_pll_fix == 1)
2171 usb_amd_quirk_pll_enable(); 2121 usb_amd_quirk_pll_enable();
@@ -2179,28 +2129,20 @@ sitd_complete (
2179 dev->devpath, stream->bEndpointAddress & 0x0f, 2129 dev->devpath, stream->bEndpointAddress & 0x0f,
2180 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); 2130 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out");
2181 } 2131 }
2182 iso_stream_put (ehci, stream);
2183 2132
2184done: 2133done:
2185 sitd->urb = NULL; 2134 sitd->urb = NULL;
2186 if (ehci->clock_frame != sitd->frame) { 2135
2187 /* OK to recycle this SITD now. */ 2136 /* Add to the end of the free list for later reuse */
2188 sitd->stream = NULL; 2137 list_move_tail(&sitd->sitd_list, &stream->free_list);
2189 list_move(&sitd->sitd_list, &stream->free_list); 2138
2190 iso_stream_put(ehci, stream); 2139 /* Recycle the siTDs when the pipeline is empty (ep no longer in use) */
2191 } else { 2140 if (list_empty(&stream->td_list)) {
2192 /* HW might remember this SITD, so we can't recycle it yet. 2141 list_splice_tail_init(&stream->free_list,
2193 * Move it to a safe place until a new frame starts. 2142 &ehci->cached_sitd_list);
2194 */ 2143 start_free_itds(ehci);
2195 list_move(&sitd->sitd_list, &ehci->cached_sitd_list);
2196 if (stream->refcount == 2) {
2197 /* If iso_stream_put() were called here, stream
2198 * would be freed. Instead, just prevent reuse.
2199 */
2200 stream->ep->hcpriv = NULL;
2201 stream->ep = NULL;
2202 }
2203 } 2144 }
2145
2204 return retval; 2146 return retval;
2205} 2147}
2206 2148
@@ -2254,74 +2196,39 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
2254 sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); 2196 sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
2255 else 2197 else
2256 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb); 2198 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
2257done_not_linked: 2199 done_not_linked:
2258 spin_unlock_irqrestore (&ehci->lock, flags); 2200 spin_unlock_irqrestore (&ehci->lock, flags);
2259 2201 done:
2260done:
2261 if (status < 0)
2262 iso_stream_put (ehci, stream);
2263 return status; 2202 return status;
2264} 2203}
2265 2204
2266/*-------------------------------------------------------------------------*/ 2205/*-------------------------------------------------------------------------*/
2267 2206
2268static void free_cached_lists(struct ehci_hcd *ehci) 2207static void scan_isoc(struct ehci_hcd *ehci)
2269{ 2208{
2270 struct ehci_itd *itd, *n; 2209 unsigned uf, now_frame, frame;
2271 struct ehci_sitd *sitd, *sn; 2210 unsigned fmask = ehci->periodic_size - 1;
2272 2211 bool modified, live;
2273 list_for_each_entry_safe(itd, n, &ehci->cached_itd_list, itd_list) {
2274 struct ehci_iso_stream *stream = itd->stream;
2275 itd->stream = NULL;
2276 list_move(&itd->itd_list, &stream->free_list);
2277 iso_stream_put(ehci, stream);
2278 }
2279
2280 list_for_each_entry_safe(sitd, sn, &ehci->cached_sitd_list, sitd_list) {
2281 struct ehci_iso_stream *stream = sitd->stream;
2282 sitd->stream = NULL;
2283 list_move(&sitd->sitd_list, &stream->free_list);
2284 iso_stream_put(ehci, stream);
2285 }
2286}
2287
2288/*-------------------------------------------------------------------------*/
2289
2290static void
2291scan_periodic (struct ehci_hcd *ehci)
2292{
2293 unsigned now_uframe, frame, clock, clock_frame, mod;
2294 unsigned modified;
2295
2296 mod = ehci->periodic_size << 3;
2297 2212
2298 /* 2213 /*
2299 * When running, scan from last scan point up to "now" 2214 * When running, scan from last scan point up to "now"
2300 * else clean up by scanning everything that's left. 2215 * else clean up by scanning everything that's left.
2301 * Touches as few pages as possible: cache-friendly. 2216 * Touches as few pages as possible: cache-friendly.
2302 */ 2217 */
2303 now_uframe = ehci->next_uframe; 2218 if (ehci->rh_state >= EHCI_RH_RUNNING) {
2304 if (ehci->rh_state == EHCI_RH_RUNNING) { 2219 uf = ehci_read_frame_index(ehci);
2305 clock = ehci_read_frame_index(ehci); 2220 now_frame = (uf >> 3) & fmask;
2306 clock_frame = (clock >> 3) & (ehci->periodic_size - 1); 2221 live = true;
2307 } else { 2222 } else {
2308 clock = now_uframe + mod - 1; 2223 now_frame = (ehci->next_frame - 1) & fmask;
2309 clock_frame = -1; 2224 live = false;
2310 } 2225 }
2311 if (ehci->clock_frame != clock_frame) { 2226 ehci->now_frame = now_frame;
2312 free_cached_lists(ehci);
2313 ehci->clock_frame = clock_frame;
2314 }
2315 clock &= mod - 1;
2316 clock_frame = clock >> 3;
2317 ++ehci->periodic_stamp;
2318 2227
2228 frame = ehci->next_frame;
2319 for (;;) { 2229 for (;;) {
2320 union ehci_shadow q, *q_p; 2230 union ehci_shadow q, *q_p;
2321 __hc32 type, *hw_p; 2231 __hc32 type, *hw_p;
2322 unsigned incomplete = false;
2323
2324 frame = now_uframe >> 3;
2325 2232
2326restart: 2233restart:
2327 /* scan each element in frame's queue for completions */ 2234 /* scan each element in frame's queue for completions */
@@ -2329,48 +2236,17 @@ restart:
2329 hw_p = &ehci->periodic [frame]; 2236 hw_p = &ehci->periodic [frame];
2330 q.ptr = q_p->ptr; 2237 q.ptr = q_p->ptr;
2331 type = Q_NEXT_TYPE(ehci, *hw_p); 2238 type = Q_NEXT_TYPE(ehci, *hw_p);
2332 modified = 0; 2239 modified = false;
2333 2240
2334 while (q.ptr != NULL) { 2241 while (q.ptr != NULL) {
2335 unsigned uf;
2336 union ehci_shadow temp;
2337 int live;
2338
2339 live = (ehci->rh_state == EHCI_RH_RUNNING);
2340 switch (hc32_to_cpu(ehci, type)) { 2242 switch (hc32_to_cpu(ehci, type)) {
2341 case Q_TYPE_QH:
2342 /* handle any completions */
2343 temp.qh = qh_get (q.qh);
2344 type = Q_NEXT_TYPE(ehci, q.qh->hw->hw_next);
2345 q = q.qh->qh_next;
2346 if (temp.qh->stamp != ehci->periodic_stamp) {
2347 modified = qh_completions(ehci, temp.qh);
2348 if (!modified)
2349 temp.qh->stamp = ehci->periodic_stamp;
2350 if (unlikely(list_empty(&temp.qh->qtd_list) ||
2351 temp.qh->needs_rescan))
2352 intr_deschedule(ehci, temp.qh);
2353 }
2354 qh_put (temp.qh);
2355 break;
2356 case Q_TYPE_FSTN:
2357 /* for "save place" FSTNs, look at QH entries
2358 * in the previous frame for completions.
2359 */
2360 if (q.fstn->hw_prev != EHCI_LIST_END(ehci)) {
2361 ehci_dbg(ehci,
2362 "ignoring completions from FSTNs\n");
2363 }
2364 type = Q_NEXT_TYPE(ehci, q.fstn->hw_next);
2365 q = q.fstn->fstn_next;
2366 break;
2367 case Q_TYPE_ITD: 2243 case Q_TYPE_ITD:
2368 /* If this ITD is still active, leave it for 2244 /* If this ITD is still active, leave it for
2369 * later processing ... check the next entry. 2245 * later processing ... check the next entry.
2370 * No need to check for activity unless the 2246 * No need to check for activity unless the
2371 * frame is current. 2247 * frame is current.
2372 */ 2248 */
2373 if (frame == clock_frame && live) { 2249 if (frame == now_frame && live) {
2374 rmb(); 2250 rmb();
2375 for (uf = 0; uf < 8; uf++) { 2251 for (uf = 0; uf < 8; uf++) {
2376 if (q.itd->hw_transaction[uf] & 2252 if (q.itd->hw_transaction[uf] &
@@ -2378,7 +2254,6 @@ restart:
2378 break; 2254 break;
2379 } 2255 }
2380 if (uf < 8) { 2256 if (uf < 8) {
2381 incomplete = true;
2382 q_p = &q.itd->itd_next; 2257 q_p = &q.itd->itd_next;
2383 hw_p = &q.itd->hw_next; 2258 hw_p = &q.itd->hw_next;
2384 type = Q_NEXT_TYPE(ehci, 2259 type = Q_NEXT_TYPE(ehci,
@@ -2410,14 +2285,12 @@ restart:
2410 * No need to check for activity unless the 2285 * No need to check for activity unless the
2411 * frame is current. 2286 * frame is current.
2412 */ 2287 */
2413 if (((frame == clock_frame) || 2288 if (((frame == now_frame) ||
2414 (((frame + 1) & (ehci->periodic_size - 1)) 2289 (((frame + 1) & fmask) == now_frame))
2415 == clock_frame))
2416 && live 2290 && live
2417 && (q.sitd->hw_results & 2291 && (q.sitd->hw_results &
2418 SITD_ACTIVE(ehci))) { 2292 SITD_ACTIVE(ehci))) {
2419 2293
2420 incomplete = true;
2421 q_p = &q.sitd->sitd_next; 2294 q_p = &q.sitd->sitd_next;
2422 hw_p = &q.sitd->hw_next; 2295 hw_p = &q.sitd->hw_next;
2423 type = Q_NEXT_TYPE(ehci, 2296 type = Q_NEXT_TYPE(ehci,
@@ -2445,58 +2318,23 @@ restart:
2445 ehci_dbg(ehci, "corrupt type %d frame %d shadow %p\n", 2318 ehci_dbg(ehci, "corrupt type %d frame %d shadow %p\n",
2446 type, frame, q.ptr); 2319 type, frame, q.ptr);
2447 // BUG (); 2320 // BUG ();
2321 /* FALL THROUGH */
2322 case Q_TYPE_QH:
2323 case Q_TYPE_FSTN:
2324 /* End of the iTDs and siTDs */
2448 q.ptr = NULL; 2325 q.ptr = NULL;
2326 break;
2449 } 2327 }
2450 2328
2451 /* assume completion callbacks modify the queue */ 2329 /* assume completion callbacks modify the queue */
2452 if (unlikely (modified)) { 2330 if (unlikely(modified && ehci->isoc_count > 0))
2453 if (likely(ehci->periodic_sched > 0)) 2331 goto restart;
2454 goto restart;
2455 /* short-circuit this scan */
2456 now_uframe = clock;
2457 break;
2458 }
2459 } 2332 }
2460 2333
2461 /* If we can tell we caught up to the hardware, stop now. 2334 /* Stop when we have reached the current frame */
2462 * We can't advance our scan without collecting the ISO 2335 if (frame == now_frame)
2463 * transfers that are still pending in this frame.
2464 */
2465 if (incomplete && ehci->rh_state == EHCI_RH_RUNNING) {
2466 ehci->next_uframe = now_uframe;
2467 break; 2336 break;
2468 } 2337 frame = (frame + 1) & fmask;
2469
2470 // FIXME: this assumes we won't get lapped when
2471 // latencies climb; that should be rare, but...
2472 // detect it, and just go all the way around.
2473 // FLR might help detect this case, so long as latencies
2474 // don't exceed periodic_size msec (default 1.024 sec).
2475
2476 // FIXME: likewise assumes HC doesn't halt mid-scan
2477
2478 if (now_uframe == clock) {
2479 unsigned now;
2480
2481 if (ehci->rh_state != EHCI_RH_RUNNING
2482 || ehci->periodic_sched == 0)
2483 break;
2484 ehci->next_uframe = now_uframe;
2485 now = ehci_read_frame_index(ehci) & (mod - 1);
2486 if (now_uframe == now)
2487 break;
2488
2489 /* rescan the rest of this frame, then ... */
2490 clock = now;
2491 clock_frame = clock >> 3;
2492 if (ehci->clock_frame != clock_frame) {
2493 free_cached_lists(ehci);
2494 ehci->clock_frame = clock_frame;
2495 ++ehci->periodic_stamp;
2496 }
2497 } else {
2498 now_uframe++;
2499 now_uframe &= mod - 1;
2500 }
2501 } 2338 }
2339 ehci->next_frame = now_frame;
2502} 2340}
diff --git a/drivers/usb/host/ehci-sead3.c b/drivers/usb/host/ehci-sead3.c
index cc199e87a7a9..58c96bd50d22 100644
--- a/drivers/usb/host/ehci-sead3.c
+++ b/drivers/usb/host/ehci-sead3.c
@@ -160,84 +160,16 @@ static int ehci_hcd_sead3_drv_remove(struct platform_device *pdev)
160static int ehci_hcd_sead3_drv_suspend(struct device *dev) 160static int ehci_hcd_sead3_drv_suspend(struct device *dev)
161{ 161{
162 struct usb_hcd *hcd = dev_get_drvdata(dev); 162 struct usb_hcd *hcd = dev_get_drvdata(dev);
163 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 163 bool do_wakeup = device_may_wakeup(dev);
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 164
182 /* could save FLADJ in case of Vaux power loss 165 return ehci_suspend(hcd, do_wakeup);
183 * ... we'd only use it to handle clock skew
184 */
185
186 return rc;
187} 166}
188 167
189static int ehci_hcd_sead3_drv_resume(struct device *dev) 168static int ehci_hcd_sead3_drv_resume(struct device *dev)
190{ 169{
191 struct usb_hcd *hcd = dev_get_drvdata(dev); 170 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 171
172 ehci_resume(hcd, false);
241 return 0; 173 return 0;
242} 174}
243 175
diff --git a/drivers/usb/host/ehci-sh.c b/drivers/usb/host/ehci-sh.c
index e7cb3925abf8..b3f1e3650da0 100644
--- a/drivers/usb/host/ehci-sh.c
+++ b/drivers/usb/host/ehci-sh.c
@@ -24,25 +24,11 @@ static int ehci_sh_reset(struct usb_hcd *hcd)
24 int ret; 24 int ret;
25 25
26 ehci->caps = hcd->regs; 26 ehci->caps = hcd->regs;
27 ehci->regs = hcd->regs + HC_LENGTH(ehci, ehci_readl(ehci,
28 &ehci->caps->hc_capbase));
29 27
30 dbg_hcs_params(ehci, "reset"); 28 ret = ehci_setup(hcd);
31 dbg_hcc_params(ehci, "reset");
32
33 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
34
35 ret = ehci_halt(ehci);
36 if (unlikely(ret))
37 return ret;
38
39 ret = ehci_init(hcd);
40 if (unlikely(ret)) 29 if (unlikely(ret))
41 return ret; 30 return ret;
42 31
43 ehci->sbrn = 0x20;
44
45 ehci_reset(ehci);
46 ehci_port_power(ehci, 0); 32 ehci_port_power(ehci, 0);
47 33
48 return ret; 34 return ret;
diff --git a/drivers/usb/host/ehci-spear.c b/drivers/usb/host/ehci-spear.c
index 37ba8c8d2fd0..c718a065e154 100644
--- a/drivers/usb/host/ehci-spear.c
+++ b/drivers/usb/host/ehci-spear.c
@@ -41,19 +41,11 @@ static int ehci_spear_setup(struct usb_hcd *hcd)
41 41
42 /* registers start at offset 0x0 */ 42 /* registers start at offset 0x0 */
43 ehci->caps = hcd->regs; 43 ehci->caps = hcd->regs;
44 ehci->regs = hcd->regs + HC_LENGTH(ehci, ehci_readl(ehci,
45 &ehci->caps->hc_capbase));
46 /* cache this readonly data; minimize chip reads */
47 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
48 retval = ehci_halt(ehci);
49 if (retval)
50 return retval;
51 44
52 retval = ehci_init(hcd); 45 retval = ehci_setup(hcd);
53 if (retval) 46 if (retval)
54 return retval; 47 return retval;
55 48
56 ehci_reset(ehci);
57 ehci_port_power(ehci, 0); 49 ehci_port_power(ehci, 0);
58 50
59 return retval; 51 return retval;
@@ -97,71 +89,16 @@ static const struct hc_driver ehci_spear_hc_driver = {
97static int ehci_spear_drv_suspend(struct device *dev) 89static int ehci_spear_drv_suspend(struct device *dev)
98{ 90{
99 struct usb_hcd *hcd = dev_get_drvdata(dev); 91 struct usb_hcd *hcd = dev_get_drvdata(dev);
100 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 92 bool do_wakeup = device_may_wakeup(dev);
101 unsigned long flags;
102 int rc = 0;
103 93
104 if (time_before(jiffies, ehci->next_statechange)) 94 return ehci_suspend(hcd, do_wakeup);
105 msleep(10);
106
107 /*
108 * Root hub was already suspended. Disable irq emission and mark HW
109 * unaccessible. The PM and USB cores make sure that the root hub is
110 * either suspended or stopped.
111 */
112 spin_lock_irqsave(&ehci->lock, flags);
113 ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
114 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
115 ehci_readl(ehci, &ehci->regs->intr_enable);
116 spin_unlock_irqrestore(&ehci->lock, flags);
117
118 return rc;
119} 95}
120 96
121static int ehci_spear_drv_resume(struct device *dev) 97static int ehci_spear_drv_resume(struct device *dev)
122{ 98{
123 struct usb_hcd *hcd = dev_get_drvdata(dev); 99 struct usb_hcd *hcd = dev_get_drvdata(dev);
124 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
125
126 if (time_before(jiffies, ehci->next_statechange))
127 msleep(100);
128
129 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
130 int mask = INTR_MASK;
131
132 ehci_prepare_ports_for_controller_resume(ehci);
133
134 if (!hcd->self.root_hub->do_remote_wakeup)
135 mask &= ~STS_PCD;
136
137 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
138 ehci_readl(ehci, &ehci->regs->intr_enable);
139 return 0;
140 }
141
142 usb_root_hub_lost_power(hcd->self.root_hub);
143
144 /*
145 * Else reset, to cope with power loss or flush-to-storage style
146 * "resume" having let BIOS kick in during reboot.
147 */
148 ehci_halt(ehci);
149 ehci_reset(ehci);
150
151 /* emptying the schedule aborts any urbs */
152 spin_lock_irq(&ehci->lock);
153 if (ehci->reclaim)
154 end_unlink_async(ehci);
155
156 ehci_work(ehci);
157 spin_unlock_irq(&ehci->lock);
158
159 ehci_writel(ehci, ehci->command, &ehci->regs->command);
160 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
161 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
162 100
163 /* here we "know" root ports should always stay powered */ 101 ehci_resume(hcd, false);
164 ehci_port_power(ehci, 1);
165 return 0; 102 return 0;
166} 103}
167#endif /* CONFIG_PM */ 104#endif /* CONFIG_PM */
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index ab8a3bf628e3..950e95efa381 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -17,6 +17,7 @@
17 */ 17 */
18 18
19#include <linux/clk.h> 19#include <linux/clk.h>
20#include <linux/err.h>
20#include <linux/platform_device.h> 21#include <linux/platform_device.h>
21#include <linux/platform_data/tegra_usb.h> 22#include <linux/platform_data/tegra_usb.h>
22#include <linux/irq.h> 23#include <linux/irq.h>
@@ -280,30 +281,14 @@ static int tegra_ehci_setup(struct usb_hcd *hcd)
280 281
281 /* EHCI registers start at offset 0x100 */ 282 /* EHCI registers start at offset 0x100 */
282 ehci->caps = hcd->regs + 0x100; 283 ehci->caps = hcd->regs + 0x100;
283 ehci->regs = hcd->regs + 0x100 +
284 HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
285
286 dbg_hcs_params(ehci, "reset");
287 dbg_hcc_params(ehci, "reset");
288
289 /* cache this readonly data; minimize chip reads */
290 ehci->hcs_params = readl(&ehci->caps->hcs_params);
291 284
292 /* switch to host mode */ 285 /* switch to host mode */
293 hcd->has_tt = 1; 286 hcd->has_tt = 1;
294 ehci_reset(ehci);
295
296 retval = ehci_halt(ehci);
297 if (retval)
298 return retval;
299 287
300 /* data structure init */ 288 retval = ehci_setup(hcd);
301 retval = ehci_init(hcd);
302 if (retval) 289 if (retval)
303 return retval; 290 return retval;
304 291
305 ehci->sbrn = 0x20;
306
307 ehci_port_power(ehci, 1); 292 ehci_port_power(ehci, 1);
308 return retval; 293 return retval;
309} 294}
@@ -460,12 +445,11 @@ static int controller_suspend(struct device *dev)
460 if (time_before(jiffies, ehci->next_statechange)) 445 if (time_before(jiffies, ehci->next_statechange))
461 msleep(10); 446 msleep(10);
462 447
463 spin_lock_irqsave(&ehci->lock, flags); 448 ehci_halt(ehci);
464 449
450 spin_lock_irqsave(&ehci->lock, flags);
465 tegra->port_speed = (readl(&hw->port_status[0]) >> 26) & 0x3; 451 tegra->port_speed = (readl(&hw->port_status[0]) >> 26) & 0x3;
466 ehci_halt(ehci);
467 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 452 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
468
469 spin_unlock_irqrestore(&ehci->lock, flags); 453 spin_unlock_irqrestore(&ehci->lock, flags);
470 454
471 tegra_ehci_power_down(hcd); 455 tegra_ehci_power_down(hcd);
@@ -749,8 +733,8 @@ static int tegra_ehci_probe(struct platform_device *pdev)
749 733
750#ifdef CONFIG_USB_OTG_UTILS 734#ifdef CONFIG_USB_OTG_UTILS
751 if (pdata->operating_mode == TEGRA_USB_OTG) { 735 if (pdata->operating_mode == TEGRA_USB_OTG) {
752 tegra->transceiver = usb_get_transceiver(); 736 tegra->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
753 if (tegra->transceiver) 737 if (!IS_ERR_OR_NULL(tegra->transceiver))
754 otg_set_host(tegra->transceiver->otg, &hcd->self); 738 otg_set_host(tegra->transceiver->otg, &hcd->self);
755 } 739 }
756#endif 740#endif
@@ -773,9 +757,9 @@ static int tegra_ehci_probe(struct platform_device *pdev)
773 757
774fail: 758fail:
775#ifdef CONFIG_USB_OTG_UTILS 759#ifdef CONFIG_USB_OTG_UTILS
776 if (tegra->transceiver) { 760 if (!IS_ERR_OR_NULL(tegra->transceiver)) {
777 otg_set_host(tegra->transceiver->otg, NULL); 761 otg_set_host(tegra->transceiver->otg, NULL);
778 usb_put_transceiver(tegra->transceiver); 762 usb_put_phy(tegra->transceiver);
779 } 763 }
780#endif 764#endif
781 tegra_usb_phy_close(tegra->phy); 765 tegra_usb_phy_close(tegra->phy);
@@ -808,9 +792,9 @@ static int tegra_ehci_remove(struct platform_device *pdev)
808 pm_runtime_put_noidle(&pdev->dev); 792 pm_runtime_put_noidle(&pdev->dev);
809 793
810#ifdef CONFIG_USB_OTG_UTILS 794#ifdef CONFIG_USB_OTG_UTILS
811 if (tegra->transceiver) { 795 if (!IS_ERR_OR_NULL(tegra->transceiver)) {
812 otg_set_host(tegra->transceiver->otg, NULL); 796 otg_set_host(tegra->transceiver->otg, NULL);
813 usb_put_transceiver(tegra->transceiver); 797 usb_put_phy(tegra->transceiver);
814 } 798 }
815#endif 799#endif
816 800
diff --git a/drivers/usb/host/ehci-timer.c b/drivers/usb/host/ehci-timer.c
new file mode 100644
index 000000000000..eb896a2c8f2e
--- /dev/null
+++ b/drivers/usb/host/ehci-timer.c
@@ -0,0 +1,401 @@
1/*
2 * Copyright (C) 2012 by Alan Stern
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15/* This file is part of ehci-hcd.c */
16
17/*-------------------------------------------------------------------------*/
18
19/* Set a bit in the USBCMD register */
20static void ehci_set_command_bit(struct ehci_hcd *ehci, u32 bit)
21{
22 ehci->command |= bit;
23 ehci_writel(ehci, ehci->command, &ehci->regs->command);
24
25 /* unblock posted write */
26 ehci_readl(ehci, &ehci->regs->command);
27}
28
29/* Clear a bit in the USBCMD register */
30static void ehci_clear_command_bit(struct ehci_hcd *ehci, u32 bit)
31{
32 ehci->command &= ~bit;
33 ehci_writel(ehci, ehci->command, &ehci->regs->command);
34
35 /* unblock posted write */
36 ehci_readl(ehci, &ehci->regs->command);
37}
38
39/*-------------------------------------------------------------------------*/
40
41/*
42 * EHCI timer support... Now using hrtimers.
43 *
44 * Lots of different events are triggered from ehci->hrtimer. Whenever
45 * the timer routine runs, it checks each possible event; events that are
46 * currently enabled and whose expiration time has passed get handled.
47 * The set of enabled events is stored as a collection of bitflags in
48 * ehci->enabled_hrtimer_events, and they are numbered in order of
49 * increasing delay values (ranging between 1 ms and 100 ms).
50 *
51 * Rather than implementing a sorted list or tree of all pending events,
52 * we keep track only of the lowest-numbered pending event, in
53 * ehci->next_hrtimer_event. Whenever ehci->hrtimer gets restarted, its
54 * expiration time is set to the timeout value for this event.
55 *
56 * As a result, events might not get handled right away; the actual delay
57 * could be anywhere up to twice the requested delay. This doesn't
58 * matter, because none of the events are especially time-critical. The
59 * ones that matter most all have a delay of 1 ms, so they will be
60 * handled after 2 ms at most, which is okay. In addition to this, we
61 * allow for an expiration range of 1 ms.
62 */
63
64/*
65 * Delay lengths for the hrtimer event types.
66 * Keep this list sorted by delay length, in the same order as
67 * the event types indexed by enum ehci_hrtimer_event in ehci.h.
68 */
69static unsigned event_delays_ns[] = {
70 1 * NSEC_PER_MSEC, /* EHCI_HRTIMER_POLL_ASS */
71 1 * NSEC_PER_MSEC, /* EHCI_HRTIMER_POLL_PSS */
72 1 * NSEC_PER_MSEC, /* EHCI_HRTIMER_POLL_DEAD */
73 1125 * NSEC_PER_USEC, /* EHCI_HRTIMER_UNLINK_INTR */
74 2 * NSEC_PER_MSEC, /* EHCI_HRTIMER_FREE_ITDS */
75 6 * NSEC_PER_MSEC, /* EHCI_HRTIMER_ASYNC_UNLINKS */
76 10 * NSEC_PER_MSEC, /* EHCI_HRTIMER_IAA_WATCHDOG */
77 10 * NSEC_PER_MSEC, /* EHCI_HRTIMER_DISABLE_PERIODIC */
78 15 * NSEC_PER_MSEC, /* EHCI_HRTIMER_DISABLE_ASYNC */
79 100 * NSEC_PER_MSEC, /* EHCI_HRTIMER_IO_WATCHDOG */
80};
81
82/* Enable a pending hrtimer event */
83static void ehci_enable_event(struct ehci_hcd *ehci, unsigned event,
84 bool resched)
85{
86 ktime_t *timeout = &ehci->hr_timeouts[event];
87
88 if (resched)
89 *timeout = ktime_add(ktime_get(),
90 ktime_set(0, event_delays_ns[event]));
91 ehci->enabled_hrtimer_events |= (1 << event);
92
93 /* Track only the lowest-numbered pending event */
94 if (event < ehci->next_hrtimer_event) {
95 ehci->next_hrtimer_event = event;
96 hrtimer_start_range_ns(&ehci->hrtimer, *timeout,
97 NSEC_PER_MSEC, HRTIMER_MODE_ABS);
98 }
99}
100
101
102/* Poll the STS_ASS status bit; see when it agrees with CMD_ASE */
103static void ehci_poll_ASS(struct ehci_hcd *ehci)
104{
105 unsigned actual, want;
106
107 /* Don't enable anything if the controller isn't running (e.g., died) */
108 if (ehci->rh_state != EHCI_RH_RUNNING)
109 return;
110
111 want = (ehci->command & CMD_ASE) ? STS_ASS : 0;
112 actual = ehci_readl(ehci, &ehci->regs->status) & STS_ASS;
113
114 if (want != actual) {
115
116 /* Poll again later, but give up after about 20 ms */
117 if (ehci->ASS_poll_count++ < 20) {
118 ehci_enable_event(ehci, EHCI_HRTIMER_POLL_ASS, true);
119 return;
120 }
121 ehci_warn(ehci, "Waited too long for the async schedule status, giving up\n");
122 }
123 ehci->ASS_poll_count = 0;
124
125 /* The status is up-to-date; restart or stop the schedule as needed */
126 if (want == 0) { /* Stopped */
127 if (ehci->async_count > 0)
128 ehci_set_command_bit(ehci, CMD_ASE);
129
130 } else { /* Running */
131 if (ehci->async_count == 0) {
132
133 /* Turn off the schedule after a while */
134 ehci_enable_event(ehci, EHCI_HRTIMER_DISABLE_ASYNC,
135 true);
136 }
137 }
138}
139
140/* Turn off the async schedule after a brief delay */
141static void ehci_disable_ASE(struct ehci_hcd *ehci)
142{
143 ehci_clear_command_bit(ehci, CMD_ASE);
144}
145
146
147/* Poll the STS_PSS status bit; see when it agrees with CMD_PSE */
148static void ehci_poll_PSS(struct ehci_hcd *ehci)
149{
150 unsigned actual, want;
151
152 /* Don't do anything if the controller isn't running (e.g., died) */
153 if (ehci->rh_state != EHCI_RH_RUNNING)
154 return;
155
156 want = (ehci->command & CMD_PSE) ? STS_PSS : 0;
157 actual = ehci_readl(ehci, &ehci->regs->status) & STS_PSS;
158
159 if (want != actual) {
160
161 /* Poll again later, but give up after about 20 ms */
162 if (ehci->PSS_poll_count++ < 20) {
163 ehci_enable_event(ehci, EHCI_HRTIMER_POLL_PSS, true);
164 return;
165 }
166 ehci_warn(ehci, "Waited too long for the periodic schedule status, giving up\n");
167 }
168 ehci->PSS_poll_count = 0;
169
170 /* The status is up-to-date; restart or stop the schedule as needed */
171 if (want == 0) { /* Stopped */
172 if (ehci->periodic_count > 0)
173 ehci_set_command_bit(ehci, CMD_PSE);
174
175 } else { /* Running */
176 if (ehci->periodic_count == 0) {
177
178 /* Turn off the schedule after a while */
179 ehci_enable_event(ehci, EHCI_HRTIMER_DISABLE_PERIODIC,
180 true);
181 }
182 }
183}
184
185/* Turn off the periodic schedule after a brief delay */
186static void ehci_disable_PSE(struct ehci_hcd *ehci)
187{
188 ehci_clear_command_bit(ehci, CMD_PSE);
189}
190
191
192/* Poll the STS_HALT status bit; see when a dead controller stops */
193static void ehci_handle_controller_death(struct ehci_hcd *ehci)
194{
195 if (!(ehci_readl(ehci, &ehci->regs->status) & STS_HALT)) {
196
197 /* Give up after a few milliseconds */
198 if (ehci->died_poll_count++ < 5) {
199 /* Try again later */
200 ehci_enable_event(ehci, EHCI_HRTIMER_POLL_DEAD, true);
201 return;
202 }
203 ehci_warn(ehci, "Waited too long for the controller to stop, giving up\n");
204 }
205
206 /* Clean up the mess */
207 ehci->rh_state = EHCI_RH_HALTED;
208 ehci_writel(ehci, 0, &ehci->regs->configured_flag);
209 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
210 ehci_work(ehci);
211 end_unlink_async(ehci);
212
213 /* Not in process context, so don't try to reset the controller */
214}
215
216
217/* Handle unlinked interrupt QHs once they are gone from the hardware */
218static void ehci_handle_intr_unlinks(struct ehci_hcd *ehci)
219{
220 bool stopped = (ehci->rh_state < EHCI_RH_RUNNING);
221
222 /*
223 * Process all the QHs on the intr_unlink list that were added
224 * before the current unlink cycle began. The list is in
225 * temporal order, so stop when we reach the first entry in the
226 * current cycle. But if the root hub isn't running then
227 * process all the QHs on the list.
228 */
229 ehci->intr_unlinking = true;
230 while (ehci->intr_unlink) {
231 struct ehci_qh *qh = ehci->intr_unlink;
232
233 if (!stopped && qh->unlink_cycle == ehci->intr_unlink_cycle)
234 break;
235 ehci->intr_unlink = qh->unlink_next;
236 qh->unlink_next = NULL;
237 end_unlink_intr(ehci, qh);
238 }
239
240 /* Handle remaining entries later */
241 if (ehci->intr_unlink) {
242 ehci_enable_event(ehci, EHCI_HRTIMER_UNLINK_INTR, true);
243 ++ehci->intr_unlink_cycle;
244 }
245 ehci->intr_unlinking = false;
246}
247
248
249/* Start another free-iTDs/siTDs cycle */
250static void start_free_itds(struct ehci_hcd *ehci)
251{
252 if (!(ehci->enabled_hrtimer_events & BIT(EHCI_HRTIMER_FREE_ITDS))) {
253 ehci->last_itd_to_free = list_entry(
254 ehci->cached_itd_list.prev,
255 struct ehci_itd, itd_list);
256 ehci->last_sitd_to_free = list_entry(
257 ehci->cached_sitd_list.prev,
258 struct ehci_sitd, sitd_list);
259 ehci_enable_event(ehci, EHCI_HRTIMER_FREE_ITDS, true);
260 }
261}
262
263/* Wait for controller to stop using old iTDs and siTDs */
264static void end_free_itds(struct ehci_hcd *ehci)
265{
266 struct ehci_itd *itd, *n;
267 struct ehci_sitd *sitd, *sn;
268
269 if (ehci->rh_state < EHCI_RH_RUNNING) {
270 ehci->last_itd_to_free = NULL;
271 ehci->last_sitd_to_free = NULL;
272 }
273
274 list_for_each_entry_safe(itd, n, &ehci->cached_itd_list, itd_list) {
275 list_del(&itd->itd_list);
276 dma_pool_free(ehci->itd_pool, itd, itd->itd_dma);
277 if (itd == ehci->last_itd_to_free)
278 break;
279 }
280 list_for_each_entry_safe(sitd, sn, &ehci->cached_sitd_list, sitd_list) {
281 list_del(&sitd->sitd_list);
282 dma_pool_free(ehci->sitd_pool, sitd, sitd->sitd_dma);
283 if (sitd == ehci->last_sitd_to_free)
284 break;
285 }
286
287 if (!list_empty(&ehci->cached_itd_list) ||
288 !list_empty(&ehci->cached_sitd_list))
289 start_free_itds(ehci);
290}
291
292
293/* Handle lost (or very late) IAA interrupts */
294static void ehci_iaa_watchdog(struct ehci_hcd *ehci)
295{
296 if (ehci->rh_state != EHCI_RH_RUNNING)
297 return;
298
299 /*
300 * Lost IAA irqs wedge things badly; seen first with a vt8235.
301 * So we need this watchdog, but must protect it against both
302 * (a) SMP races against real IAA firing and retriggering, and
303 * (b) clean HC shutdown, when IAA watchdog was pending.
304 */
305 if (ehci->async_iaa) {
306 u32 cmd, status;
307
308 /* If we get here, IAA is *REALLY* late. It's barely
309 * conceivable that the system is so busy that CMD_IAAD
310 * is still legitimately set, so let's be sure it's
311 * clear before we read STS_IAA. (The HC should clear
312 * CMD_IAAD when it sets STS_IAA.)
313 */
314 cmd = ehci_readl(ehci, &ehci->regs->command);
315
316 /*
317 * If IAA is set here it either legitimately triggered
318 * after the watchdog timer expired (_way_ late, so we'll
319 * still count it as lost) ... or a silicon erratum:
320 * - VIA seems to set IAA without triggering the IRQ;
321 * - IAAD potentially cleared without setting IAA.
322 */
323 status = ehci_readl(ehci, &ehci->regs->status);
324 if ((status & STS_IAA) || !(cmd & CMD_IAAD)) {
325 COUNT(ehci->stats.lost_iaa);
326 ehci_writel(ehci, STS_IAA, &ehci->regs->status);
327 }
328
329 ehci_vdbg(ehci, "IAA watchdog: status %x cmd %x\n",
330 status, cmd);
331 end_unlink_async(ehci);
332 }
333}
334
335
336/* Enable the I/O watchdog, if appropriate */
337static void turn_on_io_watchdog(struct ehci_hcd *ehci)
338{
339 /* Not needed if the controller isn't running or it's already enabled */
340 if (ehci->rh_state != EHCI_RH_RUNNING ||
341 (ehci->enabled_hrtimer_events &
342 BIT(EHCI_HRTIMER_IO_WATCHDOG)))
343 return;
344
345 /*
346 * Isochronous transfers always need the watchdog.
347 * For other sorts we use it only if the flag is set.
348 */
349 if (ehci->isoc_count > 0 || (ehci->need_io_watchdog &&
350 ehci->async_count + ehci->intr_count > 0))
351 ehci_enable_event(ehci, EHCI_HRTIMER_IO_WATCHDOG, true);
352}
353
354
355/*
356 * Handler functions for the hrtimer event types.
357 * Keep this array in the same order as the event types indexed by
358 * enum ehci_hrtimer_event in ehci.h.
359 */
360static void (*event_handlers[])(struct ehci_hcd *) = {
361 ehci_poll_ASS, /* EHCI_HRTIMER_POLL_ASS */
362 ehci_poll_PSS, /* EHCI_HRTIMER_POLL_PSS */
363 ehci_handle_controller_death, /* EHCI_HRTIMER_POLL_DEAD */
364 ehci_handle_intr_unlinks, /* EHCI_HRTIMER_UNLINK_INTR */
365 end_free_itds, /* EHCI_HRTIMER_FREE_ITDS */
366 unlink_empty_async, /* EHCI_HRTIMER_ASYNC_UNLINKS */
367 ehci_iaa_watchdog, /* EHCI_HRTIMER_IAA_WATCHDOG */
368 ehci_disable_PSE, /* EHCI_HRTIMER_DISABLE_PERIODIC */
369 ehci_disable_ASE, /* EHCI_HRTIMER_DISABLE_ASYNC */
370 ehci_work, /* EHCI_HRTIMER_IO_WATCHDOG */
371};
372
373static enum hrtimer_restart ehci_hrtimer_func(struct hrtimer *t)
374{
375 struct ehci_hcd *ehci = container_of(t, struct ehci_hcd, hrtimer);
376 ktime_t now;
377 unsigned long events;
378 unsigned long flags;
379 unsigned e;
380
381 spin_lock_irqsave(&ehci->lock, flags);
382
383 events = ehci->enabled_hrtimer_events;
384 ehci->enabled_hrtimer_events = 0;
385 ehci->next_hrtimer_event = EHCI_HRTIMER_NO_EVENT;
386
387 /*
388 * Check each pending event. If its time has expired, handle
389 * the event; otherwise re-enable it.
390 */
391 now = ktime_get();
392 for_each_set_bit(e, &events, EHCI_HRTIMER_NUM_EVENTS) {
393 if (now.tv64 >= ehci->hr_timeouts[e].tv64)
394 event_handlers[e](ehci);
395 else
396 ehci_enable_event(ehci, e, false);
397 }
398
399 spin_unlock_irqrestore(&ehci->lock, flags);
400 return HRTIMER_NORESTART;
401}
diff --git a/drivers/usb/host/ehci-vt8500.c b/drivers/usb/host/ehci-vt8500.c
index c1eda73916cd..4d147c4e33f5 100644
--- a/drivers/usb/host/ehci-vt8500.c
+++ b/drivers/usb/host/ehci-vt8500.c
@@ -48,7 +48,7 @@ static const struct hc_driver vt8500_ehci_hc_driver = {
48 /* 48 /*
49 * basic lifecycle operations 49 * basic lifecycle operations
50 */ 50 */
51 .reset = ehci_init, 51 .reset = ehci_setup,
52 .start = ehci_run, 52 .start = ehci_run,
53 .stop = ehci_stop, 53 .stop = ehci_stop,
54 .shutdown = ehci_shutdown, 54 .shutdown = ehci_shutdown,
@@ -121,18 +121,6 @@ static int vt8500_ehci_drv_probe(struct platform_device *pdev)
121 121
122 ehci = hcd_to_ehci(hcd); 122 ehci = hcd_to_ehci(hcd);
123 ehci->caps = hcd->regs; 123 ehci->caps = hcd->regs;
124 ehci->regs = hcd->regs +
125 HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase));
126
127 dbg_hcs_params(ehci, "reset");
128 dbg_hcc_params(ehci, "reset");
129
130 /* cache this readonly data; minimize chip reads */
131 ehci->hcs_params = readl(&ehci->caps->hcs_params);
132
133 ehci_port_power(ehci, 1);
134
135 ehci_reset(ehci);
136 124
137 ret = usb_add_hcd(hcd, pdev->resource[1].start, 125 ret = usb_add_hcd(hcd, pdev->resource[1].start,
138 IRQF_SHARED); 126 IRQF_SHARED);
diff --git a/drivers/usb/host/ehci-w90x900.c b/drivers/usb/host/ehci-w90x900.c
index 3d2e26cbb34c..ec598082c14b 100644
--- a/drivers/usb/host/ehci-w90x900.c
+++ b/drivers/usb/host/ehci-w90x900.c
@@ -71,21 +71,14 @@ static int __devinit usb_w90x900_probe(const struct hc_driver *driver,
71 val |= ENPHY; 71 val |= ENPHY;
72 __raw_writel(val, ehci->regs+PHY1_CTR); 72 __raw_writel(val, ehci->regs+PHY1_CTR);
73 73
74 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
75 ehci->sbrn = 0x20;
76
77 irq = platform_get_irq(pdev, 0); 74 irq = platform_get_irq(pdev, 0);
78 if (irq < 0) 75 if (irq < 0)
79 goto err4; 76 goto err4;
80 77
81 ehci_reset(ehci);
82
83 retval = usb_add_hcd(hcd, irq, IRQF_SHARED); 78 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
84 if (retval != 0) 79 if (retval != 0)
85 goto err4; 80 goto err4;
86 81
87 ehci_writel(ehci, 1, &ehci->regs->configured_flag);
88
89 return retval; 82 return retval;
90err4: 83err4:
91 iounmap(hcd->regs); 84 iounmap(hcd->regs);
@@ -120,7 +113,7 @@ static const struct hc_driver ehci_w90x900_hc_driver = {
120 /* 113 /*
121 * basic lifecycle operations 114 * basic lifecycle operations
122 */ 115 */
123 .reset = ehci_init, 116 .reset = ehci_setup,
124 .start = ehci_run, 117 .start = ehci_run,
125 118
126 .stop = ehci_stop, 119 .stop = ehci_stop,
diff --git a/drivers/usb/host/ehci-xilinx-of.c b/drivers/usb/host/ehci-xilinx-of.c
index e9713d589e30..39f24fa37ebe 100644
--- a/drivers/usb/host/ehci-xilinx-of.c
+++ b/drivers/usb/host/ehci-xilinx-of.c
@@ -32,30 +32,6 @@
32#include <linux/of_address.h> 32#include <linux/of_address.h>
33 33
34/** 34/**
35 * ehci_xilinx_of_setup - Initialize the device for ehci_reset()
36 * @hcd: Pointer to the usb_hcd device to which the host controller bound
37 *
38 * called during probe() after chip reset completes.
39 */
40static int ehci_xilinx_of_setup(struct usb_hcd *hcd)
41{
42 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
43 int retval;
44
45 retval = ehci_halt(ehci);
46 if (retval)
47 return retval;
48
49 retval = ehci_init(hcd);
50 if (retval)
51 return retval;
52
53 ehci->sbrn = 0x20;
54
55 return ehci_reset(ehci);
56}
57
58/**
59 * ehci_xilinx_port_handed_over - hand the port out if failed to enable it 35 * ehci_xilinx_port_handed_over - hand the port out if failed to enable it
60 * @hcd: Pointer to the usb_hcd device to which the host controller bound 36 * @hcd: Pointer to the usb_hcd device to which the host controller bound
61 * @portnum:Port number to which the device is attached. 37 * @portnum:Port number to which the device is attached.
@@ -107,7 +83,7 @@ static const struct hc_driver ehci_xilinx_of_hc_driver = {
107 /* 83 /*
108 * basic lifecycle operations 84 * basic lifecycle operations
109 */ 85 */
110 .reset = ehci_xilinx_of_setup, 86 .reset = ehci_setup,
111 .start = ehci_run, 87 .start = ehci_run,
112 .stop = ehci_stop, 88 .stop = ehci_stop,
113 .shutdown = ehci_shutdown, 89 .shutdown = ehci_shutdown,
@@ -219,11 +195,6 @@ static int __devinit ehci_hcd_xilinx_of_probe(struct platform_device *op)
219 /* Debug registers are at the first 0x100 region 195 /* Debug registers are at the first 0x100 region
220 */ 196 */
221 ehci->caps = hcd->regs + 0x100; 197 ehci->caps = hcd->regs + 0x100;
222 ehci->regs = hcd->regs + 0x100 +
223 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
224
225 /* cache this readonly data; minimize chip reads */
226 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
227 198
228 rv = usb_add_hcd(hcd, irq, 0); 199 rv = usb_add_hcd(hcd, irq, 0);
229 if (rv == 0) 200 if (rv == 0)
diff --git a/drivers/usb/host/ehci-xls.c b/drivers/usb/host/ehci-xls.c
index 72f08196f8cd..8dc6a22d90b8 100644
--- a/drivers/usb/host/ehci-xls.c
+++ b/drivers/usb/host/ehci-xls.c
@@ -14,30 +14,11 @@
14 14
15static int ehci_xls_setup(struct usb_hcd *hcd) 15static int ehci_xls_setup(struct usb_hcd *hcd)
16{ 16{
17 int retval;
18 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 17 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
19 18
20 ehci->caps = hcd->regs; 19 ehci->caps = hcd->regs;
21 ehci->regs = hcd->regs +
22 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
23 dbg_hcs_params(ehci, "reset");
24 dbg_hcc_params(ehci, "reset");
25 20
26 /* cache this readonly data; minimize chip reads */ 21 return ehci_setup(hcd);
27 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
28
29 retval = ehci_halt(ehci);
30 if (retval)
31 return retval;
32
33 /* data structure init */
34 retval = ehci_init(hcd);
35 if (retval)
36 return retval;
37
38 ehci_reset(ehci);
39
40 return retval;
41} 22}
42 23
43int ehci_xls_probe_internal(const struct hc_driver *driver, 24int ehci_xls_probe_internal(const struct hc_driver *driver,
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 2694ed6558d2..da07d98f7d1d 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -42,7 +42,7 @@ struct ehci_stats {
42 /* irq usage */ 42 /* irq usage */
43 unsigned long normal; 43 unsigned long normal;
44 unsigned long error; 44 unsigned long error;
45 unsigned long reclaim; 45 unsigned long iaa;
46 unsigned long lost_iaa; 46 unsigned long lost_iaa;
47 47
48 /* termination of urbs from core */ 48 /* termination of urbs from core */
@@ -51,7 +51,7 @@ struct ehci_stats {
51}; 51};
52 52
53/* ehci_hcd->lock guards shared data against other CPUs: 53/* ehci_hcd->lock guards shared data against other CPUs:
54 * ehci_hcd: async, reclaim, periodic (and shadow), ... 54 * ehci_hcd: async, unlink, periodic (and shadow), ...
55 * usb_host_endpoint: hcpriv 55 * usb_host_endpoint: hcpriv
56 * ehci_qh: qh_next, qtd_list 56 * ehci_qh: qh_next, qtd_list
57 * ehci_qtd: qtd_list 57 * ehci_qtd: qtd_list
@@ -62,13 +62,48 @@ struct ehci_stats {
62 62
63#define EHCI_MAX_ROOT_PORTS 15 /* see HCS_N_PORTS */ 63#define EHCI_MAX_ROOT_PORTS 15 /* see HCS_N_PORTS */
64 64
65/*
66 * ehci_rh_state values of EHCI_RH_RUNNING or above mean that the
67 * controller may be doing DMA. Lower values mean there's no DMA.
68 */
65enum ehci_rh_state { 69enum ehci_rh_state {
66 EHCI_RH_HALTED, 70 EHCI_RH_HALTED,
67 EHCI_RH_SUSPENDED, 71 EHCI_RH_SUSPENDED,
68 EHCI_RH_RUNNING 72 EHCI_RH_RUNNING,
73 EHCI_RH_STOPPING
69}; 74};
70 75
76/*
77 * Timer events, ordered by increasing delay length.
78 * Always update event_delays_ns[] and event_handlers[] (defined in
79 * ehci-timer.c) in parallel with this list.
80 */
81enum ehci_hrtimer_event {
82 EHCI_HRTIMER_POLL_ASS, /* Poll for async schedule off */
83 EHCI_HRTIMER_POLL_PSS, /* Poll for periodic schedule off */
84 EHCI_HRTIMER_POLL_DEAD, /* Wait for dead controller to stop */
85 EHCI_HRTIMER_UNLINK_INTR, /* Wait for interrupt QH unlink */
86 EHCI_HRTIMER_FREE_ITDS, /* Wait for unused iTDs and siTDs */
87 EHCI_HRTIMER_ASYNC_UNLINKS, /* Unlink empty async QHs */
88 EHCI_HRTIMER_IAA_WATCHDOG, /* Handle lost IAA interrupts */
89 EHCI_HRTIMER_DISABLE_PERIODIC, /* Wait to disable periodic sched */
90 EHCI_HRTIMER_DISABLE_ASYNC, /* Wait to disable async sched */
91 EHCI_HRTIMER_IO_WATCHDOG, /* Check for missing IRQs */
92 EHCI_HRTIMER_NUM_EVENTS /* Must come last */
93};
94#define EHCI_HRTIMER_NO_EVENT 99
95
71struct ehci_hcd { /* one per controller */ 96struct ehci_hcd { /* one per controller */
97 /* timing support */
98 enum ehci_hrtimer_event next_hrtimer_event;
99 unsigned enabled_hrtimer_events;
100 ktime_t hr_timeouts[EHCI_HRTIMER_NUM_EVENTS];
101 struct hrtimer hrtimer;
102
103 int PSS_poll_count;
104 int ASS_poll_count;
105 int died_poll_count;
106
72 /* glue to PCI and HCD framework */ 107 /* glue to PCI and HCD framework */
73 struct ehci_caps __iomem *caps; 108 struct ehci_caps __iomem *caps;
74 struct ehci_regs __iomem *regs; 109 struct ehci_regs __iomem *regs;
@@ -78,30 +113,48 @@ struct ehci_hcd { /* one per controller */
78 spinlock_t lock; 113 spinlock_t lock;
79 enum ehci_rh_state rh_state; 114 enum ehci_rh_state rh_state;
80 115
116 /* general schedule support */
117 bool scanning:1;
118 bool need_rescan:1;
119 bool intr_unlinking:1;
120 bool async_unlinking:1;
121 bool shutdown:1;
122 struct ehci_qh *qh_scan_next;
123
81 /* async schedule support */ 124 /* async schedule support */
82 struct ehci_qh *async; 125 struct ehci_qh *async;
83 struct ehci_qh *dummy; /* For AMD quirk use */ 126 struct ehci_qh *dummy; /* For AMD quirk use */
84 struct ehci_qh *reclaim; 127 struct ehci_qh *async_unlink;
85 struct ehci_qh *qh_scan_next; 128 struct ehci_qh *async_unlink_last;
86 unsigned scanning : 1; 129 struct ehci_qh *async_iaa;
130 unsigned async_unlink_cycle;
131 unsigned async_count; /* async activity count */
87 132
88 /* periodic schedule support */ 133 /* periodic schedule support */
89#define DEFAULT_I_TDPS 1024 /* some HCs can do less */ 134#define DEFAULT_I_TDPS 1024 /* some HCs can do less */
90 unsigned periodic_size; 135 unsigned periodic_size;
91 __hc32 *periodic; /* hw periodic table */ 136 __hc32 *periodic; /* hw periodic table */
92 dma_addr_t periodic_dma; 137 dma_addr_t periodic_dma;
138 struct list_head intr_qh_list;
93 unsigned i_thresh; /* uframes HC might cache */ 139 unsigned i_thresh; /* uframes HC might cache */
94 140
95 union ehci_shadow *pshadow; /* mirror hw periodic table */ 141 union ehci_shadow *pshadow; /* mirror hw periodic table */
96 int next_uframe; /* scan periodic, start here */ 142 struct ehci_qh *intr_unlink;
97 unsigned periodic_sched; /* periodic activity count */ 143 struct ehci_qh *intr_unlink_last;
144 unsigned intr_unlink_cycle;
145 unsigned now_frame; /* frame from HC hardware */
146 unsigned next_frame; /* scan periodic, start here */
147 unsigned intr_count; /* intr activity count */
148 unsigned isoc_count; /* isoc activity count */
149 unsigned periodic_count; /* periodic activity count */
98 unsigned uframe_periodic_max; /* max periodic time per uframe */ 150 unsigned uframe_periodic_max; /* max periodic time per uframe */
99 151
100 152
101 /* list of itds & sitds completed while clock_frame was still active */ 153 /* list of itds & sitds completed while now_frame was still active */
102 struct list_head cached_itd_list; 154 struct list_head cached_itd_list;
155 struct ehci_itd *last_itd_to_free;
103 struct list_head cached_sitd_list; 156 struct list_head cached_sitd_list;
104 unsigned clock_frame; 157 struct ehci_sitd *last_sitd_to_free;
105 158
106 /* per root hub port */ 159 /* per root hub port */
107 unsigned long reset_done [EHCI_MAX_ROOT_PORTS]; 160 unsigned long reset_done [EHCI_MAX_ROOT_PORTS];
@@ -126,10 +179,6 @@ struct ehci_hcd { /* one per controller */
126 struct dma_pool *itd_pool; /* itd per iso urb */ 179 struct dma_pool *itd_pool; /* itd per iso urb */
127 struct dma_pool *sitd_pool; /* sitd per split iso urb */ 180 struct dma_pool *sitd_pool; /* sitd per split iso urb */
128 181
129 struct timer_list iaa_watchdog;
130 struct timer_list watchdog;
131 unsigned long actions;
132 unsigned periodic_stamp;
133 unsigned random_frame; 182 unsigned random_frame;
134 unsigned long next_statechange; 183 unsigned long next_statechange;
135 ktime_t last_periodic_enable; 184 ktime_t last_periodic_enable;
@@ -143,7 +192,6 @@ struct ehci_hcd { /* one per controller */
143 unsigned big_endian_capbase:1; 192 unsigned big_endian_capbase:1;
144 unsigned has_amcc_usb23:1; 193 unsigned has_amcc_usb23:1;
145 unsigned need_io_watchdog:1; 194 unsigned need_io_watchdog:1;
146 unsigned broken_periodic:1;
147 unsigned amd_pll_fix:1; 195 unsigned amd_pll_fix:1;
148 unsigned fs_i_thresh:1; /* Intel iso scheduling */ 196 unsigned fs_i_thresh:1; /* Intel iso scheduling */
149 unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/ 197 unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/
@@ -175,10 +223,6 @@ struct ehci_hcd { /* one per controller */
175#ifdef DEBUG 223#ifdef DEBUG
176 struct dentry *debug_dir; 224 struct dentry *debug_dir;
177#endif 225#endif
178 /*
179 * OTG controllers and transceivers need software interaction
180 */
181 struct usb_phy *transceiver;
182}; 226};
183 227
184/* convert between an HCD pointer and the corresponding EHCI_HCD */ 228/* convert between an HCD pointer and the corresponding EHCI_HCD */
@@ -191,34 +235,6 @@ static inline struct usb_hcd *ehci_to_hcd (struct ehci_hcd *ehci)
191 return container_of ((void *) ehci, struct usb_hcd, hcd_priv); 235 return container_of ((void *) ehci, struct usb_hcd, hcd_priv);
192} 236}
193 237
194
195static inline void
196iaa_watchdog_start(struct ehci_hcd *ehci)
197{
198 WARN_ON(timer_pending(&ehci->iaa_watchdog));
199 mod_timer(&ehci->iaa_watchdog,
200 jiffies + msecs_to_jiffies(EHCI_IAA_MSECS));
201}
202
203static inline void iaa_watchdog_done(struct ehci_hcd *ehci)
204{
205 del_timer(&ehci->iaa_watchdog);
206}
207
208enum ehci_timer_action {
209 TIMER_IO_WATCHDOG,
210 TIMER_ASYNC_SHRINK,
211 TIMER_ASYNC_OFF,
212};
213
214static inline void
215timer_action_done (struct ehci_hcd *ehci, enum ehci_timer_action action)
216{
217 clear_bit (action, &ehci->actions);
218}
219
220static void free_cached_lists(struct ehci_hcd *ehci);
221
222/*-------------------------------------------------------------------------*/ 238/*-------------------------------------------------------------------------*/
223 239
224#include <linux/usb/ehci_def.h> 240#include <linux/usb/ehci_def.h>
@@ -328,7 +344,13 @@ union ehci_shadow {
328struct ehci_qh_hw { 344struct ehci_qh_hw {
329 __hc32 hw_next; /* see EHCI 3.6.1 */ 345 __hc32 hw_next; /* see EHCI 3.6.1 */
330 __hc32 hw_info1; /* see EHCI 3.6.2 */ 346 __hc32 hw_info1; /* see EHCI 3.6.2 */
331#define QH_HEAD 0x00008000 347#define QH_CONTROL_EP (1 << 27) /* FS/LS control endpoint */
348#define QH_HEAD (1 << 15) /* Head of async reclamation list */
349#define QH_TOGGLE_CTL (1 << 14) /* Data toggle control */
350#define QH_HIGH_SPEED (2 << 12) /* Endpoint speed */
351#define QH_LOW_SPEED (1 << 12)
352#define QH_FULL_SPEED (0 << 12)
353#define QH_INACTIVATE (1 << 7) /* Inactivate on next transaction */
332 __hc32 hw_info2; /* see EHCI 3.6.2 */ 354 __hc32 hw_info2; /* see EHCI 3.6.2 */
333#define QH_SMASK 0x000000ff 355#define QH_SMASK 0x000000ff
334#define QH_CMASK 0x0000ff00 356#define QH_CMASK 0x0000ff00
@@ -346,32 +368,23 @@ struct ehci_qh_hw {
346} __attribute__ ((aligned(32))); 368} __attribute__ ((aligned(32)));
347 369
348struct ehci_qh { 370struct ehci_qh {
349 struct ehci_qh_hw *hw; 371 struct ehci_qh_hw *hw; /* Must come first */
350 /* the rest is HCD-private */ 372 /* the rest is HCD-private */
351 dma_addr_t qh_dma; /* address of qh */ 373 dma_addr_t qh_dma; /* address of qh */
352 union ehci_shadow qh_next; /* ptr to qh; or periodic */ 374 union ehci_shadow qh_next; /* ptr to qh; or periodic */
353 struct list_head qtd_list; /* sw qtd list */ 375 struct list_head qtd_list; /* sw qtd list */
376 struct list_head intr_node; /* list of intr QHs */
354 struct ehci_qtd *dummy; 377 struct ehci_qtd *dummy;
355 struct ehci_qh *reclaim; /* next to reclaim */ 378 struct ehci_qh *unlink_next; /* next on unlink list */
356
357 struct ehci_hcd *ehci;
358 unsigned long unlink_time;
359 379
360 /* 380 unsigned unlink_cycle;
361 * Do NOT use atomic operations for QH refcounting. On some CPUs
362 * (PPC7448 for example), atomic operations cannot be performed on
363 * memory that is cache-inhibited (i.e. being used for DMA).
364 * Spinlocks are used to protect all QH fields.
365 */
366 u32 refcount;
367 unsigned stamp;
368 381
369 u8 needs_rescan; /* Dequeue during giveback */ 382 u8 needs_rescan; /* Dequeue during giveback */
370 u8 qh_state; 383 u8 qh_state;
371#define QH_STATE_LINKED 1 /* HC sees this */ 384#define QH_STATE_LINKED 1 /* HC sees this */
372#define QH_STATE_UNLINK 2 /* HC may still see this */ 385#define QH_STATE_UNLINK 2 /* HC may still see this */
373#define QH_STATE_IDLE 3 /* HC doesn't see this */ 386#define QH_STATE_IDLE 3 /* HC doesn't see this */
374#define QH_STATE_UNLINK_WAIT 4 /* LINKED and on reclaim q */ 387#define QH_STATE_UNLINK_WAIT 4 /* LINKED and on unlink q */
375#define QH_STATE_COMPLETING 5 /* don't touch token.HALT */ 388#define QH_STATE_COMPLETING 5 /* don't touch token.HALT */
376 389
377 u8 xacterrs; /* XactErr retry counter */ 390 u8 xacterrs; /* XactErr retry counter */
@@ -421,7 +434,6 @@ struct ehci_iso_stream {
421 /* first field matches ehci_hq, but is NULL */ 434 /* first field matches ehci_hq, but is NULL */
422 struct ehci_qh_hw *hw; 435 struct ehci_qh_hw *hw;
423 436
424 u32 refcount;
425 u8 bEndpointAddress; 437 u8 bEndpointAddress;
426 u8 highspeed; 438 u8 highspeed;
427 struct list_head td_list; /* queued itds/sitds */ 439 struct list_head td_list; /* queued itds/sitds */
diff --git a/drivers/usb/host/fhci-dbg.c b/drivers/usb/host/fhci-dbg.c
index 6fe550049119..f238cb37305c 100644
--- a/drivers/usb/host/fhci-dbg.c
+++ b/drivers/usb/host/fhci-dbg.c
@@ -41,7 +41,7 @@ void fhci_dbg_isr(struct fhci_hcd *fhci, int usb_er)
41static int fhci_dfs_regs_show(struct seq_file *s, void *v) 41static int fhci_dfs_regs_show(struct seq_file *s, void *v)
42{ 42{
43 struct fhci_hcd *fhci = s->private; 43 struct fhci_hcd *fhci = s->private;
44 struct fhci_regs __iomem *regs = fhci->regs; 44 struct qe_usb_ctlr __iomem *regs = fhci->regs;
45 45
46 seq_printf(s, 46 seq_printf(s,
47 "mode: 0x%x\n" "addr: 0x%x\n" 47 "mode: 0x%x\n" "addr: 0x%x\n"
@@ -50,11 +50,11 @@ static int fhci_dfs_regs_show(struct seq_file *s, void *v)
50 "status: 0x%x\n" "SOF timer: %d\n" 50 "status: 0x%x\n" "SOF timer: %d\n"
51 "frame number: %d\n" 51 "frame number: %d\n"
52 "lines status: 0x%x\n", 52 "lines status: 0x%x\n",
53 in_8(&regs->usb_mod), in_8(&regs->usb_addr), 53 in_8(&regs->usb_usmod), in_8(&regs->usb_usadr),
54 in_8(&regs->usb_comm), in_be16(&regs->usb_ep[0]), 54 in_8(&regs->usb_uscom), in_be16(&regs->usb_usep[0]),
55 in_be16(&regs->usb_event), in_be16(&regs->usb_mask), 55 in_be16(&regs->usb_usber), in_be16(&regs->usb_usbmr),
56 in_8(&regs->usb_status), in_be16(&regs->usb_sof_tmr), 56 in_8(&regs->usb_usbs), in_be16(&regs->usb_ussft),
57 in_be16(&regs->usb_frame_num), 57 in_be16(&regs->usb_usfrn),
58 fhci_ioports_check_bus_state(fhci)); 58 fhci_ioports_check_bus_state(fhci));
59 59
60 return 0; 60 return 0;
diff --git a/drivers/usb/host/fhci-hcd.c b/drivers/usb/host/fhci-hcd.c
index d2623747b489..7da1a26bed2e 100644
--- a/drivers/usb/host/fhci-hcd.c
+++ b/drivers/usb/host/fhci-hcd.c
@@ -40,8 +40,8 @@ void fhci_start_sof_timer(struct fhci_hcd *fhci)
40 /* clear frame_n */ 40 /* clear frame_n */
41 out_be16(&fhci->pram->frame_num, 0); 41 out_be16(&fhci->pram->frame_num, 0);
42 42
43 out_be16(&fhci->regs->usb_sof_tmr, 0); 43 out_be16(&fhci->regs->usb_ussft, 0);
44 setbits8(&fhci->regs->usb_mod, USB_MODE_SFTE); 44 setbits8(&fhci->regs->usb_usmod, USB_MODE_SFTE);
45 45
46 fhci_dbg(fhci, "<- %s\n", __func__); 46 fhci_dbg(fhci, "<- %s\n", __func__);
47} 47}
@@ -50,7 +50,7 @@ void fhci_stop_sof_timer(struct fhci_hcd *fhci)
50{ 50{
51 fhci_dbg(fhci, "-> %s\n", __func__); 51 fhci_dbg(fhci, "-> %s\n", __func__);
52 52
53 clrbits8(&fhci->regs->usb_mod, USB_MODE_SFTE); 53 clrbits8(&fhci->regs->usb_usmod, USB_MODE_SFTE);
54 gtm_stop_timer16(fhci->timer); 54 gtm_stop_timer16(fhci->timer);
55 55
56 fhci_dbg(fhci, "<- %s\n", __func__); 56 fhci_dbg(fhci, "<- %s\n", __func__);
@@ -58,7 +58,7 @@ void fhci_stop_sof_timer(struct fhci_hcd *fhci)
58 58
59u16 fhci_get_sof_timer_count(struct fhci_usb *usb) 59u16 fhci_get_sof_timer_count(struct fhci_usb *usb)
60{ 60{
61 return be16_to_cpu(in_be16(&usb->fhci->regs->usb_sof_tmr) / 12); 61 return be16_to_cpu(in_be16(&usb->fhci->regs->usb_ussft) / 12);
62} 62}
63 63
64/* initialize the endpoint zero */ 64/* initialize the endpoint zero */
@@ -88,8 +88,8 @@ void fhci_usb_enable_interrupt(struct fhci_usb *usb)
88 enable_irq(fhci_to_hcd(fhci)->irq); 88 enable_irq(fhci_to_hcd(fhci)->irq);
89 89
90 /* initialize the event register and mask register */ 90 /* initialize the event register and mask register */
91 out_be16(&usb->fhci->regs->usb_event, 0xffff); 91 out_be16(&usb->fhci->regs->usb_usber, 0xffff);
92 out_be16(&usb->fhci->regs->usb_mask, usb->saved_msk); 92 out_be16(&usb->fhci->regs->usb_usbmr, usb->saved_msk);
93 93
94 /* enable the timer interrupts */ 94 /* enable the timer interrupts */
95 enable_irq(fhci->timer->irq); 95 enable_irq(fhci->timer->irq);
@@ -109,7 +109,7 @@ void fhci_usb_disable_interrupt(struct fhci_usb *usb)
109 109
110 /* disable the usb interrupt */ 110 /* disable the usb interrupt */
111 disable_irq_nosync(fhci_to_hcd(fhci)->irq); 111 disable_irq_nosync(fhci_to_hcd(fhci)->irq);
112 out_be16(&usb->fhci->regs->usb_mask, 0); 112 out_be16(&usb->fhci->regs->usb_usbmr, 0);
113 } 113 }
114 usb->intr_nesting_cnt++; 114 usb->intr_nesting_cnt++;
115} 115}
@@ -119,9 +119,9 @@ static u32 fhci_usb_enable(struct fhci_hcd *fhci)
119{ 119{
120 struct fhci_usb *usb = fhci->usb_lld; 120 struct fhci_usb *usb = fhci->usb_lld;
121 121
122 out_be16(&usb->fhci->regs->usb_event, 0xffff); 122 out_be16(&usb->fhci->regs->usb_usber, 0xffff);
123 out_be16(&usb->fhci->regs->usb_mask, usb->saved_msk); 123 out_be16(&usb->fhci->regs->usb_usbmr, usb->saved_msk);
124 setbits8(&usb->fhci->regs->usb_mod, USB_MODE_EN); 124 setbits8(&usb->fhci->regs->usb_usmod, USB_MODE_EN);
125 125
126 mdelay(100); 126 mdelay(100);
127 127
@@ -141,7 +141,7 @@ static u32 fhci_usb_disable(struct fhci_hcd *fhci)
141 usb->port_status == FHCI_PORT_LOW) 141 usb->port_status == FHCI_PORT_LOW)
142 fhci_device_disconnected_interrupt(fhci); 142 fhci_device_disconnected_interrupt(fhci);
143 143
144 clrbits8(&usb->fhci->regs->usb_mod, USB_MODE_EN); 144 clrbits8(&usb->fhci->regs->usb_usmod, USB_MODE_EN);
145 145
146 return 0; 146 return 0;
147} 147}
@@ -285,13 +285,13 @@ static int fhci_usb_init(struct fhci_hcd *fhci)
285 USB_E_IDLE_MASK | 285 USB_E_IDLE_MASK |
286 USB_E_RESET_MASK | USB_E_SFT_MASK | USB_E_MSF_MASK); 286 USB_E_RESET_MASK | USB_E_SFT_MASK | USB_E_MSF_MASK);
287 287
288 out_8(&usb->fhci->regs->usb_mod, USB_MODE_HOST | USB_MODE_EN); 288 out_8(&usb->fhci->regs->usb_usmod, USB_MODE_HOST | USB_MODE_EN);
289 289
290 /* clearing the mask register */ 290 /* clearing the mask register */
291 out_be16(&usb->fhci->regs->usb_mask, 0); 291 out_be16(&usb->fhci->regs->usb_usbmr, 0);
292 292
293 /* initialing the event register */ 293 /* initialing the event register */
294 out_be16(&usb->fhci->regs->usb_event, 0xffff); 294 out_be16(&usb->fhci->regs->usb_usber, 0xffff);
295 295
296 if (endpoint_zero_init(usb, DEFAULT_DATA_MEM, DEFAULT_RING_LEN) != 0) { 296 if (endpoint_zero_init(usb, DEFAULT_DATA_MEM, DEFAULT_RING_LEN) != 0) {
297 fhci_usb_free(usb); 297 fhci_usb_free(usb);
@@ -745,8 +745,8 @@ static int __devinit of_fhci_probe(struct platform_device *ofdev)
745 } 745 }
746 746
747 /* Clear and disable any pending interrupts. */ 747 /* Clear and disable any pending interrupts. */
748 out_be16(&fhci->regs->usb_event, 0xffff); 748 out_be16(&fhci->regs->usb_usber, 0xffff);
749 out_be16(&fhci->regs->usb_mask, 0); 749 out_be16(&fhci->regs->usb_usbmr, 0);
750 750
751 ret = usb_add_hcd(hcd, usb_irq, 0); 751 ret = usb_add_hcd(hcd, usb_irq, 0);
752 if (ret < 0) 752 if (ret < 0)
diff --git a/drivers/usb/host/fhci-hub.c b/drivers/usb/host/fhci-hub.c
index 348fe62e94f7..6af2512f8378 100644
--- a/drivers/usb/host/fhci-hub.c
+++ b/drivers/usb/host/fhci-hub.c
@@ -97,7 +97,7 @@ void fhci_port_disable(struct fhci_hcd *fhci)
97 97
98 /* Enable IDLE since we want to know if something comes along */ 98 /* Enable IDLE since we want to know if something comes along */
99 usb->saved_msk |= USB_E_IDLE_MASK; 99 usb->saved_msk |= USB_E_IDLE_MASK;
100 out_be16(&usb->fhci->regs->usb_mask, usb->saved_msk); 100 out_be16(&usb->fhci->regs->usb_usbmr, usb->saved_msk);
101 101
102 /* check if during the disconnection process attached new device */ 102 /* check if during the disconnection process attached new device */
103 if (port_status == FHCI_PORT_WAITING) 103 if (port_status == FHCI_PORT_WAITING)
@@ -158,21 +158,21 @@ void fhci_port_reset(void *lld)
158 158
159 fhci_stop_sof_timer(fhci); 159 fhci_stop_sof_timer(fhci);
160 /* disable the USB controller */ 160 /* disable the USB controller */
161 mode = in_8(&fhci->regs->usb_mod); 161 mode = in_8(&fhci->regs->usb_usmod);
162 out_8(&fhci->regs->usb_mod, mode & (~USB_MODE_EN)); 162 out_8(&fhci->regs->usb_usmod, mode & (~USB_MODE_EN));
163 163
164 /* disable idle interrupts */ 164 /* disable idle interrupts */
165 mask = in_be16(&fhci->regs->usb_mask); 165 mask = in_be16(&fhci->regs->usb_usbmr);
166 out_be16(&fhci->regs->usb_mask, mask & (~USB_E_IDLE_MASK)); 166 out_be16(&fhci->regs->usb_usbmr, mask & (~USB_E_IDLE_MASK));
167 167
168 fhci_io_port_generate_reset(fhci); 168 fhci_io_port_generate_reset(fhci);
169 169
170 /* enable interrupt on this endpoint */ 170 /* enable interrupt on this endpoint */
171 out_be16(&fhci->regs->usb_mask, mask); 171 out_be16(&fhci->regs->usb_usbmr, mask);
172 172
173 /* enable the USB controller */ 173 /* enable the USB controller */
174 mode = in_8(&fhci->regs->usb_mod); 174 mode = in_8(&fhci->regs->usb_usmod);
175 out_8(&fhci->regs->usb_mod, mode | USB_MODE_EN); 175 out_8(&fhci->regs->usb_usmod, mode | USB_MODE_EN);
176 fhci_start_sof_timer(fhci); 176 fhci_start_sof_timer(fhci);
177 177
178 fhci_dbg(fhci, "<- %s\n", __func__); 178 fhci_dbg(fhci, "<- %s\n", __func__);
diff --git a/drivers/usb/host/fhci-sched.c b/drivers/usb/host/fhci-sched.c
index 2df851b4bc7c..2dc8a40e39d7 100644
--- a/drivers/usb/host/fhci-sched.c
+++ b/drivers/usb/host/fhci-sched.c
@@ -132,8 +132,8 @@ void fhci_flush_all_transmissions(struct fhci_usb *usb)
132 u8 mode; 132 u8 mode;
133 struct td *td; 133 struct td *td;
134 134
135 mode = in_8(&usb->fhci->regs->usb_mod); 135 mode = in_8(&usb->fhci->regs->usb_usmod);
136 clrbits8(&usb->fhci->regs->usb_mod, USB_MODE_EN); 136 clrbits8(&usb->fhci->regs->usb_usmod, USB_MODE_EN);
137 137
138 fhci_flush_bds(usb); 138 fhci_flush_bds(usb);
139 139
@@ -147,9 +147,9 @@ void fhci_flush_all_transmissions(struct fhci_usb *usb)
147 usb->actual_frame->frame_status = FRAME_END_TRANSMISSION; 147 usb->actual_frame->frame_status = FRAME_END_TRANSMISSION;
148 148
149 /* reset the event register */ 149 /* reset the event register */
150 out_be16(&usb->fhci->regs->usb_event, 0xffff); 150 out_be16(&usb->fhci->regs->usb_usber, 0xffff);
151 /* enable the USB controller */ 151 /* enable the USB controller */
152 out_8(&usb->fhci->regs->usb_mod, mode | USB_MODE_EN); 152 out_8(&usb->fhci->regs->usb_usmod, mode | USB_MODE_EN);
153} 153}
154 154
155/* 155/*
@@ -414,7 +414,7 @@ static void sof_interrupt(struct fhci_hcd *fhci)
414 usb->port_status = FHCI_PORT_FULL; 414 usb->port_status = FHCI_PORT_FULL;
415 /* Disable IDLE */ 415 /* Disable IDLE */
416 usb->saved_msk &= ~USB_E_IDLE_MASK; 416 usb->saved_msk &= ~USB_E_IDLE_MASK;
417 out_be16(&usb->fhci->regs->usb_mask, usb->saved_msk); 417 out_be16(&usb->fhci->regs->usb_usbmr, usb->saved_msk);
418 } 418 }
419 419
420 gtm_set_exact_timer16(fhci->timer, usb->max_frame_usage, false); 420 gtm_set_exact_timer16(fhci->timer, usb->max_frame_usage, false);
@@ -433,14 +433,14 @@ void fhci_device_disconnected_interrupt(struct fhci_hcd *fhci)
433 fhci_dbg(fhci, "-> %s\n", __func__); 433 fhci_dbg(fhci, "-> %s\n", __func__);
434 434
435 fhci_usb_disable_interrupt(usb); 435 fhci_usb_disable_interrupt(usb);
436 clrbits8(&usb->fhci->regs->usb_mod, USB_MODE_LSS); 436 clrbits8(&usb->fhci->regs->usb_usmod, USB_MODE_LSS);
437 usb->port_status = FHCI_PORT_DISABLED; 437 usb->port_status = FHCI_PORT_DISABLED;
438 438
439 fhci_stop_sof_timer(fhci); 439 fhci_stop_sof_timer(fhci);
440 440
441 /* Enable IDLE since we want to know if something comes along */ 441 /* Enable IDLE since we want to know if something comes along */
442 usb->saved_msk |= USB_E_IDLE_MASK; 442 usb->saved_msk |= USB_E_IDLE_MASK;
443 out_be16(&usb->fhci->regs->usb_mask, usb->saved_msk); 443 out_be16(&usb->fhci->regs->usb_usbmr, usb->saved_msk);
444 444
445 usb->vroot_hub->port.wPortStatus &= ~USB_PORT_STAT_CONNECTION; 445 usb->vroot_hub->port.wPortStatus &= ~USB_PORT_STAT_CONNECTION;
446 usb->vroot_hub->port.wPortChange |= USB_PORT_STAT_C_CONNECTION; 446 usb->vroot_hub->port.wPortChange |= USB_PORT_STAT_C_CONNECTION;
@@ -473,7 +473,7 @@ void fhci_device_connected_interrupt(struct fhci_hcd *fhci)
473 } 473 }
474 474
475 usb->port_status = FHCI_PORT_LOW; 475 usb->port_status = FHCI_PORT_LOW;
476 setbits8(&usb->fhci->regs->usb_mod, USB_MODE_LSS); 476 setbits8(&usb->fhci->regs->usb_usmod, USB_MODE_LSS);
477 usb->vroot_hub->port.wPortStatus |= 477 usb->vroot_hub->port.wPortStatus |=
478 (USB_PORT_STAT_LOW_SPEED | 478 (USB_PORT_STAT_LOW_SPEED |
479 USB_PORT_STAT_CONNECTION); 479 USB_PORT_STAT_CONNECTION);
@@ -491,7 +491,7 @@ void fhci_device_connected_interrupt(struct fhci_hcd *fhci)
491 } 491 }
492 492
493 usb->port_status = FHCI_PORT_FULL; 493 usb->port_status = FHCI_PORT_FULL;
494 clrbits8(&usb->fhci->regs->usb_mod, USB_MODE_LSS); 494 clrbits8(&usb->fhci->regs->usb_usmod, USB_MODE_LSS);
495 usb->vroot_hub->port.wPortStatus &= 495 usb->vroot_hub->port.wPortStatus &=
496 ~USB_PORT_STAT_LOW_SPEED; 496 ~USB_PORT_STAT_LOW_SPEED;
497 usb->vroot_hub->port.wPortStatus |= 497 usb->vroot_hub->port.wPortStatus |=
@@ -535,7 +535,7 @@ static void abort_transmission(struct fhci_usb *usb)
535 /* issue stop Tx command */ 535 /* issue stop Tx command */
536 qe_issue_cmd(QE_USB_STOP_TX, QE_CR_SUBBLOCK_USB, EP_ZERO, 0); 536 qe_issue_cmd(QE_USB_STOP_TX, QE_CR_SUBBLOCK_USB, EP_ZERO, 0);
537 /* flush Tx FIFOs */ 537 /* flush Tx FIFOs */
538 out_8(&usb->fhci->regs->usb_comm, USB_CMD_FLUSH_FIFO | EP_ZERO); 538 out_8(&usb->fhci->regs->usb_uscom, USB_CMD_FLUSH_FIFO | EP_ZERO);
539 udelay(1000); 539 udelay(1000);
540 /* reset Tx BDs */ 540 /* reset Tx BDs */
541 fhci_flush_bds(usb); 541 fhci_flush_bds(usb);
@@ -555,11 +555,11 @@ irqreturn_t fhci_irq(struct usb_hcd *hcd)
555 555
556 usb = fhci->usb_lld; 556 usb = fhci->usb_lld;
557 557
558 usb_er |= in_be16(&usb->fhci->regs->usb_event) & 558 usb_er |= in_be16(&usb->fhci->regs->usb_usber) &
559 in_be16(&usb->fhci->regs->usb_mask); 559 in_be16(&usb->fhci->regs->usb_usbmr);
560 560
561 /* clear event bits for next time */ 561 /* clear event bits for next time */
562 out_be16(&usb->fhci->regs->usb_event, usb_er); 562 out_be16(&usb->fhci->regs->usb_usber, usb_er);
563 563
564 fhci_dbg_isr(fhci, usb_er); 564 fhci_dbg_isr(fhci, usb_er);
565 565
@@ -573,7 +573,7 @@ irqreturn_t fhci_irq(struct usb_hcd *hcd)
573 573
574 /* Turn on IDLE since we want to disconnect */ 574 /* Turn on IDLE since we want to disconnect */
575 usb->saved_msk |= USB_E_IDLE_MASK; 575 usb->saved_msk |= USB_E_IDLE_MASK;
576 out_be16(&usb->fhci->regs->usb_event, 576 out_be16(&usb->fhci->regs->usb_usber,
577 usb->saved_msk); 577 usb->saved_msk);
578 } else if (usb->port_status == FHCI_PORT_DISABLED) { 578 } else if (usb->port_status == FHCI_PORT_DISABLED) {
579 if (fhci_ioports_check_bus_state(fhci) == 1) 579 if (fhci_ioports_check_bus_state(fhci) == 1)
@@ -611,7 +611,7 @@ irqreturn_t fhci_irq(struct usb_hcd *hcd)
611 /* XXX usb->port_status = FHCI_PORT_WAITING; */ 611 /* XXX usb->port_status = FHCI_PORT_WAITING; */
612 /* Disable IDLE */ 612 /* Disable IDLE */
613 usb->saved_msk &= ~USB_E_IDLE_MASK; 613 usb->saved_msk &= ~USB_E_IDLE_MASK;
614 out_be16(&usb->fhci->regs->usb_mask, 614 out_be16(&usb->fhci->regs->usb_usbmr,
615 usb->saved_msk); 615 usb->saved_msk);
616 } else { 616 } else {
617 fhci_dbg_isr(fhci, -1); 617 fhci_dbg_isr(fhci, -1);
diff --git a/drivers/usb/host/fhci-tds.c b/drivers/usb/host/fhci-tds.c
index c5ed88199292..1498061f0aea 100644
--- a/drivers/usb/host/fhci-tds.c
+++ b/drivers/usb/host/fhci-tds.c
@@ -249,7 +249,7 @@ void fhci_init_ep_registers(struct fhci_usb *usb, struct endpoint *ep,
249 u8 rt; 249 u8 rt;
250 250
251 /* set the endpoint registers according to the endpoint */ 251 /* set the endpoint registers according to the endpoint */
252 out_be16(&usb->fhci->regs->usb_ep[0], 252 out_be16(&usb->fhci->regs->usb_usep[0],
253 USB_TRANS_CTR | USB_EP_MF | USB_EP_RTE); 253 USB_TRANS_CTR | USB_EP_MF | USB_EP_RTE);
254 out_be16(&usb->fhci->pram->ep_ptr[0], 254 out_be16(&usb->fhci->pram->ep_ptr[0],
255 cpm_muram_offset(ep->ep_pram_ptr)); 255 cpm_muram_offset(ep->ep_pram_ptr));
@@ -463,7 +463,7 @@ u32 fhci_host_transaction(struct fhci_usb *usb,
463 cq_put(&ep->conf_frame_Q, pkt); 463 cq_put(&ep->conf_frame_Q, pkt);
464 464
465 if (cq_howmany(&ep->conf_frame_Q) == 1) 465 if (cq_howmany(&ep->conf_frame_Q) == 1)
466 out_8(&usb->fhci->regs->usb_comm, USB_CMD_STR_FIFO); 466 out_8(&usb->fhci->regs->usb_uscom, USB_CMD_STR_FIFO);
467 467
468 return 0; 468 return 0;
469} 469}
@@ -535,8 +535,8 @@ void fhci_flush_actual_frame(struct fhci_usb *usb)
535 struct endpoint *ep = usb->ep0; 535 struct endpoint *ep = usb->ep0;
536 536
537 /* disable the USB controller */ 537 /* disable the USB controller */
538 mode = in_8(&usb->fhci->regs->usb_mod); 538 mode = in_8(&usb->fhci->regs->usb_usmod);
539 out_8(&usb->fhci->regs->usb_mod, mode & ~USB_MODE_EN); 539 out_8(&usb->fhci->regs->usb_usmod, mode & ~USB_MODE_EN);
540 540
541 tb_ptr = in_be16(&ep->ep_pram_ptr->tx_bd_ptr); 541 tb_ptr = in_be16(&ep->ep_pram_ptr->tx_bd_ptr);
542 td = cpm_muram_addr(tb_ptr); 542 td = cpm_muram_addr(tb_ptr);
@@ -571,9 +571,9 @@ void fhci_flush_actual_frame(struct fhci_usb *usb)
571 usb->actual_frame->frame_status = FRAME_TIMER_END_TRANSMISSION; 571 usb->actual_frame->frame_status = FRAME_TIMER_END_TRANSMISSION;
572 572
573 /* reset the event register */ 573 /* reset the event register */
574 out_be16(&usb->fhci->regs->usb_event, 0xffff); 574 out_be16(&usb->fhci->regs->usb_usber, 0xffff);
575 /* enable the USB controller */ 575 /* enable the USB controller */
576 out_8(&usb->fhci->regs->usb_mod, mode | USB_MODE_EN); 576 out_8(&usb->fhci->regs->usb_usmod, mode | USB_MODE_EN);
577} 577}
578 578
579/* handles Tx confirm and Tx error interrupt */ 579/* handles Tx confirm and Tx error interrupt */
@@ -613,7 +613,7 @@ void fhci_host_transmit_actual_frame(struct fhci_usb *usb)
613 613
614 /* start transmit only if we have something in the TDs */ 614 /* start transmit only if we have something in the TDs */
615 if (in_be16(&td->status) & TD_R) 615 if (in_be16(&td->status) & TD_R)
616 out_8(&usb->fhci->regs->usb_comm, USB_CMD_STR_FIFO); 616 out_8(&usb->fhci->regs->usb_uscom, USB_CMD_STR_FIFO);
617 617
618 if (in_be32(&ep->conf_td->buf_ptr) == DUMMY_BD_BUFFER) { 618 if (in_be32(&ep->conf_td->buf_ptr) == DUMMY_BD_BUFFER) {
619 out_be32(&old_td->buf_ptr, 0); 619 out_be32(&old_td->buf_ptr, 0);
diff --git a/drivers/usb/host/fhci.h b/drivers/usb/host/fhci.h
index dc6939a44a1a..7cc1c32dc36c 100644
--- a/drivers/usb/host/fhci.h
+++ b/drivers/usb/host/fhci.h
@@ -28,6 +28,7 @@
28#include <linux/usb.h> 28#include <linux/usb.h>
29#include <linux/usb/hcd.h> 29#include <linux/usb/hcd.h>
30#include <asm/qe.h> 30#include <asm/qe.h>
31#include <asm/immap_qe.h>
31 32
32#define USB_CLOCK 48000000 33#define USB_CLOCK 48000000
33 34
@@ -173,25 +174,6 @@
173#define USB_E_TXB_MASK 0x0002 174#define USB_E_TXB_MASK 0x0002
174#define USB_E_RXB_MASK 0x0001 175#define USB_E_RXB_MASK 0x0001
175 176
176/* Freescale USB Host controller registers */
177struct fhci_regs {
178 u8 usb_mod; /* mode register */
179 u8 usb_addr; /* address register */
180 u8 usb_comm; /* command register */
181 u8 reserved1[1];
182 __be16 usb_ep[4]; /* endpoint register */
183 u8 reserved2[4];
184 __be16 usb_event; /* event register */
185 u8 reserved3[2];
186 __be16 usb_mask; /* mask register */
187 u8 reserved4[1];
188 u8 usb_status; /* status register */
189 __be16 usb_sof_tmr; /* Start Of Frame timer */
190 u8 reserved5[2];
191 __be16 usb_frame_num; /* frame number register */
192 u8 reserved6[1];
193};
194
195/* Freescale USB HOST */ 177/* Freescale USB HOST */
196struct fhci_pram { 178struct fhci_pram {
197 __be16 ep_ptr[4]; /* Endpoint porter reg */ 179 __be16 ep_ptr[4]; /* Endpoint porter reg */
@@ -267,7 +249,7 @@ struct fhci_hcd {
267 int gpios[NUM_GPIOS]; 249 int gpios[NUM_GPIOS];
268 bool alow_gpios[NUM_GPIOS]; 250 bool alow_gpios[NUM_GPIOS];
269 251
270 struct fhci_regs __iomem *regs; /* I/O memory used to communicate */ 252 struct qe_usb_ctlr __iomem *regs; /* I/O memory used to communicate */
271 struct fhci_pram __iomem *pram; /* Parameter RAM */ 253 struct fhci_pram __iomem *pram; /* Parameter RAM */
272 struct gtm_timer *timer; 254 struct gtm_timer *timer;
273 255
diff --git a/drivers/usb/host/imx21-hcd.c b/drivers/usb/host/imx21-hcd.c
index ff471c1c165e..f19e2690c232 100644
--- a/drivers/usb/host/imx21-hcd.c
+++ b/drivers/usb/host/imx21-hcd.c
@@ -1811,7 +1811,7 @@ static int imx21_remove(struct platform_device *pdev)
1811 usb_remove_hcd(hcd); 1811 usb_remove_hcd(hcd);
1812 1812
1813 if (res != NULL) { 1813 if (res != NULL) {
1814 clk_disable(imx21->clk); 1814 clk_disable_unprepare(imx21->clk);
1815 clk_put(imx21->clk); 1815 clk_put(imx21->clk);
1816 iounmap(imx21->regs); 1816 iounmap(imx21->regs);
1817 release_mem_region(res->start, resource_size(res)); 1817 release_mem_region(res->start, resource_size(res));
@@ -1884,7 +1884,7 @@ static int imx21_probe(struct platform_device *pdev)
1884 ret = clk_set_rate(imx21->clk, clk_round_rate(imx21->clk, 48000000)); 1884 ret = clk_set_rate(imx21->clk, clk_round_rate(imx21->clk, 48000000));
1885 if (ret) 1885 if (ret)
1886 goto failed_clock_set; 1886 goto failed_clock_set;
1887 ret = clk_enable(imx21->clk); 1887 ret = clk_prepare_enable(imx21->clk);
1888 if (ret) 1888 if (ret)
1889 goto failed_clock_enable; 1889 goto failed_clock_enable;
1890 1890
@@ -1900,7 +1900,7 @@ static int imx21_probe(struct platform_device *pdev)
1900 return 0; 1900 return 0;
1901 1901
1902failed_add_hcd: 1902failed_add_hcd:
1903 clk_disable(imx21->clk); 1903 clk_disable_unprepare(imx21->clk);
1904failed_clock_enable: 1904failed_clock_enable:
1905failed_clock_set: 1905failed_clock_set:
1906 clk_put(imx21->clk); 1906 clk_put(imx21->clk);
diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c
index 2909621ea196..fc3091bd2379 100644
--- a/drivers/usb/host/ohci-exynos.c
+++ b/drivers/usb/host/ohci-exynos.c
@@ -12,6 +12,7 @@
12 */ 12 */
13 13
14#include <linux/clk.h> 14#include <linux/clk.h>
15#include <linux/of.h>
15#include <linux/platform_device.h> 16#include <linux/platform_device.h>
16#include <mach/ohci.h> 17#include <mach/ohci.h>
17#include <plat/usb-phy.h> 18#include <plat/usb-phy.h>
@@ -71,6 +72,8 @@ static const struct hc_driver exynos_ohci_hc_driver = {
71 .start_port_reset = ohci_start_port_reset, 72 .start_port_reset = ohci_start_port_reset,
72}; 73};
73 74
75static u64 ohci_exynos_dma_mask = DMA_BIT_MASK(32);
76
74static int __devinit exynos_ohci_probe(struct platform_device *pdev) 77static int __devinit exynos_ohci_probe(struct platform_device *pdev)
75{ 78{
76 struct exynos4_ohci_platdata *pdata; 79 struct exynos4_ohci_platdata *pdata;
@@ -87,7 +90,18 @@ static int __devinit exynos_ohci_probe(struct platform_device *pdev)
87 return -EINVAL; 90 return -EINVAL;
88 } 91 }
89 92
90 exynos_ohci = kzalloc(sizeof(struct exynos_ohci_hcd), GFP_KERNEL); 93 /*
94 * Right now device-tree probed devices don't get dma_mask set.
95 * Since shared usb code relies on it, set it here for now.
96 * Once we move to full device tree support this will vanish off.
97 */
98 if (!pdev->dev.dma_mask)
99 pdev->dev.dma_mask = &ohci_exynos_dma_mask;
100 if (!pdev->dev.coherent_dma_mask)
101 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
102
103 exynos_ohci = devm_kzalloc(&pdev->dev, sizeof(struct exynos_ohci_hcd),
104 GFP_KERNEL);
91 if (!exynos_ohci) 105 if (!exynos_ohci)
92 return -ENOMEM; 106 return -ENOMEM;
93 107
@@ -97,8 +111,7 @@ static int __devinit exynos_ohci_probe(struct platform_device *pdev)
97 dev_name(&pdev->dev)); 111 dev_name(&pdev->dev));
98 if (!hcd) { 112 if (!hcd) {
99 dev_err(&pdev->dev, "Unable to create HCD\n"); 113 dev_err(&pdev->dev, "Unable to create HCD\n");
100 err = -ENOMEM; 114 return -ENOMEM;
101 goto fail_hcd;
102 } 115 }
103 116
104 exynos_ohci->hcd = hcd; 117 exynos_ohci->hcd = hcd;
@@ -123,7 +136,7 @@ static int __devinit exynos_ohci_probe(struct platform_device *pdev)
123 136
124 hcd->rsrc_start = res->start; 137 hcd->rsrc_start = res->start;
125 hcd->rsrc_len = resource_size(res); 138 hcd->rsrc_len = resource_size(res);
126 hcd->regs = ioremap(res->start, resource_size(res)); 139 hcd->regs = devm_ioremap(&pdev->dev, res->start, hcd->rsrc_len);
127 if (!hcd->regs) { 140 if (!hcd->regs) {
128 dev_err(&pdev->dev, "Failed to remap I/O memory\n"); 141 dev_err(&pdev->dev, "Failed to remap I/O memory\n");
129 err = -ENOMEM; 142 err = -ENOMEM;
@@ -134,7 +147,7 @@ static int __devinit exynos_ohci_probe(struct platform_device *pdev)
134 if (!irq) { 147 if (!irq) {
135 dev_err(&pdev->dev, "Failed to get IRQ\n"); 148 dev_err(&pdev->dev, "Failed to get IRQ\n");
136 err = -ENODEV; 149 err = -ENODEV;
137 goto fail; 150 goto fail_io;
138 } 151 }
139 152
140 if (pdata->phy_init) 153 if (pdata->phy_init)
@@ -146,23 +159,19 @@ static int __devinit exynos_ohci_probe(struct platform_device *pdev)
146 err = usb_add_hcd(hcd, irq, IRQF_SHARED); 159 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
147 if (err) { 160 if (err) {
148 dev_err(&pdev->dev, "Failed to add USB HCD\n"); 161 dev_err(&pdev->dev, "Failed to add USB HCD\n");
149 goto fail; 162 goto fail_io;
150 } 163 }
151 164
152 platform_set_drvdata(pdev, exynos_ohci); 165 platform_set_drvdata(pdev, exynos_ohci);
153 166
154 return 0; 167 return 0;
155 168
156fail:
157 iounmap(hcd->regs);
158fail_io: 169fail_io:
159 clk_disable(exynos_ohci->clk); 170 clk_disable(exynos_ohci->clk);
160fail_clken: 171fail_clken:
161 clk_put(exynos_ohci->clk); 172 clk_put(exynos_ohci->clk);
162fail_clk: 173fail_clk:
163 usb_put_hcd(hcd); 174 usb_put_hcd(hcd);
164fail_hcd:
165 kfree(exynos_ohci);
166 return err; 175 return err;
167} 176}
168 177
@@ -177,13 +186,10 @@ static int __devexit exynos_ohci_remove(struct platform_device *pdev)
177 if (pdata && pdata->phy_exit) 186 if (pdata && pdata->phy_exit)
178 pdata->phy_exit(pdev, S5P_USB_PHY_HOST); 187 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
179 188
180 iounmap(hcd->regs);
181
182 clk_disable(exynos_ohci->clk); 189 clk_disable(exynos_ohci->clk);
183 clk_put(exynos_ohci->clk); 190 clk_put(exynos_ohci->clk);
184 191
185 usb_put_hcd(hcd); 192 usb_put_hcd(hcd);
186 kfree(exynos_ohci);
187 193
188 return 0; 194 return 0;
189} 195}
@@ -225,6 +231,9 @@ static int exynos_ohci_suspend(struct device *dev)
225 231
226 if (pdata && pdata->phy_exit) 232 if (pdata && pdata->phy_exit)
227 pdata->phy_exit(pdev, S5P_USB_PHY_HOST); 233 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
234
235 clk_disable(exynos_ohci->clk);
236
228fail: 237fail:
229 spin_unlock_irqrestore(&ohci->lock, flags); 238 spin_unlock_irqrestore(&ohci->lock, flags);
230 239
@@ -238,6 +247,8 @@ static int exynos_ohci_resume(struct device *dev)
238 struct platform_device *pdev = to_platform_device(dev); 247 struct platform_device *pdev = to_platform_device(dev);
239 struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data; 248 struct exynos4_ohci_platdata *pdata = pdev->dev.platform_data;
240 249
250 clk_enable(exynos_ohci->clk);
251
241 if (pdata && pdata->phy_init) 252 if (pdata && pdata->phy_init)
242 pdata->phy_init(pdev, S5P_USB_PHY_HOST); 253 pdata->phy_init(pdev, S5P_USB_PHY_HOST);
243 254
@@ -258,6 +269,14 @@ static const struct dev_pm_ops exynos_ohci_pm_ops = {
258 .resume = exynos_ohci_resume, 269 .resume = exynos_ohci_resume,
259}; 270};
260 271
272#ifdef CONFIG_OF
273static const struct of_device_id exynos_ohci_match[] = {
274 { .compatible = "samsung,exynos-ohci" },
275 {},
276};
277MODULE_DEVICE_TABLE(of, exynos_ohci_match);
278#endif
279
261static struct platform_driver exynos_ohci_driver = { 280static struct platform_driver exynos_ohci_driver = {
262 .probe = exynos_ohci_probe, 281 .probe = exynos_ohci_probe,
263 .remove = __devexit_p(exynos_ohci_remove), 282 .remove = __devexit_p(exynos_ohci_remove),
@@ -266,6 +285,7 @@ static struct platform_driver exynos_ohci_driver = {
266 .name = "exynos-ohci", 285 .name = "exynos-ohci",
267 .owner = THIS_MODULE, 286 .owner = THIS_MODULE,
268 .pm = &exynos_ohci_pm_ops, 287 .pm = &exynos_ohci_pm_ops,
288 .of_match_table = of_match_ptr(exynos_ohci_match),
269 } 289 }
270}; 290};
271 291
diff --git a/drivers/usb/host/ohci-nxp.c b/drivers/usb/host/ohci-nxp.c
index 1e364ec962fb..a446386bf779 100644
--- a/drivers/usb/host/ohci-nxp.c
+++ b/drivers/usb/host/ohci-nxp.c
@@ -43,16 +43,6 @@
43#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) 44#define PAD_CONTROL_LAST_DRIVEN (1 << 19)
45 45
46#define USB_OTG_CLK_CTRL IO_ADDRESS(USB_CONFIG_BASE + 0xFF4)
47#define USB_OTG_CLK_STAT IO_ADDRESS(USB_CONFIG_BASE + 0xFF8)
48
49/* USB_OTG_CLK_CTRL bit defines */
50#define AHB_M_CLOCK_ON (1 << 4)
51#define OTG_CLOCK_ON (1 << 3)
52#define I2C_CLOCK_ON (1 << 2)
53#define DEV_CLOCK_ON (1 << 1)
54#define HOST_CLOCK_ON (1 << 0)
55
56#define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110) 46#define USB_OTG_STAT_CONTROL IO_ADDRESS(USB_CONFIG_BASE + 0x110)
57 47
58/* USB_OTG_STAT_CONTROL bit defines */ 48/* USB_OTG_STAT_CONTROL bit defines */
@@ -72,7 +62,9 @@ static struct i2c_client *isp1301_i2c_client;
72 62
73extern int usb_disabled(void); 63extern int usb_disabled(void);
74 64
75static struct clk *usb_clk; 65static struct clk *usb_pll_clk;
66static struct clk *usb_dev_clk;
67static struct clk *usb_otg_clk;
76 68
77static void isp1301_configure_pnx4008(void) 69static void isp1301_configure_pnx4008(void)
78{ 70{
@@ -249,8 +241,6 @@ static const struct hc_driver ohci_nxp_hc_driver = {
249 .start_port_reset = ohci_start_port_reset, 241 .start_port_reset = ohci_start_port_reset,
250}; 242};
251 243
252#define USB_CLOCK_MASK (AHB_M_CLOCK_ON| OTG_CLOCK_ON | HOST_CLOCK_ON | I2C_CLOCK_ON)
253
254static void nxp_set_usb_bits(void) 244static void nxp_set_usb_bits(void)
255{ 245{
256 if (machine_is_pnx4008()) { 246 if (machine_is_pnx4008()) {
@@ -327,41 +317,63 @@ static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
327 /* Enable AHB slave USB clock, needed for further USB clock control */ 317 /* Enable AHB slave USB clock, needed for further USB clock control */
328 __raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL); 318 __raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL);
329 319
330 isp1301_configure();
331
332 /* Enable USB PLL */ 320 /* Enable USB PLL */
333 usb_clk = clk_get(&pdev->dev, "ck_pll5"); 321 usb_pll_clk = clk_get(&pdev->dev, "ck_pll5");
334 if (IS_ERR(usb_clk)) { 322 if (IS_ERR(usb_pll_clk)) {
335 dev_err(&pdev->dev, "failed to acquire USB PLL\n"); 323 dev_err(&pdev->dev, "failed to acquire USB PLL\n");
336 ret = PTR_ERR(usb_clk); 324 ret = PTR_ERR(usb_pll_clk);
337 goto out1; 325 goto out1;
338 } 326 }
339 327
340 ret = clk_enable(usb_clk); 328 ret = clk_enable(usb_pll_clk);
341 if (ret < 0) { 329 if (ret < 0) {
342 dev_err(&pdev->dev, "failed to start USB PLL\n"); 330 dev_err(&pdev->dev, "failed to start USB PLL\n");
343 goto out2; 331 goto out2;
344 } 332 }
345 333
346 ret = clk_set_rate(usb_clk, 48000); 334 ret = clk_set_rate(usb_pll_clk, 48000);
347 if (ret < 0) { 335 if (ret < 0) {
348 dev_err(&pdev->dev, "failed to set USB clock rate\n"); 336 dev_err(&pdev->dev, "failed to set USB clock rate\n");
349 goto out3; 337 goto out3;
350 } 338 }
351 339
340 /* Enable USB device clock */
341 usb_dev_clk = clk_get(&pdev->dev, "ck_usbd");
342 if (IS_ERR(usb_dev_clk)) {
343 dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n");
344 ret = PTR_ERR(usb_dev_clk);
345 goto out4;
346 }
347
348 ret = clk_enable(usb_dev_clk);
349 if (ret < 0) {
350 dev_err(&pdev->dev, "failed to start USB DEV Clock\n");
351 goto out5;
352 }
353
354 /* Enable USB otg clocks */
355 usb_otg_clk = clk_get(&pdev->dev, "ck_usb_otg");
356 if (IS_ERR(usb_otg_clk)) {
357 dev_err(&pdev->dev, "failed to acquire USB DEV Clock\n");
358 ret = PTR_ERR(usb_dev_clk);
359 goto out6;
360 }
361
352 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL); 362 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
353 363
354 /* Set to enable all needed USB clocks */ 364 ret = clk_enable(usb_otg_clk);
355 __raw_writel(USB_CLOCK_MASK, USB_OTG_CLK_CTRL); 365 if (ret < 0) {
366 dev_err(&pdev->dev, "failed to start USB DEV Clock\n");
367 goto out7;
368 }
356 369
357 while ((__raw_readl(USB_OTG_CLK_STAT) & USB_CLOCK_MASK) != 370 isp1301_configure();
358 USB_CLOCK_MASK) ;
359 371
360 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); 372 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
361 if (!hcd) { 373 if (!hcd) {
362 dev_err(&pdev->dev, "Failed to allocate HC buffer\n"); 374 dev_err(&pdev->dev, "Failed to allocate HC buffer\n");
363 ret = -ENOMEM; 375 ret = -ENOMEM;
364 goto out3; 376 goto out8;
365 } 377 }
366 378
367 /* Set all USB bits in the Start Enable register */ 379 /* Set all USB bits in the Start Enable register */
@@ -371,14 +383,14 @@ static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
371 if (!res) { 383 if (!res) {
372 dev_err(&pdev->dev, "Failed to get MEM resource\n"); 384 dev_err(&pdev->dev, "Failed to get MEM resource\n");
373 ret = -ENOMEM; 385 ret = -ENOMEM;
374 goto out4; 386 goto out8;
375 } 387 }
376 388
377 hcd->regs = devm_request_and_ioremap(&pdev->dev, res); 389 hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
378 if (!hcd->regs) { 390 if (!hcd->regs) {
379 dev_err(&pdev->dev, "Failed to devm_request_and_ioremap\n"); 391 dev_err(&pdev->dev, "Failed to devm_request_and_ioremap\n");
380 ret = -ENOMEM; 392 ret = -ENOMEM;
381 goto out4; 393 goto out8;
382 } 394 }
383 hcd->rsrc_start = res->start; 395 hcd->rsrc_start = res->start;
384 hcd->rsrc_len = resource_size(res); 396 hcd->rsrc_len = resource_size(res);
@@ -386,7 +398,7 @@ static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
386 irq = platform_get_irq(pdev, 0); 398 irq = platform_get_irq(pdev, 0);
387 if (irq < 0) { 399 if (irq < 0) {
388 ret = -ENXIO; 400 ret = -ENXIO;
389 goto out4; 401 goto out8;
390 } 402 }
391 403
392 nxp_start_hc(); 404 nxp_start_hc();
@@ -400,13 +412,21 @@ static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
400 return ret; 412 return ret;
401 413
402 nxp_stop_hc(); 414 nxp_stop_hc();
403out4: 415out8:
404 nxp_unset_usb_bits(); 416 nxp_unset_usb_bits();
405 usb_put_hcd(hcd); 417 usb_put_hcd(hcd);
418out7:
419 clk_disable(usb_otg_clk);
420out6:
421 clk_put(usb_otg_clk);
422out5:
423 clk_disable(usb_dev_clk);
424out4:
425 clk_put(usb_dev_clk);
406out3: 426out3:
407 clk_disable(usb_clk); 427 clk_disable(usb_pll_clk);
408out2: 428out2:
409 clk_put(usb_clk); 429 clk_put(usb_pll_clk);
410out1: 430out1:
411 isp1301_i2c_client = NULL; 431 isp1301_i2c_client = NULL;
412out: 432out:
@@ -422,8 +442,10 @@ static int usb_hcd_nxp_remove(struct platform_device *pdev)
422 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 442 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
423 usb_put_hcd(hcd); 443 usb_put_hcd(hcd);
424 nxp_unset_usb_bits(); 444 nxp_unset_usb_bits();
425 clk_disable(usb_clk); 445 clk_disable(usb_pll_clk);
426 clk_put(usb_clk); 446 clk_put(usb_pll_clk);
447 clk_disable(usb_dev_clk);
448 clk_put(usb_dev_clk);
427 i2c_unregister_device(isp1301_i2c_client); 449 i2c_unregister_device(isp1301_i2c_client);
428 isp1301_i2c_client = NULL; 450 isp1301_i2c_client = NULL;
429 451
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index b02c344e2cc9..e7d75d295988 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -18,6 +18,7 @@
18#include <linux/jiffies.h> 18#include <linux/jiffies.h>
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/clk.h> 20#include <linux/clk.h>
21#include <linux/err.h>
21#include <linux/gpio.h> 22#include <linux/gpio.h>
22 23
23#include <asm/io.h> 24#include <asm/io.h>
@@ -168,14 +169,15 @@ static int omap_1510_local_bus_init(void)
168 169
169static void start_hnp(struct ohci_hcd *ohci) 170static void start_hnp(struct ohci_hcd *ohci)
170{ 171{
171 const unsigned port = ohci_to_hcd(ohci)->self.otg_port - 1; 172 struct usb_hcd *hcd = ohci_to_hcd(ohci);
173 const unsigned port = hcd->self.otg_port - 1;
172 unsigned long flags; 174 unsigned long flags;
173 u32 l; 175 u32 l;
174 176
175 otg_start_hnp(ohci->transceiver->otg); 177 otg_start_hnp(hcd->phy->otg);
176 178
177 local_irq_save(flags); 179 local_irq_save(flags);
178 ohci->transceiver->state = OTG_STATE_A_SUSPEND; 180 hcd->phy->state = OTG_STATE_A_SUSPEND;
179 writel (RH_PS_PSS, &ohci->regs->roothub.portstatus [port]); 181 writel (RH_PS_PSS, &ohci->regs->roothub.portstatus [port]);
180 l = omap_readl(OTG_CTRL); 182 l = omap_readl(OTG_CTRL);
181 l &= ~OTG_A_BUSREQ; 183 l &= ~OTG_A_BUSREQ;
@@ -212,18 +214,18 @@ static int ohci_omap_init(struct usb_hcd *hcd)
212 214
213#ifdef CONFIG_USB_OTG 215#ifdef CONFIG_USB_OTG
214 if (need_transceiver) { 216 if (need_transceiver) {
215 ohci->transceiver = usb_get_transceiver(); 217 hcd->phy = usb_get_phy(USB_PHY_TYPE_USB2);
216 if (ohci->transceiver) { 218 if (!IS_ERR_OR_NULL(hcd->phy)) {
217 int status = otg_set_host(ohci->transceiver->otg, 219 int status = otg_set_host(hcd->phy->otg,
218 &ohci_to_hcd(ohci)->self); 220 &ohci_to_hcd(ohci)->self);
219 dev_dbg(hcd->self.controller, "init %s transceiver, status %d\n", 221 dev_dbg(hcd->self.controller, "init %s phy, status %d\n",
220 ohci->transceiver->label, status); 222 hcd->phy->label, status);
221 if (status) { 223 if (status) {
222 usb_put_transceiver(ohci->transceiver); 224 usb_put_phy(hcd->phy);
223 return status; 225 return status;
224 } 226 }
225 } else { 227 } else {
226 dev_err(hcd->self.controller, "can't find transceiver\n"); 228 dev_err(hcd->self.controller, "can't find phy\n");
227 return -ENODEV; 229 return -ENODEV;
228 } 230 }
229 ohci->start_hnp = start_hnp; 231 ohci->start_hnp = start_hnp;
@@ -404,9 +406,9 @@ usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev)
404 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 406 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
405 407
406 usb_remove_hcd(hcd); 408 usb_remove_hcd(hcd);
407 if (ohci->transceiver) { 409 if (!IS_ERR_OR_NULL(hcd->phy)) {
408 (void) otg_set_host(ohci->transceiver->otg, 0); 410 (void) otg_set_host(hcd->phy->otg, 0);
409 usb_put_transceiver(ohci->transceiver); 411 usb_put_phy(hcd->phy);
410 } 412 }
411 if (machine_is_omap_osk()) 413 if (machine_is_omap_osk())
412 gpio_free(9); 414 gpio_free(9);
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index 1b19aea25a2b..d3299143d9e2 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -372,11 +372,6 @@ struct ohci_hcd {
372 struct ed *ed_controltail; /* last in ctrl list */ 372 struct ed *ed_controltail; /* last in ctrl list */
373 struct ed *periodic [NUM_INTS]; /* shadow int_table */ 373 struct ed *periodic [NUM_INTS]; /* shadow int_table */
374 374
375 /*
376 * OTG controllers and transceivers need software interaction;
377 * other external transceivers should be software-transparent
378 */
379 struct usb_phy *transceiver;
380 void (*start_hnp)(struct ohci_hcd *ohci); 375 void (*start_hnp)(struct ohci_hcd *ohci);
381 376
382 /* 377 /*
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 7b01094d7993..74bfc868b7ad 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -544,12 +544,18 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
544 if (hcd->speed != HCD_USB3) 544 if (hcd->speed != HCD_USB3)
545 goto error; 545 goto error;
546 546
547 /* Set the U1 and U2 exit latencies. */
547 memcpy(buf, &usb_bos_descriptor, 548 memcpy(buf, &usb_bos_descriptor,
548 USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE); 549 USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE);
549 temp = xhci_readl(xhci, &xhci->cap_regs->hcs_params3); 550 temp = xhci_readl(xhci, &xhci->cap_regs->hcs_params3);
550 buf[12] = HCS_U1_LATENCY(temp); 551 buf[12] = HCS_U1_LATENCY(temp);
551 put_unaligned_le16(HCS_U2_LATENCY(temp), &buf[13]); 552 put_unaligned_le16(HCS_U2_LATENCY(temp), &buf[13]);
552 553
554 /* Indicate whether the host has LTM support. */
555 temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
556 if (HCC_LTC(temp))
557 buf[8] |= USB_LTM_SUPPORT;
558
553 spin_unlock_irqrestore(&xhci->lock, flags); 559 spin_unlock_irqrestore(&xhci->lock, flags);
554 return USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE; 560 return USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE;
555 case GetPortStatus: 561 case GetPortStatus:
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index a979cd0dbe0f..7648b2d4b268 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4450,6 +4450,8 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
4450 4450
4451 /* Accept arbitrarily long scatter-gather lists */ 4451 /* Accept arbitrarily long scatter-gather lists */
4452 hcd->self.sg_tablesize = ~0; 4452 hcd->self.sg_tablesize = ~0;
4453 /* XHCI controllers don't stop the ep queue on short packets :| */
4454 hcd->self.no_stop_on_short = 1;
4453 4455
4454 if (usb_hcd_is_primary_hcd(hcd)) { 4456 if (usb_hcd_is_primary_hcd(hcd)) {
4455 xhci = kzalloc(sizeof(struct xhci_hcd), GFP_KERNEL); 4457 xhci = kzalloc(sizeof(struct xhci_hcd), GFP_KERNEL);