diff options
Diffstat (limited to 'drivers/usb/host')
75 files changed, 3690 insertions, 934 deletions
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index ab085f12d570..060e0e2b1ae6 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig | |||
| @@ -19,7 +19,7 @@ config USB_C67X00_HCD | |||
| 19 | 19 | ||
| 20 | config USB_XHCI_HCD | 20 | config USB_XHCI_HCD |
| 21 | tristate "xHCI HCD (USB 3.0) support (EXPERIMENTAL)" | 21 | tristate "xHCI HCD (USB 3.0) support (EXPERIMENTAL)" |
| 22 | depends on USB && PCI && EXPERIMENTAL | 22 | depends on USB && USB_ARCH_HAS_XHCI && EXPERIMENTAL |
| 23 | ---help--- | 23 | ---help--- |
| 24 | The eXtensible Host Controller Interface (xHCI) is standard for USB 3.0 | 24 | The eXtensible Host Controller Interface (xHCI) is standard for USB 3.0 |
| 25 | "SuperSpeed" host controller hardware. | 25 | "SuperSpeed" host controller hardware. |
| @@ -515,6 +515,19 @@ config USB_R8A66597_HCD | |||
| 515 | To compile this driver as a module, choose M here: the | 515 | To compile this driver as a module, choose M here: the |
| 516 | module will be called r8a66597-hcd. | 516 | module will be called r8a66597-hcd. |
| 517 | 517 | ||
| 518 | config USB_RENESAS_USBHS_HCD | ||
| 519 | tristate "Renesas USBHS HCD support" | ||
| 520 | depends on USB | ||
| 521 | depends on USB_RENESAS_USBHS | ||
| 522 | help | ||
| 523 | The Renesas USBHS is a USB 2.0 host and peripheral controller. | ||
| 524 | |||
| 525 | Enable this option if your board has this chip, and you want | ||
| 526 | to use it as a host controller. If unsure, say N. | ||
| 527 | |||
| 528 | To compile this driver as a module, choose M here: the | ||
| 529 | module will be called renesas-usbhs. | ||
| 530 | |||
| 518 | config USB_WHCI_HCD | 531 | config USB_WHCI_HCD |
| 519 | tristate "Wireless USB Host Controller Interface (WHCI) driver (EXPERIMENTAL)" | 532 | tristate "Wireless USB Host Controller Interface (WHCI) driver (EXPERIMENTAL)" |
| 520 | depends on EXPERIMENTAL | 533 | depends on EXPERIMENTAL |
| @@ -544,11 +557,11 @@ config USB_HWA_HCD | |||
| 544 | will be called "hwa-hc". | 557 | will be called "hwa-hc". |
| 545 | 558 | ||
| 546 | config USB_IMX21_HCD | 559 | config USB_IMX21_HCD |
| 547 | tristate "iMX21 HCD support" | 560 | tristate "i.MX21 HCD support" |
| 548 | depends on USB && ARM && MACH_MX21 | 561 | depends on USB && ARM && ARCH_MXC |
| 549 | help | 562 | help |
| 550 | This driver enables support for the on-chip USB host in the | 563 | This driver enables support for the on-chip USB host in the |
| 551 | iMX21 processor. | 564 | i.MX21 processor. |
| 552 | 565 | ||
| 553 | To compile this driver as a module, choose M here: the | 566 | To compile this driver as a module, choose M here: the |
| 554 | module will be called "imx21-hcd". | 567 | module will be called "imx21-hcd". |
| @@ -578,3 +591,10 @@ config USB_OCTEON_OHCI | |||
| 578 | config USB_OCTEON2_COMMON | 591 | config USB_OCTEON2_COMMON |
| 579 | bool | 592 | bool |
| 580 | default y if USB_OCTEON_EHCI || USB_OCTEON_OHCI | 593 | default y if USB_OCTEON_EHCI || USB_OCTEON_OHCI |
| 594 | |||
| 595 | config USB_PXA168_EHCI | ||
| 596 | bool "Marvell PXA168 on-chip EHCI HCD support" | ||
| 597 | depends on USB_EHCI_HCD && ARCH_MMP | ||
| 598 | help | ||
| 599 | Enable support for Marvell PXA168 SoC's on-chip EHCI | ||
| 600 | host controller | ||
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index 624a362f2fee..7ca290fcb070 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile | |||
| @@ -11,8 +11,9 @@ fhci-y += fhci-mem.o fhci-tds.o fhci-sched.o | |||
| 11 | 11 | ||
| 12 | fhci-$(CONFIG_FHCI_DEBUG) += fhci-dbg.o | 12 | fhci-$(CONFIG_FHCI_DEBUG) += fhci-dbg.o |
| 13 | 13 | ||
| 14 | xhci-hcd-y := xhci.o xhci-mem.o xhci-pci.o | 14 | xhci-hcd-y := xhci.o xhci-mem.o |
| 15 | xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o | 15 | xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o |
| 16 | xhci-hcd-$(CONFIG_PCI) += xhci-pci.o | ||
| 16 | 17 | ||
| 17 | obj-$(CONFIG_USB_WHCI_HCD) += whci/ | 18 | obj-$(CONFIG_USB_WHCI_HCD) += whci/ |
| 18 | 19 | ||
| @@ -35,3 +36,4 @@ obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o | |||
| 35 | obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o | 36 | obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o |
| 36 | obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o | 37 | obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o |
| 37 | obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o | 38 | obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o |
| 39 | obj-$(CONFIG_MIPS_ALCHEMY) += alchemy-common.o | ||
diff --git a/drivers/usb/host/alchemy-common.c b/drivers/usb/host/alchemy-common.c new file mode 100644 index 000000000000..b4192c964d0d --- /dev/null +++ b/drivers/usb/host/alchemy-common.c | |||
| @@ -0,0 +1,337 @@ | |||
| 1 | /* | ||
| 2 | * USB block power/access management abstraction. | ||
| 3 | * | ||
| 4 | * Au1000+: The OHCI block control register is at the far end of the OHCI memory | ||
| 5 | * area. Au1550 has OHCI on different base address. No need to handle | ||
| 6 | * UDC here. | ||
| 7 | * Au1200: one register to control access and clocks to O/EHCI, UDC and OTG | ||
| 8 | * as well as the PHY for EHCI and UDC. | ||
| 9 | * | ||
| 10 | */ | ||
| 11 | |||
| 12 | #include <linux/init.h> | ||
| 13 | #include <linux/io.h> | ||
| 14 | #include <linux/module.h> | ||
| 15 | #include <linux/spinlock.h> | ||
| 16 | #include <linux/syscore_ops.h> | ||
| 17 | #include <asm/mach-au1x00/au1000.h> | ||
| 18 | |||
| 19 | /* control register offsets */ | ||
| 20 | #define AU1000_OHCICFG 0x7fffc | ||
| 21 | #define AU1550_OHCICFG 0x07ffc | ||
| 22 | #define AU1200_USBCFG 0x04 | ||
| 23 | |||
| 24 | /* Au1000 USB block config bits */ | ||
| 25 | #define USBHEN_RD (1 << 4) /* OHCI reset-done indicator */ | ||
| 26 | #define USBHEN_CE (1 << 3) /* OHCI block clock enable */ | ||
| 27 | #define USBHEN_E (1 << 2) /* OHCI block enable */ | ||
| 28 | #define USBHEN_C (1 << 1) /* OHCI block coherency bit */ | ||
| 29 | #define USBHEN_BE (1 << 0) /* OHCI Big-Endian */ | ||
| 30 | |||
| 31 | /* Au1200 USB config bits */ | ||
| 32 | #define USBCFG_PFEN (1 << 31) /* prefetch enable (undoc) */ | ||
| 33 | #define USBCFG_RDCOMB (1 << 30) /* read combining (undoc) */ | ||
| 34 | #define USBCFG_UNKNOWN (5 << 20) /* unknown, leave this way */ | ||
| 35 | #define USBCFG_SSD (1 << 23) /* serial short detect en */ | ||
| 36 | #define USBCFG_PPE (1 << 19) /* HS PHY PLL */ | ||
| 37 | #define USBCFG_UCE (1 << 18) /* UDC clock enable */ | ||
| 38 | #define USBCFG_ECE (1 << 17) /* EHCI clock enable */ | ||
| 39 | #define USBCFG_OCE (1 << 16) /* OHCI clock enable */ | ||
| 40 | #define USBCFG_FLA(x) (((x) & 0x3f) << 8) | ||
| 41 | #define USBCFG_UCAM (1 << 7) /* coherent access (undoc) */ | ||
| 42 | #define USBCFG_GME (1 << 6) /* OTG mem access */ | ||
| 43 | #define USBCFG_DBE (1 << 5) /* UDC busmaster enable */ | ||
| 44 | #define USBCFG_DME (1 << 4) /* UDC mem enable */ | ||
| 45 | #define USBCFG_EBE (1 << 3) /* EHCI busmaster enable */ | ||
| 46 | #define USBCFG_EME (1 << 2) /* EHCI mem enable */ | ||
| 47 | #define USBCFG_OBE (1 << 1) /* OHCI busmaster enable */ | ||
| 48 | #define USBCFG_OME (1 << 0) /* OHCI mem enable */ | ||
| 49 | #define USBCFG_INIT_AU1200 (USBCFG_PFEN | USBCFG_RDCOMB | USBCFG_UNKNOWN |\ | ||
| 50 | USBCFG_SSD | USBCFG_FLA(0x20) | USBCFG_UCAM | \ | ||
| 51 | USBCFG_GME | USBCFG_DBE | USBCFG_DME | \ | ||
| 52 | USBCFG_EBE | USBCFG_EME | USBCFG_OBE | \ | ||
| 53 | USBCFG_OME) | ||
| 54 | |||
| 55 | |||
| 56 | static DEFINE_SPINLOCK(alchemy_usb_lock); | ||
| 57 | |||
| 58 | |||
| 59 | static inline void __au1200_ohci_control(void __iomem *base, int enable) | ||
| 60 | { | ||
| 61 | unsigned long r = __raw_readl(base + AU1200_USBCFG); | ||
| 62 | if (enable) { | ||
| 63 | __raw_writel(r | USBCFG_OCE, base + AU1200_USBCFG); | ||
| 64 | wmb(); | ||
| 65 | udelay(2000); | ||
| 66 | } else { | ||
| 67 | __raw_writel(r & ~USBCFG_OCE, base + AU1200_USBCFG); | ||
| 68 | wmb(); | ||
| 69 | udelay(1000); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | static inline void __au1200_ehci_control(void __iomem *base, int enable) | ||
| 74 | { | ||
| 75 | unsigned long r = __raw_readl(base + AU1200_USBCFG); | ||
| 76 | if (enable) { | ||
| 77 | __raw_writel(r | USBCFG_ECE | USBCFG_PPE, base + AU1200_USBCFG); | ||
| 78 | wmb(); | ||
| 79 | udelay(1000); | ||
| 80 | } else { | ||
| 81 | if (!(r & USBCFG_UCE)) /* UDC also off? */ | ||
| 82 | r &= ~USBCFG_PPE; /* yes: disable HS PHY PLL */ | ||
| 83 | __raw_writel(r & ~USBCFG_ECE, base + AU1200_USBCFG); | ||
| 84 | wmb(); | ||
| 85 | udelay(1000); | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | static inline void __au1200_udc_control(void __iomem *base, int enable) | ||
| 90 | { | ||
| 91 | unsigned long r = __raw_readl(base + AU1200_USBCFG); | ||
| 92 | if (enable) { | ||
| 93 | __raw_writel(r | USBCFG_UCE | USBCFG_PPE, base + AU1200_USBCFG); | ||
| 94 | wmb(); | ||
| 95 | } else { | ||
| 96 | if (!(r & USBCFG_ECE)) /* EHCI also off? */ | ||
| 97 | r &= ~USBCFG_PPE; /* yes: disable HS PHY PLL */ | ||
| 98 | __raw_writel(r & ~USBCFG_UCE, base + AU1200_USBCFG); | ||
| 99 | wmb(); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | static inline int au1200_coherency_bug(void) | ||
| 104 | { | ||
| 105 | #if defined(CONFIG_DMA_COHERENT) | ||
| 106 | /* Au1200 AB USB does not support coherent memory */ | ||
| 107 | if (!(read_c0_prid() & 0xff)) { | ||
| 108 | printk(KERN_INFO "Au1200 USB: this is chip revision AB !!\n"); | ||
| 109 | printk(KERN_INFO "Au1200 USB: update your board or re-configure" | ||
| 110 | " the kernel\n"); | ||
| 111 | return -ENODEV; | ||
| 112 | } | ||
| 113 | #endif | ||
| 114 | return 0; | ||
| 115 | } | ||
| 116 | |||
| 117 | static inline int au1200_usb_control(int block, int enable) | ||
| 118 | { | ||
| 119 | void __iomem *base = | ||
| 120 | (void __iomem *)KSEG1ADDR(AU1200_USB_CTL_PHYS_ADDR); | ||
| 121 | int ret = 0; | ||
| 122 | |||
| 123 | switch (block) { | ||
| 124 | case ALCHEMY_USB_OHCI0: | ||
| 125 | ret = au1200_coherency_bug(); | ||
| 126 | if (ret && enable) | ||
| 127 | goto out; | ||
| 128 | __au1200_ohci_control(base, enable); | ||
| 129 | break; | ||
| 130 | case ALCHEMY_USB_UDC0: | ||
| 131 | __au1200_udc_control(base, enable); | ||
| 132 | break; | ||
| 133 | case ALCHEMY_USB_EHCI0: | ||
| 134 | ret = au1200_coherency_bug(); | ||
| 135 | if (ret && enable) | ||
| 136 | goto out; | ||
| 137 | __au1200_ehci_control(base, enable); | ||
| 138 | break; | ||
| 139 | default: | ||
| 140 | ret = -ENODEV; | ||
| 141 | } | ||
| 142 | out: | ||
| 143 | return ret; | ||
| 144 | } | ||
| 145 | |||
| 146 | |||
| 147 | /* initialize USB block(s) to a known working state */ | ||
| 148 | static inline void au1200_usb_init(void) | ||
| 149 | { | ||
| 150 | void __iomem *base = | ||
| 151 | (void __iomem *)KSEG1ADDR(AU1200_USB_CTL_PHYS_ADDR); | ||
| 152 | __raw_writel(USBCFG_INIT_AU1200, base + AU1200_USBCFG); | ||
| 153 | wmb(); | ||
| 154 | udelay(1000); | ||
| 155 | } | ||
| 156 | |||
| 157 | static inline void au1000_usb_init(unsigned long rb, int reg) | ||
| 158 | { | ||
| 159 | void __iomem *base = (void __iomem *)KSEG1ADDR(rb + reg); | ||
| 160 | unsigned long r = __raw_readl(base); | ||
| 161 | |||
| 162 | #if defined(__BIG_ENDIAN) | ||
| 163 | r |= USBHEN_BE; | ||
| 164 | #endif | ||
| 165 | r |= USBHEN_C; | ||
| 166 | |||
| 167 | __raw_writel(r, base); | ||
| 168 | wmb(); | ||
| 169 | udelay(1000); | ||
| 170 | } | ||
| 171 | |||
| 172 | |||
| 173 | static inline void __au1xx0_ohci_control(int enable, unsigned long rb, int creg) | ||
| 174 | { | ||
| 175 | void __iomem *base = (void __iomem *)KSEG1ADDR(rb); | ||
| 176 | unsigned long r = __raw_readl(base + creg); | ||
| 177 | |||
| 178 | if (enable) { | ||
| 179 | __raw_writel(r | USBHEN_CE, base + creg); | ||
| 180 | wmb(); | ||
| 181 | udelay(1000); | ||
| 182 | __raw_writel(r | USBHEN_CE | USBHEN_E, base + creg); | ||
| 183 | wmb(); | ||
| 184 | udelay(1000); | ||
| 185 | |||
| 186 | /* wait for reset complete (read reg twice: au1500 erratum) */ | ||
| 187 | while (__raw_readl(base + creg), | ||
| 188 | !(__raw_readl(base + creg) & USBHEN_RD)) | ||
| 189 | udelay(1000); | ||
| 190 | } else { | ||
| 191 | __raw_writel(r & ~(USBHEN_CE | USBHEN_E), base + creg); | ||
| 192 | wmb(); | ||
| 193 | } | ||
| 194 | } | ||
| 195 | |||
| 196 | static inline int au1000_usb_control(int block, int enable, unsigned long rb, | ||
| 197 | int creg) | ||
| 198 | { | ||
| 199 | int ret = 0; | ||
| 200 | |||
| 201 | switch (block) { | ||
| 202 | case ALCHEMY_USB_OHCI0: | ||
| 203 | __au1xx0_ohci_control(enable, rb, creg); | ||
| 204 | break; | ||
| 205 | default: | ||
| 206 | ret = -ENODEV; | ||
| 207 | } | ||
| 208 | return ret; | ||
| 209 | } | ||
| 210 | |||
| 211 | /* | ||
| 212 | * alchemy_usb_control - control Alchemy on-chip USB blocks | ||
| 213 | * @block: USB block to target | ||
| 214 | * @enable: set 1 to enable a block, 0 to disable | ||
| 215 | */ | ||
| 216 | int alchemy_usb_control(int block, int enable) | ||
| 217 | { | ||
| 218 | unsigned long flags; | ||
| 219 | int ret; | ||
| 220 | |||
| 221 | spin_lock_irqsave(&alchemy_usb_lock, flags); | ||
| 222 | switch (alchemy_get_cputype()) { | ||
| 223 | case ALCHEMY_CPU_AU1000: | ||
| 224 | case ALCHEMY_CPU_AU1500: | ||
| 225 | case ALCHEMY_CPU_AU1100: | ||
| 226 | ret = au1000_usb_control(block, enable, | ||
| 227 | AU1000_USB_OHCI_PHYS_ADDR, AU1000_OHCICFG); | ||
| 228 | break; | ||
| 229 | case ALCHEMY_CPU_AU1550: | ||
| 230 | ret = au1000_usb_control(block, enable, | ||
| 231 | AU1550_USB_OHCI_PHYS_ADDR, AU1550_OHCICFG); | ||
| 232 | break; | ||
| 233 | case ALCHEMY_CPU_AU1200: | ||
| 234 | ret = au1200_usb_control(block, enable); | ||
| 235 | break; | ||
| 236 | default: | ||
| 237 | ret = -ENODEV; | ||
| 238 | } | ||
| 239 | spin_unlock_irqrestore(&alchemy_usb_lock, flags); | ||
| 240 | return ret; | ||
| 241 | } | ||
| 242 | EXPORT_SYMBOL_GPL(alchemy_usb_control); | ||
| 243 | |||
| 244 | |||
| 245 | static unsigned long alchemy_usb_pmdata[2]; | ||
| 246 | |||
| 247 | static void au1000_usb_pm(unsigned long br, int creg, int susp) | ||
| 248 | { | ||
| 249 | void __iomem *base = (void __iomem *)KSEG1ADDR(br); | ||
| 250 | |||
| 251 | if (susp) { | ||
| 252 | alchemy_usb_pmdata[0] = __raw_readl(base + creg); | ||
| 253 | /* There appears to be some undocumented reset register.... */ | ||
| 254 | __raw_writel(0, base + 0x04); | ||
| 255 | wmb(); | ||
| 256 | __raw_writel(0, base + creg); | ||
| 257 | wmb(); | ||
| 258 | } else { | ||
| 259 | __raw_writel(alchemy_usb_pmdata[0], base + creg); | ||
| 260 | wmb(); | ||
| 261 | } | ||
| 262 | } | ||
| 263 | |||
| 264 | static void au1200_usb_pm(int susp) | ||
| 265 | { | ||
| 266 | void __iomem *base = | ||
| 267 | (void __iomem *)KSEG1ADDR(AU1200_USB_OTG_PHYS_ADDR); | ||
| 268 | if (susp) { | ||
| 269 | /* save OTG_CAP/MUX registers which indicate port routing */ | ||
| 270 | /* FIXME: write an OTG driver to do that */ | ||
| 271 | alchemy_usb_pmdata[0] = __raw_readl(base + 0x00); | ||
| 272 | alchemy_usb_pmdata[1] = __raw_readl(base + 0x04); | ||
| 273 | } else { | ||
| 274 | /* restore access to all MMIO areas */ | ||
| 275 | au1200_usb_init(); | ||
| 276 | |||
| 277 | /* restore OTG_CAP/MUX registers */ | ||
| 278 | __raw_writel(alchemy_usb_pmdata[0], base + 0x00); | ||
| 279 | __raw_writel(alchemy_usb_pmdata[1], base + 0x04); | ||
| 280 | wmb(); | ||
| 281 | } | ||
| 282 | } | ||
| 283 | |||
| 284 | static void alchemy_usb_pm(int susp) | ||
| 285 | { | ||
| 286 | switch (alchemy_get_cputype()) { | ||
| 287 | case ALCHEMY_CPU_AU1000: | ||
| 288 | case ALCHEMY_CPU_AU1500: | ||
| 289 | case ALCHEMY_CPU_AU1100: | ||
| 290 | au1000_usb_pm(AU1000_USB_OHCI_PHYS_ADDR, AU1000_OHCICFG, susp); | ||
| 291 | break; | ||
| 292 | case ALCHEMY_CPU_AU1550: | ||
| 293 | au1000_usb_pm(AU1550_USB_OHCI_PHYS_ADDR, AU1550_OHCICFG, susp); | ||
| 294 | break; | ||
| 295 | case ALCHEMY_CPU_AU1200: | ||
| 296 | au1200_usb_pm(susp); | ||
| 297 | break; | ||
| 298 | } | ||
| 299 | } | ||
| 300 | |||
| 301 | static int alchemy_usb_suspend(void) | ||
| 302 | { | ||
| 303 | alchemy_usb_pm(1); | ||
| 304 | return 0; | ||
| 305 | } | ||
| 306 | |||
| 307 | static void alchemy_usb_resume(void) | ||
| 308 | { | ||
| 309 | alchemy_usb_pm(0); | ||
| 310 | } | ||
| 311 | |||
| 312 | static struct syscore_ops alchemy_usb_pm_ops = { | ||
| 313 | .suspend = alchemy_usb_suspend, | ||
| 314 | .resume = alchemy_usb_resume, | ||
| 315 | }; | ||
| 316 | |||
| 317 | static int __init alchemy_usb_init(void) | ||
| 318 | { | ||
| 319 | switch (alchemy_get_cputype()) { | ||
| 320 | case ALCHEMY_CPU_AU1000: | ||
| 321 | case ALCHEMY_CPU_AU1500: | ||
| 322 | case ALCHEMY_CPU_AU1100: | ||
| 323 | au1000_usb_init(AU1000_USB_OHCI_PHYS_ADDR, AU1000_OHCICFG); | ||
| 324 | break; | ||
| 325 | case ALCHEMY_CPU_AU1550: | ||
| 326 | au1000_usb_init(AU1550_USB_OHCI_PHYS_ADDR, AU1550_OHCICFG); | ||
| 327 | break; | ||
| 328 | case ALCHEMY_CPU_AU1200: | ||
| 329 | au1200_usb_init(); | ||
| 330 | break; | ||
| 331 | } | ||
| 332 | |||
| 333 | register_syscore_ops(&alchemy_usb_pm_ops); | ||
| 334 | |||
| 335 | return 0; | ||
| 336 | } | ||
| 337 | arch_initcall(alchemy_usb_init); | ||
diff --git a/drivers/usb/host/ehci-ath79.c b/drivers/usb/host/ehci-ath79.c index 4d2e88d04dab..afb6743cf094 100644 --- a/drivers/usb/host/ehci-ath79.c +++ b/drivers/usb/host/ehci-ath79.c | |||
| @@ -163,7 +163,7 @@ static int ehci_ath79_probe(struct platform_device *pdev) | |||
| 163 | goto err_release_region; | 163 | goto err_release_region; |
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); | 166 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 167 | if (ret) | 167 | if (ret) |
| 168 | goto err_iounmap; | 168 | goto err_iounmap; |
| 169 | 169 | ||
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c index 42ae57409908..18bafa99fe57 100644 --- a/drivers/usb/host/ehci-au1xxx.c +++ b/drivers/usb/host/ehci-au1xxx.c | |||
| @@ -14,61 +14,9 @@ | |||
| 14 | #include <linux/platform_device.h> | 14 | #include <linux/platform_device.h> |
| 15 | #include <asm/mach-au1x00/au1000.h> | 15 | #include <asm/mach-au1x00/au1000.h> |
| 16 | 16 | ||
| 17 | #define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG) | ||
| 18 | #define USB_MCFG_PFEN (1<<31) | ||
| 19 | #define USB_MCFG_RDCOMB (1<<30) | ||
| 20 | #define USB_MCFG_SSDEN (1<<23) | ||
| 21 | #define USB_MCFG_PHYPLLEN (1<<19) | ||
| 22 | #define USB_MCFG_UCECLKEN (1<<18) | ||
| 23 | #define USB_MCFG_EHCCLKEN (1<<17) | ||
| 24 | #ifdef CONFIG_DMA_COHERENT | ||
| 25 | #define USB_MCFG_UCAM (1<<7) | ||
| 26 | #else | ||
| 27 | #define USB_MCFG_UCAM (0) | ||
| 28 | #endif | ||
| 29 | #define USB_MCFG_EBMEN (1<<3) | ||
| 30 | #define USB_MCFG_EMEMEN (1<<2) | ||
| 31 | |||
| 32 | #define USBH_ENABLE_CE (USB_MCFG_PHYPLLEN | USB_MCFG_EHCCLKEN) | ||
| 33 | #define USBH_ENABLE_INIT (USB_MCFG_PFEN | USB_MCFG_RDCOMB | \ | ||
| 34 | USBH_ENABLE_CE | USB_MCFG_SSDEN | \ | ||
| 35 | USB_MCFG_UCAM | USB_MCFG_EBMEN | \ | ||
| 36 | USB_MCFG_EMEMEN) | ||
| 37 | |||
| 38 | #define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN) | ||
| 39 | 17 | ||
| 40 | extern int usb_disabled(void); | 18 | extern int usb_disabled(void); |
| 41 | 19 | ||
| 42 | static void au1xxx_start_ehc(void) | ||
| 43 | { | ||
| 44 | /* enable clock to EHCI block and HS PHY PLL*/ | ||
| 45 | au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG); | ||
| 46 | au_sync(); | ||
| 47 | udelay(1000); | ||
| 48 | |||
| 49 | /* enable EHCI mmio */ | ||
| 50 | au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG); | ||
| 51 | au_sync(); | ||
| 52 | udelay(1000); | ||
| 53 | } | ||
| 54 | |||
| 55 | static void au1xxx_stop_ehc(void) | ||
| 56 | { | ||
| 57 | unsigned long c; | ||
| 58 | |||
| 59 | /* Disable mem */ | ||
| 60 | au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG); | ||
| 61 | au_sync(); | ||
| 62 | udelay(1000); | ||
| 63 | |||
| 64 | /* Disable EHC clock. If the HS PHY is unused disable it too. */ | ||
| 65 | c = au_readl(USB_HOST_CONFIG) & ~USB_MCFG_EHCCLKEN; | ||
| 66 | if (!(c & USB_MCFG_UCECLKEN)) /* UDC disabled? */ | ||
| 67 | c &= ~USB_MCFG_PHYPLLEN; /* yes: disable HS PHY PLL */ | ||
| 68 | au_writel(c, USB_HOST_CONFIG); | ||
| 69 | au_sync(); | ||
| 70 | } | ||
| 71 | |||
| 72 | static int au1xxx_ehci_setup(struct usb_hcd *hcd) | 20 | static int au1xxx_ehci_setup(struct usb_hcd *hcd) |
| 73 | { | 21 | { |
| 74 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | 22 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| @@ -136,16 +84,6 @@ static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev) | |||
| 136 | if (usb_disabled()) | 84 | if (usb_disabled()) |
| 137 | return -ENODEV; | 85 | return -ENODEV; |
| 138 | 86 | ||
| 139 | #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT) | ||
| 140 | /* Au1200 AB USB does not support coherent memory */ | ||
| 141 | if (!(read_c0_prid() & 0xff)) { | ||
| 142 | printk(KERN_INFO "%s: this is chip revision AB!\n", pdev->name); | ||
| 143 | printk(KERN_INFO "%s: update your board or re-configure" | ||
| 144 | " the kernel\n", pdev->name); | ||
| 145 | return -ENODEV; | ||
| 146 | } | ||
| 147 | #endif | ||
| 148 | |||
| 149 | if (pdev->resource[1].flags != IORESOURCE_IRQ) { | 87 | if (pdev->resource[1].flags != IORESOURCE_IRQ) { |
| 150 | pr_debug("resource[1] is not IORESOURCE_IRQ"); | 88 | pr_debug("resource[1] is not IORESOURCE_IRQ"); |
| 151 | return -ENOMEM; | 89 | return -ENOMEM; |
| @@ -171,7 +109,11 @@ static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev) | |||
| 171 | goto err2; | 109 | goto err2; |
| 172 | } | 110 | } |
| 173 | 111 | ||
| 174 | au1xxx_start_ehc(); | 112 | if (alchemy_usb_control(ALCHEMY_USB_EHCI0, 1)) { |
| 113 | printk(KERN_INFO "%s: controller init failed!\n", pdev->name); | ||
| 114 | ret = -ENODEV; | ||
| 115 | goto err3; | ||
| 116 | } | ||
| 175 | 117 | ||
| 176 | ehci = hcd_to_ehci(hcd); | 118 | ehci = hcd_to_ehci(hcd); |
| 177 | ehci->caps = hcd->regs; | 119 | ehci->caps = hcd->regs; |
| @@ -181,13 +123,14 @@ static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev) | |||
| 181 | ehci->hcs_params = readl(&ehci->caps->hcs_params); | 123 | ehci->hcs_params = readl(&ehci->caps->hcs_params); |
| 182 | 124 | ||
| 183 | ret = usb_add_hcd(hcd, pdev->resource[1].start, | 125 | ret = usb_add_hcd(hcd, pdev->resource[1].start, |
| 184 | IRQF_DISABLED | IRQF_SHARED); | 126 | IRQF_SHARED); |
| 185 | if (ret == 0) { | 127 | if (ret == 0) { |
| 186 | platform_set_drvdata(pdev, hcd); | 128 | platform_set_drvdata(pdev, hcd); |
| 187 | return ret; | 129 | return ret; |
| 188 | } | 130 | } |
| 189 | 131 | ||
| 190 | au1xxx_stop_ehc(); | 132 | alchemy_usb_control(ALCHEMY_USB_EHCI0, 0); |
| 133 | err3: | ||
| 191 | iounmap(hcd->regs); | 134 | iounmap(hcd->regs); |
| 192 | err2: | 135 | err2: |
| 193 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 136 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| @@ -201,10 +144,10 @@ static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev) | |||
| 201 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 144 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 202 | 145 | ||
| 203 | usb_remove_hcd(hcd); | 146 | usb_remove_hcd(hcd); |
| 147 | alchemy_usb_control(ALCHEMY_USB_EHCI0, 0); | ||
| 204 | iounmap(hcd->regs); | 148 | iounmap(hcd->regs); |
| 205 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 149 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 206 | usb_put_hcd(hcd); | 150 | usb_put_hcd(hcd); |
| 207 | au1xxx_stop_ehc(); | ||
| 208 | platform_set_drvdata(pdev, NULL); | 151 | platform_set_drvdata(pdev, NULL); |
| 209 | 152 | ||
| 210 | return 0; | 153 | return 0; |
| @@ -236,7 +179,7 @@ static int ehci_hcd_au1xxx_drv_suspend(struct device *dev) | |||
| 236 | // could save FLADJ in case of Vaux power loss | 179 | // could save FLADJ in case of Vaux power loss |
| 237 | // ... we'd only use it to handle clock skew | 180 | // ... we'd only use it to handle clock skew |
| 238 | 181 | ||
| 239 | au1xxx_stop_ehc(); | 182 | alchemy_usb_control(ALCHEMY_USB_EHCI0, 0); |
| 240 | 183 | ||
| 241 | return rc; | 184 | return rc; |
| 242 | } | 185 | } |
| @@ -246,7 +189,7 @@ static int ehci_hcd_au1xxx_drv_resume(struct device *dev) | |||
| 246 | struct usb_hcd *hcd = dev_get_drvdata(dev); | 189 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 247 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | 190 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 248 | 191 | ||
| 249 | au1xxx_start_ehc(); | 192 | alchemy_usb_control(ALCHEMY_USB_EHCI0, 1); |
| 250 | 193 | ||
| 251 | // maybe restore FLADJ | 194 | // maybe restore FLADJ |
| 252 | 195 | ||
| @@ -293,7 +236,7 @@ static int ehci_hcd_au1xxx_drv_resume(struct device *dev) | |||
| 293 | /* here we "know" root ports should always stay powered */ | 236 | /* here we "know" root ports should always stay powered */ |
| 294 | ehci_port_power(ehci, 1); | 237 | ehci_port_power(ehci, 1); |
| 295 | 238 | ||
| 296 | hcd->state = HC_STATE_SUSPENDED; | 239 | ehci->rh_state = EHCI_RH_SUSPENDED; |
| 297 | 240 | ||
| 298 | return 0; | 241 | return 0; |
| 299 | } | 242 | } |
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c index 40a844c1dbb4..d6d74d2e09f4 100644 --- a/drivers/usb/host/ehci-dbg.c +++ b/drivers/usb/host/ehci-dbg.c | |||
| @@ -697,6 +697,19 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf) | |||
| 697 | } | 697 | } |
| 698 | #undef DBG_SCHED_LIMIT | 698 | #undef DBG_SCHED_LIMIT |
| 699 | 699 | ||
| 700 | static const char *rh_state_string(struct ehci_hcd *ehci) | ||
| 701 | { | ||
| 702 | switch (ehci->rh_state) { | ||
| 703 | case EHCI_RH_HALTED: | ||
| 704 | return "halted"; | ||
| 705 | case EHCI_RH_SUSPENDED: | ||
| 706 | return "suspended"; | ||
| 707 | case EHCI_RH_RUNNING: | ||
| 708 | return "running"; | ||
| 709 | } | ||
| 710 | return "?"; | ||
| 711 | } | ||
| 712 | |||
| 700 | static ssize_t fill_registers_buffer(struct debug_buffer *buf) | 713 | static ssize_t fill_registers_buffer(struct debug_buffer *buf) |
| 701 | { | 714 | { |
| 702 | struct usb_hcd *hcd; | 715 | struct usb_hcd *hcd; |
| @@ -730,11 +743,11 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf) | |||
| 730 | temp = scnprintf (next, size, | 743 | temp = scnprintf (next, size, |
| 731 | "bus %s, device %s\n" | 744 | "bus %s, device %s\n" |
| 732 | "%s\n" | 745 | "%s\n" |
| 733 | "EHCI %x.%02x, hcd state %d\n", | 746 | "EHCI %x.%02x, rh state %s\n", |
| 734 | hcd->self.controller->bus->name, | 747 | hcd->self.controller->bus->name, |
| 735 | dev_name(hcd->self.controller), | 748 | dev_name(hcd->self.controller), |
| 736 | hcd->product_desc, | 749 | hcd->product_desc, |
| 737 | i >> 8, i & 0x0ff, hcd->state); | 750 | i >> 8, i & 0x0ff, rh_state_string(ehci)); |
| 738 | size -= temp; | 751 | size -= temp; |
| 739 | next += temp; | 752 | next += temp; |
| 740 | 753 | ||
| @@ -808,7 +821,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf) | |||
| 808 | next += temp; | 821 | next += temp; |
| 809 | 822 | ||
| 810 | temp = scnprintf (next, size, "uframe %04x\n", | 823 | temp = scnprintf (next, size, "uframe %04x\n", |
| 811 | ehci_readl(ehci, &ehci->regs->frame_index)); | 824 | ehci_read_frame_index(ehci)); |
| 812 | size -= temp; | 825 | size -= temp; |
| 813 | next += temp; | 826 | next += temp; |
| 814 | 827 | ||
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c index 34a3140d1e5f..e90344a17631 100644 --- a/drivers/usb/host/ehci-fsl.c +++ b/drivers/usb/host/ehci-fsl.c | |||
| @@ -134,7 +134,7 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver, | |||
| 134 | 134 | ||
| 135 | /* Don't need to set host mode here. It will be done by tdi_reset() */ | 135 | /* Don't need to set host mode here. It will be done by tdi_reset() */ |
| 136 | 136 | ||
| 137 | retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); | 137 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 138 | if (retval != 0) | 138 | if (retval != 0) |
| 139 | goto err4; | 139 | goto err4; |
| 140 | 140 | ||
| @@ -392,7 +392,7 @@ static int ehci_fsl_mpc512x_drv_suspend(struct device *dev) | |||
| 392 | 392 | ||
| 393 | dev_dbg(dev, "suspending...\n"); | 393 | dev_dbg(dev, "suspending...\n"); |
| 394 | 394 | ||
| 395 | hcd->state = HC_STATE_SUSPENDED; | 395 | ehci->rh_state = EHCI_RH_SUSPENDED; |
| 396 | dev->power.power_state = PMSG_SUSPEND; | 396 | dev->power.power_state = PMSG_SUSPEND; |
| 397 | 397 | ||
| 398 | /* ignore non-host interrupts */ | 398 | /* ignore non-host interrupts */ |
| @@ -481,7 +481,7 @@ static int ehci_fsl_mpc512x_drv_resume(struct device *dev) | |||
| 481 | ehci_writel(ehci, pdata->pm_portsc, &ehci->regs->port_status[0]); | 481 | ehci_writel(ehci, pdata->pm_portsc, &ehci->regs->port_status[0]); |
| 482 | 482 | ||
| 483 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 483 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
| 484 | hcd->state = HC_STATE_RUNNING; | 484 | ehci->rh_state = EHCI_RH_RUNNING; |
| 485 | dev->power.power_state = PMSG_ON; | 485 | dev->power.power_state = PMSG_ON; |
| 486 | 486 | ||
| 487 | tmp = ehci_readl(ehci, &ehci->regs->command); | 487 | tmp = ehci_readl(ehci, &ehci->regs->command); |
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index f72ae0b6ee7f..3ff9f82f7263 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c | |||
| @@ -95,7 +95,7 @@ static const char hcd_name [] = "ehci_hcd"; | |||
| 95 | #define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */ | 95 | #define EHCI_IO_JIFFIES (HZ/10) /* io watchdog > irq_thresh */ |
| 96 | #define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */ | 96 | #define EHCI_ASYNC_JIFFIES (HZ/20) /* async idle timeout */ |
| 97 | #define EHCI_SHRINK_JIFFIES (DIV_ROUND_UP(HZ, 200) + 1) | 97 | #define EHCI_SHRINK_JIFFIES (DIV_ROUND_UP(HZ, 200) + 1) |
| 98 | /* 200-ms async qh unlink delay */ | 98 | /* 5-ms async qh unlink delay */ |
| 99 | 99 | ||
| 100 | /* Initial IRQ latency: faster than hw default */ | 100 | /* Initial IRQ latency: faster than hw default */ |
| 101 | static int log2_irq_thresh = 0; // 0 to 6 | 101 | static int log2_irq_thresh = 0; // 0 to 6 |
| @@ -238,7 +238,7 @@ static int handshake_on_error_set_halt(struct ehci_hcd *ehci, void __iomem *ptr, | |||
| 238 | error = handshake(ehci, ptr, mask, done, usec); | 238 | error = handshake(ehci, ptr, mask, done, usec); |
| 239 | if (error) { | 239 | if (error) { |
| 240 | ehci_halt(ehci); | 240 | ehci_halt(ehci); |
| 241 | ehci_to_hcd(ehci)->state = HC_STATE_HALT; | 241 | ehci->rh_state = EHCI_RH_HALTED; |
| 242 | ehci_err(ehci, "force halt; handshake %p %08x %08x -> %d\n", | 242 | ehci_err(ehci, "force halt; handshake %p %08x %08x -> %d\n", |
| 243 | ptr, mask, done, error); | 243 | ptr, mask, done, error); |
| 244 | } | 244 | } |
| @@ -278,7 +278,7 @@ static int ehci_reset (struct ehci_hcd *ehci) | |||
| 278 | command |= CMD_RESET; | 278 | command |= CMD_RESET; |
| 279 | dbg_cmd (ehci, "reset", command); | 279 | dbg_cmd (ehci, "reset", command); |
| 280 | ehci_writel(ehci, command, &ehci->regs->command); | 280 | ehci_writel(ehci, command, &ehci->regs->command); |
| 281 | ehci_to_hcd(ehci)->state = HC_STATE_HALT; | 281 | ehci->rh_state = EHCI_RH_HALTED; |
| 282 | ehci->next_statechange = jiffies; | 282 | ehci->next_statechange = jiffies; |
| 283 | retval = handshake (ehci, &ehci->regs->command, | 283 | retval = handshake (ehci, &ehci->regs->command, |
| 284 | CMD_RESET, 0, 250 * 1000); | 284 | CMD_RESET, 0, 250 * 1000); |
| @@ -307,7 +307,7 @@ static void ehci_quiesce (struct ehci_hcd *ehci) | |||
| 307 | u32 temp; | 307 | u32 temp; |
| 308 | 308 | ||
| 309 | #ifdef DEBUG | 309 | #ifdef DEBUG |
| 310 | if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state)) | 310 | if (ehci->rh_state != EHCI_RH_RUNNING) |
| 311 | BUG (); | 311 | BUG (); |
| 312 | #endif | 312 | #endif |
| 313 | 313 | ||
| @@ -356,7 +356,7 @@ static void ehci_iaa_watchdog(unsigned long param) | |||
| 356 | */ | 356 | */ |
| 357 | if (ehci->reclaim | 357 | if (ehci->reclaim |
| 358 | && !timer_pending(&ehci->iaa_watchdog) | 358 | && !timer_pending(&ehci->iaa_watchdog) |
| 359 | && HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { | 359 | && ehci->rh_state == EHCI_RH_RUNNING) { |
| 360 | u32 cmd, status; | 360 | u32 cmd, status; |
| 361 | 361 | ||
| 362 | /* If we get here, IAA is *REALLY* late. It's barely | 362 | /* If we get here, IAA is *REALLY* late. It's barely |
| @@ -496,7 +496,7 @@ static void ehci_work (struct ehci_hcd *ehci) | |||
| 496 | * misplace IRQs, and should let us run completely without IRQs. | 496 | * misplace IRQs, and should let us run completely without IRQs. |
| 497 | * such lossage has been observed on both VT6202 and VT8235. | 497 | * such lossage has been observed on both VT6202 and VT8235. |
| 498 | */ | 498 | */ |
| 499 | if (HC_IS_RUNNING (ehci_to_hcd(ehci)->state) && | 499 | if (ehci->rh_state == EHCI_RH_RUNNING && |
| 500 | (ehci->async->qh_next.ptr != NULL || | 500 | (ehci->async->qh_next.ptr != NULL || |
| 501 | ehci->periodic_sched != 0)) | 501 | ehci->periodic_sched != 0)) |
| 502 | timer_action (ehci, TIMER_IO_WATCHDOG); | 502 | timer_action (ehci, TIMER_IO_WATCHDOG); |
| @@ -516,7 +516,7 @@ static void ehci_stop (struct usb_hcd *hcd) | |||
| 516 | del_timer_sync(&ehci->iaa_watchdog); | 516 | del_timer_sync(&ehci->iaa_watchdog); |
| 517 | 517 | ||
| 518 | spin_lock_irq(&ehci->lock); | 518 | spin_lock_irq(&ehci->lock); |
| 519 | if (HC_IS_RUNNING (hcd->state)) | 519 | if (ehci->rh_state == EHCI_RH_RUNNING) |
| 520 | ehci_quiesce (ehci); | 520 | ehci_quiesce (ehci); |
| 521 | 521 | ||
| 522 | ehci_silence_controller(ehci); | 522 | ehci_silence_controller(ehci); |
| @@ -741,7 +741,7 @@ static int ehci_run (struct usb_hcd *hcd) | |||
| 741 | * be started before the port switching actions could complete. | 741 | * be started before the port switching actions could complete. |
| 742 | */ | 742 | */ |
| 743 | down_write(&ehci_cf_port_reset_rwsem); | 743 | down_write(&ehci_cf_port_reset_rwsem); |
| 744 | hcd->state = HC_STATE_RUNNING; | 744 | ehci->rh_state = EHCI_RH_RUNNING; |
| 745 | ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); | 745 | ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); |
| 746 | ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ | 746 | ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ |
| 747 | msleep(5); | 747 | msleep(5); |
| @@ -768,6 +768,35 @@ static int ehci_run (struct usb_hcd *hcd) | |||
| 768 | return 0; | 768 | return 0; |
| 769 | } | 769 | } |
| 770 | 770 | ||
| 771 | static int __maybe_unused ehci_setup (struct usb_hcd *hcd) | ||
| 772 | { | ||
| 773 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
| 774 | int retval; | ||
| 775 | |||
| 776 | ehci->regs = (void __iomem *)ehci->caps + | ||
| 777 | HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); | ||
| 778 | dbg_hcs_params(ehci, "reset"); | ||
| 779 | dbg_hcc_params(ehci, "reset"); | ||
| 780 | |||
| 781 | /* cache this readonly data; minimize chip reads */ | ||
| 782 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); | ||
| 783 | |||
| 784 | ehci->sbrn = HCD_USB2; | ||
| 785 | |||
| 786 | retval = ehci_halt(ehci); | ||
| 787 | if (retval) | ||
| 788 | return retval; | ||
| 789 | |||
| 790 | /* data structure init */ | ||
| 791 | retval = ehci_init(hcd); | ||
| 792 | if (retval) | ||
| 793 | return retval; | ||
| 794 | |||
| 795 | ehci_reset(ehci); | ||
| 796 | |||
| 797 | return 0; | ||
| 798 | } | ||
| 799 | |||
| 771 | /*-------------------------------------------------------------------------*/ | 800 | /*-------------------------------------------------------------------------*/ |
| 772 | 801 | ||
| 773 | static irqreturn_t ehci_irq (struct usb_hcd *hcd) | 802 | static irqreturn_t ehci_irq (struct usb_hcd *hcd) |
| @@ -788,7 +817,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd) | |||
| 788 | 817 | ||
| 789 | /* Shared IRQ? */ | 818 | /* Shared IRQ? */ |
| 790 | masked_status = status & INTR_MASK; | 819 | masked_status = status & INTR_MASK; |
| 791 | if (!masked_status || unlikely(hcd->state == HC_STATE_HALT)) { | 820 | if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) { |
| 792 | spin_unlock(&ehci->lock); | 821 | spin_unlock(&ehci->lock); |
| 793 | return IRQ_NONE; | 822 | return IRQ_NONE; |
| 794 | } | 823 | } |
| @@ -952,7 +981,7 @@ static int ehci_urb_enqueue ( | |||
| 952 | static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) | 981 | static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) |
| 953 | { | 982 | { |
| 954 | /* failfast */ | 983 | /* failfast */ |
| 955 | if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state) && ehci->reclaim) | 984 | if (ehci->rh_state != EHCI_RH_RUNNING && ehci->reclaim) |
| 956 | end_unlink_async(ehci); | 985 | end_unlink_async(ehci); |
| 957 | 986 | ||
| 958 | /* If the QH isn't linked then there's nothing we can do | 987 | /* If the QH isn't linked then there's nothing we can do |
| @@ -1079,7 +1108,7 @@ rescan: | |||
| 1079 | goto idle_timeout; | 1108 | goto idle_timeout; |
| 1080 | } | 1109 | } |
| 1081 | 1110 | ||
| 1082 | if (!HC_IS_RUNNING (hcd->state)) | 1111 | if (ehci->rh_state != EHCI_RH_RUNNING) |
| 1083 | qh->qh_state = QH_STATE_IDLE; | 1112 | qh->qh_state = QH_STATE_IDLE; |
| 1084 | switch (qh->qh_state) { | 1113 | switch (qh->qh_state) { |
| 1085 | case QH_STATE_LINKED: | 1114 | case QH_STATE_LINKED: |
| @@ -1166,8 +1195,7 @@ ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep) | |||
| 1166 | static int ehci_get_frame (struct usb_hcd *hcd) | 1195 | static int ehci_get_frame (struct usb_hcd *hcd) |
| 1167 | { | 1196 | { |
| 1168 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); | 1197 | struct ehci_hcd *ehci = hcd_to_ehci (hcd); |
| 1169 | return (ehci_readl(ehci, &ehci->regs->frame_index) >> 3) % | 1198 | return (ehci_read_frame_index(ehci) >> 3) % ehci->periodic_size; |
| 1170 | ehci->periodic_size; | ||
| 1171 | } | 1199 | } |
| 1172 | 1200 | ||
| 1173 | /*-------------------------------------------------------------------------*/ | 1201 | /*-------------------------------------------------------------------------*/ |
| @@ -1196,7 +1224,7 @@ MODULE_LICENSE ("GPL"); | |||
| 1196 | #define PLATFORM_DRIVER ehci_hcd_sh_driver | 1224 | #define PLATFORM_DRIVER ehci_hcd_sh_driver |
| 1197 | #endif | 1225 | #endif |
| 1198 | 1226 | ||
| 1199 | #ifdef CONFIG_SOC_AU1200 | 1227 | #ifdef CONFIG_MIPS_ALCHEMY |
| 1200 | #include "ehci-au1xxx.c" | 1228 | #include "ehci-au1xxx.c" |
| 1201 | #define PLATFORM_DRIVER ehci_hcd_au1xxx_driver | 1229 | #define PLATFORM_DRIVER ehci_hcd_au1xxx_driver |
| 1202 | #endif | 1230 | #endif |
| @@ -1291,6 +1319,16 @@ MODULE_LICENSE ("GPL"); | |||
| 1291 | #define PLATFORM_DRIVER ehci_grlib_driver | 1319 | #define PLATFORM_DRIVER ehci_grlib_driver |
| 1292 | #endif | 1320 | #endif |
| 1293 | 1321 | ||
| 1322 | #ifdef CONFIG_USB_PXA168_EHCI | ||
| 1323 | #include "ehci-pxa168.c" | ||
| 1324 | #define PLATFORM_DRIVER ehci_pxa168_driver | ||
| 1325 | #endif | ||
| 1326 | |||
| 1327 | #ifdef CONFIG_NLM_XLR | ||
| 1328 | #include "ehci-xls.c" | ||
| 1329 | #define PLATFORM_DRIVER ehci_xls_driver | ||
| 1330 | #endif | ||
| 1331 | |||
| 1294 | #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ | 1332 | #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ |
| 1295 | !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \ | 1333 | !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \ |
| 1296 | !defined(XILINX_OF_PLATFORM_DRIVER) | 1334 | !defined(XILINX_OF_PLATFORM_DRIVER) |
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index 4c32cb19b405..77bbb2357e47 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c | |||
| @@ -236,10 +236,8 @@ static int ehci_bus_suspend (struct usb_hcd *hcd) | |||
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | /* stop schedules, clean any completed work */ | 238 | /* stop schedules, clean any completed work */ |
| 239 | if (HC_IS_RUNNING(hcd->state)) { | 239 | if (ehci->rh_state == EHCI_RH_RUNNING) |
| 240 | ehci_quiesce (ehci); | 240 | ehci_quiesce (ehci); |
| 241 | hcd->state = HC_STATE_QUIESCING; | ||
| 242 | } | ||
| 243 | ehci->command = ehci_readl(ehci, &ehci->regs->command); | 241 | ehci->command = ehci_readl(ehci, &ehci->regs->command); |
| 244 | ehci_work(ehci); | 242 | ehci_work(ehci); |
| 245 | 243 | ||
| @@ -313,7 +311,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd) | |||
| 313 | 311 | ||
| 314 | /* turn off now-idle HC */ | 312 | /* turn off now-idle HC */ |
| 315 | ehci_halt (ehci); | 313 | ehci_halt (ehci); |
| 316 | hcd->state = HC_STATE_SUSPENDED; | 314 | ehci->rh_state = EHCI_RH_SUSPENDED; |
| 317 | 315 | ||
| 318 | if (ehci->reclaim) | 316 | if (ehci->reclaim) |
| 319 | end_unlink_async(ehci); | 317 | end_unlink_async(ehci); |
| @@ -382,6 +380,7 @@ static int ehci_bus_resume (struct usb_hcd *hcd) | |||
| 382 | 380 | ||
| 383 | /* restore CMD_RUN, framelist size, and irq threshold */ | 381 | /* restore CMD_RUN, framelist size, and irq threshold */ |
| 384 | ehci_writel(ehci, ehci->command, &ehci->regs->command); | 382 | ehci_writel(ehci, ehci->command, &ehci->regs->command); |
| 383 | ehci->rh_state = EHCI_RH_RUNNING; | ||
| 385 | 384 | ||
| 386 | /* Some controller/firmware combinations need a delay during which | 385 | /* Some controller/firmware combinations need a delay during which |
| 387 | * they set up the port statuses. See Bugzilla #8190. */ | 386 | * they set up the port statuses. See Bugzilla #8190. */ |
| @@ -451,7 +450,6 @@ static int ehci_bus_resume (struct usb_hcd *hcd) | |||
| 451 | } | 450 | } |
| 452 | 451 | ||
| 453 | ehci->next_statechange = jiffies + msecs_to_jiffies(5); | 452 | ehci->next_statechange = jiffies + msecs_to_jiffies(5); |
| 454 | hcd->state = HC_STATE_RUNNING; | ||
| 455 | 453 | ||
| 456 | /* Now we can safely re-enable irqs */ | 454 | /* Now we can safely re-enable irqs */ |
| 457 | ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); | 455 | ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); |
| @@ -563,7 +561,7 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf) | |||
| 563 | u32 ppcd = 0; | 561 | u32 ppcd = 0; |
| 564 | 562 | ||
| 565 | /* if !USB_SUSPEND, root hub timers won't get shut down ... */ | 563 | /* if !USB_SUSPEND, root hub timers won't get shut down ... */ |
| 566 | if (!HC_IS_RUNNING(hcd->state)) | 564 | if (ehci->rh_state != EHCI_RH_RUNNING) |
| 567 | return 0; | 565 | return 0; |
| 568 | 566 | ||
| 569 | /* init status to no-changes */ | 567 | /* init status to no-changes */ |
diff --git a/drivers/usb/host/ehci-mxc.c b/drivers/usb/host/ehci-mxc.c index 555a73c864b5..55978fcfa4b2 100644 --- a/drivers/usb/host/ehci-mxc.c +++ b/drivers/usb/host/ehci-mxc.c | |||
| @@ -236,7 +236,7 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev) | |||
| 236 | priv->hcd = hcd; | 236 | priv->hcd = hcd; |
| 237 | platform_set_drvdata(pdev, priv); | 237 | platform_set_drvdata(pdev, priv); |
| 238 | 238 | ||
| 239 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); | 239 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 240 | if (ret) | 240 | if (ret) |
| 241 | goto err_add; | 241 | goto err_add; |
| 242 | 242 | ||
diff --git a/drivers/usb/host/ehci-octeon.c b/drivers/usb/host/ehci-octeon.c index c3ba3ed5f3a6..ba1f51361134 100644 --- a/drivers/usb/host/ehci-octeon.c +++ b/drivers/usb/host/ehci-octeon.c | |||
| @@ -155,7 +155,7 @@ static int ehci_octeon_drv_probe(struct platform_device *pdev) | |||
| 155 | /* cache this readonly data; minimize chip reads */ | 155 | /* cache this readonly data; minimize chip reads */ |
| 156 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); | 156 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); |
| 157 | 157 | ||
| 158 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); | 158 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 159 | if (ret) { | 159 | if (ret) { |
| 160 | dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret); | 160 | dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret); |
| 161 | goto err3; | 161 | goto err3; |
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c index 45240321ca09..e39b0297bad1 100644 --- a/drivers/usb/host/ehci-omap.c +++ b/drivers/usb/host/ehci-omap.c | |||
| @@ -228,7 +228,7 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev) | |||
| 228 | /* cache this readonly data; minimize chip reads */ | 228 | /* cache this readonly data; minimize chip reads */ |
| 229 | omap_ehci->hcs_params = readl(&omap_ehci->caps->hcs_params); | 229 | omap_ehci->hcs_params = readl(&omap_ehci->caps->hcs_params); |
| 230 | 230 | ||
| 231 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); | 231 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 232 | if (ret) { | 232 | if (ret) { |
| 233 | dev_err(dev, "failed to add hcd with err %d\n", ret); | 233 | dev_err(dev, "failed to add hcd with err %d\n", ret); |
| 234 | goto err_add_hcd; | 234 | goto err_add_hcd; |
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c index 395bdb0248d5..a68a2a5c4b83 100644 --- a/drivers/usb/host/ehci-orion.c +++ b/drivers/usb/host/ehci-orion.c | |||
| @@ -277,7 +277,7 @@ static int __devinit ehci_orion_drv_probe(struct platform_device *pdev) | |||
| 277 | printk(KERN_WARNING "Orion ehci -USB phy version isn't supported.\n"); | 277 | printk(KERN_WARNING "Orion ehci -USB phy version isn't supported.\n"); |
| 278 | } | 278 | } |
| 279 | 279 | ||
| 280 | err = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_DISABLED); | 280 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 281 | if (err) | 281 | if (err) |
| 282 | goto err4; | 282 | goto err4; |
| 283 | 283 | ||
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c index 1102ce65a3a9..f4b627d343ac 100644 --- a/drivers/usb/host/ehci-pci.c +++ b/drivers/usb/host/ehci-pci.c | |||
| @@ -224,6 +224,11 @@ static int ehci_pci_setup(struct usb_hcd *hcd) | |||
| 224 | pci_dev_put(p_smbus); | 224 | pci_dev_put(p_smbus); |
| 225 | } | 225 | } |
| 226 | break; | 226 | break; |
| 227 | case PCI_VENDOR_ID_NETMOS: | ||
| 228 | /* MosChip frame-index-register bug */ | ||
| 229 | ehci_info(ehci, "applying MosChip frame-index workaround\n"); | ||
| 230 | ehci->frame_index_bug = 1; | ||
| 231 | break; | ||
| 227 | } | 232 | } |
| 228 | 233 | ||
| 229 | /* optional debug port, normally in the first BAR */ | 234 | /* optional debug port, normally in the first BAR */ |
| @@ -439,7 +444,7 @@ static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated) | |||
| 439 | /* here we "know" root ports should always stay powered */ | 444 | /* here we "know" root ports should always stay powered */ |
| 440 | ehci_port_power(ehci, 1); | 445 | ehci_port_power(ehci, 1); |
| 441 | 446 | ||
| 442 | hcd->state = HC_STATE_SUSPENDED; | 447 | ehci->rh_state = EHCI_RH_SUSPENDED; |
| 443 | return 0; | 448 | return 0; |
| 444 | } | 449 | } |
| 445 | #endif | 450 | #endif |
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c index 64626a777d61..2dc32da75cfc 100644 --- a/drivers/usb/host/ehci-ps3.c +++ b/drivers/usb/host/ehci-ps3.c | |||
| @@ -167,7 +167,7 @@ static int __devinit ps3_ehci_probe(struct ps3_system_bus_device *dev) | |||
| 167 | 167 | ||
| 168 | ps3_system_bus_set_drvdata(dev, hcd); | 168 | ps3_system_bus_set_drvdata(dev, hcd); |
| 169 | 169 | ||
| 170 | result = usb_add_hcd(hcd, virq, IRQF_DISABLED); | 170 | result = usb_add_hcd(hcd, virq, 0); |
| 171 | 171 | ||
| 172 | if (result) { | 172 | if (result) { |
| 173 | dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n", | 173 | dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n", |
diff --git a/drivers/usb/host/ehci-pxa168.c b/drivers/usb/host/ehci-pxa168.c new file mode 100644 index 000000000000..ac0c16e8f539 --- /dev/null +++ b/drivers/usb/host/ehci-pxa168.c | |||
| @@ -0,0 +1,363 @@ | |||
| 1 | /* | ||
| 2 | * drivers/usb/host/ehci-pxa168.c | ||
| 3 | * | ||
| 4 | * Tanmay Upadhyay <tanmay.upadhyay@einfochips.com> | ||
| 5 | * | ||
| 6 | * Based on drivers/usb/host/ehci-orion.c | ||
| 7 | * | ||
| 8 | * This file is licensed under the terms of the GNU General Public | ||
| 9 | * License version 2. This program is licensed "as is" without any | ||
| 10 | * warranty of any kind, whether express or implied. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <linux/kernel.h> | ||
| 14 | #include <linux/module.h> | ||
| 15 | #include <linux/platform_device.h> | ||
| 16 | #include <linux/clk.h> | ||
| 17 | #include <mach/pxa168.h> | ||
| 18 | |||
| 19 | #define USB_PHY_CTRL_REG 0x4 | ||
| 20 | #define USB_PHY_PLL_REG 0x8 | ||
| 21 | #define USB_PHY_TX_REG 0xc | ||
| 22 | |||
| 23 | #define FBDIV_SHIFT 4 | ||
| 24 | |||
| 25 | #define ICP_SHIFT 12 | ||
| 26 | #define ICP_15 2 | ||
| 27 | #define ICP_20 3 | ||
| 28 | #define ICP_25 4 | ||
| 29 | |||
| 30 | #define KVCO_SHIFT 15 | ||
| 31 | |||
| 32 | #define PLLCALI12_SHIFT 25 | ||
| 33 | #define CALI12_VDD 0 | ||
| 34 | #define CALI12_09 1 | ||
| 35 | #define CALI12_10 2 | ||
| 36 | #define CALI12_11 3 | ||
| 37 | |||
| 38 | #define PLLVDD12_SHIFT 27 | ||
| 39 | #define VDD12_VDD 0 | ||
| 40 | #define VDD12_10 1 | ||
| 41 | #define VDD12_11 2 | ||
| 42 | #define VDD12_12 3 | ||
| 43 | |||
| 44 | #define PLLVDD18_SHIFT 29 | ||
| 45 | #define VDD18_19 0 | ||
| 46 | #define VDD18_20 1 | ||
| 47 | #define VDD18_21 2 | ||
| 48 | #define VDD18_22 3 | ||
| 49 | |||
| 50 | |||
| 51 | #define PLL_READY (1 << 23) | ||
| 52 | #define VCOCAL_START (1 << 21) | ||
| 53 | #define REG_RCAL_START (1 << 12) | ||
| 54 | |||
| 55 | struct pxa168_usb_drv_data { | ||
| 56 | struct ehci_hcd ehci; | ||
| 57 | struct clk *pxa168_usb_clk; | ||
| 58 | struct resource *usb_phy_res; | ||
| 59 | void __iomem *usb_phy_reg_base; | ||
| 60 | }; | ||
| 61 | |||
| 62 | static int ehci_pxa168_setup(struct usb_hcd *hcd) | ||
| 63 | { | ||
| 64 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
| 65 | int retval; | ||
| 66 | |||
| 67 | ehci_reset(ehci); | ||
| 68 | retval = ehci_halt(ehci); | ||
| 69 | if (retval) | ||
| 70 | return retval; | ||
| 71 | |||
| 72 | /* | ||
| 73 | * data structure init | ||
| 74 | */ | ||
| 75 | retval = ehci_init(hcd); | ||
| 76 | if (retval) | ||
| 77 | return retval; | ||
| 78 | |||
| 79 | hcd->has_tt = 1; | ||
| 80 | |||
| 81 | ehci_port_power(ehci, 0); | ||
| 82 | |||
| 83 | return retval; | ||
| 84 | } | ||
| 85 | |||
| 86 | static const struct hc_driver ehci_pxa168_hc_driver = { | ||
| 87 | .description = hcd_name, | ||
| 88 | .product_desc = "Marvell PXA168 EHCI", | ||
| 89 | .hcd_priv_size = sizeof(struct pxa168_usb_drv_data), | ||
| 90 | |||
| 91 | /* | ||
| 92 | * generic hardware linkage | ||
| 93 | */ | ||
| 94 | .irq = ehci_irq, | ||
| 95 | .flags = HCD_MEMORY | HCD_USB2, | ||
| 96 | |||
| 97 | /* | ||
| 98 | * basic lifecycle operations | ||
| 99 | */ | ||
| 100 | .reset = ehci_pxa168_setup, | ||
| 101 | .start = ehci_run, | ||
| 102 | .stop = ehci_stop, | ||
| 103 | .shutdown = ehci_shutdown, | ||
| 104 | |||
| 105 | /* | ||
| 106 | * managing i/o requests and associated device resources | ||
| 107 | */ | ||
| 108 | .urb_enqueue = ehci_urb_enqueue, | ||
| 109 | .urb_dequeue = ehci_urb_dequeue, | ||
| 110 | .endpoint_disable = ehci_endpoint_disable, | ||
| 111 | .endpoint_reset = ehci_endpoint_reset, | ||
| 112 | |||
| 113 | /* | ||
| 114 | * scheduling support | ||
| 115 | */ | ||
| 116 | .get_frame_number = ehci_get_frame, | ||
| 117 | |||
| 118 | /* | ||
| 119 | * root hub support | ||
| 120 | */ | ||
| 121 | .hub_status_data = ehci_hub_status_data, | ||
| 122 | .hub_control = ehci_hub_control, | ||
| 123 | .bus_suspend = ehci_bus_suspend, | ||
| 124 | .bus_resume = ehci_bus_resume, | ||
| 125 | .relinquish_port = ehci_relinquish_port, | ||
| 126 | .port_handed_over = ehci_port_handed_over, | ||
| 127 | |||
| 128 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, | ||
| 129 | }; | ||
| 130 | |||
| 131 | static int pxa168_usb_phy_init(struct platform_device *pdev) | ||
| 132 | { | ||
| 133 | struct resource *res; | ||
| 134 | void __iomem *usb_phy_reg_base; | ||
| 135 | struct pxa168_usb_pdata *pdata; | ||
| 136 | struct pxa168_usb_drv_data *drv_data; | ||
| 137 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | ||
| 138 | unsigned long reg_val; | ||
| 139 | int pll_retry_cont = 10000, err = 0; | ||
| 140 | |||
| 141 | drv_data = (struct pxa168_usb_drv_data *)hcd->hcd_priv; | ||
| 142 | pdata = (struct pxa168_usb_pdata *)pdev->dev.platform_data; | ||
| 143 | |||
| 144 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
| 145 | if (!res) { | ||
| 146 | dev_err(&pdev->dev, | ||
| 147 | "Found HC with no PHY register addr. Check %s setup!\n", | ||
| 148 | dev_name(&pdev->dev)); | ||
| 149 | return -ENODEV; | ||
| 150 | } | ||
| 151 | |||
| 152 | if (!request_mem_region(res->start, resource_size(res), | ||
| 153 | ehci_pxa168_hc_driver.description)) { | ||
| 154 | dev_dbg(&pdev->dev, "controller already in use\n"); | ||
| 155 | return -EBUSY; | ||
| 156 | } | ||
| 157 | |||
| 158 | usb_phy_reg_base = ioremap(res->start, resource_size(res)); | ||
| 159 | if (usb_phy_reg_base == NULL) { | ||
| 160 | dev_dbg(&pdev->dev, "error mapping memory\n"); | ||
| 161 | err = -EFAULT; | ||
| 162 | goto err1; | ||
| 163 | } | ||
| 164 | drv_data->usb_phy_reg_base = usb_phy_reg_base; | ||
| 165 | drv_data->usb_phy_res = res; | ||
| 166 | |||
| 167 | /* If someone wants to init USB phy in board specific way */ | ||
| 168 | if (pdata && pdata->phy_init) | ||
| 169 | return pdata->phy_init(usb_phy_reg_base); | ||
| 170 | |||
| 171 | /* Power up the PHY and PLL */ | ||
| 172 | writel(readl(usb_phy_reg_base + USB_PHY_CTRL_REG) | 0x3, | ||
| 173 | usb_phy_reg_base + USB_PHY_CTRL_REG); | ||
| 174 | |||
| 175 | /* Configure PHY PLL */ | ||
| 176 | reg_val = readl(usb_phy_reg_base + USB_PHY_PLL_REG) & ~(0x7e03ffff); | ||
| 177 | reg_val |= (VDD18_22 << PLLVDD18_SHIFT | VDD12_12 << PLLVDD12_SHIFT | | ||
| 178 | CALI12_11 << PLLCALI12_SHIFT | 3 << KVCO_SHIFT | | ||
| 179 | ICP_15 << ICP_SHIFT | 0xee << FBDIV_SHIFT | 0xb); | ||
| 180 | writel(reg_val, usb_phy_reg_base + USB_PHY_PLL_REG); | ||
| 181 | |||
| 182 | /* Make sure PHY PLL is ready */ | ||
| 183 | while (!(readl(usb_phy_reg_base + USB_PHY_PLL_REG) & PLL_READY)) { | ||
| 184 | if (!(pll_retry_cont--)) { | ||
| 185 | dev_dbg(&pdev->dev, "USB PHY PLL not ready\n"); | ||
| 186 | err = -EIO; | ||
| 187 | goto err2; | ||
| 188 | } | ||
| 189 | } | ||
| 190 | |||
| 191 | /* Toggle VCOCAL_START bit of U2PLL for PLL calibration */ | ||
| 192 | udelay(200); | ||
| 193 | writel(readl(usb_phy_reg_base + USB_PHY_PLL_REG) | VCOCAL_START, | ||
| 194 | usb_phy_reg_base + USB_PHY_PLL_REG); | ||
| 195 | udelay(40); | ||
| 196 | writel(readl(usb_phy_reg_base + USB_PHY_PLL_REG) & ~VCOCAL_START, | ||
| 197 | usb_phy_reg_base + USB_PHY_PLL_REG); | ||
| 198 | |||
| 199 | /* Toggle REG_RCAL_START bit of U2PTX for impedance calibration */ | ||
| 200 | udelay(400); | ||
| 201 | writel(readl(usb_phy_reg_base + USB_PHY_TX_REG) | REG_RCAL_START, | ||
| 202 | usb_phy_reg_base + USB_PHY_TX_REG); | ||
| 203 | udelay(40); | ||
| 204 | writel(readl(usb_phy_reg_base + USB_PHY_TX_REG) & ~REG_RCAL_START, | ||
| 205 | usb_phy_reg_base + USB_PHY_TX_REG); | ||
| 206 | |||
| 207 | /* Make sure PHY PLL is ready again */ | ||
| 208 | pll_retry_cont = 0; | ||
| 209 | while (!(readl(usb_phy_reg_base + USB_PHY_PLL_REG) & PLL_READY)) { | ||
| 210 | if (!(pll_retry_cont--)) { | ||
| 211 | dev_dbg(&pdev->dev, "USB PHY PLL not ready\n"); | ||
| 212 | err = -EIO; | ||
| 213 | goto err2; | ||
| 214 | } | ||
| 215 | } | ||
| 216 | |||
| 217 | return 0; | ||
| 218 | err2: | ||
| 219 | iounmap(usb_phy_reg_base); | ||
| 220 | err1: | ||
| 221 | release_mem_region(res->start, resource_size(res)); | ||
| 222 | return err; | ||
| 223 | } | ||
| 224 | |||
| 225 | static int __devinit ehci_pxa168_drv_probe(struct platform_device *pdev) | ||
| 226 | { | ||
| 227 | struct resource *res; | ||
| 228 | struct usb_hcd *hcd; | ||
| 229 | struct ehci_hcd *ehci; | ||
| 230 | struct pxa168_usb_drv_data *drv_data; | ||
| 231 | void __iomem *regs; | ||
| 232 | int irq, err = 0; | ||
| 233 | |||
| 234 | if (usb_disabled()) | ||
| 235 | return -ENODEV; | ||
| 236 | |||
| 237 | pr_debug("Initializing pxa168-SoC USB Host Controller\n"); | ||
| 238 | |||
| 239 | irq = platform_get_irq(pdev, 0); | ||
| 240 | if (irq <= 0) { | ||
| 241 | dev_err(&pdev->dev, | ||
| 242 | "Found HC with no IRQ. Check %s setup!\n", | ||
| 243 | dev_name(&pdev->dev)); | ||
| 244 | err = -ENODEV; | ||
| 245 | goto err1; | ||
| 246 | } | ||
| 247 | |||
| 248 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 249 | if (!res) { | ||
| 250 | dev_err(&pdev->dev, | ||
| 251 | "Found HC with no register addr. Check %s setup!\n", | ||
| 252 | dev_name(&pdev->dev)); | ||
| 253 | err = -ENODEV; | ||
| 254 | goto err1; | ||
| 255 | } | ||
| 256 | |||
| 257 | if (!request_mem_region(res->start, resource_size(res), | ||
| 258 | ehci_pxa168_hc_driver.description)) { | ||
| 259 | dev_dbg(&pdev->dev, "controller already in use\n"); | ||
| 260 | err = -EBUSY; | ||
| 261 | goto err1; | ||
| 262 | } | ||
| 263 | |||
| 264 | regs = ioremap(res->start, resource_size(res)); | ||
| 265 | if (regs == NULL) { | ||
| 266 | dev_dbg(&pdev->dev, "error mapping memory\n"); | ||
| 267 | err = -EFAULT; | ||
| 268 | goto err2; | ||
| 269 | } | ||
| 270 | |||
| 271 | hcd = usb_create_hcd(&ehci_pxa168_hc_driver, | ||
| 272 | &pdev->dev, dev_name(&pdev->dev)); | ||
| 273 | if (!hcd) { | ||
| 274 | err = -ENOMEM; | ||
| 275 | goto err3; | ||
| 276 | } | ||
| 277 | |||
| 278 | drv_data = (struct pxa168_usb_drv_data *)hcd->hcd_priv; | ||
| 279 | |||
| 280 | /* Enable USB clock */ | ||
| 281 | drv_data->pxa168_usb_clk = clk_get(&pdev->dev, "PXA168-USBCLK"); | ||
| 282 | if (IS_ERR(drv_data->pxa168_usb_clk)) { | ||
| 283 | dev_err(&pdev->dev, "Couldn't get USB clock\n"); | ||
| 284 | err = PTR_ERR(drv_data->pxa168_usb_clk); | ||
| 285 | goto err4; | ||
| 286 | } | ||
| 287 | clk_enable(drv_data->pxa168_usb_clk); | ||
| 288 | |||
| 289 | err = pxa168_usb_phy_init(pdev); | ||
| 290 | if (err) { | ||
| 291 | dev_err(&pdev->dev, "USB PHY initialization failed\n"); | ||
| 292 | goto err5; | ||
| 293 | } | ||
| 294 | |||
| 295 | hcd->rsrc_start = res->start; | ||
| 296 | hcd->rsrc_len = resource_size(res); | ||
| 297 | hcd->regs = regs; | ||
| 298 | |||
| 299 | ehci = hcd_to_ehci(hcd); | ||
| 300 | ehci->caps = hcd->regs + 0x100; | ||
| 301 | ehci->regs = hcd->regs + 0x100 + | ||
| 302 | HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); | ||
| 303 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); | ||
| 304 | hcd->has_tt = 1; | ||
| 305 | ehci->sbrn = 0x20; | ||
| 306 | |||
| 307 | err = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_DISABLED); | ||
| 308 | if (err) | ||
| 309 | goto err5; | ||
| 310 | |||
| 311 | return 0; | ||
| 312 | |||
| 313 | err5: | ||
| 314 | clk_disable(drv_data->pxa168_usb_clk); | ||
| 315 | clk_put(drv_data->pxa168_usb_clk); | ||
| 316 | err4: | ||
| 317 | usb_put_hcd(hcd); | ||
| 318 | err3: | ||
| 319 | iounmap(regs); | ||
| 320 | err2: | ||
| 321 | release_mem_region(res->start, resource_size(res)); | ||
| 322 | err1: | ||
| 323 | dev_err(&pdev->dev, "init %s fail, %d\n", | ||
| 324 | dev_name(&pdev->dev), err); | ||
| 325 | |||
| 326 | return err; | ||
| 327 | } | ||
| 328 | |||
| 329 | static int __exit ehci_pxa168_drv_remove(struct platform_device *pdev) | ||
| 330 | { | ||
| 331 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | ||
| 332 | struct pxa168_usb_drv_data *drv_data = | ||
| 333 | (struct pxa168_usb_drv_data *)hcd->hcd_priv; | ||
| 334 | |||
| 335 | usb_remove_hcd(hcd); | ||
| 336 | |||
| 337 | /* Power down PHY & PLL */ | ||
| 338 | writel(readl(drv_data->usb_phy_reg_base + USB_PHY_CTRL_REG) & (~0x3), | ||
| 339 | drv_data->usb_phy_reg_base + USB_PHY_CTRL_REG); | ||
| 340 | |||
| 341 | clk_disable(drv_data->pxa168_usb_clk); | ||
| 342 | clk_put(drv_data->pxa168_usb_clk); | ||
| 343 | |||
| 344 | iounmap(hcd->regs); | ||
| 345 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
| 346 | |||
| 347 | iounmap(drv_data->usb_phy_reg_base); | ||
| 348 | release_mem_region(drv_data->usb_phy_res->start, | ||
| 349 | resource_size(drv_data->usb_phy_res)); | ||
| 350 | |||
| 351 | usb_put_hcd(hcd); | ||
| 352 | |||
| 353 | return 0; | ||
| 354 | } | ||
| 355 | |||
| 356 | MODULE_ALIAS("platform:pxa168-ehci"); | ||
| 357 | |||
| 358 | static struct platform_driver ehci_pxa168_driver = { | ||
| 359 | .probe = ehci_pxa168_drv_probe, | ||
| 360 | .remove = __exit_p(ehci_pxa168_drv_remove), | ||
| 361 | .shutdown = usb_hcd_platform_shutdown, | ||
| 362 | .driver.name = "pxa168-ehci", | ||
| 363 | }; | ||
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c index 0917e3a32465..4e4066c35a09 100644 --- a/drivers/usb/host/ehci-q.c +++ b/drivers/usb/host/ehci-q.c | |||
| @@ -111,8 +111,6 @@ qh_update (struct ehci_hcd *ehci, struct ehci_qh *qh, struct ehci_qtd *qtd) | |||
| 111 | } | 111 | } |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | /* HC must see latest qtd and qh data before we clear ACTIVE+HALT */ | ||
| 115 | wmb (); | ||
| 116 | hw->hw_token &= cpu_to_hc32(ehci, QTD_TOGGLE | QTD_STS_PING); | 114 | hw->hw_token &= cpu_to_hc32(ehci, QTD_TOGGLE | QTD_STS_PING); |
| 117 | } | 115 | } |
| 118 | 116 | ||
| @@ -153,7 +151,7 @@ static void ehci_clear_tt_buffer_complete(struct usb_hcd *hcd, | |||
| 153 | spin_lock_irqsave(&ehci->lock, flags); | 151 | spin_lock_irqsave(&ehci->lock, flags); |
| 154 | qh->clearing_tt = 0; | 152 | qh->clearing_tt = 0; |
| 155 | if (qh->qh_state == QH_STATE_IDLE && !list_empty(&qh->qtd_list) | 153 | if (qh->qh_state == QH_STATE_IDLE && !list_empty(&qh->qtd_list) |
| 156 | && HC_IS_RUNNING(hcd->state)) | 154 | && ehci->rh_state == EHCI_RH_RUNNING) |
| 157 | qh_link_async(ehci, qh); | 155 | qh_link_async(ehci, qh); |
| 158 | spin_unlock_irqrestore(&ehci->lock, flags); | 156 | spin_unlock_irqrestore(&ehci->lock, flags); |
| 159 | } | 157 | } |
| @@ -425,7 +423,7 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
| 425 | 423 | ||
| 426 | /* stop scanning when we reach qtds the hc is using */ | 424 | /* stop scanning when we reach qtds the hc is using */ |
| 427 | } else if (likely (!stopped | 425 | } else if (likely (!stopped |
| 428 | && HC_IS_RUNNING (ehci_to_hcd(ehci)->state))) { | 426 | && ehci->rh_state == EHCI_RH_RUNNING)) { |
| 429 | break; | 427 | break; |
| 430 | 428 | ||
| 431 | /* scan the whole queue for unlinks whenever it stops */ | 429 | /* scan the whole queue for unlinks whenever it stops */ |
| @@ -433,7 +431,7 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
| 433 | stopped = 1; | 431 | stopped = 1; |
| 434 | 432 | ||
| 435 | /* cancel everything if we halt, suspend, etc */ | 433 | /* cancel everything if we halt, suspend, etc */ |
| 436 | if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) | 434 | if (ehci->rh_state != EHCI_RH_RUNNING) |
| 437 | last_status = -ESHUTDOWN; | 435 | last_status = -ESHUTDOWN; |
| 438 | 436 | ||
| 439 | /* this qtd is active; skip it unless a previous qtd | 437 | /* this qtd is active; skip it unless a previous qtd |
| @@ -724,7 +722,8 @@ qh_urb_transaction ( | |||
| 724 | 722 | ||
| 725 | /* | 723 | /* |
| 726 | * control requests may need a terminating data "status" ack; | 724 | * control requests may need a terminating data "status" ack; |
| 727 | * bulk ones may need a terminating short packet (zero length). | 725 | * other OUT ones may need a terminating short packet |
| 726 | * (zero length). | ||
| 728 | */ | 727 | */ |
| 729 | if (likely (urb->transfer_buffer_length != 0)) { | 728 | if (likely (urb->transfer_buffer_length != 0)) { |
| 730 | int one_more = 0; | 729 | int one_more = 0; |
| @@ -733,7 +732,7 @@ qh_urb_transaction ( | |||
| 733 | one_more = 1; | 732 | one_more = 1; |
| 734 | token ^= 0x0100; /* "in" <--> "out" */ | 733 | token ^= 0x0100; /* "in" <--> "out" */ |
| 735 | token |= QTD_TOGGLE; /* force DATA1 */ | 734 | token |= QTD_TOGGLE; /* force DATA1 */ |
| 736 | } else if (usb_pipebulk (urb->pipe) | 735 | } else if (usb_pipeout(urb->pipe) |
| 737 | && (urb->transfer_flags & URB_ZERO_PACKET) | 736 | && (urb->transfer_flags & URB_ZERO_PACKET) |
| 738 | && !(urb->transfer_buffer_length % maxpacket)) { | 737 | && !(urb->transfer_buffer_length % maxpacket)) { |
| 739 | one_more = 1; | 738 | one_more = 1; |
| @@ -977,9 +976,8 @@ static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
| 977 | /* in case a clear of CMD_ASE didn't take yet */ | 976 | /* in case a clear of CMD_ASE didn't take yet */ |
| 978 | (void)handshake(ehci, &ehci->regs->status, | 977 | (void)handshake(ehci, &ehci->regs->status, |
| 979 | STS_ASS, 0, 150); | 978 | STS_ASS, 0, 150); |
| 980 | cmd |= CMD_ASE | CMD_RUN; | 979 | cmd |= CMD_ASE; |
| 981 | ehci_writel(ehci, cmd, &ehci->regs->command); | 980 | ehci_writel(ehci, cmd, &ehci->regs->command); |
| 982 | ehci_to_hcd(ehci)->state = HC_STATE_RUNNING; | ||
| 983 | /* posted write need not be known to HC yet ... */ | 981 | /* posted write need not be known to HC yet ... */ |
| 984 | } | 982 | } |
| 985 | } | 983 | } |
| @@ -1058,7 +1056,7 @@ static struct ehci_qh *qh_append_tds ( | |||
| 1058 | */ | 1056 | */ |
| 1059 | token = qtd->hw_token; | 1057 | token = qtd->hw_token; |
| 1060 | qtd->hw_token = HALT_BIT(ehci); | 1058 | qtd->hw_token = HALT_BIT(ehci); |
| 1061 | wmb (); | 1059 | |
| 1062 | dummy = qh->dummy; | 1060 | dummy = qh->dummy; |
| 1063 | 1061 | ||
| 1064 | dma = dummy->qtd_dma; | 1062 | dma = dummy->qtd_dma; |
| @@ -1168,14 +1166,13 @@ static void end_unlink_async (struct ehci_hcd *ehci) | |||
| 1168 | 1166 | ||
| 1169 | qh_completions (ehci, qh); | 1167 | qh_completions (ehci, qh); |
| 1170 | 1168 | ||
| 1171 | if (!list_empty (&qh->qtd_list) | 1169 | if (!list_empty(&qh->qtd_list) && ehci->rh_state == EHCI_RH_RUNNING) { |
| 1172 | && HC_IS_RUNNING (ehci_to_hcd(ehci)->state)) | ||
| 1173 | qh_link_async (ehci, qh); | 1170 | qh_link_async (ehci, qh); |
| 1174 | else { | 1171 | } else { |
| 1175 | /* it's not free to turn the async schedule on/off; leave it | 1172 | /* it's not free to turn the async schedule on/off; leave it |
| 1176 | * active but idle for a while once it empties. | 1173 | * active but idle for a while once it empties. |
| 1177 | */ | 1174 | */ |
| 1178 | if (HC_IS_RUNNING (ehci_to_hcd(ehci)->state) | 1175 | if (ehci->rh_state == EHCI_RH_RUNNING |
| 1179 | && ehci->async->qh_next.qh == NULL) | 1176 | && ehci->async->qh_next.qh == NULL) |
| 1180 | timer_action (ehci, TIMER_ASYNC_OFF); | 1177 | timer_action (ehci, TIMER_ASYNC_OFF); |
| 1181 | } | 1178 | } |
| @@ -1211,7 +1208,7 @@ static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
| 1211 | /* stop async schedule right now? */ | 1208 | /* stop async schedule right now? */ |
| 1212 | if (unlikely (qh == ehci->async)) { | 1209 | if (unlikely (qh == ehci->async)) { |
| 1213 | /* can't get here without STS_ASS set */ | 1210 | /* can't get here without STS_ASS set */ |
| 1214 | if (ehci_to_hcd(ehci)->state != HC_STATE_HALT | 1211 | if (ehci->rh_state != EHCI_RH_HALTED |
| 1215 | && !ehci->reclaim) { | 1212 | && !ehci->reclaim) { |
| 1216 | /* ... and CMD_IAAD clear */ | 1213 | /* ... and CMD_IAAD clear */ |
| 1217 | ehci_writel(ehci, cmd & ~CMD_ASE, | 1214 | ehci_writel(ehci, cmd & ~CMD_ASE, |
| @@ -1237,7 +1234,7 @@ static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
| 1237 | wmb (); | 1234 | wmb (); |
| 1238 | 1235 | ||
| 1239 | /* If the controller isn't running, we don't have to wait for it */ | 1236 | /* If the controller isn't running, we don't have to wait for it */ |
| 1240 | if (unlikely(!HC_IS_RUNNING(ehci_to_hcd(ehci)->state))) { | 1237 | if (unlikely(ehci->rh_state != EHCI_RH_RUNNING)) { |
| 1241 | /* if (unlikely (qh->reclaim != 0)) | 1238 | /* if (unlikely (qh->reclaim != 0)) |
| 1242 | * this will recurse, probably not much | 1239 | * this will recurse, probably not much |
| 1243 | */ | 1240 | */ |
| @@ -1260,7 +1257,7 @@ static void scan_async (struct ehci_hcd *ehci) | |||
| 1260 | enum ehci_timer_action action = TIMER_IO_WATCHDOG; | 1257 | enum ehci_timer_action action = TIMER_IO_WATCHDOG; |
| 1261 | 1258 | ||
| 1262 | timer_action_done (ehci, TIMER_ASYNC_SHRINK); | 1259 | timer_action_done (ehci, TIMER_ASYNC_SHRINK); |
| 1263 | stopped = !HC_IS_RUNNING(ehci_to_hcd(ehci)->state); | 1260 | stopped = (ehci->rh_state != EHCI_RH_RUNNING); |
| 1264 | 1261 | ||
| 1265 | ehci->qh_scan_next = ehci->async->qh_next.qh; | 1262 | ehci->qh_scan_next = ehci->async->qh_next.qh; |
| 1266 | while (ehci->qh_scan_next) { | 1263 | while (ehci->qh_scan_next) { |
diff --git a/drivers/usb/host/ehci-s5p.c b/drivers/usb/host/ehci-s5p.c index 9e77f1c8bdbd..024b65c4990d 100644 --- a/drivers/usb/host/ehci-s5p.c +++ b/drivers/usb/host/ehci-s5p.c | |||
| @@ -136,7 +136,7 @@ static int __devinit s5p_ehci_probe(struct platform_device *pdev) | |||
| 136 | /* cache this readonly data; minimize chip reads */ | 136 | /* cache this readonly data; minimize chip reads */ |
| 137 | ehci->hcs_params = readl(&ehci->caps->hcs_params); | 137 | ehci->hcs_params = readl(&ehci->caps->hcs_params); |
| 138 | 138 | ||
| 139 | err = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); | 139 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 140 | if (err) { | 140 | if (err) { |
| 141 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); | 141 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); |
| 142 | goto fail; | 142 | goto fail; |
| @@ -270,7 +270,7 @@ static int s5p_ehci_resume(struct device *dev) | |||
| 270 | /* here we "know" root ports should always stay powered */ | 270 | /* here we "know" root ports should always stay powered */ |
| 271 | ehci_port_power(ehci, 1); | 271 | ehci_port_power(ehci, 1); |
| 272 | 272 | ||
| 273 | hcd->state = HC_STATE_SUSPENDED; | 273 | ehci->rh_state = EHCI_RH_SUSPENDED; |
| 274 | 274 | ||
| 275 | return 0; | 275 | return 0; |
| 276 | } | 276 | } |
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c index 2abf8543f083..56a32033adb3 100644 --- a/drivers/usb/host/ehci-sched.c +++ b/drivers/usb/host/ehci-sched.c | |||
| @@ -36,6 +36,27 @@ | |||
| 36 | 36 | ||
| 37 | static int ehci_get_frame (struct usb_hcd *hcd); | 37 | static int ehci_get_frame (struct usb_hcd *hcd); |
| 38 | 38 | ||
| 39 | #ifdef CONFIG_PCI | ||
| 40 | |||
| 41 | static unsigned ehci_read_frame_index(struct ehci_hcd *ehci) | ||
| 42 | { | ||
| 43 | unsigned uf; | ||
| 44 | |||
| 45 | /* | ||
| 46 | * The MosChip MCS9990 controller updates its microframe counter | ||
| 47 | * a little before the frame counter, and occasionally we will read | ||
| 48 | * the invalid intermediate value. Avoid problems by checking the | ||
| 49 | * microframe number (the low-order 3 bits); if they are 0 then | ||
| 50 | * re-read the register to get the correct value. | ||
| 51 | */ | ||
| 52 | uf = ehci_readl(ehci, &ehci->regs->frame_index); | ||
| 53 | if (unlikely(ehci->frame_index_bug && ((uf & 7) == 0))) | ||
| 54 | uf = ehci_readl(ehci, &ehci->regs->frame_index); | ||
| 55 | return uf; | ||
| 56 | } | ||
| 57 | |||
| 58 | #endif | ||
| 59 | |||
| 39 | /*-------------------------------------------------------------------------*/ | 60 | /*-------------------------------------------------------------------------*/ |
| 40 | 61 | ||
| 41 | /* | 62 | /* |
| @@ -479,10 +500,9 @@ static int enable_periodic (struct ehci_hcd *ehci) | |||
| 479 | cmd = ehci_readl(ehci, &ehci->regs->command) | CMD_PSE; | 500 | cmd = ehci_readl(ehci, &ehci->regs->command) | CMD_PSE; |
| 480 | ehci_writel(ehci, cmd, &ehci->regs->command); | 501 | ehci_writel(ehci, cmd, &ehci->regs->command); |
| 481 | /* posted write ... PSS happens later */ | 502 | /* posted write ... PSS happens later */ |
| 482 | ehci_to_hcd(ehci)->state = HC_STATE_RUNNING; | ||
| 483 | 503 | ||
| 484 | /* make sure ehci_work scans these */ | 504 | /* make sure ehci_work scans these */ |
| 485 | ehci->next_uframe = ehci_readl(ehci, &ehci->regs->frame_index) | 505 | ehci->next_uframe = ehci_read_frame_index(ehci) |
| 486 | % (ehci->periodic_size << 3); | 506 | % (ehci->periodic_size << 3); |
| 487 | if (unlikely(ehci->broken_periodic)) | 507 | if (unlikely(ehci->broken_periodic)) |
| 488 | ehci->last_periodic_enable = ktime_get_real(); | 508 | ehci->last_periodic_enable = ktime_get_real(); |
| @@ -677,7 +697,7 @@ static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh) | |||
| 677 | 697 | ||
| 678 | /* reschedule QH iff another request is queued */ | 698 | /* reschedule QH iff another request is queued */ |
| 679 | if (!list_empty(&qh->qtd_list) && | 699 | if (!list_empty(&qh->qtd_list) && |
| 680 | HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { | 700 | ehci->rh_state == EHCI_RH_RUNNING) { |
| 681 | rc = qh_schedule(ehci, qh); | 701 | rc = qh_schedule(ehci, qh); |
| 682 | 702 | ||
| 683 | /* An error here likely indicates handshake failure | 703 | /* An error here likely indicates handshake failure |
| @@ -1409,7 +1429,7 @@ iso_stream_schedule ( | |||
| 1409 | goto fail; | 1429 | goto fail; |
| 1410 | } | 1430 | } |
| 1411 | 1431 | ||
| 1412 | now = ehci_readl(ehci, &ehci->regs->frame_index) & (mod - 1); | 1432 | now = ehci_read_frame_index(ehci) & (mod - 1); |
| 1413 | 1433 | ||
| 1414 | /* Typical case: reuse current schedule, stream is still active. | 1434 | /* Typical case: reuse current schedule, stream is still active. |
| 1415 | * Hopefully there are no gaps from the host falling behind | 1435 | * Hopefully there are no gaps from the host falling behind |
| @@ -1459,10 +1479,15 @@ iso_stream_schedule ( | |||
| 1459 | 1479 | ||
| 1460 | /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */ | 1480 | /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */ |
| 1461 | 1481 | ||
| 1462 | /* find a uframe slot with enough bandwidth */ | 1482 | /* find a uframe slot with enough bandwidth. |
| 1463 | next = start + period; | 1483 | * Early uframes are more precious because full-speed |
| 1464 | for (; start < next; start++) { | 1484 | * iso IN transfers can't use late uframes, |
| 1465 | 1485 | * and therefore they should be allocated last. | |
| 1486 | */ | ||
| 1487 | next = start; | ||
| 1488 | start += period; | ||
| 1489 | do { | ||
| 1490 | start--; | ||
| 1466 | /* check schedule: enough space? */ | 1491 | /* check schedule: enough space? */ |
| 1467 | if (stream->highspeed) { | 1492 | if (stream->highspeed) { |
| 1468 | if (itd_slot_ok(ehci, mod, start, | 1493 | if (itd_slot_ok(ehci, mod, start, |
| @@ -1475,7 +1500,7 @@ iso_stream_schedule ( | |||
| 1475 | start, sched, period)) | 1500 | start, sched, period)) |
| 1476 | break; | 1501 | break; |
| 1477 | } | 1502 | } |
| 1478 | } | 1503 | } while (start > next); |
| 1479 | 1504 | ||
| 1480 | /* no room in the schedule */ | 1505 | /* no room in the schedule */ |
| 1481 | if (start == next) { | 1506 | if (start == next) { |
| @@ -2275,8 +2300,8 @@ scan_periodic (struct ehci_hcd *ehci) | |||
| 2275 | * Touches as few pages as possible: cache-friendly. | 2300 | * Touches as few pages as possible: cache-friendly. |
| 2276 | */ | 2301 | */ |
| 2277 | now_uframe = ehci->next_uframe; | 2302 | now_uframe = ehci->next_uframe; |
| 2278 | if (HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { | 2303 | if (ehci->rh_state == EHCI_RH_RUNNING) { |
| 2279 | clock = ehci_readl(ehci, &ehci->regs->frame_index); | 2304 | clock = ehci_read_frame_index(ehci); |
| 2280 | clock_frame = (clock >> 3) & (ehci->periodic_size - 1); | 2305 | clock_frame = (clock >> 3) & (ehci->periodic_size - 1); |
| 2281 | } else { | 2306 | } else { |
| 2282 | clock = now_uframe + mod - 1; | 2307 | clock = now_uframe + mod - 1; |
| @@ -2310,7 +2335,7 @@ restart: | |||
| 2310 | union ehci_shadow temp; | 2335 | union ehci_shadow temp; |
| 2311 | int live; | 2336 | int live; |
| 2312 | 2337 | ||
| 2313 | live = HC_IS_RUNNING (ehci_to_hcd(ehci)->state); | 2338 | live = (ehci->rh_state == EHCI_RH_RUNNING); |
| 2314 | switch (hc32_to_cpu(ehci, type)) { | 2339 | switch (hc32_to_cpu(ehci, type)) { |
| 2315 | case Q_TYPE_QH: | 2340 | case Q_TYPE_QH: |
| 2316 | /* handle any completions */ | 2341 | /* handle any completions */ |
| @@ -2435,7 +2460,7 @@ restart: | |||
| 2435 | * We can't advance our scan without collecting the ISO | 2460 | * We can't advance our scan without collecting the ISO |
| 2436 | * transfers that are still pending in this frame. | 2461 | * transfers that are still pending in this frame. |
| 2437 | */ | 2462 | */ |
| 2438 | if (incomplete && HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { | 2463 | if (incomplete && ehci->rh_state == EHCI_RH_RUNNING) { |
| 2439 | ehci->next_uframe = now_uframe; | 2464 | ehci->next_uframe = now_uframe; |
| 2440 | break; | 2465 | break; |
| 2441 | } | 2466 | } |
| @@ -2451,12 +2476,11 @@ restart: | |||
| 2451 | if (now_uframe == clock) { | 2476 | if (now_uframe == clock) { |
| 2452 | unsigned now; | 2477 | unsigned now; |
| 2453 | 2478 | ||
| 2454 | if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state) | 2479 | if (ehci->rh_state != EHCI_RH_RUNNING |
| 2455 | || ehci->periodic_sched == 0) | 2480 | || ehci->periodic_sched == 0) |
| 2456 | break; | 2481 | break; |
| 2457 | ehci->next_uframe = now_uframe; | 2482 | ehci->next_uframe = now_uframe; |
| 2458 | now = ehci_readl(ehci, &ehci->regs->frame_index) & | 2483 | now = ehci_read_frame_index(ehci) & (mod - 1); |
| 2459 | (mod - 1); | ||
| 2460 | if (now_uframe == now) | 2484 | if (now_uframe == now) |
| 2461 | break; | 2485 | break; |
| 2462 | 2486 | ||
diff --git a/drivers/usb/host/ehci-sh.c b/drivers/usb/host/ehci-sh.c index 86a95bb80a61..9d9cf47d80da 100644 --- a/drivers/usb/host/ehci-sh.c +++ b/drivers/usb/host/ehci-sh.c | |||
| @@ -168,7 +168,7 @@ static int ehci_hcd_sh_probe(struct platform_device *pdev) | |||
| 168 | clk_enable(priv->fclk); | 168 | clk_enable(priv->fclk); |
| 169 | clk_enable(priv->iclk); | 169 | clk_enable(priv->iclk); |
| 170 | 170 | ||
| 171 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); | 171 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 172 | if (ret != 0) { | 172 | if (ret != 0) { |
| 173 | dev_err(&pdev->dev, "Failed to add hcd"); | 173 | dev_err(&pdev->dev, "Failed to add hcd"); |
| 174 | goto fail_add_hcd; | 174 | goto fail_add_hcd; |
diff --git a/drivers/usb/host/ehci-spear.c b/drivers/usb/host/ehci-spear.c index dbf1e4ef3c17..b115b0b76e33 100644 --- a/drivers/usb/host/ehci-spear.c +++ b/drivers/usb/host/ehci-spear.c | |||
| @@ -154,7 +154,7 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev) | |||
| 154 | ehci->clk = usbh_clk; | 154 | ehci->clk = usbh_clk; |
| 155 | 155 | ||
| 156 | spear_start_ehci(ehci); | 156 | spear_start_ehci(ehci); |
| 157 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_DISABLED); | 157 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 158 | if (retval) | 158 | if (retval) |
| 159 | goto fail_add_hcd; | 159 | goto fail_add_hcd; |
| 160 | 160 | ||
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c index 02b2bfd49a10..db9d1b4bfbdc 100644 --- a/drivers/usb/host/ehci-tegra.c +++ b/drivers/usb/host/ehci-tegra.c | |||
| @@ -674,7 +674,7 @@ static int tegra_ehci_probe(struct platform_device *pdev) | |||
| 674 | } | 674 | } |
| 675 | #endif | 675 | #endif |
| 676 | 676 | ||
| 677 | err = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); | 677 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 678 | if (err) { | 678 | if (err) { |
| 679 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); | 679 | dev_err(&pdev->dev, "Failed to add USB HCD\n"); |
| 680 | goto fail; | 680 | goto fail; |
diff --git a/drivers/usb/host/ehci-vt8500.c b/drivers/usb/host/ehci-vt8500.c index 47d749631bc7..54d1ab8aec49 100644 --- a/drivers/usb/host/ehci-vt8500.c +++ b/drivers/usb/host/ehci-vt8500.c | |||
| @@ -133,7 +133,7 @@ static int vt8500_ehci_drv_probe(struct platform_device *pdev) | |||
| 133 | ehci_port_power(ehci, 1); | 133 | ehci_port_power(ehci, 1); |
| 134 | 134 | ||
| 135 | ret = usb_add_hcd(hcd, pdev->resource[1].start, | 135 | ret = usb_add_hcd(hcd, pdev->resource[1].start, |
| 136 | IRQF_DISABLED | IRQF_SHARED); | 136 | IRQF_SHARED); |
| 137 | if (ret == 0) { | 137 | if (ret == 0) { |
| 138 | platform_set_drvdata(pdev, hcd); | 138 | platform_set_drvdata(pdev, hcd); |
| 139 | return ret; | 139 | return ret; |
diff --git a/drivers/usb/host/ehci-xls.c b/drivers/usb/host/ehci-xls.c new file mode 100644 index 000000000000..b4fb511d24bc --- /dev/null +++ b/drivers/usb/host/ehci-xls.c | |||
| @@ -0,0 +1,161 @@ | |||
| 1 | /* | ||
| 2 | * EHCI HCD for Netlogic XLS processors. | ||
| 3 | * | ||
| 4 | * (C) Copyright 2011 Netlogic Microsystems Inc. | ||
| 5 | * | ||
| 6 | * Based on various ehci-*.c drivers | ||
| 7 | * | ||
| 8 | * This file is subject to the terms and conditions of the GNU General Public | ||
| 9 | * License. See the file COPYING in the main directory of this archive for | ||
| 10 | * more details. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <linux/platform_device.h> | ||
| 14 | |||
| 15 | static int ehci_xls_setup(struct usb_hcd *hcd) | ||
| 16 | { | ||
| 17 | int retval; | ||
| 18 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); | ||
| 19 | |||
| 20 | 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 | |||
| 26 | /* cache this readonly data; minimize chip reads */ | ||
| 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 | } | ||
| 42 | |||
| 43 | int ehci_xls_probe_internal(const struct hc_driver *driver, | ||
| 44 | struct platform_device *pdev) | ||
| 45 | { | ||
| 46 | struct usb_hcd *hcd; | ||
| 47 | struct resource *res; | ||
| 48 | int retval, irq; | ||
| 49 | |||
| 50 | /* Get our IRQ from an earlier registered Platform Resource */ | ||
| 51 | irq = platform_get_irq(pdev, 0); | ||
| 52 | if (irq < 0) { | ||
| 53 | dev_err(&pdev->dev, "Found HC with no IRQ. Check %s setup!\n", | ||
| 54 | dev_name(&pdev->dev)); | ||
| 55 | return -ENODEV; | ||
| 56 | } | ||
| 57 | |||
| 58 | /* Get our Memory Handle */ | ||
| 59 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 60 | if (!res) { | ||
| 61 | dev_err(&pdev->dev, "Error: MMIO Handle %s setup!\n", | ||
| 62 | dev_name(&pdev->dev)); | ||
| 63 | return -ENODEV; | ||
| 64 | } | ||
| 65 | hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); | ||
| 66 | if (!hcd) { | ||
| 67 | retval = -ENOMEM; | ||
| 68 | goto err1; | ||
| 69 | } | ||
| 70 | |||
| 71 | hcd->rsrc_start = res->start; | ||
| 72 | hcd->rsrc_len = res->end - res->start + 1; | ||
| 73 | |||
| 74 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, | ||
| 75 | driver->description)) { | ||
| 76 | dev_dbg(&pdev->dev, "controller already in use\n"); | ||
| 77 | retval = -EBUSY; | ||
| 78 | goto err2; | ||
| 79 | } | ||
| 80 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); | ||
| 81 | |||
| 82 | if (hcd->regs == NULL) { | ||
| 83 | dev_dbg(&pdev->dev, "error mapping memory\n"); | ||
| 84 | retval = -EFAULT; | ||
| 85 | goto err3; | ||
| 86 | } | ||
| 87 | |||
| 88 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); | ||
| 89 | if (retval != 0) | ||
| 90 | goto err4; | ||
| 91 | return retval; | ||
| 92 | |||
| 93 | err4: | ||
| 94 | iounmap(hcd->regs); | ||
| 95 | err3: | ||
| 96 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
| 97 | err2: | ||
| 98 | usb_put_hcd(hcd); | ||
| 99 | err1: | ||
| 100 | dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), | ||
| 101 | retval); | ||
| 102 | return retval; | ||
| 103 | } | ||
| 104 | |||
| 105 | static struct hc_driver ehci_xls_hc_driver = { | ||
| 106 | .description = hcd_name, | ||
| 107 | .product_desc = "XLS EHCI Host Controller", | ||
| 108 | .hcd_priv_size = sizeof(struct ehci_hcd), | ||
| 109 | .irq = ehci_irq, | ||
| 110 | .flags = HCD_USB2 | HCD_MEMORY, | ||
| 111 | .reset = ehci_xls_setup, | ||
| 112 | .start = ehci_run, | ||
| 113 | .stop = ehci_stop, | ||
| 114 | .shutdown = ehci_shutdown, | ||
| 115 | |||
| 116 | .urb_enqueue = ehci_urb_enqueue, | ||
| 117 | .urb_dequeue = ehci_urb_dequeue, | ||
| 118 | .endpoint_disable = ehci_endpoint_disable, | ||
| 119 | .endpoint_reset = ehci_endpoint_reset, | ||
| 120 | |||
| 121 | .get_frame_number = ehci_get_frame, | ||
| 122 | |||
| 123 | .hub_status_data = ehci_hub_status_data, | ||
| 124 | .hub_control = ehci_hub_control, | ||
| 125 | .bus_suspend = ehci_bus_suspend, | ||
| 126 | .bus_resume = ehci_bus_resume, | ||
| 127 | .relinquish_port = ehci_relinquish_port, | ||
| 128 | .port_handed_over = ehci_port_handed_over, | ||
| 129 | |||
| 130 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, | ||
| 131 | }; | ||
| 132 | |||
| 133 | static int ehci_xls_probe(struct platform_device *pdev) | ||
| 134 | { | ||
| 135 | if (usb_disabled()) | ||
| 136 | return -ENODEV; | ||
| 137 | |||
| 138 | return ehci_xls_probe_internal(&ehci_xls_hc_driver, pdev); | ||
| 139 | } | ||
| 140 | |||
| 141 | static int ehci_xls_remove(struct platform_device *pdev) | ||
| 142 | { | ||
| 143 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | ||
| 144 | |||
| 145 | usb_remove_hcd(hcd); | ||
| 146 | iounmap(hcd->regs); | ||
| 147 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
| 148 | usb_put_hcd(hcd); | ||
| 149 | return 0; | ||
| 150 | } | ||
| 151 | |||
| 152 | MODULE_ALIAS("ehci-xls"); | ||
| 153 | |||
| 154 | static struct platform_driver ehci_xls_driver = { | ||
| 155 | .probe = ehci_xls_probe, | ||
| 156 | .remove = ehci_xls_remove, | ||
| 157 | .shutdown = usb_hcd_platform_shutdown, | ||
| 158 | .driver = { | ||
| 159 | .name = "ehci-xls", | ||
| 160 | }, | ||
| 161 | }; | ||
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index cc7d337ec355..0a5fda73b3f2 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h | |||
| @@ -62,6 +62,12 @@ 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 | enum ehci_rh_state { | ||
| 66 | EHCI_RH_HALTED, | ||
| 67 | EHCI_RH_SUSPENDED, | ||
| 68 | EHCI_RH_RUNNING | ||
| 69 | }; | ||
| 70 | |||
| 65 | struct ehci_hcd { /* one per controller */ | 71 | struct ehci_hcd { /* one per controller */ |
| 66 | /* glue to PCI and HCD framework */ | 72 | /* glue to PCI and HCD framework */ |
| 67 | struct ehci_caps __iomem *caps; | 73 | struct ehci_caps __iomem *caps; |
| @@ -70,6 +76,7 @@ struct ehci_hcd { /* one per controller */ | |||
| 70 | 76 | ||
| 71 | __u32 hcs_params; /* cached register copy */ | 77 | __u32 hcs_params; /* cached register copy */ |
| 72 | spinlock_t lock; | 78 | spinlock_t lock; |
| 79 | enum ehci_rh_state rh_state; | ||
| 73 | 80 | ||
| 74 | /* async schedule support */ | 81 | /* async schedule support */ |
| 75 | struct ehci_qh *async; | 82 | struct ehci_qh *async; |
| @@ -139,6 +146,7 @@ struct ehci_hcd { /* one per controller */ | |||
| 139 | unsigned fs_i_thresh:1; /* Intel iso scheduling */ | 146 | unsigned fs_i_thresh:1; /* Intel iso scheduling */ |
| 140 | unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/ | 147 | unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/ |
| 141 | unsigned has_synopsys_hc_bug:1; /* Synopsys HC */ | 148 | unsigned has_synopsys_hc_bug:1; /* Synopsys HC */ |
| 149 | unsigned frame_index_bug:1; /* MosChip (AKA NetMos) */ | ||
| 142 | 150 | ||
| 143 | /* required for usb32 quirk */ | 151 | /* required for usb32 quirk */ |
| 144 | #define OHCI_CTRL_HCFS (3 << 6) | 152 | #define OHCI_CTRL_HCFS (3 << 6) |
| @@ -740,6 +748,22 @@ static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x) | |||
| 740 | 748 | ||
| 741 | /*-------------------------------------------------------------------------*/ | 749 | /*-------------------------------------------------------------------------*/ |
| 742 | 750 | ||
| 751 | #ifdef CONFIG_PCI | ||
| 752 | |||
| 753 | /* For working around the MosChip frame-index-register bug */ | ||
| 754 | static unsigned ehci_read_frame_index(struct ehci_hcd *ehci); | ||
| 755 | |||
| 756 | #else | ||
| 757 | |||
| 758 | static inline unsigned ehci_read_frame_index(struct ehci_hcd *ehci) | ||
| 759 | { | ||
| 760 | return ehci_readl(ehci, &ehci->regs->frame_index); | ||
| 761 | } | ||
| 762 | |||
| 763 | #endif | ||
| 764 | |||
| 765 | /*-------------------------------------------------------------------------*/ | ||
| 766 | |||
| 743 | #ifndef DEBUG | 767 | #ifndef DEBUG |
| 744 | #define STUB_DEBUG_FILES | 768 | #define STUB_DEBUG_FILES |
| 745 | #endif /* DEBUG */ | 769 | #endif /* DEBUG */ |
diff --git a/drivers/usb/host/fhci-hcd.c b/drivers/usb/host/fhci-hcd.c index 572ea53b0226..4ed6d19f2a54 100644 --- a/drivers/usb/host/fhci-hcd.c +++ b/drivers/usb/host/fhci-hcd.c | |||
| @@ -621,12 +621,15 @@ static int __devinit of_fhci_probe(struct platform_device *ofdev) | |||
| 621 | goto err_pram; | 621 | goto err_pram; |
| 622 | } | 622 | } |
| 623 | 623 | ||
| 624 | pram_addr = cpm_muram_alloc_fixed(iprop[2], FHCI_PRAM_SIZE); | 624 | pram_addr = cpm_muram_alloc(FHCI_PRAM_SIZE, 64); |
| 625 | if (IS_ERR_VALUE(pram_addr)) { | 625 | if (IS_ERR_VALUE(pram_addr)) { |
| 626 | dev_err(dev, "failed to allocate usb pram\n"); | 626 | dev_err(dev, "failed to allocate usb pram\n"); |
| 627 | ret = -ENOMEM; | 627 | ret = -ENOMEM; |
| 628 | goto err_pram; | 628 | goto err_pram; |
| 629 | } | 629 | } |
| 630 | |||
| 631 | qe_issue_cmd(QE_ASSIGN_PAGE_TO_DEVICE, QE_CR_SUBBLOCK_USB, | ||
| 632 | QE_CR_PROTOCOL_UNSPECIFIED, pram_addr); | ||
| 630 | fhci->pram = cpm_muram_addr(pram_addr); | 633 | fhci->pram = cpm_muram_addr(pram_addr); |
| 631 | 634 | ||
| 632 | /* GPIOs and pins */ | 635 | /* GPIOs and pins */ |
| @@ -686,7 +689,7 @@ static int __devinit of_fhci_probe(struct platform_device *ofdev) | |||
| 686 | } | 689 | } |
| 687 | 690 | ||
| 688 | ret = request_irq(fhci->timer->irq, fhci_frame_limit_timer_irq, | 691 | ret = request_irq(fhci->timer->irq, fhci_frame_limit_timer_irq, |
| 689 | IRQF_DISABLED, "qe timer (usb)", hcd); | 692 | 0, "qe timer (usb)", hcd); |
| 690 | if (ret) { | 693 | if (ret) { |
| 691 | dev_err(dev, "failed to request timer irq"); | 694 | dev_err(dev, "failed to request timer irq"); |
| 692 | goto err_timer_irq; | 695 | goto err_timer_irq; |
| @@ -745,7 +748,7 @@ static int __devinit of_fhci_probe(struct platform_device *ofdev) | |||
| 745 | out_be16(&fhci->regs->usb_event, 0xffff); | 748 | out_be16(&fhci->regs->usb_event, 0xffff); |
| 746 | out_be16(&fhci->regs->usb_mask, 0); | 749 | out_be16(&fhci->regs->usb_mask, 0); |
| 747 | 750 | ||
| 748 | ret = usb_add_hcd(hcd, usb_irq, IRQF_DISABLED); | 751 | ret = usb_add_hcd(hcd, usb_irq, 0); |
| 749 | if (ret < 0) | 752 | if (ret < 0) |
| 750 | goto err_add_hcd; | 753 | goto err_add_hcd; |
| 751 | 754 | ||
diff --git a/drivers/usb/host/fhci-sched.c b/drivers/usb/host/fhci-sched.c index a42ef380e917..2df851b4bc7c 100644 --- a/drivers/usb/host/fhci-sched.c +++ b/drivers/usb/host/fhci-sched.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Freescale QUICC Engine USB Host Controller Driver | 2 | * Freescale QUICC Engine USB Host Controller Driver |
| 3 | * | 3 | * |
| 4 | * Copyright (c) Freescale Semicondutor, Inc. 2006. | 4 | * Copyright (c) Freescale Semicondutor, Inc. 2006, 2011. |
| 5 | * Shlomi Gridish <gridish@freescale.com> | 5 | * Shlomi Gridish <gridish@freescale.com> |
| 6 | * Jerry Huang <Chang-Ming.Huang@freescale.com> | 6 | * Jerry Huang <Chang-Ming.Huang@freescale.com> |
| 7 | * Copyright (c) Logic Product Development, Inc. 2007 | 7 | * Copyright (c) Logic Product Development, Inc. 2007 |
| @@ -810,9 +810,11 @@ void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb) | |||
| 810 | ed->dev_addr = usb_pipedevice(urb->pipe); | 810 | ed->dev_addr = usb_pipedevice(urb->pipe); |
| 811 | ed->max_pkt_size = usb_maxpacket(urb->dev, urb->pipe, | 811 | ed->max_pkt_size = usb_maxpacket(urb->dev, urb->pipe, |
| 812 | usb_pipeout(urb->pipe)); | 812 | usb_pipeout(urb->pipe)); |
| 813 | /* setup stage */ | ||
| 813 | td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt++, FHCI_TA_SETUP, | 814 | td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt++, FHCI_TA_SETUP, |
| 814 | USB_TD_TOGGLE_DATA0, urb->setup_packet, 8, 0, 0, true); | 815 | USB_TD_TOGGLE_DATA0, urb->setup_packet, 8, 0, 0, true); |
| 815 | 816 | ||
| 817 | /* data stage */ | ||
| 816 | if (data_len > 0) { | 818 | if (data_len > 0) { |
| 817 | td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt++, | 819 | td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt++, |
| 818 | usb_pipeout(urb->pipe) ? FHCI_TA_OUT : | 820 | usb_pipeout(urb->pipe) ? FHCI_TA_OUT : |
| @@ -820,9 +822,18 @@ void fhci_queue_urb(struct fhci_hcd *fhci, struct urb *urb) | |||
| 820 | USB_TD_TOGGLE_DATA1, data, data_len, 0, 0, | 822 | USB_TD_TOGGLE_DATA1, data, data_len, 0, 0, |
| 821 | true); | 823 | true); |
| 822 | } | 824 | } |
| 823 | td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt++, | 825 | |
| 824 | usb_pipeout(urb->pipe) ? FHCI_TA_IN : FHCI_TA_OUT, | 826 | /* status stage */ |
| 825 | USB_TD_TOGGLE_DATA1, data, 0, 0, 0, true); | 827 | if (data_len > 0) |
| 828 | td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt++, | ||
| 829 | (usb_pipeout(urb->pipe) ? FHCI_TA_IN : | ||
| 830 | FHCI_TA_OUT), | ||
| 831 | USB_TD_TOGGLE_DATA1, data, 0, 0, 0, true); | ||
| 832 | else | ||
| 833 | td = fhci_td_fill(fhci, urb, urb_priv, ed, cnt++, | ||
| 834 | FHCI_TA_IN, | ||
| 835 | USB_TD_TOGGLE_DATA1, data, 0, 0, 0, true); | ||
| 836 | |||
| 826 | urb_state = US_CTRL_SETUP; | 837 | urb_state = US_CTRL_SETUP; |
| 827 | break; | 838 | break; |
| 828 | case FHCI_TF_ISO: | 839 | case FHCI_TF_ISO: |
diff --git a/drivers/usb/host/fsl-mph-dr-of.c b/drivers/usb/host/fsl-mph-dr-of.c index 79a66d622f9c..9037035ad1e4 100644 --- a/drivers/usb/host/fsl-mph-dr-of.c +++ b/drivers/usb/host/fsl-mph-dr-of.c | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | #include <linux/io.h> | 16 | #include <linux/io.h> |
| 17 | #include <linux/of_platform.h> | 17 | #include <linux/of_platform.h> |
| 18 | #include <linux/clk.h> | 18 | #include <linux/clk.h> |
| 19 | #include <linux/module.h> | ||
| 19 | 20 | ||
| 20 | struct fsl_usb2_dev_data { | 21 | struct fsl_usb2_dev_data { |
| 21 | char *dr_mode; /* controller mode */ | 22 | char *dr_mode; /* controller mode */ |
diff --git a/drivers/usb/host/imx21-hcd.c b/drivers/usb/host/imx21-hcd.c index af05718bdc73..2ee18cfa1efe 100644 --- a/drivers/usb/host/imx21-hcd.c +++ b/drivers/usb/host/imx21-hcd.c | |||
| @@ -1891,7 +1891,7 @@ static int imx21_probe(struct platform_device *pdev) | |||
| 1891 | dev_info(imx21->dev, "Hardware HC revision: 0x%02X\n", | 1891 | dev_info(imx21->dev, "Hardware HC revision: 0x%02X\n", |
| 1892 | (readl(imx21->regs + USBOTG_HWMODE) >> 16) & 0xFF); | 1892 | (readl(imx21->regs + USBOTG_HWMODE) >> 16) & 0xFF); |
| 1893 | 1893 | ||
| 1894 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED); | 1894 | ret = usb_add_hcd(hcd, irq, 0); |
| 1895 | if (ret != 0) { | 1895 | if (ret != 0) { |
| 1896 | dev_err(imx21->dev, "usb_add_hcd() returned %d\n", ret); | 1896 | dev_err(imx21->dev, "usb_add_hcd() returned %d\n", ret); |
| 1897 | goto failed_add_hcd; | 1897 | goto failed_add_hcd; |
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c index baae4ccd16ac..d91e5f211a76 100644 --- a/drivers/usb/host/isp116x-hcd.c +++ b/drivers/usb/host/isp116x-hcd.c | |||
| @@ -1639,7 +1639,7 @@ static int __devinit isp116x_probe(struct platform_device *pdev) | |||
| 1639 | goto err6; | 1639 | goto err6; |
| 1640 | } | 1640 | } |
| 1641 | 1641 | ||
| 1642 | ret = usb_add_hcd(hcd, irq, irqflags | IRQF_DISABLED); | 1642 | ret = usb_add_hcd(hcd, irq, irqflags); |
| 1643 | if (ret) | 1643 | if (ret) |
| 1644 | goto err6; | 1644 | goto err6; |
| 1645 | 1645 | ||
diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c index 9c37dad3e816..e5fd8aa57af1 100644 --- a/drivers/usb/host/isp1362-hcd.c +++ b/drivers/usb/host/isp1362-hcd.c | |||
| @@ -2358,7 +2358,7 @@ static int isp1362_hc_reset(struct usb_hcd *hcd) | |||
| 2358 | unsigned long flags; | 2358 | unsigned long flags; |
| 2359 | int clkrdy = 0; | 2359 | int clkrdy = 0; |
| 2360 | 2360 | ||
| 2361 | pr_info("%s:\n", __func__); | 2361 | pr_debug("%s:\n", __func__); |
| 2362 | 2362 | ||
| 2363 | if (isp1362_hcd->board && isp1362_hcd->board->reset) { | 2363 | if (isp1362_hcd->board && isp1362_hcd->board->reset) { |
| 2364 | isp1362_hcd->board->reset(hcd->self.controller, 1); | 2364 | isp1362_hcd->board->reset(hcd->self.controller, 1); |
| @@ -2395,7 +2395,7 @@ static void isp1362_hc_stop(struct usb_hcd *hcd) | |||
| 2395 | unsigned long flags; | 2395 | unsigned long flags; |
| 2396 | u32 tmp; | 2396 | u32 tmp; |
| 2397 | 2397 | ||
| 2398 | pr_info("%s:\n", __func__); | 2398 | pr_debug("%s:\n", __func__); |
| 2399 | 2399 | ||
| 2400 | del_timer_sync(&hcd->rh_timer); | 2400 | del_timer_sync(&hcd->rh_timer); |
| 2401 | 2401 | ||
| @@ -2523,7 +2523,7 @@ static int isp1362_hc_start(struct usb_hcd *hcd) | |||
| 2523 | u16 chipid; | 2523 | u16 chipid; |
| 2524 | unsigned long flags; | 2524 | unsigned long flags; |
| 2525 | 2525 | ||
| 2526 | pr_info("%s:\n", __func__); | 2526 | pr_debug("%s:\n", __func__); |
| 2527 | 2527 | ||
| 2528 | spin_lock_irqsave(&isp1362_hcd->lock, flags); | 2528 | spin_lock_irqsave(&isp1362_hcd->lock, flags); |
| 2529 | chipid = isp1362_read_reg16(isp1362_hcd, HCCHIPID); | 2529 | chipid = isp1362_read_reg16(isp1362_hcd, HCCHIPID); |
| @@ -2773,7 +2773,7 @@ static int __devinit isp1362_probe(struct platform_device *pdev) | |||
| 2773 | if (irq_res->flags & IORESOURCE_IRQ_LOWLEVEL) | 2773 | if (irq_res->flags & IORESOURCE_IRQ_LOWLEVEL) |
| 2774 | irq_flags |= IRQF_TRIGGER_LOW; | 2774 | irq_flags |= IRQF_TRIGGER_LOW; |
| 2775 | 2775 | ||
| 2776 | retval = usb_add_hcd(hcd, irq, irq_flags | IRQF_DISABLED | IRQF_SHARED); | 2776 | retval = usb_add_hcd(hcd, irq, irq_flags | IRQF_SHARED); |
| 2777 | if (retval != 0) | 2777 | if (retval != 0) |
| 2778 | goto err6; | 2778 | goto err6; |
| 2779 | pr_info("%s, irq %d\n", hcd->product_desc, irq); | 2779 | pr_info("%s, irq %d\n", hcd->product_desc, irq); |
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c index 840beda66dd9..27dfab80ed8f 100644 --- a/drivers/usb/host/isp1760-hcd.c +++ b/drivers/usb/host/isp1760-hcd.c | |||
| @@ -21,8 +21,10 @@ | |||
| 21 | #include <linux/uaccess.h> | 21 | #include <linux/uaccess.h> |
| 22 | #include <linux/io.h> | 22 | #include <linux/io.h> |
| 23 | #include <linux/mm.h> | 23 | #include <linux/mm.h> |
| 24 | #include <linux/timer.h> | ||
| 24 | #include <asm/unaligned.h> | 25 | #include <asm/unaligned.h> |
| 25 | #include <asm/cacheflush.h> | 26 | #include <asm/cacheflush.h> |
| 27 | #include <linux/gpio.h> | ||
| 26 | 28 | ||
| 27 | #include "isp1760-hcd.h" | 29 | #include "isp1760-hcd.h" |
| 28 | 30 | ||
| @@ -39,7 +41,6 @@ struct isp1760_hcd { | |||
| 39 | int int_done_map; | 41 | int int_done_map; |
| 40 | struct memory_chunk memory_pool[BLOCKS]; | 42 | struct memory_chunk memory_pool[BLOCKS]; |
| 41 | struct list_head controlqhs, bulkqhs, interruptqhs; | 43 | struct list_head controlqhs, bulkqhs, interruptqhs; |
| 42 | int active_ptds; | ||
| 43 | 44 | ||
| 44 | /* periodic schedule support */ | 45 | /* periodic schedule support */ |
| 45 | #define DEFAULT_I_TDPS 1024 | 46 | #define DEFAULT_I_TDPS 1024 |
| @@ -48,6 +49,8 @@ struct isp1760_hcd { | |||
| 48 | unsigned long reset_done; | 49 | unsigned long reset_done; |
| 49 | unsigned long next_statechange; | 50 | unsigned long next_statechange; |
| 50 | unsigned int devflags; | 51 | unsigned int devflags; |
| 52 | |||
| 53 | int rst_gpio; | ||
| 51 | }; | 54 | }; |
| 52 | 55 | ||
| 53 | static inline struct isp1760_hcd *hcd_to_priv(struct usb_hcd *hcd) | 56 | static inline struct isp1760_hcd *hcd_to_priv(struct usb_hcd *hcd) |
| @@ -114,6 +117,7 @@ struct isp1760_qh { | |||
| 114 | u32 toggle; | 117 | u32 toggle; |
| 115 | u32 ping; | 118 | u32 ping; |
| 116 | int slot; | 119 | int slot; |
| 120 | int tt_buffer_dirty; /* See USB2.0 spec section 11.17.5 */ | ||
| 117 | }; | 121 | }; |
| 118 | 122 | ||
| 119 | struct urb_listitem { | 123 | struct urb_listitem { |
| @@ -432,6 +436,18 @@ static int isp1760_hc_setup(struct usb_hcd *hcd) | |||
| 432 | int result; | 436 | int result; |
| 433 | u32 scratch, hwmode; | 437 | u32 scratch, hwmode; |
| 434 | 438 | ||
| 439 | /* low-level chip reset */ | ||
| 440 | if (gpio_is_valid(priv->rst_gpio)) { | ||
| 441 | unsigned int rst_lvl; | ||
| 442 | |||
| 443 | rst_lvl = (priv->devflags & | ||
| 444 | ISP1760_FLAG_RESET_ACTIVE_HIGH) ? 1 : 0; | ||
| 445 | |||
| 446 | gpio_set_value(priv->rst_gpio, rst_lvl); | ||
| 447 | mdelay(50); | ||
| 448 | gpio_set_value(priv->rst_gpio, !rst_lvl); | ||
| 449 | } | ||
| 450 | |||
| 435 | /* Setup HW Mode Control: This assumes a level active-low interrupt */ | 451 | /* Setup HW Mode Control: This assumes a level active-low interrupt */ |
| 436 | hwmode = HW_DATA_BUS_32BIT; | 452 | hwmode = HW_DATA_BUS_32BIT; |
| 437 | 453 | ||
| @@ -489,10 +505,6 @@ static int isp1760_hc_setup(struct usb_hcd *hcd) | |||
| 489 | 16 : 32, (priv->devflags & ISP1760_FLAG_ANALOG_OC) ? | 505 | 16 : 32, (priv->devflags & ISP1760_FLAG_ANALOG_OC) ? |
| 490 | "analog" : "digital"); | 506 | "analog" : "digital"); |
| 491 | 507 | ||
| 492 | /* This is weird: at the first plug-in of a device there seems to be | ||
| 493 | one packet queued that never gets returned? */ | ||
| 494 | priv->active_ptds = -1; | ||
| 495 | |||
| 496 | /* ATL reset */ | 508 | /* ATL reset */ |
| 497 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode | ALL_ATX_RESET); | 509 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode | ALL_ATX_RESET); |
| 498 | mdelay(10); | 510 | mdelay(10); |
| @@ -514,83 +526,6 @@ static int isp1760_hc_setup(struct usb_hcd *hcd) | |||
| 514 | return priv_init(hcd); | 526 | return priv_init(hcd); |
| 515 | } | 527 | } |
| 516 | 528 | ||
| 517 | static void isp1760_init_maps(struct usb_hcd *hcd) | ||
| 518 | { | ||
| 519 | /*set last maps, for iso its only 1, else 32 tds bitmap*/ | ||
| 520 | reg_write32(hcd->regs, HC_ATL_PTD_LASTPTD_REG, 0x80000000); | ||
| 521 | reg_write32(hcd->regs, HC_INT_PTD_LASTPTD_REG, 0x80000000); | ||
| 522 | reg_write32(hcd->regs, HC_ISO_PTD_LASTPTD_REG, 0x00000001); | ||
| 523 | |||
| 524 | reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, 0xffffffff); | ||
| 525 | reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, 0xffffffff); | ||
| 526 | reg_write32(hcd->regs, HC_ISO_PTD_SKIPMAP_REG, 0xffffffff); | ||
| 527 | |||
| 528 | reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, | ||
| 529 | ATL_BUF_FILL | INT_BUF_FILL); | ||
| 530 | } | ||
| 531 | |||
| 532 | static void isp1760_enable_interrupts(struct usb_hcd *hcd) | ||
| 533 | { | ||
| 534 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_AND_REG, 0); | ||
| 535 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, 0xffffffff); | ||
| 536 | reg_write32(hcd->regs, HC_INT_IRQ_MASK_AND_REG, 0); | ||
| 537 | reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, 0xffffffff); | ||
| 538 | reg_write32(hcd->regs, HC_ISO_IRQ_MASK_AND_REG, 0); | ||
| 539 | reg_write32(hcd->regs, HC_ISO_IRQ_MASK_OR_REG, 0xffffffff); | ||
| 540 | /* step 23 passed */ | ||
| 541 | } | ||
| 542 | |||
| 543 | static int isp1760_run(struct usb_hcd *hcd) | ||
| 544 | { | ||
| 545 | int retval; | ||
| 546 | u32 temp; | ||
| 547 | u32 command; | ||
| 548 | u32 chipid; | ||
| 549 | |||
| 550 | hcd->uses_new_polling = 1; | ||
| 551 | |||
| 552 | hcd->state = HC_STATE_RUNNING; | ||
| 553 | isp1760_enable_interrupts(hcd); | ||
| 554 | temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL); | ||
| 555 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp | HW_GLOBAL_INTR_EN); | ||
| 556 | |||
| 557 | command = reg_read32(hcd->regs, HC_USBCMD); | ||
| 558 | command &= ~(CMD_LRESET|CMD_RESET); | ||
| 559 | command |= CMD_RUN; | ||
| 560 | reg_write32(hcd->regs, HC_USBCMD, command); | ||
| 561 | |||
| 562 | retval = handshake(hcd, HC_USBCMD, CMD_RUN, CMD_RUN, 250 * 1000); | ||
| 563 | if (retval) | ||
| 564 | return retval; | ||
| 565 | |||
| 566 | /* | ||
| 567 | * XXX | ||
| 568 | * Spec says to write FLAG_CF as last config action, priv code grabs | ||
| 569 | * the semaphore while doing so. | ||
| 570 | */ | ||
| 571 | down_write(&ehci_cf_port_reset_rwsem); | ||
| 572 | reg_write32(hcd->regs, HC_CONFIGFLAG, FLAG_CF); | ||
| 573 | |||
| 574 | retval = handshake(hcd, HC_CONFIGFLAG, FLAG_CF, FLAG_CF, 250 * 1000); | ||
| 575 | up_write(&ehci_cf_port_reset_rwsem); | ||
| 576 | if (retval) | ||
| 577 | return retval; | ||
| 578 | |||
| 579 | chipid = reg_read32(hcd->regs, HC_CHIP_ID_REG); | ||
| 580 | dev_info(hcd->self.controller, "USB ISP %04x HW rev. %d started\n", | ||
| 581 | chipid & 0xffff, chipid >> 16); | ||
| 582 | |||
| 583 | /* PTD Register Init Part 2, Step 28 */ | ||
| 584 | /* enable INTs */ | ||
| 585 | isp1760_init_maps(hcd); | ||
| 586 | |||
| 587 | /* GRR this is run-once init(), being done every time the HC starts. | ||
| 588 | * So long as they're part of class devices, we can't do it init() | ||
| 589 | * since the class device isn't created that early. | ||
| 590 | */ | ||
| 591 | return 0; | ||
| 592 | } | ||
| 593 | |||
| 594 | static u32 base_to_chip(u32 base) | 529 | static u32 base_to_chip(u32 base) |
| 595 | { | 530 | { |
| 596 | return ((base - 0x400) >> 3); | 531 | return ((base - 0x400) >> 3); |
| @@ -813,28 +748,29 @@ static void start_bus_transfer(struct usb_hcd *hcd, u32 ptd_offset, int slot, | |||
| 813 | WARN_ON(slots[slot].qh); | 748 | WARN_ON(slots[slot].qh); |
| 814 | WARN_ON(qtd->status != QTD_PAYLOAD_ALLOC); | 749 | WARN_ON(qtd->status != QTD_PAYLOAD_ALLOC); |
| 815 | 750 | ||
| 816 | slots[slot].qtd = qtd; | ||
| 817 | slots[slot].qh = qh; | ||
| 818 | qh->slot = slot; | ||
| 819 | qtd->status = QTD_XFER_STARTED; /* Set this before writing ptd, since | ||
| 820 | interrupt routine may preempt and expects this value. */ | ||
| 821 | ptd_write(hcd->regs, ptd_offset, slot, ptd); | ||
| 822 | priv->active_ptds++; | ||
| 823 | |||
| 824 | /* Make sure done map has not triggered from some unlinked transfer */ | 751 | /* Make sure done map has not triggered from some unlinked transfer */ |
| 825 | if (ptd_offset == ATL_PTD_OFFSET) { | 752 | if (ptd_offset == ATL_PTD_OFFSET) { |
| 826 | priv->atl_done_map |= reg_read32(hcd->regs, | 753 | priv->atl_done_map |= reg_read32(hcd->regs, |
| 827 | HC_ATL_PTD_DONEMAP_REG); | 754 | HC_ATL_PTD_DONEMAP_REG); |
| 828 | priv->atl_done_map &= ~(1 << qh->slot); | 755 | priv->atl_done_map &= ~(1 << slot); |
| 756 | } else { | ||
| 757 | priv->int_done_map |= reg_read32(hcd->regs, | ||
| 758 | HC_INT_PTD_DONEMAP_REG); | ||
| 759 | priv->int_done_map &= ~(1 << slot); | ||
| 760 | } | ||
| 761 | |||
| 762 | qh->slot = slot; | ||
| 763 | qtd->status = QTD_XFER_STARTED; | ||
| 764 | slots[slot].timestamp = jiffies; | ||
| 765 | slots[slot].qtd = qtd; | ||
| 766 | slots[slot].qh = qh; | ||
| 767 | ptd_write(hcd->regs, ptd_offset, slot, ptd); | ||
| 829 | 768 | ||
| 769 | if (ptd_offset == ATL_PTD_OFFSET) { | ||
| 830 | skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); | 770 | skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); |
| 831 | skip_map &= ~(1 << qh->slot); | 771 | skip_map &= ~(1 << qh->slot); |
| 832 | reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map); | 772 | reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map); |
| 833 | } else { | 773 | } else { |
| 834 | priv->int_done_map |= reg_read32(hcd->regs, | ||
| 835 | HC_INT_PTD_DONEMAP_REG); | ||
| 836 | priv->int_done_map &= ~(1 << qh->slot); | ||
| 837 | |||
| 838 | skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); | 774 | skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); |
| 839 | skip_map &= ~(1 << qh->slot); | 775 | skip_map &= ~(1 << qh->slot); |
| 840 | reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map); | 776 | reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map); |
| @@ -858,10 +794,7 @@ static void collect_qtds(struct usb_hcd *hcd, struct isp1760_qh *qh, | |||
| 858 | if (qtd->status < QTD_XFER_COMPLETE) | 794 | if (qtd->status < QTD_XFER_COMPLETE) |
| 859 | break; | 795 | break; |
| 860 | 796 | ||
| 861 | if (list_is_last(&qtd->qtd_list, &qh->qtd_list)) | 797 | last_qtd = last_qtd_of_urb(qtd, qh); |
| 862 | last_qtd = 1; | ||
| 863 | else | ||
| 864 | last_qtd = qtd->urb != qtd_next->urb; | ||
| 865 | 798 | ||
| 866 | if ((!last_qtd) && (qtd->status == QTD_RETIRE)) | 799 | if ((!last_qtd) && (qtd->status == QTD_RETIRE)) |
| 867 | qtd_next->status = QTD_RETIRE; | 800 | qtd_next->status = QTD_RETIRE; |
| @@ -902,7 +835,7 @@ static void collect_qtds(struct usb_hcd *hcd, struct isp1760_qh *qh, | |||
| 902 | urb_listitem = kmem_cache_zalloc(urb_listitem_cachep, | 835 | urb_listitem = kmem_cache_zalloc(urb_listitem_cachep, |
| 903 | GFP_ATOMIC); | 836 | GFP_ATOMIC); |
| 904 | if (unlikely(!urb_listitem)) | 837 | if (unlikely(!urb_listitem)) |
| 905 | break; | 838 | break; /* Try again on next call */ |
| 906 | urb_listitem->urb = qtd->urb; | 839 | urb_listitem->urb = qtd->urb; |
| 907 | list_add_tail(&urb_listitem->urb_list, urb_list); | 840 | list_add_tail(&urb_listitem->urb_list, urb_list); |
| 908 | } | 841 | } |
| @@ -928,6 +861,10 @@ static void enqueue_qtds(struct usb_hcd *hcd, struct isp1760_qh *qh) | |||
| 928 | return; | 861 | return; |
| 929 | } | 862 | } |
| 930 | 863 | ||
| 864 | /* Make sure this endpoint's TT buffer is clean before queueing ptds */ | ||
| 865 | if (qh->tt_buffer_dirty) | ||
| 866 | return; | ||
| 867 | |||
| 931 | if (usb_pipeint(list_entry(qh->qtd_list.next, struct isp1760_qtd, | 868 | if (usb_pipeint(list_entry(qh->qtd_list.next, struct isp1760_qtd, |
| 932 | qtd_list)->urb->pipe)) { | 869 | qtd_list)->urb->pipe)) { |
| 933 | ptd_offset = INT_PTD_OFFSET; | 870 | ptd_offset = INT_PTD_OFFSET; |
| @@ -1168,11 +1105,9 @@ static int check_atl_transfer(struct usb_hcd *hcd, struct ptd *ptd, | |||
| 1168 | return PTD_STATE_QTD_DONE; | 1105 | return PTD_STATE_QTD_DONE; |
| 1169 | } | 1106 | } |
| 1170 | 1107 | ||
| 1171 | static irqreturn_t isp1760_irq(struct usb_hcd *hcd) | 1108 | static void handle_done_ptds(struct usb_hcd *hcd) |
| 1172 | { | 1109 | { |
| 1173 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | 1110 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 1174 | u32 imask; | ||
| 1175 | irqreturn_t irqret = IRQ_NONE; | ||
| 1176 | struct ptd ptd; | 1111 | struct ptd ptd; |
| 1177 | struct isp1760_qh *qh; | 1112 | struct isp1760_qh *qh; |
| 1178 | int slot; | 1113 | int slot; |
| @@ -1181,27 +1116,14 @@ static irqreturn_t isp1760_irq(struct usb_hcd *hcd) | |||
| 1181 | u32 ptd_offset; | 1116 | u32 ptd_offset; |
| 1182 | struct isp1760_qtd *qtd; | 1117 | struct isp1760_qtd *qtd; |
| 1183 | int modified; | 1118 | int modified; |
| 1184 | static int last_active_ptds; | 1119 | int skip_map; |
| 1185 | int int_skip_map, atl_skip_map; | ||
| 1186 | |||
| 1187 | spin_lock(&priv->lock); | ||
| 1188 | |||
| 1189 | if (!(hcd->state & HC_STATE_RUNNING)) | ||
| 1190 | goto leave; | ||
| 1191 | |||
| 1192 | imask = reg_read32(hcd->regs, HC_INTERRUPT_REG); | ||
| 1193 | if (unlikely(!imask)) | ||
| 1194 | goto leave; | ||
| 1195 | reg_write32(hcd->regs, HC_INTERRUPT_REG, imask); /* Clear */ | ||
| 1196 | 1120 | ||
| 1197 | int_skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); | 1121 | skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); |
| 1198 | atl_skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); | 1122 | priv->int_done_map &= ~skip_map; |
| 1199 | priv->int_done_map |= reg_read32(hcd->regs, HC_INT_PTD_DONEMAP_REG); | 1123 | skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); |
| 1200 | priv->atl_done_map |= reg_read32(hcd->regs, HC_ATL_PTD_DONEMAP_REG); | 1124 | priv->atl_done_map &= ~skip_map; |
| 1201 | priv->int_done_map &= ~int_skip_map; | ||
| 1202 | priv->atl_done_map &= ~atl_skip_map; | ||
| 1203 | 1125 | ||
| 1204 | modified = priv->int_done_map | priv->atl_done_map; | 1126 | modified = priv->int_done_map || priv->atl_done_map; |
| 1205 | 1127 | ||
| 1206 | while (priv->int_done_map || priv->atl_done_map) { | 1128 | while (priv->int_done_map || priv->atl_done_map) { |
| 1207 | if (priv->int_done_map) { | 1129 | if (priv->int_done_map) { |
| @@ -1240,7 +1162,6 @@ static irqreturn_t isp1760_irq(struct usb_hcd *hcd) | |||
| 1240 | slots[slot].qtd = NULL; | 1162 | slots[slot].qtd = NULL; |
| 1241 | qh = slots[slot].qh; | 1163 | qh = slots[slot].qh; |
| 1242 | slots[slot].qh = NULL; | 1164 | slots[slot].qh = NULL; |
| 1243 | priv->active_ptds--; | ||
| 1244 | qh->slot = -1; | 1165 | qh->slot = -1; |
| 1245 | 1166 | ||
| 1246 | WARN_ON(qtd->status != QTD_XFER_STARTED); | 1167 | WARN_ON(qtd->status != QTD_XFER_STARTED); |
| @@ -1281,6 +1202,15 @@ static irqreturn_t isp1760_irq(struct usb_hcd *hcd) | |||
| 1281 | 1202 | ||
| 1282 | case PTD_STATE_URB_RETIRE: | 1203 | case PTD_STATE_URB_RETIRE: |
| 1283 | qtd->status = QTD_RETIRE; | 1204 | qtd->status = QTD_RETIRE; |
| 1205 | if ((qtd->urb->dev->speed != USB_SPEED_HIGH) && | ||
| 1206 | (qtd->urb->status != -EPIPE) && | ||
| 1207 | (qtd->urb->status != -EREMOTEIO)) { | ||
| 1208 | qh->tt_buffer_dirty = 1; | ||
| 1209 | if (usb_hub_clear_tt_buffer(qtd->urb)) | ||
| 1210 | /* Clear failed; let's hope things work | ||
| 1211 | anyway */ | ||
| 1212 | qh->tt_buffer_dirty = 0; | ||
| 1213 | } | ||
| 1284 | qtd = NULL; | 1214 | qtd = NULL; |
| 1285 | qh->toggle = 0; | 1215 | qh->toggle = 0; |
| 1286 | qh->ping = 0; | 1216 | qh->ping = 0; |
| @@ -1311,22 +1241,28 @@ static irqreturn_t isp1760_irq(struct usb_hcd *hcd) | |||
| 1311 | 1241 | ||
| 1312 | if (modified) | 1242 | if (modified) |
| 1313 | schedule_ptds(hcd); | 1243 | schedule_ptds(hcd); |
| 1244 | } | ||
| 1314 | 1245 | ||
| 1315 | /* ISP1760 Errata 2 explains that interrupts may be missed (or not | 1246 | static irqreturn_t isp1760_irq(struct usb_hcd *hcd) |
| 1316 | happen?) if two USB devices are running simultaneously. Perhaps | 1247 | { |
| 1317 | this happens when a PTD is finished during interrupt handling; | 1248 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 1318 | enable SOF interrupts if PTDs are still scheduled when exiting this | 1249 | u32 imask; |
| 1319 | interrupt handler, just to be safe. */ | 1250 | irqreturn_t irqret = IRQ_NONE; |
| 1320 | 1251 | ||
| 1321 | if (priv->active_ptds != last_active_ptds) { | 1252 | spin_lock(&priv->lock); |
| 1322 | if (priv->active_ptds > 0) | 1253 | |
| 1323 | reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, | 1254 | if (!(hcd->state & HC_STATE_RUNNING)) |
| 1324 | INTERRUPT_ENABLE_SOT_MASK); | 1255 | goto leave; |
| 1325 | else | 1256 | |
| 1326 | reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, | 1257 | imask = reg_read32(hcd->regs, HC_INTERRUPT_REG); |
| 1327 | INTERRUPT_ENABLE_MASK); | 1258 | if (unlikely(!imask)) |
| 1328 | last_active_ptds = priv->active_ptds; | 1259 | goto leave; |
| 1329 | } | 1260 | reg_write32(hcd->regs, HC_INTERRUPT_REG, imask); /* Clear */ |
| 1261 | |||
| 1262 | priv->int_done_map |= reg_read32(hcd->regs, HC_INT_PTD_DONEMAP_REG); | ||
| 1263 | priv->atl_done_map |= reg_read32(hcd->regs, HC_ATL_PTD_DONEMAP_REG); | ||
| 1264 | |||
| 1265 | handle_done_ptds(hcd); | ||
| 1330 | 1266 | ||
| 1331 | irqret = IRQ_HANDLED; | 1267 | irqret = IRQ_HANDLED; |
| 1332 | leave: | 1268 | leave: |
| @@ -1335,6 +1271,138 @@ leave: | |||
| 1335 | return irqret; | 1271 | return irqret; |
| 1336 | } | 1272 | } |
| 1337 | 1273 | ||
| 1274 | /* | ||
| 1275 | * Workaround for problem described in chip errata 2: | ||
| 1276 | * | ||
| 1277 | * Sometimes interrupts are not generated when ATL (not INT?) completion occurs. | ||
| 1278 | * One solution suggested in the errata is to use SOF interrupts _instead_of_ | ||
| 1279 | * ATL done interrupts (the "instead of" might be important since it seems | ||
| 1280 | * enabling ATL interrupts also causes the chip to sometimes - rarely - "forget" | ||
| 1281 | * to set the PTD's done bit in addition to not generating an interrupt!). | ||
| 1282 | * | ||
| 1283 | * So if we use SOF + ATL interrupts, we sometimes get stale PTDs since their | ||
| 1284 | * done bit is not being set. This is bad - it blocks the endpoint until reboot. | ||
| 1285 | * | ||
| 1286 | * If we use SOF interrupts only, we get latency between ptd completion and the | ||
| 1287 | * actual handling. This is very noticeable in testusb runs which takes several | ||
| 1288 | * minutes longer without ATL interrupts. | ||
| 1289 | * | ||
| 1290 | * A better solution is to run the code below every SLOT_CHECK_PERIOD ms. If it | ||
| 1291 | * finds active ATL slots which are older than SLOT_TIMEOUT ms, it checks the | ||
| 1292 | * slot's ACTIVE and VALID bits. If these are not set, the ptd is considered | ||
| 1293 | * completed and its done map bit is set. | ||
| 1294 | * | ||
| 1295 | * The values of SLOT_TIMEOUT and SLOT_CHECK_PERIOD have been arbitrarily chosen | ||
| 1296 | * not to cause too much lag when this HW bug occurs, while still hopefully | ||
| 1297 | * ensuring that the check does not falsely trigger. | ||
| 1298 | */ | ||
| 1299 | #define SLOT_TIMEOUT 300 | ||
| 1300 | #define SLOT_CHECK_PERIOD 200 | ||
| 1301 | static struct timer_list errata2_timer; | ||
| 1302 | |||
| 1303 | void errata2_function(unsigned long data) | ||
| 1304 | { | ||
| 1305 | struct usb_hcd *hcd = (struct usb_hcd *) data; | ||
| 1306 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | ||
| 1307 | int slot; | ||
| 1308 | struct ptd ptd; | ||
| 1309 | unsigned long spinflags; | ||
| 1310 | |||
| 1311 | spin_lock_irqsave(&priv->lock, spinflags); | ||
| 1312 | |||
| 1313 | for (slot = 0; slot < 32; slot++) | ||
| 1314 | if (priv->atl_slots[slot].qh && time_after(jiffies, | ||
| 1315 | priv->atl_slots[slot].timestamp + | ||
| 1316 | SLOT_TIMEOUT * HZ / 1000)) { | ||
| 1317 | ptd_read(hcd->regs, ATL_PTD_OFFSET, slot, &ptd); | ||
| 1318 | if (!FROM_DW0_VALID(ptd.dw0) && | ||
| 1319 | !FROM_DW3_ACTIVE(ptd.dw3)) | ||
| 1320 | priv->atl_done_map |= 1 << slot; | ||
| 1321 | } | ||
| 1322 | |||
| 1323 | if (priv->atl_done_map) | ||
| 1324 | handle_done_ptds(hcd); | ||
| 1325 | |||
| 1326 | spin_unlock_irqrestore(&priv->lock, spinflags); | ||
| 1327 | |||
| 1328 | errata2_timer.expires = jiffies + SLOT_CHECK_PERIOD * HZ / 1000; | ||
| 1329 | add_timer(&errata2_timer); | ||
| 1330 | } | ||
| 1331 | |||
| 1332 | static int isp1760_run(struct usb_hcd *hcd) | ||
| 1333 | { | ||
| 1334 | int retval; | ||
| 1335 | u32 temp; | ||
| 1336 | u32 command; | ||
| 1337 | u32 chipid; | ||
| 1338 | |||
| 1339 | hcd->uses_new_polling = 1; | ||
| 1340 | |||
| 1341 | hcd->state = HC_STATE_RUNNING; | ||
| 1342 | |||
| 1343 | /* Set PTD interrupt AND & OR maps */ | ||
| 1344 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_AND_REG, 0); | ||
| 1345 | reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, 0xffffffff); | ||
| 1346 | reg_write32(hcd->regs, HC_INT_IRQ_MASK_AND_REG, 0); | ||
| 1347 | reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, 0xffffffff); | ||
| 1348 | reg_write32(hcd->regs, HC_ISO_IRQ_MASK_AND_REG, 0); | ||
| 1349 | reg_write32(hcd->regs, HC_ISO_IRQ_MASK_OR_REG, 0xffffffff); | ||
| 1350 | /* step 23 passed */ | ||
| 1351 | |||
| 1352 | temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL); | ||
| 1353 | reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp | HW_GLOBAL_INTR_EN); | ||
| 1354 | |||
| 1355 | command = reg_read32(hcd->regs, HC_USBCMD); | ||
| 1356 | command &= ~(CMD_LRESET|CMD_RESET); | ||
| 1357 | command |= CMD_RUN; | ||
| 1358 | reg_write32(hcd->regs, HC_USBCMD, command); | ||
| 1359 | |||
| 1360 | retval = handshake(hcd, HC_USBCMD, CMD_RUN, CMD_RUN, 250 * 1000); | ||
| 1361 | if (retval) | ||
| 1362 | return retval; | ||
| 1363 | |||
| 1364 | /* | ||
| 1365 | * XXX | ||
| 1366 | * Spec says to write FLAG_CF as last config action, priv code grabs | ||
| 1367 | * the semaphore while doing so. | ||
| 1368 | */ | ||
| 1369 | down_write(&ehci_cf_port_reset_rwsem); | ||
| 1370 | reg_write32(hcd->regs, HC_CONFIGFLAG, FLAG_CF); | ||
| 1371 | |||
| 1372 | retval = handshake(hcd, HC_CONFIGFLAG, FLAG_CF, FLAG_CF, 250 * 1000); | ||
| 1373 | up_write(&ehci_cf_port_reset_rwsem); | ||
| 1374 | if (retval) | ||
| 1375 | return retval; | ||
| 1376 | |||
| 1377 | init_timer(&errata2_timer); | ||
| 1378 | errata2_timer.function = errata2_function; | ||
| 1379 | errata2_timer.data = (unsigned long) hcd; | ||
| 1380 | errata2_timer.expires = jiffies + SLOT_CHECK_PERIOD * HZ / 1000; | ||
| 1381 | add_timer(&errata2_timer); | ||
| 1382 | |||
| 1383 | chipid = reg_read32(hcd->regs, HC_CHIP_ID_REG); | ||
| 1384 | dev_info(hcd->self.controller, "USB ISP %04x HW rev. %d started\n", | ||
| 1385 | chipid & 0xffff, chipid >> 16); | ||
| 1386 | |||
| 1387 | /* PTD Register Init Part 2, Step 28 */ | ||
| 1388 | |||
| 1389 | /* Setup registers controlling PTD checking */ | ||
| 1390 | reg_write32(hcd->regs, HC_ATL_PTD_LASTPTD_REG, 0x80000000); | ||
| 1391 | reg_write32(hcd->regs, HC_INT_PTD_LASTPTD_REG, 0x80000000); | ||
| 1392 | reg_write32(hcd->regs, HC_ISO_PTD_LASTPTD_REG, 0x00000001); | ||
| 1393 | reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, 0xffffffff); | ||
| 1394 | reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, 0xffffffff); | ||
| 1395 | reg_write32(hcd->regs, HC_ISO_PTD_SKIPMAP_REG, 0xffffffff); | ||
| 1396 | reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, | ||
| 1397 | ATL_BUF_FILL | INT_BUF_FILL); | ||
| 1398 | |||
| 1399 | /* GRR this is run-once init(), being done every time the HC starts. | ||
| 1400 | * So long as they're part of class devices, we can't do it init() | ||
| 1401 | * since the class device isn't created that early. | ||
| 1402 | */ | ||
| 1403 | return 0; | ||
| 1404 | } | ||
| 1405 | |||
| 1338 | static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len) | 1406 | static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len) |
| 1339 | { | 1407 | { |
| 1340 | qtd->data_buffer = databuffer; | 1408 | qtd->data_buffer = databuffer; |
| @@ -1503,7 +1571,6 @@ static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, | |||
| 1503 | packetize_urb(hcd, urb, &new_qtds, mem_flags); | 1571 | packetize_urb(hcd, urb, &new_qtds, mem_flags); |
| 1504 | if (list_empty(&new_qtds)) | 1572 | if (list_empty(&new_qtds)) |
| 1505 | return -ENOMEM; | 1573 | return -ENOMEM; |
| 1506 | urb->hcpriv = NULL; /* Used to signal unlink to interrupt handler */ | ||
| 1507 | 1574 | ||
| 1508 | retval = 0; | 1575 | retval = 0; |
| 1509 | spin_lock_irqsave(&priv->lock, spinflags); | 1576 | spin_lock_irqsave(&priv->lock, spinflags); |
| @@ -1531,6 +1598,7 @@ static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, | |||
| 1531 | qh = qh_alloc(GFP_ATOMIC); | 1598 | qh = qh_alloc(GFP_ATOMIC); |
| 1532 | if (!qh) { | 1599 | if (!qh) { |
| 1533 | retval = -ENOMEM; | 1600 | retval = -ENOMEM; |
| 1601 | usb_hcd_unlink_urb_from_ep(hcd, urb); | ||
| 1534 | goto out; | 1602 | goto out; |
| 1535 | } | 1603 | } |
| 1536 | list_add_tail(&qh->qh_list, ep_queue); | 1604 | list_add_tail(&qh->qh_list, ep_queue); |
| @@ -1570,7 +1638,41 @@ static void kill_transfer(struct usb_hcd *hcd, struct urb *urb, | |||
| 1570 | } | 1638 | } |
| 1571 | 1639 | ||
| 1572 | qh->slot = -1; | 1640 | qh->slot = -1; |
| 1573 | priv->active_ptds--; | 1641 | } |
| 1642 | |||
| 1643 | /* | ||
| 1644 | * Retire the qtds beginning at 'qtd' and belonging all to the same urb, killing | ||
| 1645 | * any active transfer belonging to the urb in the process. | ||
| 1646 | */ | ||
| 1647 | static void dequeue_urb_from_qtd(struct usb_hcd *hcd, struct isp1760_qh *qh, | ||
| 1648 | struct isp1760_qtd *qtd) | ||
| 1649 | { | ||
| 1650 | struct urb *urb; | ||
| 1651 | int urb_was_running; | ||
| 1652 | |||
| 1653 | urb = qtd->urb; | ||
| 1654 | urb_was_running = 0; | ||
| 1655 | list_for_each_entry_from(qtd, &qh->qtd_list, qtd_list) { | ||
| 1656 | if (qtd->urb != urb) | ||
| 1657 | break; | ||
| 1658 | |||
| 1659 | if (qtd->status >= QTD_XFER_STARTED) | ||
| 1660 | urb_was_running = 1; | ||
| 1661 | if (last_qtd_of_urb(qtd, qh) && | ||
| 1662 | (qtd->status >= QTD_XFER_COMPLETE)) | ||
| 1663 | urb_was_running = 0; | ||
| 1664 | |||
| 1665 | if (qtd->status == QTD_XFER_STARTED) | ||
| 1666 | kill_transfer(hcd, urb, qh); | ||
| 1667 | qtd->status = QTD_RETIRE; | ||
| 1668 | } | ||
| 1669 | |||
| 1670 | if ((urb->dev->speed != USB_SPEED_HIGH) && urb_was_running) { | ||
| 1671 | qh->tt_buffer_dirty = 1; | ||
| 1672 | if (usb_hub_clear_tt_buffer(urb)) | ||
| 1673 | /* Clear failed; let's hope things work anyway */ | ||
| 1674 | qh->tt_buffer_dirty = 0; | ||
| 1675 | } | ||
| 1574 | } | 1676 | } |
| 1575 | 1677 | ||
| 1576 | static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, | 1678 | static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, |
| @@ -1595,9 +1697,8 @@ static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, | |||
| 1595 | 1697 | ||
| 1596 | list_for_each_entry(qtd, &qh->qtd_list, qtd_list) | 1698 | list_for_each_entry(qtd, &qh->qtd_list, qtd_list) |
| 1597 | if (qtd->urb == urb) { | 1699 | if (qtd->urb == urb) { |
| 1598 | if (qtd->status == QTD_XFER_STARTED) | 1700 | dequeue_urb_from_qtd(hcd, qh, qtd); |
| 1599 | kill_transfer(hcd, urb, qh); | 1701 | break; |
| 1600 | qtd->status = QTD_RETIRE; | ||
| 1601 | } | 1702 | } |
| 1602 | 1703 | ||
| 1603 | urb->status = status; | 1704 | urb->status = status; |
| @@ -1622,12 +1723,11 @@ static void isp1760_endpoint_disable(struct usb_hcd *hcd, | |||
| 1622 | if (!qh) | 1723 | if (!qh) |
| 1623 | goto out; | 1724 | goto out; |
| 1624 | 1725 | ||
| 1625 | list_for_each_entry(qtd, &qh->qtd_list, qtd_list) { | 1726 | list_for_each_entry(qtd, &qh->qtd_list, qtd_list) |
| 1626 | if (qtd->status == QTD_XFER_STARTED) | 1727 | if (qtd->status != QTD_RETIRE) { |
| 1627 | kill_transfer(hcd, qtd->urb, qh); | 1728 | dequeue_urb_from_qtd(hcd, qh, qtd); |
| 1628 | qtd->status = QTD_RETIRE; | 1729 | qtd->urb->status = -ECONNRESET; |
| 1629 | qtd->urb->status = -ECONNRESET; | 1730 | } |
| 1630 | } | ||
| 1631 | 1731 | ||
| 1632 | ep->hcpriv = NULL; | 1732 | ep->hcpriv = NULL; |
| 1633 | /* Cannot free qh here since it will be parsed by schedule_ptds() */ | 1733 | /* Cannot free qh here since it will be parsed by schedule_ptds() */ |
| @@ -2021,6 +2121,8 @@ static void isp1760_stop(struct usb_hcd *hcd) | |||
| 2021 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | 2121 | struct isp1760_hcd *priv = hcd_to_priv(hcd); |
| 2022 | u32 temp; | 2122 | u32 temp; |
| 2023 | 2123 | ||
| 2124 | del_timer(&errata2_timer); | ||
| 2125 | |||
| 2024 | isp1760_hub_control(hcd, ClearPortFeature, USB_PORT_FEAT_POWER, 1, | 2126 | isp1760_hub_control(hcd, ClearPortFeature, USB_PORT_FEAT_POWER, 1, |
| 2025 | NULL, 0); | 2127 | NULL, 0); |
| 2026 | mdelay(20); | 2128 | mdelay(20); |
| @@ -2048,6 +2150,23 @@ static void isp1760_shutdown(struct usb_hcd *hcd) | |||
| 2048 | reg_write32(hcd->regs, HC_USBCMD, command); | 2150 | reg_write32(hcd->regs, HC_USBCMD, command); |
| 2049 | } | 2151 | } |
| 2050 | 2152 | ||
| 2153 | static void isp1760_clear_tt_buffer_complete(struct usb_hcd *hcd, | ||
| 2154 | struct usb_host_endpoint *ep) | ||
| 2155 | { | ||
| 2156 | struct isp1760_hcd *priv = hcd_to_priv(hcd); | ||
| 2157 | struct isp1760_qh *qh = ep->hcpriv; | ||
| 2158 | unsigned long spinflags; | ||
| 2159 | |||
| 2160 | if (!qh) | ||
| 2161 | return; | ||
| 2162 | |||
| 2163 | spin_lock_irqsave(&priv->lock, spinflags); | ||
| 2164 | qh->tt_buffer_dirty = 0; | ||
| 2165 | schedule_ptds(hcd); | ||
| 2166 | spin_unlock_irqrestore(&priv->lock, spinflags); | ||
| 2167 | } | ||
| 2168 | |||
| 2169 | |||
| 2051 | static const struct hc_driver isp1760_hc_driver = { | 2170 | static const struct hc_driver isp1760_hc_driver = { |
| 2052 | .description = "isp1760-hcd", | 2171 | .description = "isp1760-hcd", |
| 2053 | .product_desc = "NXP ISP1760 USB Host Controller", | 2172 | .product_desc = "NXP ISP1760 USB Host Controller", |
| @@ -2064,6 +2183,7 @@ static const struct hc_driver isp1760_hc_driver = { | |||
| 2064 | .get_frame_number = isp1760_get_frame, | 2183 | .get_frame_number = isp1760_get_frame, |
| 2065 | .hub_status_data = isp1760_hub_status_data, | 2184 | .hub_status_data = isp1760_hub_status_data, |
| 2066 | .hub_control = isp1760_hub_control, | 2185 | .hub_control = isp1760_hub_control, |
| 2186 | .clear_tt_buffer_complete = isp1760_clear_tt_buffer_complete, | ||
| 2067 | }; | 2187 | }; |
| 2068 | 2188 | ||
| 2069 | int __init init_kmem_once(void) | 2189 | int __init init_kmem_once(void) |
| @@ -2102,6 +2222,7 @@ void deinit_kmem_cache(void) | |||
| 2102 | 2222 | ||
| 2103 | struct usb_hcd *isp1760_register(phys_addr_t res_start, resource_size_t res_len, | 2223 | struct usb_hcd *isp1760_register(phys_addr_t res_start, resource_size_t res_len, |
| 2104 | int irq, unsigned long irqflags, | 2224 | int irq, unsigned long irqflags, |
| 2225 | int rst_gpio, | ||
| 2105 | struct device *dev, const char *busname, | 2226 | struct device *dev, const char *busname, |
| 2106 | unsigned int devflags) | 2227 | unsigned int devflags) |
| 2107 | { | 2228 | { |
| @@ -2121,6 +2242,7 @@ struct usb_hcd *isp1760_register(phys_addr_t res_start, resource_size_t res_len, | |||
| 2121 | 2242 | ||
| 2122 | priv = hcd_to_priv(hcd); | 2243 | priv = hcd_to_priv(hcd); |
| 2123 | priv->devflags = devflags; | 2244 | priv->devflags = devflags; |
| 2245 | priv->rst_gpio = rst_gpio; | ||
| 2124 | init_memory(priv); | 2246 | init_memory(priv); |
| 2125 | hcd->regs = ioremap(res_start, res_len); | 2247 | hcd->regs = ioremap(res_start, res_len); |
| 2126 | if (!hcd->regs) { | 2248 | if (!hcd->regs) { |
diff --git a/drivers/usb/host/isp1760-hcd.h b/drivers/usb/host/isp1760-hcd.h index 014a7dfadf91..33dc79ccaa6b 100644 --- a/drivers/usb/host/isp1760-hcd.h +++ b/drivers/usb/host/isp1760-hcd.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | /* exports for if */ | 4 | /* exports for if */ |
| 5 | struct usb_hcd *isp1760_register(phys_addr_t res_start, resource_size_t res_len, | 5 | struct usb_hcd *isp1760_register(phys_addr_t res_start, resource_size_t res_len, |
| 6 | int irq, unsigned long irqflags, | 6 | int irq, unsigned long irqflags, |
| 7 | int rst_gpio, | ||
| 7 | struct device *dev, const char *busname, | 8 | struct device *dev, const char *busname, |
| 8 | unsigned int devflags); | 9 | unsigned int devflags); |
| 9 | int init_kmem_once(void); | 10 | int init_kmem_once(void); |
| @@ -73,7 +74,6 @@ void deinit_kmem_cache(void); | |||
| 73 | #define HC_EOT_INT (1 << 3) | 74 | #define HC_EOT_INT (1 << 3) |
| 74 | #define HC_SOT_INT (1 << 1) | 75 | #define HC_SOT_INT (1 << 1) |
| 75 | #define INTERRUPT_ENABLE_MASK (HC_INTL_INT | HC_ATL_INT) | 76 | #define INTERRUPT_ENABLE_MASK (HC_INTL_INT | HC_ATL_INT) |
| 76 | #define INTERRUPT_ENABLE_SOT_MASK (HC_SOT_INT) | ||
| 77 | 77 | ||
| 78 | #define HC_ISO_IRQ_MASK_OR_REG 0x318 | 78 | #define HC_ISO_IRQ_MASK_OR_REG 0x318 |
| 79 | #define HC_INT_IRQ_MASK_OR_REG 0x31C | 79 | #define HC_INT_IRQ_MASK_OR_REG 0x31C |
| @@ -107,6 +107,7 @@ struct ptd { | |||
| 107 | struct slotinfo { | 107 | struct slotinfo { |
| 108 | struct isp1760_qh *qh; | 108 | struct isp1760_qh *qh; |
| 109 | struct isp1760_qtd *qtd; | 109 | struct isp1760_qtd *qtd; |
| 110 | unsigned long timestamp; | ||
| 110 | }; | 111 | }; |
| 111 | 112 | ||
| 112 | 113 | ||
| @@ -126,6 +127,7 @@ typedef void (packet_enqueue)(struct usb_hcd *hcd, struct isp1760_qh *qh, | |||
| 126 | #define ISP1760_FLAG_ISP1761 0x00000040 /* Chip is ISP1761 */ | 127 | #define ISP1760_FLAG_ISP1761 0x00000040 /* Chip is ISP1761 */ |
| 127 | #define ISP1760_FLAG_INTR_POL_HIGH 0x00000080 /* Interrupt polarity active high */ | 128 | #define ISP1760_FLAG_INTR_POL_HIGH 0x00000080 /* Interrupt polarity active high */ |
| 128 | #define ISP1760_FLAG_INTR_EDGE_TRIG 0x00000100 /* Interrupt edge triggered */ | 129 | #define ISP1760_FLAG_INTR_EDGE_TRIG 0x00000100 /* Interrupt edge triggered */ |
| 130 | #define ISP1760_FLAG_RESET_ACTIVE_HIGH 0x80000000 /* RESET GPIO active high */ | ||
| 129 | 131 | ||
| 130 | /* chip memory management */ | 132 | /* chip memory management */ |
| 131 | struct memory_chunk { | 133 | struct memory_chunk { |
| @@ -188,6 +190,7 @@ struct memory_chunk { | |||
| 188 | #define DW3_BABBLE_BIT (1 << 29) | 190 | #define DW3_BABBLE_BIT (1 << 29) |
| 189 | #define DW3_HALT_BIT (1 << 30) | 191 | #define DW3_HALT_BIT (1 << 30) |
| 190 | #define DW3_ACTIVE_BIT (1 << 31) | 192 | #define DW3_ACTIVE_BIT (1 << 31) |
| 193 | #define FROM_DW3_ACTIVE(x) (((x) >> 31) & 0x01) | ||
| 191 | 194 | ||
| 192 | #define INT_UNDERRUN (1 << 2) | 195 | #define INT_UNDERRUN (1 << 2) |
| 193 | #define INT_BABBLE (1 << 1) | 196 | #define INT_BABBLE (1 << 1) |
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c index 7ee30056f373..a7dc1e1d45f2 100644 --- a/drivers/usb/host/isp1760-if.c +++ b/drivers/usb/host/isp1760-if.c | |||
| @@ -11,25 +11,35 @@ | |||
| 11 | 11 | ||
| 12 | #include <linux/usb.h> | 12 | #include <linux/usb.h> |
| 13 | #include <linux/io.h> | 13 | #include <linux/io.h> |
| 14 | #include <linux/module.h> | ||
| 14 | #include <linux/platform_device.h> | 15 | #include <linux/platform_device.h> |
| 15 | #include <linux/usb/isp1760.h> | 16 | #include <linux/usb/isp1760.h> |
| 16 | #include <linux/usb/hcd.h> | 17 | #include <linux/usb/hcd.h> |
| 17 | 18 | ||
| 18 | #include "isp1760-hcd.h" | 19 | #include "isp1760-hcd.h" |
| 19 | 20 | ||
| 20 | #ifdef CONFIG_PPC_OF | 21 | #ifdef CONFIG_OF |
| 22 | #include <linux/slab.h> | ||
| 21 | #include <linux/of.h> | 23 | #include <linux/of.h> |
| 22 | #include <linux/of_platform.h> | 24 | #include <linux/of_platform.h> |
| 25 | #include <linux/of_address.h> | ||
| 26 | #include <linux/of_irq.h> | ||
| 27 | #include <linux/of_gpio.h> | ||
| 23 | #endif | 28 | #endif |
| 24 | 29 | ||
| 25 | #ifdef CONFIG_PCI | 30 | #ifdef CONFIG_PCI |
| 26 | #include <linux/pci.h> | 31 | #include <linux/pci.h> |
| 27 | #endif | 32 | #endif |
| 28 | 33 | ||
| 29 | #ifdef CONFIG_PPC_OF | 34 | #ifdef CONFIG_OF |
| 35 | struct isp1760 { | ||
| 36 | struct usb_hcd *hcd; | ||
| 37 | int rst_gpio; | ||
| 38 | }; | ||
| 39 | |||
| 30 | static int of_isp1760_probe(struct platform_device *dev) | 40 | static int of_isp1760_probe(struct platform_device *dev) |
| 31 | { | 41 | { |
| 32 | struct usb_hcd *hcd; | 42 | struct isp1760 *drvdata; |
| 33 | struct device_node *dp = dev->dev.of_node; | 43 | struct device_node *dp = dev->dev.of_node; |
| 34 | struct resource *res; | 44 | struct resource *res; |
| 35 | struct resource memory; | 45 | struct resource memory; |
| @@ -39,6 +49,11 @@ static int of_isp1760_probe(struct platform_device *dev) | |||
| 39 | int ret; | 49 | int ret; |
| 40 | const unsigned int *prop; | 50 | const unsigned int *prop; |
| 41 | unsigned int devflags = 0; | 51 | unsigned int devflags = 0; |
| 52 | enum of_gpio_flags gpio_flags; | ||
| 53 | |||
| 54 | drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL); | ||
| 55 | if (!drvdata) | ||
| 56 | return -ENOMEM; | ||
| 42 | 57 | ||
| 43 | ret = of_address_to_resource(dp, 0, &memory); | 58 | ret = of_address_to_resource(dp, 0, &memory); |
| 44 | if (ret) | 59 | if (ret) |
| @@ -78,32 +93,57 @@ static int of_isp1760_probe(struct platform_device *dev) | |||
| 78 | if (of_get_property(dp, "dreq-polarity", NULL) != NULL) | 93 | if (of_get_property(dp, "dreq-polarity", NULL) != NULL) |
| 79 | devflags |= ISP1760_FLAG_DREQ_POL_HIGH; | 94 | devflags |= ISP1760_FLAG_DREQ_POL_HIGH; |
| 80 | 95 | ||
| 81 | hcd = isp1760_register(memory.start, res_len, virq, | 96 | drvdata->rst_gpio = of_get_gpio_flags(dp, 0, &gpio_flags); |
| 82 | IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev_name(&dev->dev), | 97 | if (gpio_is_valid(drvdata->rst_gpio)) { |
| 83 | devflags); | 98 | ret = gpio_request(drvdata->rst_gpio, dev_name(&dev->dev)); |
| 84 | if (IS_ERR(hcd)) { | 99 | if (!ret) { |
| 85 | ret = PTR_ERR(hcd); | 100 | if (!(gpio_flags & OF_GPIO_ACTIVE_LOW)) { |
| 86 | goto release_reg; | 101 | devflags |= ISP1760_FLAG_RESET_ACTIVE_HIGH; |
| 102 | gpio_direction_output(drvdata->rst_gpio, 0); | ||
| 103 | } else { | ||
| 104 | gpio_direction_output(drvdata->rst_gpio, 1); | ||
| 105 | } | ||
| 106 | } else { | ||
| 107 | drvdata->rst_gpio = ret; | ||
| 108 | } | ||
| 87 | } | 109 | } |
| 88 | 110 | ||
| 89 | dev_set_drvdata(&dev->dev, hcd); | 111 | drvdata->hcd = isp1760_register(memory.start, res_len, virq, |
| 112 | IRQF_SHARED, drvdata->rst_gpio, | ||
| 113 | &dev->dev, dev_name(&dev->dev), | ||
| 114 | devflags); | ||
| 115 | if (IS_ERR(drvdata->hcd)) { | ||
| 116 | ret = PTR_ERR(drvdata->hcd); | ||
| 117 | goto free_gpio; | ||
| 118 | } | ||
| 119 | |||
| 120 | dev_set_drvdata(&dev->dev, drvdata); | ||
| 90 | return ret; | 121 | return ret; |
| 91 | 122 | ||
| 123 | free_gpio: | ||
| 124 | if (gpio_is_valid(drvdata->rst_gpio)) | ||
| 125 | gpio_free(drvdata->rst_gpio); | ||
| 92 | release_reg: | 126 | release_reg: |
| 93 | release_mem_region(memory.start, res_len); | 127 | release_mem_region(memory.start, res_len); |
| 128 | kfree(drvdata); | ||
| 94 | return ret; | 129 | return ret; |
| 95 | } | 130 | } |
| 96 | 131 | ||
| 97 | static int of_isp1760_remove(struct platform_device *dev) | 132 | static int of_isp1760_remove(struct platform_device *dev) |
| 98 | { | 133 | { |
| 99 | struct usb_hcd *hcd = dev_get_drvdata(&dev->dev); | 134 | struct isp1760 *drvdata = dev_get_drvdata(&dev->dev); |
| 100 | 135 | ||
| 101 | dev_set_drvdata(&dev->dev, NULL); | 136 | dev_set_drvdata(&dev->dev, NULL); |
| 102 | 137 | ||
| 103 | usb_remove_hcd(hcd); | 138 | usb_remove_hcd(drvdata->hcd); |
| 104 | iounmap(hcd->regs); | 139 | iounmap(drvdata->hcd->regs); |
| 105 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 140 | release_mem_region(drvdata->hcd->rsrc_start, drvdata->hcd->rsrc_len); |
| 106 | usb_put_hcd(hcd); | 141 | usb_put_hcd(drvdata->hcd); |
| 142 | |||
| 143 | if (gpio_is_valid(drvdata->rst_gpio)) | ||
| 144 | gpio_free(drvdata->rst_gpio); | ||
| 145 | |||
| 146 | kfree(drvdata); | ||
| 107 | return 0; | 147 | return 0; |
| 108 | } | 148 | } |
| 109 | 149 | ||
| @@ -240,7 +280,7 @@ static int __devinit isp1761_pci_probe(struct pci_dev *dev, | |||
| 240 | 280 | ||
| 241 | dev->dev.dma_mask = NULL; | 281 | dev->dev.dma_mask = NULL; |
| 242 | hcd = isp1760_register(pci_mem_phy0, memlength, dev->irq, | 282 | hcd = isp1760_register(pci_mem_phy0, memlength, dev->irq, |
| 243 | IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev_name(&dev->dev), | 283 | IRQF_SHARED, -ENOENT, &dev->dev, dev_name(&dev->dev), |
| 244 | devflags); | 284 | devflags); |
| 245 | if (IS_ERR(hcd)) { | 285 | if (IS_ERR(hcd)) { |
| 246 | ret_status = -ENODEV; | 286 | ret_status = -ENODEV; |
| @@ -313,7 +353,7 @@ static int __devinit isp1760_plat_probe(struct platform_device *pdev) | |||
| 313 | resource_size_t mem_size; | 353 | resource_size_t mem_size; |
| 314 | struct isp1760_platform_data *priv = pdev->dev.platform_data; | 354 | struct isp1760_platform_data *priv = pdev->dev.platform_data; |
| 315 | unsigned int devflags = 0; | 355 | unsigned int devflags = 0; |
| 316 | unsigned long irqflags = IRQF_SHARED | IRQF_DISABLED; | 356 | unsigned long irqflags = IRQF_SHARED; |
| 317 | 357 | ||
| 318 | mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 358 | mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 319 | if (!mem_res) { | 359 | if (!mem_res) { |
| @@ -351,7 +391,8 @@ static int __devinit isp1760_plat_probe(struct platform_device *pdev) | |||
| 351 | } | 391 | } |
| 352 | 392 | ||
| 353 | hcd = isp1760_register(mem_res->start, mem_size, irq_res->start, | 393 | hcd = isp1760_register(mem_res->start, mem_size, irq_res->start, |
| 354 | irqflags, &pdev->dev, dev_name(&pdev->dev), devflags); | 394 | irqflags, -ENOENT, |
| 395 | &pdev->dev, dev_name(&pdev->dev), devflags); | ||
| 355 | if (IS_ERR(hcd)) { | 396 | if (IS_ERR(hcd)) { |
| 356 | pr_warning("isp1760: Failed to register the HCD device\n"); | 397 | pr_warning("isp1760: Failed to register the HCD device\n"); |
| 357 | ret = -ENODEV; | 398 | ret = -ENODEV; |
| @@ -396,7 +437,7 @@ static int __init isp1760_init(void) | |||
| 396 | ret = platform_driver_register(&isp1760_plat_driver); | 437 | ret = platform_driver_register(&isp1760_plat_driver); |
| 397 | if (!ret) | 438 | if (!ret) |
| 398 | any_ret = 0; | 439 | any_ret = 0; |
| 399 | #ifdef CONFIG_PPC_OF | 440 | #ifdef CONFIG_OF |
| 400 | ret = platform_driver_register(&isp1760_of_driver); | 441 | ret = platform_driver_register(&isp1760_of_driver); |
| 401 | if (!ret) | 442 | if (!ret) |
| 402 | any_ret = 0; | 443 | any_ret = 0; |
| @@ -416,7 +457,7 @@ module_init(isp1760_init); | |||
| 416 | static void __exit isp1760_exit(void) | 457 | static void __exit isp1760_exit(void) |
| 417 | { | 458 | { |
| 418 | platform_driver_unregister(&isp1760_plat_driver); | 459 | platform_driver_unregister(&isp1760_plat_driver); |
| 419 | #ifdef CONFIG_PPC_OF | 460 | #ifdef CONFIG_OF |
| 420 | platform_driver_unregister(&isp1760_of_driver); | 461 | platform_driver_unregister(&isp1760_of_driver); |
| 421 | #endif | 462 | #endif |
| 422 | #ifdef CONFIG_PCI | 463 | #ifdef CONFIG_PCI |
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c index 944291e10f97..95a9fec38e89 100644 --- a/drivers/usb/host/ohci-at91.c +++ b/drivers/usb/host/ohci-at91.c | |||
| @@ -35,8 +35,7 @@ extern int usb_disabled(void); | |||
| 35 | 35 | ||
| 36 | static void at91_start_clock(void) | 36 | static void at91_start_clock(void) |
| 37 | { | 37 | { |
| 38 | if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) | 38 | clk_enable(hclk); |
| 39 | clk_enable(hclk); | ||
| 40 | clk_enable(iclk); | 39 | clk_enable(iclk); |
| 41 | clk_enable(fclk); | 40 | clk_enable(fclk); |
| 42 | clocked = 1; | 41 | clocked = 1; |
| @@ -46,8 +45,7 @@ static void at91_stop_clock(void) | |||
| 46 | { | 45 | { |
| 47 | clk_disable(fclk); | 46 | clk_disable(fclk); |
| 48 | clk_disable(iclk); | 47 | clk_disable(iclk); |
| 49 | if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) | 48 | clk_disable(hclk); |
| 50 | clk_disable(hclk); | ||
| 51 | clocked = 0; | 49 | clocked = 0; |
| 52 | } | 50 | } |
| 53 | 51 | ||
| @@ -142,8 +140,7 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver, | |||
| 142 | 140 | ||
| 143 | iclk = clk_get(&pdev->dev, "ohci_clk"); | 141 | iclk = clk_get(&pdev->dev, "ohci_clk"); |
| 144 | fclk = clk_get(&pdev->dev, "uhpck"); | 142 | fclk = clk_get(&pdev->dev, "uhpck"); |
| 145 | if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) | 143 | hclk = clk_get(&pdev->dev, "hclk"); |
| 146 | hclk = clk_get(&pdev->dev, "hck0"); | ||
| 147 | 144 | ||
| 148 | at91_start_hc(pdev); | 145 | at91_start_hc(pdev); |
| 149 | ohci_hcd_init(hcd_to_ohci(hcd)); | 146 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| @@ -155,8 +152,7 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver, | |||
| 155 | /* Error handling */ | 152 | /* Error handling */ |
| 156 | at91_stop_hc(pdev); | 153 | at91_stop_hc(pdev); |
| 157 | 154 | ||
| 158 | if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) | 155 | clk_put(hclk); |
| 159 | clk_put(hclk); | ||
| 160 | clk_put(fclk); | 156 | clk_put(fclk); |
| 161 | clk_put(iclk); | 157 | clk_put(iclk); |
| 162 | 158 | ||
| @@ -192,8 +188,7 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd, | |||
| 192 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 188 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 193 | usb_put_hcd(hcd); | 189 | usb_put_hcd(hcd); |
| 194 | 190 | ||
| 195 | if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) | 191 | clk_put(hclk); |
| 196 | clk_put(hclk); | ||
| 197 | clk_put(fclk); | 192 | clk_put(fclk); |
| 198 | clk_put(iclk); | 193 | clk_put(iclk); |
| 199 | fclk = iclk = hclk = NULL; | 194 | fclk = iclk = hclk = NULL; |
| @@ -223,6 +218,162 @@ ohci_at91_start (struct usb_hcd *hcd) | |||
| 223 | return 0; | 218 | return 0; |
| 224 | } | 219 | } |
| 225 | 220 | ||
| 221 | static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable) | ||
| 222 | { | ||
| 223 | if (port < 0 || port >= 2) | ||
| 224 | return; | ||
| 225 | |||
| 226 | if (pdata->vbus_pin[port] <= 0) | ||
| 227 | return; | ||
| 228 | |||
| 229 | gpio_set_value(pdata->vbus_pin[port], !pdata->vbus_pin_inverted ^ enable); | ||
| 230 | } | ||
| 231 | |||
| 232 | static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port) | ||
| 233 | { | ||
| 234 | if (port < 0 || port >= 2) | ||
| 235 | return -EINVAL; | ||
| 236 | |||
| 237 | if (pdata->vbus_pin[port] <= 0) | ||
| 238 | return -EINVAL; | ||
| 239 | |||
| 240 | return gpio_get_value(pdata->vbus_pin[port]) ^ !pdata->vbus_pin_inverted; | ||
| 241 | } | ||
| 242 | |||
| 243 | /* | ||
| 244 | * Update the status data from the hub with the over-current indicator change. | ||
| 245 | */ | ||
| 246 | static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf) | ||
| 247 | { | ||
| 248 | struct at91_usbh_data *pdata = hcd->self.controller->platform_data; | ||
| 249 | int length = ohci_hub_status_data(hcd, buf); | ||
| 250 | int port; | ||
| 251 | |||
| 252 | for (port = 0; port < ARRAY_SIZE(pdata->overcurrent_pin); port++) { | ||
| 253 | if (pdata->overcurrent_changed[port]) { | ||
| 254 | if (! length) | ||
| 255 | length = 1; | ||
| 256 | buf[0] |= 1 << (port + 1); | ||
| 257 | } | ||
| 258 | } | ||
| 259 | |||
| 260 | return length; | ||
| 261 | } | ||
| 262 | |||
| 263 | /* | ||
| 264 | * Look at the control requests to the root hub and see if we need to override. | ||
| 265 | */ | ||
| 266 | static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | ||
| 267 | u16 wIndex, char *buf, u16 wLength) | ||
| 268 | { | ||
| 269 | struct at91_usbh_data *pdata = hcd->self.controller->platform_data; | ||
| 270 | struct usb_hub_descriptor *desc; | ||
| 271 | int ret = -EINVAL; | ||
| 272 | u32 *data = (u32 *)buf; | ||
| 273 | |||
| 274 | dev_dbg(hcd->self.controller, | ||
| 275 | "ohci_at91_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n", | ||
| 276 | hcd, typeReq, wValue, wIndex, buf, wLength); | ||
| 277 | |||
| 278 | switch (typeReq) { | ||
| 279 | case SetPortFeature: | ||
| 280 | if (wValue == USB_PORT_FEAT_POWER) { | ||
| 281 | dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n"); | ||
| 282 | ohci_at91_usb_set_power(pdata, wIndex - 1, 1); | ||
| 283 | goto out; | ||
| 284 | } | ||
| 285 | break; | ||
| 286 | |||
| 287 | case ClearPortFeature: | ||
| 288 | switch (wValue) { | ||
| 289 | case USB_PORT_FEAT_C_OVER_CURRENT: | ||
| 290 | dev_dbg(hcd->self.controller, | ||
| 291 | "ClearPortFeature: C_OVER_CURRENT\n"); | ||
| 292 | |||
| 293 | if (wIndex == 1 || wIndex == 2) { | ||
| 294 | pdata->overcurrent_changed[wIndex-1] = 0; | ||
| 295 | pdata->overcurrent_status[wIndex-1] = 0; | ||
| 296 | } | ||
| 297 | |||
| 298 | goto out; | ||
| 299 | |||
| 300 | case USB_PORT_FEAT_OVER_CURRENT: | ||
| 301 | dev_dbg(hcd->self.controller, | ||
| 302 | "ClearPortFeature: OVER_CURRENT\n"); | ||
| 303 | |||
| 304 | if (wIndex == 1 || wIndex == 2) { | ||
| 305 | pdata->overcurrent_status[wIndex-1] = 0; | ||
| 306 | } | ||
| 307 | |||
| 308 | goto out; | ||
| 309 | |||
| 310 | case USB_PORT_FEAT_POWER: | ||
| 311 | dev_dbg(hcd->self.controller, | ||
| 312 | "ClearPortFeature: POWER\n"); | ||
| 313 | |||
| 314 | if (wIndex == 1 || wIndex == 2) { | ||
| 315 | ohci_at91_usb_set_power(pdata, wIndex - 1, 0); | ||
| 316 | return 0; | ||
| 317 | } | ||
| 318 | } | ||
| 319 | break; | ||
| 320 | } | ||
| 321 | |||
| 322 | ret = ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength); | ||
| 323 | if (ret) | ||
| 324 | goto out; | ||
| 325 | |||
| 326 | switch (typeReq) { | ||
| 327 | case GetHubDescriptor: | ||
| 328 | |||
| 329 | /* update the hub's descriptor */ | ||
| 330 | |||
| 331 | desc = (struct usb_hub_descriptor *)buf; | ||
| 332 | |||
| 333 | dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n", | ||
| 334 | desc->wHubCharacteristics); | ||
| 335 | |||
| 336 | /* remove the old configurations for power-switching, and | ||
| 337 | * over-current protection, and insert our new configuration | ||
| 338 | */ | ||
| 339 | |||
| 340 | desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM); | ||
| 341 | desc->wHubCharacteristics |= cpu_to_le16(0x0001); | ||
| 342 | |||
| 343 | if (pdata->overcurrent_supported) { | ||
| 344 | desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_OCPM); | ||
| 345 | desc->wHubCharacteristics |= cpu_to_le16(0x0008|0x0001); | ||
| 346 | } | ||
| 347 | |||
| 348 | dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n", | ||
| 349 | desc->wHubCharacteristics); | ||
| 350 | |||
| 351 | return ret; | ||
| 352 | |||
| 353 | case GetPortStatus: | ||
| 354 | /* check port status */ | ||
| 355 | |||
| 356 | dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex); | ||
| 357 | |||
| 358 | if (wIndex == 1 || wIndex == 2) { | ||
| 359 | if (! ohci_at91_usb_get_power(pdata, wIndex-1)) { | ||
| 360 | *data &= ~cpu_to_le32(RH_PS_PPS); | ||
| 361 | } | ||
| 362 | |||
| 363 | if (pdata->overcurrent_changed[wIndex-1]) { | ||
| 364 | *data |= cpu_to_le32(RH_PS_OCIC); | ||
| 365 | } | ||
| 366 | |||
| 367 | if (pdata->overcurrent_status[wIndex-1]) { | ||
| 368 | *data |= cpu_to_le32(RH_PS_POCI); | ||
| 369 | } | ||
| 370 | } | ||
| 371 | } | ||
| 372 | |||
| 373 | out: | ||
| 374 | return ret; | ||
| 375 | } | ||
| 376 | |||
| 226 | /*-------------------------------------------------------------------------*/ | 377 | /*-------------------------------------------------------------------------*/ |
| 227 | 378 | ||
| 228 | static const struct hc_driver ohci_at91_hc_driver = { | 379 | static const struct hc_driver ohci_at91_hc_driver = { |
| @@ -258,8 +409,8 @@ static const struct hc_driver ohci_at91_hc_driver = { | |||
| 258 | /* | 409 | /* |
| 259 | * root hub support | 410 | * root hub support |
| 260 | */ | 411 | */ |
| 261 | .hub_status_data = ohci_hub_status_data, | 412 | .hub_status_data = ohci_at91_hub_status_data, |
| 262 | .hub_control = ohci_hub_control, | 413 | .hub_control = ohci_at91_hub_control, |
| 263 | #ifdef CONFIG_PM | 414 | #ifdef CONFIG_PM |
| 264 | .bus_suspend = ohci_bus_suspend, | 415 | .bus_suspend = ohci_bus_suspend, |
| 265 | .bus_resume = ohci_bus_resume, | 416 | .bus_resume = ohci_bus_resume, |
| @@ -269,22 +420,71 @@ static const struct hc_driver ohci_at91_hc_driver = { | |||
| 269 | 420 | ||
| 270 | /*-------------------------------------------------------------------------*/ | 421 | /*-------------------------------------------------------------------------*/ |
| 271 | 422 | ||
| 423 | static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data) | ||
| 424 | { | ||
| 425 | struct platform_device *pdev = data; | ||
| 426 | struct at91_usbh_data *pdata = pdev->dev.platform_data; | ||
| 427 | int val, gpio, port; | ||
| 428 | |||
| 429 | /* From the GPIO notifying the over-current situation, find | ||
| 430 | * out the corresponding port */ | ||
| 431 | gpio = irq_to_gpio(irq); | ||
| 432 | for (port = 0; port < ARRAY_SIZE(pdata->overcurrent_pin); port++) { | ||
| 433 | if (pdata->overcurrent_pin[port] == gpio) | ||
| 434 | break; | ||
| 435 | } | ||
| 436 | |||
| 437 | if (port == ARRAY_SIZE(pdata->overcurrent_pin)) { | ||
| 438 | dev_err(& pdev->dev, "overcurrent interrupt from unknown GPIO\n"); | ||
| 439 | return IRQ_HANDLED; | ||
| 440 | } | ||
| 441 | |||
| 442 | val = gpio_get_value(gpio); | ||
| 443 | |||
| 444 | /* When notified of an over-current situation, disable power | ||
| 445 | on the corresponding port, and mark this port in | ||
| 446 | over-current. */ | ||
| 447 | if (! val) { | ||
| 448 | ohci_at91_usb_set_power(pdata, port, 0); | ||
| 449 | pdata->overcurrent_status[port] = 1; | ||
| 450 | pdata->overcurrent_changed[port] = 1; | ||
| 451 | } | ||
| 452 | |||
| 453 | dev_dbg(& pdev->dev, "overcurrent situation %s\n", | ||
| 454 | val ? "exited" : "notified"); | ||
| 455 | |||
| 456 | return IRQ_HANDLED; | ||
| 457 | } | ||
| 458 | |||
| 459 | /*-------------------------------------------------------------------------*/ | ||
| 460 | |||
| 272 | static int ohci_hcd_at91_drv_probe(struct platform_device *pdev) | 461 | static int ohci_hcd_at91_drv_probe(struct platform_device *pdev) |
| 273 | { | 462 | { |
| 274 | struct at91_usbh_data *pdata = pdev->dev.platform_data; | 463 | struct at91_usbh_data *pdata = pdev->dev.platform_data; |
| 275 | int i; | 464 | int i; |
| 276 | 465 | ||
| 277 | if (pdata) { | 466 | if (pdata) { |
| 278 | /* REVISIT make the driver support per-port power switching, | ||
| 279 | * and also overcurrent detection. Here we assume the ports | ||
| 280 | * are always powered while this driver is active, and use | ||
| 281 | * active-low power switches. | ||
| 282 | */ | ||
| 283 | for (i = 0; i < ARRAY_SIZE(pdata->vbus_pin); i++) { | 467 | for (i = 0; i < ARRAY_SIZE(pdata->vbus_pin); i++) { |
| 284 | if (pdata->vbus_pin[i] <= 0) | 468 | if (pdata->vbus_pin[i] <= 0) |
| 285 | continue; | 469 | continue; |
| 286 | gpio_request(pdata->vbus_pin[i], "ohci_vbus"); | 470 | gpio_request(pdata->vbus_pin[i], "ohci_vbus"); |
| 287 | gpio_direction_output(pdata->vbus_pin[i], 0); | 471 | ohci_at91_usb_set_power(pdata, i, 1); |
| 472 | } | ||
| 473 | |||
| 474 | for (i = 0; i < ARRAY_SIZE(pdata->overcurrent_pin); i++) { | ||
| 475 | int ret; | ||
| 476 | |||
| 477 | if (pdata->overcurrent_pin[i] <= 0) | ||
| 478 | continue; | ||
| 479 | gpio_request(pdata->overcurrent_pin[i], "ohci_overcurrent"); | ||
| 480 | |||
| 481 | ret = request_irq(gpio_to_irq(pdata->overcurrent_pin[i]), | ||
| 482 | ohci_hcd_at91_overcurrent_irq, | ||
| 483 | IRQF_SHARED, "ohci_overcurrent", pdev); | ||
| 484 | if (ret) { | ||
| 485 | gpio_free(pdata->overcurrent_pin[i]); | ||
| 486 | dev_warn(& pdev->dev, "cannot get GPIO IRQ for overcurrent\n"); | ||
| 487 | } | ||
| 288 | } | 488 | } |
| 289 | } | 489 | } |
| 290 | 490 | ||
| @@ -301,9 +501,16 @@ static int ohci_hcd_at91_drv_remove(struct platform_device *pdev) | |||
| 301 | for (i = 0; i < ARRAY_SIZE(pdata->vbus_pin); i++) { | 501 | for (i = 0; i < ARRAY_SIZE(pdata->vbus_pin); i++) { |
| 302 | if (pdata->vbus_pin[i] <= 0) | 502 | if (pdata->vbus_pin[i] <= 0) |
| 303 | continue; | 503 | continue; |
| 304 | gpio_direction_output(pdata->vbus_pin[i], 1); | 504 | ohci_at91_usb_set_power(pdata, i, 0); |
| 305 | gpio_free(pdata->vbus_pin[i]); | 505 | gpio_free(pdata->vbus_pin[i]); |
| 306 | } | 506 | } |
| 507 | |||
| 508 | for (i = 0; i < ARRAY_SIZE(pdata->overcurrent_pin); i++) { | ||
| 509 | if (pdata->overcurrent_pin[i] <= 0) | ||
| 510 | continue; | ||
| 511 | free_irq(gpio_to_irq(pdata->overcurrent_pin[i]), pdev); | ||
| 512 | gpio_free(pdata->overcurrent_pin[i]); | ||
| 513 | } | ||
| 307 | } | 514 | } |
| 308 | 515 | ||
| 309 | device_init_wakeup(&pdev->dev, 0); | 516 | device_init_wakeup(&pdev->dev, 0); |
diff --git a/drivers/usb/host/ohci-ath79.c b/drivers/usb/host/ohci-ath79.c index c620c50f6770..18d574d6958b 100644 --- a/drivers/usb/host/ohci-ath79.c +++ b/drivers/usb/host/ohci-ath79.c | |||
| @@ -111,7 +111,7 @@ static int ohci_ath79_probe(struct platform_device *pdev) | |||
| 111 | 111 | ||
| 112 | ohci_hcd_init(hcd_to_ohci(hcd)); | 112 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 113 | 113 | ||
| 114 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED); | 114 | ret = usb_add_hcd(hcd, irq, 0); |
| 115 | if (ret) | 115 | if (ret) |
| 116 | goto err_stop_hcd; | 116 | goto err_stop_hcd; |
| 117 | 117 | ||
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c index 958d985f2951..9b66df8278f3 100644 --- a/drivers/usb/host/ohci-au1xxx.c +++ b/drivers/usb/host/ohci-au1xxx.c | |||
| @@ -23,92 +23,9 @@ | |||
| 23 | 23 | ||
| 24 | #include <asm/mach-au1x00/au1000.h> | 24 | #include <asm/mach-au1x00/au1000.h> |
| 25 | 25 | ||
| 26 | #ifndef CONFIG_SOC_AU1200 | ||
| 27 | |||
| 28 | #define USBH_ENABLE_BE (1<<0) | ||
| 29 | #define USBH_ENABLE_C (1<<1) | ||
| 30 | #define USBH_ENABLE_E (1<<2) | ||
| 31 | #define USBH_ENABLE_CE (1<<3) | ||
| 32 | #define USBH_ENABLE_RD (1<<4) | ||
| 33 | |||
| 34 | #ifdef __LITTLE_ENDIAN | ||
| 35 | #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C) | ||
| 36 | #elif defined(__BIG_ENDIAN) | ||
| 37 | #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | \ | ||
| 38 | USBH_ENABLE_BE) | ||
| 39 | #else | ||
| 40 | #error not byte order defined | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #else /* Au1200 */ | ||
| 44 | |||
| 45 | #define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG) | ||
| 46 | #define USB_MCFG_PFEN (1<<31) | ||
| 47 | #define USB_MCFG_RDCOMB (1<<30) | ||
| 48 | #define USB_MCFG_SSDEN (1<<23) | ||
| 49 | #define USB_MCFG_OHCCLKEN (1<<16) | ||
| 50 | #ifdef CONFIG_DMA_COHERENT | ||
| 51 | #define USB_MCFG_UCAM (1<<7) | ||
| 52 | #else | ||
| 53 | #define USB_MCFG_UCAM (0) | ||
| 54 | #endif | ||
| 55 | #define USB_MCFG_OBMEN (1<<1) | ||
| 56 | #define USB_MCFG_OMEMEN (1<<0) | ||
| 57 | |||
| 58 | #define USBH_ENABLE_CE USB_MCFG_OHCCLKEN | ||
| 59 | |||
| 60 | #define USBH_ENABLE_INIT (USB_MCFG_PFEN | USB_MCFG_RDCOMB | \ | ||
| 61 | USBH_ENABLE_CE | USB_MCFG_SSDEN | \ | ||
| 62 | USB_MCFG_UCAM | \ | ||
| 63 | USB_MCFG_OBMEN | USB_MCFG_OMEMEN) | ||
| 64 | |||
| 65 | #define USBH_DISABLE (USB_MCFG_OBMEN | USB_MCFG_OMEMEN) | ||
| 66 | |||
| 67 | #endif /* Au1200 */ | ||
| 68 | 26 | ||
| 69 | extern int usb_disabled(void); | 27 | extern int usb_disabled(void); |
| 70 | 28 | ||
| 71 | static void au1xxx_start_ohc(void) | ||
| 72 | { | ||
| 73 | /* enable host controller */ | ||
| 74 | #ifndef CONFIG_SOC_AU1200 | ||
| 75 | au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG); | ||
| 76 | au_sync(); | ||
| 77 | udelay(1000); | ||
| 78 | |||
| 79 | au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG); | ||
| 80 | au_sync(); | ||
| 81 | udelay(1000); | ||
| 82 | |||
| 83 | /* wait for reset complete (read register twice; see au1500 errata) */ | ||
| 84 | while (au_readl(USB_HOST_CONFIG), | ||
| 85 | !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD)) | ||
| 86 | udelay(1000); | ||
| 87 | |||
| 88 | #else /* Au1200 */ | ||
| 89 | au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG); | ||
| 90 | au_sync(); | ||
| 91 | udelay(1000); | ||
| 92 | |||
| 93 | au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG); | ||
| 94 | au_sync(); | ||
| 95 | udelay(2000); | ||
| 96 | #endif /* Au1200 */ | ||
| 97 | } | ||
| 98 | |||
| 99 | static void au1xxx_stop_ohc(void) | ||
| 100 | { | ||
| 101 | #ifdef CONFIG_SOC_AU1200 | ||
| 102 | /* Disable mem */ | ||
| 103 | au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG); | ||
| 104 | au_sync(); | ||
| 105 | udelay(1000); | ||
| 106 | #endif | ||
| 107 | /* Disable clock */ | ||
| 108 | au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG); | ||
| 109 | au_sync(); | ||
| 110 | } | ||
| 111 | |||
| 112 | static int __devinit ohci_au1xxx_start(struct usb_hcd *hcd) | 29 | static int __devinit ohci_au1xxx_start(struct usb_hcd *hcd) |
| 113 | { | 30 | { |
| 114 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | 31 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
| @@ -178,17 +95,6 @@ static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev) | |||
| 178 | if (usb_disabled()) | 95 | if (usb_disabled()) |
| 179 | return -ENODEV; | 96 | return -ENODEV; |
| 180 | 97 | ||
| 181 | #if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT) | ||
| 182 | /* Au1200 AB USB does not support coherent memory */ | ||
| 183 | if (!(read_c0_prid() & 0xff)) { | ||
| 184 | printk(KERN_INFO "%s: this is chip revision AB !!\n", | ||
| 185 | pdev->name); | ||
| 186 | printk(KERN_INFO "%s: update your board or re-configure " | ||
| 187 | "the kernel\n", pdev->name); | ||
| 188 | return -ENODEV; | ||
| 189 | } | ||
| 190 | #endif | ||
| 191 | |||
| 192 | if (pdev->resource[1].flags != IORESOURCE_IRQ) { | 98 | if (pdev->resource[1].flags != IORESOURCE_IRQ) { |
| 193 | pr_debug("resource[1] is not IORESOURCE_IRQ\n"); | 99 | pr_debug("resource[1] is not IORESOURCE_IRQ\n"); |
| 194 | return -ENOMEM; | 100 | return -ENOMEM; |
| @@ -214,17 +120,23 @@ static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev) | |||
| 214 | goto err2; | 120 | goto err2; |
| 215 | } | 121 | } |
| 216 | 122 | ||
| 217 | au1xxx_start_ohc(); | 123 | if (alchemy_usb_control(ALCHEMY_USB_OHCI0, 1)) { |
| 124 | printk(KERN_INFO "%s: controller init failed!\n", pdev->name); | ||
| 125 | ret = -ENODEV; | ||
| 126 | goto err3; | ||
| 127 | } | ||
| 128 | |||
| 218 | ohci_hcd_init(hcd_to_ohci(hcd)); | 129 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 219 | 130 | ||
| 220 | ret = usb_add_hcd(hcd, pdev->resource[1].start, | 131 | ret = usb_add_hcd(hcd, pdev->resource[1].start, |
| 221 | IRQF_DISABLED | IRQF_SHARED); | 132 | IRQF_SHARED); |
| 222 | if (ret == 0) { | 133 | if (ret == 0) { |
| 223 | platform_set_drvdata(pdev, hcd); | 134 | platform_set_drvdata(pdev, hcd); |
| 224 | return ret; | 135 | return ret; |
| 225 | } | 136 | } |
| 226 | 137 | ||
| 227 | au1xxx_stop_ohc(); | 138 | alchemy_usb_control(ALCHEMY_USB_OHCI0, 0); |
| 139 | err3: | ||
| 228 | iounmap(hcd->regs); | 140 | iounmap(hcd->regs); |
| 229 | err2: | 141 | err2: |
| 230 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 142 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| @@ -238,7 +150,7 @@ static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev) | |||
| 238 | struct usb_hcd *hcd = platform_get_drvdata(pdev); | 150 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 239 | 151 | ||
| 240 | usb_remove_hcd(hcd); | 152 | usb_remove_hcd(hcd); |
| 241 | au1xxx_stop_ohc(); | 153 | alchemy_usb_control(ALCHEMY_USB_OHCI0, 0); |
| 242 | iounmap(hcd->regs); | 154 | iounmap(hcd->regs); |
| 243 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | 155 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 244 | usb_put_hcd(hcd); | 156 | usb_put_hcd(hcd); |
| @@ -275,7 +187,7 @@ static int ohci_hcd_au1xxx_drv_suspend(struct device *dev) | |||
| 275 | 187 | ||
| 276 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 188 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
| 277 | 189 | ||
| 278 | au1xxx_stop_ohc(); | 190 | alchemy_usb_control(ALCHEMY_USB_OHCI0, 0); |
| 279 | bail: | 191 | bail: |
| 280 | spin_unlock_irqrestore(&ohci->lock, flags); | 192 | spin_unlock_irqrestore(&ohci->lock, flags); |
| 281 | 193 | ||
| @@ -286,7 +198,7 @@ static int ohci_hcd_au1xxx_drv_resume(struct device *dev) | |||
| 286 | { | 198 | { |
| 287 | struct usb_hcd *hcd = dev_get_drvdata(dev); | 199 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 288 | 200 | ||
| 289 | au1xxx_start_ohc(); | 201 | alchemy_usb_control(ALCHEMY_USB_OHCI0, 1); |
| 290 | 202 | ||
| 291 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 203 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
| 292 | ohci_finish_controller_resume(hcd); | 204 | ohci_finish_controller_resume(hcd); |
diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c index 6aca2c4453f7..843509778a33 100644 --- a/drivers/usb/host/ohci-da8xx.c +++ b/drivers/usb/host/ohci-da8xx.c | |||
| @@ -344,7 +344,7 @@ static int usb_hcd_da8xx_probe(const struct hc_driver *driver, | |||
| 344 | error = -ENODEV; | 344 | error = -ENODEV; |
| 345 | goto err4; | 345 | goto err4; |
| 346 | } | 346 | } |
| 347 | error = usb_add_hcd(hcd, irq, IRQF_DISABLED); | 347 | error = usb_add_hcd(hcd, irq, 0); |
| 348 | if (error) | 348 | if (error) |
| 349 | goto err4; | 349 | goto err4; |
| 350 | 350 | ||
diff --git a/drivers/usb/host/ohci-ep93xx.c b/drivers/usb/host/ohci-ep93xx.c index 4e681613e7ae..dc45d489d00e 100644 --- a/drivers/usb/host/ohci-ep93xx.c +++ b/drivers/usb/host/ohci-ep93xx.c | |||
| @@ -81,7 +81,7 @@ static int usb_hcd_ep93xx_probe(const struct hc_driver *driver, | |||
| 81 | 81 | ||
| 82 | ohci_hcd_init(hcd_to_ohci(hcd)); | 82 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 83 | 83 | ||
| 84 | retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED); | 84 | retval = usb_add_hcd(hcd, pdev->resource[1].start, 0); |
| 85 | if (retval == 0) | 85 | if (retval == 0) |
| 86 | return retval; | 86 | return retval; |
| 87 | 87 | ||
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c index f9cf3f04b742..b2639191549e 100644 --- a/drivers/usb/host/ohci-hcd.c +++ b/drivers/usb/host/ohci-hcd.c | |||
| @@ -389,17 +389,14 @@ ohci_shutdown (struct usb_hcd *hcd) | |||
| 389 | struct ohci_hcd *ohci; | 389 | struct ohci_hcd *ohci; |
| 390 | 390 | ||
| 391 | ohci = hcd_to_ohci (hcd); | 391 | ohci = hcd_to_ohci (hcd); |
| 392 | ohci_writel (ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); | 392 | ohci_writel(ohci, (u32) ~0, &ohci->regs->intrdisable); |
| 393 | ohci->hc_control = ohci_readl(ohci, &ohci->regs->control); | ||
| 394 | 393 | ||
| 395 | /* If the SHUTDOWN quirk is set, don't put the controller in RESET */ | 394 | /* Software reset, after which the controller goes into SUSPEND */ |
| 396 | ohci->hc_control &= (ohci->flags & OHCI_QUIRK_SHUTDOWN ? | 395 | ohci_writel(ohci, OHCI_HCR, &ohci->regs->cmdstatus); |
| 397 | OHCI_CTRL_RWC | OHCI_CTRL_HCFS : | 396 | ohci_readl(ohci, &ohci->regs->cmdstatus); /* flush the writes */ |
| 398 | OHCI_CTRL_RWC); | 397 | udelay(10); |
| 399 | ohci_writel(ohci, ohci->hc_control, &ohci->regs->control); | ||
| 400 | 398 | ||
| 401 | /* flush the writes */ | 399 | ohci_writel(ohci, ohci->fminterval, &ohci->regs->fminterval); |
| 402 | (void) ohci_readl (ohci, &ohci->regs->control); | ||
| 403 | } | 400 | } |
| 404 | 401 | ||
| 405 | static int check_ed(struct ohci_hcd *ohci, struct ed *ed) | 402 | static int check_ed(struct ohci_hcd *ohci, struct ed *ed) |
| @@ -1114,6 +1111,11 @@ MODULE_LICENSE ("GPL"); | |||
| 1114 | #define PLATFORM_DRIVER ohci_hcd_ath79_driver | 1111 | #define PLATFORM_DRIVER ohci_hcd_ath79_driver |
| 1115 | #endif | 1112 | #endif |
| 1116 | 1113 | ||
| 1114 | #ifdef CONFIG_NLM_XLR | ||
| 1115 | #include "ohci-xls.c" | ||
| 1116 | #define PLATFORM_DRIVER ohci_xls_driver | ||
| 1117 | #endif | ||
| 1118 | |||
| 1117 | #if !defined(PCI_DRIVER) && \ | 1119 | #if !defined(PCI_DRIVER) && \ |
| 1118 | !defined(PLATFORM_DRIVER) && \ | 1120 | !defined(PLATFORM_DRIVER) && \ |
| 1119 | !defined(OMAP1_PLATFORM_DRIVER) && \ | 1121 | !defined(OMAP1_PLATFORM_DRIVER) && \ |
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c index 9154615292db..2f00040fc408 100644 --- a/drivers/usb/host/ohci-hub.c +++ b/drivers/usb/host/ohci-hub.c | |||
| @@ -356,10 +356,7 @@ static void ohci_finish_controller_resume(struct usb_hcd *hcd) | |||
| 356 | msleep(20); | 356 | msleep(20); |
| 357 | } | 357 | } |
| 358 | 358 | ||
| 359 | /* Does the root hub have a port wakeup pending? */ | 359 | usb_hcd_resume_root_hub(hcd); |
| 360 | if (ohci_readl(ohci, &ohci->regs->intrstatus) & | ||
| 361 | (OHCI_INTR_RD | OHCI_INTR_RHSC)) | ||
| 362 | usb_hcd_resume_root_hub(hcd); | ||
| 363 | } | 360 | } |
| 364 | 361 | ||
| 365 | /* Carry out polling-, autostop-, and autoresume-related state changes */ | 362 | /* Carry out polling-, autostop-, and autoresume-related state changes */ |
diff --git a/drivers/usb/host/ohci-octeon.c b/drivers/usb/host/ohci-octeon.c index d8b45647d1dc..d469bf9b9e54 100644 --- a/drivers/usb/host/ohci-octeon.c +++ b/drivers/usb/host/ohci-octeon.c | |||
| @@ -164,7 +164,7 @@ static int ohci_octeon_drv_probe(struct platform_device *pdev) | |||
| 164 | 164 | ||
| 165 | ohci_hcd_init(ohci); | 165 | ohci_hcd_init(ohci); |
| 166 | 166 | ||
| 167 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); | 167 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 168 | if (ret) { | 168 | if (ret) { |
| 169 | dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret); | 169 | dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret); |
| 170 | goto err3; | 170 | goto err3; |
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c index 5645f70b9214..e4b8782cc6e2 100644 --- a/drivers/usb/host/ohci-omap.c +++ b/drivers/usb/host/ohci-omap.c | |||
| @@ -14,7 +14,7 @@ | |||
| 14 | * This file is licenced under the GPL. | 14 | * This file is licenced under the GPL. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | #include <linux/signal.h> /* IRQF_DISABLED */ | 17 | #include <linux/signal.h> |
| 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> |
| @@ -363,7 +363,7 @@ static int usb_hcd_omap_probe (const struct hc_driver *driver, | |||
| 363 | retval = -ENXIO; | 363 | retval = -ENXIO; |
| 364 | goto err3; | 364 | goto err3; |
| 365 | } | 365 | } |
| 366 | retval = usb_add_hcd(hcd, irq, IRQF_DISABLED); | 366 | retval = usb_add_hcd(hcd, irq, 0); |
| 367 | if (retval) | 367 | if (retval) |
| 368 | goto err3; | 368 | goto err3; |
| 369 | 369 | ||
diff --git a/drivers/usb/host/ohci-omap3.c b/drivers/usb/host/ohci-omap3.c index 6048f2f64f73..516ebc4d6cc2 100644 --- a/drivers/usb/host/ohci-omap3.c +++ b/drivers/usb/host/ohci-omap3.c | |||
| @@ -149,7 +149,7 @@ static int __devinit ohci_hcd_omap3_probe(struct platform_device *pdev) | |||
| 149 | 149 | ||
| 150 | res = platform_get_resource_byname(pdev, | 150 | res = platform_get_resource_byname(pdev, |
| 151 | IORESOURCE_MEM, "ohci"); | 151 | IORESOURCE_MEM, "ohci"); |
| 152 | if (!ret) { | 152 | if (!res) { |
| 153 | dev_err(dev, "UHH OHCI get resource failed\n"); | 153 | dev_err(dev, "UHH OHCI get resource failed\n"); |
| 154 | return -ENOMEM; | 154 | return -ENOMEM; |
| 155 | } | 155 | } |
| @@ -180,7 +180,7 @@ static int __devinit ohci_hcd_omap3_probe(struct platform_device *pdev) | |||
| 180 | 180 | ||
| 181 | ohci_hcd_init(hcd_to_ohci(hcd)); | 181 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 182 | 182 | ||
| 183 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED); | 183 | ret = usb_add_hcd(hcd, irq, 0); |
| 184 | if (ret) { | 184 | if (ret) { |
| 185 | dev_dbg(dev, "failed to add hcd with err %d\n", ret); | 185 | dev_dbg(dev, "failed to add hcd with err %d\n", ret); |
| 186 | goto err_add_hcd; | 186 | goto err_add_hcd; |
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c index ad8166c681e2..bc01b064585a 100644 --- a/drivers/usb/host/ohci-pci.c +++ b/drivers/usb/host/ohci-pci.c | |||
| @@ -175,28 +175,6 @@ static int ohci_quirk_amd700(struct usb_hcd *hcd) | |||
| 175 | return 0; | 175 | return 0; |
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | /* nVidia controllers continue to drive Reset signalling on the bus | ||
| 179 | * even after system shutdown, wasting power. This flag tells the | ||
| 180 | * shutdown routine to leave the controller OPERATIONAL instead of RESET. | ||
| 181 | */ | ||
| 182 | static int ohci_quirk_nvidia_shutdown(struct usb_hcd *hcd) | ||
| 183 | { | ||
| 184 | struct pci_dev *pdev = to_pci_dev(hcd->self.controller); | ||
| 185 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
| 186 | |||
| 187 | /* Evidently nVidia fixed their later hardware; this is a guess at | ||
| 188 | * the changeover point. | ||
| 189 | */ | ||
| 190 | #define PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_USB 0x026d | ||
| 191 | |||
| 192 | if (pdev->device < PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_USB) { | ||
| 193 | ohci->flags |= OHCI_QUIRK_SHUTDOWN; | ||
| 194 | ohci_dbg(ohci, "enabled nVidia shutdown quirk\n"); | ||
| 195 | } | ||
| 196 | |||
| 197 | return 0; | ||
| 198 | } | ||
| 199 | |||
| 200 | static void sb800_prefetch(struct ohci_hcd *ohci, int on) | 178 | static void sb800_prefetch(struct ohci_hcd *ohci, int on) |
| 201 | { | 179 | { |
| 202 | struct pci_dev *pdev; | 180 | struct pci_dev *pdev; |
| @@ -260,10 +238,6 @@ static const struct pci_device_id ohci_pci_quirks[] = { | |||
| 260 | PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4399), | 238 | PCI_DEVICE(PCI_VENDOR_ID_ATI, 0x4399), |
| 261 | .driver_data = (unsigned long)ohci_quirk_amd700, | 239 | .driver_data = (unsigned long)ohci_quirk_amd700, |
| 262 | }, | 240 | }, |
| 263 | { | ||
| 264 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID), | ||
| 265 | .driver_data = (unsigned long) ohci_quirk_nvidia_shutdown, | ||
| 266 | }, | ||
| 267 | 241 | ||
| 268 | /* FIXME for some of the early AMD 760 southbridges, OHCI | 242 | /* FIXME for some of the early AMD 760 southbridges, OHCI |
| 269 | * won't work at all. blacklist them. | 243 | * won't work at all. blacklist them. |
diff --git a/drivers/usb/host/ohci-pnx4008.c b/drivers/usb/host/ohci-pnx4008.c index 653d6a60edb5..0013db7bdf92 100644 --- a/drivers/usb/host/ohci-pnx4008.c +++ b/drivers/usb/host/ohci-pnx4008.c | |||
| @@ -26,7 +26,7 @@ | |||
| 26 | 26 | ||
| 27 | #include <mach/platform.h> | 27 | #include <mach/platform.h> |
| 28 | #include <mach/irqs.h> | 28 | #include <mach/irqs.h> |
| 29 | #include <mach/gpio.h> | 29 | #include <asm/gpio.h> |
| 30 | 30 | ||
| 31 | #define USB_CTRL IO_ADDRESS(PNX4008_PWRMAN_BASE + 0x64) | 31 | #define USB_CTRL IO_ADDRESS(PNX4008_PWRMAN_BASE + 0x64) |
| 32 | 32 | ||
| @@ -398,7 +398,7 @@ static int __devinit usb_hcd_pnx4008_probe(struct platform_device *pdev) | |||
| 398 | ohci_hcd_init(ohci); | 398 | ohci_hcd_init(ohci); |
| 399 | 399 | ||
| 400 | dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq); | 400 | dev_info(&pdev->dev, "at 0x%p, irq %d\n", hcd->regs, hcd->irq); |
| 401 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED); | 401 | ret = usb_add_hcd(hcd, irq, 0); |
| 402 | if (ret == 0) | 402 | if (ret == 0) |
| 403 | return ret; | 403 | return ret; |
| 404 | 404 | ||
diff --git a/drivers/usb/host/ohci-pnx8550.c b/drivers/usb/host/ohci-pnx8550.c index 28467e288a93..f13d08f94d6b 100644 --- a/drivers/usb/host/ohci-pnx8550.c +++ b/drivers/usb/host/ohci-pnx8550.c | |||
| @@ -107,7 +107,7 @@ int usb_hcd_pnx8550_probe (const struct hc_driver *driver, | |||
| 107 | 107 | ||
| 108 | ohci_hcd_init(hcd_to_ohci(hcd)); | 108 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 109 | 109 | ||
| 110 | retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED); | 110 | retval = usb_add_hcd(hcd, dev->resource[1].start, 0); |
| 111 | if (retval == 0) | 111 | if (retval == 0) |
| 112 | return retval; | 112 | return retval; |
| 113 | 113 | ||
diff --git a/drivers/usb/host/ohci-ppc-of.c b/drivers/usb/host/ohci-ppc-of.c index 0c12f4e14dcd..d24cc89de16f 100644 --- a/drivers/usb/host/ohci-ppc-of.c +++ b/drivers/usb/host/ohci-ppc-of.c | |||
| @@ -143,7 +143,7 @@ static int __devinit ohci_hcd_ppc_of_probe(struct platform_device *op) | |||
| 143 | 143 | ||
| 144 | ohci_hcd_init(ohci); | 144 | ohci_hcd_init(ohci); |
| 145 | 145 | ||
| 146 | rv = usb_add_hcd(hcd, irq, IRQF_DISABLED); | 146 | rv = usb_add_hcd(hcd, irq, 0); |
| 147 | if (rv == 0) | 147 | if (rv == 0) |
| 148 | return 0; | 148 | return 0; |
| 149 | 149 | ||
diff --git a/drivers/usb/host/ohci-ppc-soc.c b/drivers/usb/host/ohci-ppc-soc.c index c0f595c44487..1514b7067470 100644 --- a/drivers/usb/host/ohci-ppc-soc.c +++ b/drivers/usb/host/ohci-ppc-soc.c | |||
| @@ -80,7 +80,7 @@ static int usb_hcd_ppc_soc_probe(const struct hc_driver *driver, | |||
| 80 | #endif | 80 | #endif |
| 81 | ohci_hcd_init(ohci); | 81 | ohci_hcd_init(ohci); |
| 82 | 82 | ||
| 83 | retval = usb_add_hcd(hcd, irq, IRQF_DISABLED); | 83 | retval = usb_add_hcd(hcd, irq, 0); |
| 84 | if (retval == 0) | 84 | if (retval == 0) |
| 85 | return retval; | 85 | return retval; |
| 86 | 86 | ||
diff --git a/drivers/usb/host/ohci-ps3.c b/drivers/usb/host/ohci-ps3.c index 700950455f4d..6fd4fa1f19bb 100644 --- a/drivers/usb/host/ohci-ps3.c +++ b/drivers/usb/host/ohci-ps3.c | |||
| @@ -164,7 +164,7 @@ static int __devinit ps3_ohci_probe(struct ps3_system_bus_device *dev) | |||
| 164 | 164 | ||
| 165 | ps3_system_bus_set_drvdata(dev, hcd); | 165 | ps3_system_bus_set_drvdata(dev, hcd); |
| 166 | 166 | ||
| 167 | result = usb_add_hcd(hcd, virq, IRQF_DISABLED); | 167 | result = usb_add_hcd(hcd, virq, 0); |
| 168 | 168 | ||
| 169 | if (result) { | 169 | if (result) { |
| 170 | dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n", | 170 | dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n", |
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c index 80be5472783a..29dfefe1c726 100644 --- a/drivers/usb/host/ohci-pxa27x.c +++ b/drivers/usb/host/ohci-pxa27x.c | |||
| @@ -359,7 +359,7 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device | |||
| 359 | 359 | ||
| 360 | ohci_hcd_init(hcd_to_ohci(hcd)); | 360 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 361 | 361 | ||
| 362 | retval = usb_add_hcd(hcd, irq, IRQF_DISABLED); | 362 | retval = usb_add_hcd(hcd, irq, 0); |
| 363 | if (retval == 0) | 363 | if (retval == 0) |
| 364 | return retval; | 364 | return retval; |
| 365 | 365 | ||
diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c index dd24fc115e48..15dc51ded61a 100644 --- a/drivers/usb/host/ohci-q.c +++ b/drivers/usb/host/ohci-q.c | |||
| @@ -428,7 +428,7 @@ static struct ed *ed_get ( | |||
| 428 | ed->type = usb_pipetype(pipe); | 428 | ed->type = usb_pipetype(pipe); |
| 429 | 429 | ||
| 430 | info |= (ep->desc.bEndpointAddress & ~USB_DIR_IN) << 7; | 430 | info |= (ep->desc.bEndpointAddress & ~USB_DIR_IN) << 7; |
| 431 | info |= le16_to_cpu(ep->desc.wMaxPacketSize) << 16; | 431 | info |= usb_endpoint_maxp(&ep->desc) << 16; |
| 432 | if (udev->speed == USB_SPEED_LOW) | 432 | if (udev->speed == USB_SPEED_LOW) |
| 433 | info |= ED_LOWSPEED; | 433 | info |= ED_LOWSPEED; |
| 434 | /* only control transfers store pids in tds */ | 434 | /* only control transfers store pids in tds */ |
| @@ -444,7 +444,7 @@ static struct ed *ed_get ( | |||
| 444 | ed->load = usb_calc_bus_time ( | 444 | ed->load = usb_calc_bus_time ( |
| 445 | udev->speed, !is_out, | 445 | udev->speed, !is_out, |
| 446 | ed->type == PIPE_ISOCHRONOUS, | 446 | ed->type == PIPE_ISOCHRONOUS, |
| 447 | le16_to_cpu(ep->desc.wMaxPacketSize)) | 447 | usb_endpoint_maxp(&ep->desc)) |
| 448 | / 1000; | 448 | / 1000; |
| 449 | } | 449 | } |
| 450 | } | 450 | } |
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c index 7c9a4d55526b..a1877c47601e 100644 --- a/drivers/usb/host/ohci-s3c2410.c +++ b/drivers/usb/host/ohci-s3c2410.c | |||
| @@ -384,7 +384,7 @@ static int usb_hcd_s3c2410_probe(const struct hc_driver *driver, | |||
| 384 | 384 | ||
| 385 | ohci_hcd_init(hcd_to_ohci(hcd)); | 385 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 386 | 386 | ||
| 387 | retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED); | 387 | retval = usb_add_hcd(hcd, dev->resource[1].start, 0); |
| 388 | if (retval != 0) | 388 | if (retval != 0) |
| 389 | goto err_ioremap; | 389 | goto err_ioremap; |
| 390 | 390 | ||
diff --git a/drivers/usb/host/ohci-sa1111.c b/drivers/usb/host/ohci-sa1111.c index 4204d9720d23..4bde4f9821ba 100644 --- a/drivers/usb/host/ohci-sa1111.c +++ b/drivers/usb/host/ohci-sa1111.c | |||
| @@ -143,7 +143,7 @@ int usb_hcd_sa1111_probe (const struct hc_driver *driver, | |||
| 143 | sa1111_start_hc(dev); | 143 | sa1111_start_hc(dev); |
| 144 | ohci_hcd_init(hcd_to_ohci(hcd)); | 144 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 145 | 145 | ||
| 146 | retval = usb_add_hcd(hcd, dev->irq[1], IRQF_DISABLED); | 146 | retval = usb_add_hcd(hcd, dev->irq[1], 0); |
| 147 | if (retval == 0) | 147 | if (retval == 0) |
| 148 | return retval; | 148 | return retval; |
| 149 | 149 | ||
diff --git a/drivers/usb/host/ohci-sh.c b/drivers/usb/host/ohci-sh.c index 14cecb52a9fe..afc4eb6bb9d0 100644 --- a/drivers/usb/host/ohci-sh.c +++ b/drivers/usb/host/ohci-sh.c | |||
| @@ -109,7 +109,7 @@ static int ohci_hcd_sh_probe(struct platform_device *pdev) | |||
| 109 | hcd->regs = (void __iomem *)res->start; | 109 | hcd->regs = (void __iomem *)res->start; |
| 110 | hcd->rsrc_start = res->start; | 110 | hcd->rsrc_start = res->start; |
| 111 | hcd->rsrc_len = resource_size(res); | 111 | hcd->rsrc_len = resource_size(res); |
| 112 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); | 112 | ret = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 113 | if (ret != 0) { | 113 | if (ret != 0) { |
| 114 | err("Failed to add hcd"); | 114 | err("Failed to add hcd"); |
| 115 | usb_put_hcd(hcd); | 115 | usb_put_hcd(hcd); |
diff --git a/drivers/usb/host/ohci-sm501.c b/drivers/usb/host/ohci-sm501.c index 78918ca0da23..968cea2b6d4e 100644 --- a/drivers/usb/host/ohci-sm501.c +++ b/drivers/usb/host/ohci-sm501.c | |||
| @@ -165,7 +165,7 @@ static int ohci_hcd_sm501_drv_probe(struct platform_device *pdev) | |||
| 165 | 165 | ||
| 166 | ohci_hcd_init(hcd_to_ohci(hcd)); | 166 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 167 | 167 | ||
| 168 | retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); | 168 | retval = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 169 | if (retval) | 169 | if (retval) |
| 170 | goto err5; | 170 | goto err5; |
| 171 | 171 | ||
diff --git a/drivers/usb/host/ohci-spear.c b/drivers/usb/host/ohci-spear.c index 4fd4bea9ac7a..69874654f3b5 100644 --- a/drivers/usb/host/ohci-spear.c +++ b/drivers/usb/host/ohci-spear.c | |||
| @@ -152,7 +152,7 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev) | |||
| 152 | spear_start_ohci(ohci_p); | 152 | spear_start_ohci(ohci_p); |
| 153 | ohci_hcd_init(hcd_to_ohci(hcd)); | 153 | ohci_hcd_init(hcd_to_ohci(hcd)); |
| 154 | 154 | ||
| 155 | retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), IRQF_DISABLED); | 155 | retval = usb_add_hcd(hcd, platform_get_irq(pdev, 0), 0); |
| 156 | if (retval == 0) | 156 | if (retval == 0) |
| 157 | return retval; | 157 | return retval; |
| 158 | 158 | ||
diff --git a/drivers/usb/host/ohci-ssb.c b/drivers/usb/host/ohci-ssb.c index c4aea3b8315e..5ba18595d6f7 100644 --- a/drivers/usb/host/ohci-ssb.c +++ b/drivers/usb/host/ohci-ssb.c | |||
| @@ -169,7 +169,7 @@ static int ssb_ohci_attach(struct ssb_device *dev) | |||
| 169 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); | 169 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); |
| 170 | if (!hcd->regs) | 170 | if (!hcd->regs) |
| 171 | goto err_put_hcd; | 171 | goto err_put_hcd; |
| 172 | err = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); | 172 | err = usb_add_hcd(hcd, dev->irq, IRQF_SHARED); |
| 173 | if (err) | 173 | if (err) |
| 174 | goto err_iounmap; | 174 | goto err_iounmap; |
| 175 | 175 | ||
diff --git a/drivers/usb/host/ohci-tmio.c b/drivers/usb/host/ohci-tmio.c index 57ad1271fc9b..06331d931171 100644 --- a/drivers/usb/host/ohci-tmio.c +++ b/drivers/usb/host/ohci-tmio.c | |||
| @@ -244,7 +244,7 @@ static int __devinit ohci_hcd_tmio_drv_probe(struct platform_device *dev) | |||
| 244 | ohci = hcd_to_ohci(hcd); | 244 | ohci = hcd_to_ohci(hcd); |
| 245 | ohci_hcd_init(ohci); | 245 | ohci_hcd_init(ohci); |
| 246 | 246 | ||
| 247 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED); | 247 | ret = usb_add_hcd(hcd, irq, 0); |
| 248 | if (ret) | 248 | if (ret) |
| 249 | goto err_add_hcd; | 249 | goto err_add_hcd; |
| 250 | 250 | ||
diff --git a/drivers/usb/host/ohci-xls.c b/drivers/usb/host/ohci-xls.c new file mode 100644 index 000000000000..a3a9c6f45b91 --- /dev/null +++ b/drivers/usb/host/ohci-xls.c | |||
| @@ -0,0 +1,151 @@ | |||
| 1 | /* | ||
| 2 | * OHCI HCD for Netlogic XLS processors. | ||
| 3 | * | ||
| 4 | * (C) Copyright 2011 Netlogic Microsystems Inc. | ||
| 5 | * | ||
| 6 | * Based on ohci-au1xxx.c, and other Linux OHCI drivers. | ||
| 7 | * | ||
| 8 | * This file is subject to the terms and conditions of the GNU General Public | ||
| 9 | * License. See the file COPYING in the main directory of this archive for | ||
| 10 | * more details. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <linux/platform_device.h> | ||
| 14 | #include <linux/signal.h> | ||
| 15 | |||
| 16 | static int ohci_xls_probe_internal(const struct hc_driver *driver, | ||
| 17 | struct platform_device *dev) | ||
| 18 | { | ||
| 19 | struct resource *res; | ||
| 20 | struct usb_hcd *hcd; | ||
| 21 | int retval, irq; | ||
| 22 | |||
| 23 | /* Get our IRQ from an earlier registered Platform Resource */ | ||
| 24 | irq = platform_get_irq(dev, 0); | ||
| 25 | if (irq < 0) { | ||
| 26 | dev_err(&dev->dev, "Found HC with no IRQ\n"); | ||
| 27 | return -ENODEV; | ||
| 28 | } | ||
| 29 | |||
| 30 | /* Get our Memory Handle */ | ||
| 31 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); | ||
| 32 | if (!res) { | ||
| 33 | dev_err(&dev->dev, "MMIO Handle incorrect!\n"); | ||
| 34 | return -ENODEV; | ||
| 35 | } | ||
| 36 | |||
| 37 | hcd = usb_create_hcd(driver, &dev->dev, "XLS"); | ||
| 38 | if (!hcd) { | ||
| 39 | retval = -ENOMEM; | ||
| 40 | goto err1; | ||
| 41 | } | ||
| 42 | hcd->rsrc_start = res->start; | ||
| 43 | hcd->rsrc_len = res->end - res->start + 1; | ||
| 44 | |||
| 45 | if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, | ||
| 46 | driver->description)) { | ||
| 47 | dev_dbg(&dev->dev, "Controller already in use\n"); | ||
| 48 | retval = -EBUSY; | ||
| 49 | goto err2; | ||
| 50 | } | ||
| 51 | |||
| 52 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); | ||
| 53 | if (hcd->regs == NULL) { | ||
| 54 | dev_dbg(&dev->dev, "error mapping memory\n"); | ||
| 55 | retval = -EFAULT; | ||
| 56 | goto err3; | ||
| 57 | } | ||
| 58 | |||
| 59 | retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); | ||
| 60 | if (retval != 0) | ||
| 61 | goto err4; | ||
| 62 | return retval; | ||
| 63 | |||
| 64 | err4: | ||
| 65 | iounmap(hcd->regs); | ||
| 66 | err3: | ||
| 67 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
| 68 | err2: | ||
| 69 | usb_put_hcd(hcd); | ||
| 70 | err1: | ||
| 71 | dev_err(&dev->dev, "init fail, %d\n", retval); | ||
| 72 | return retval; | ||
| 73 | } | ||
| 74 | |||
| 75 | static int ohci_xls_reset(struct usb_hcd *hcd) | ||
| 76 | { | ||
| 77 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); | ||
| 78 | |||
| 79 | ohci_hcd_init(ohci); | ||
| 80 | return ohci_init(ohci); | ||
| 81 | } | ||
| 82 | |||
| 83 | static int __devinit ohci_xls_start(struct usb_hcd *hcd) | ||
| 84 | { | ||
| 85 | struct ohci_hcd *ohci; | ||
| 86 | int ret; | ||
| 87 | |||
| 88 | ohci = hcd_to_ohci(hcd); | ||
| 89 | ret = ohci_run(ohci); | ||
| 90 | if (ret < 0) { | ||
| 91 | err("can't start %s", hcd->self.bus_name); | ||
| 92 | ohci_stop(hcd); | ||
| 93 | return ret; | ||
| 94 | } | ||
| 95 | return 0; | ||
| 96 | } | ||
| 97 | |||
| 98 | static struct hc_driver ohci_xls_hc_driver = { | ||
| 99 | .description = hcd_name, | ||
| 100 | .product_desc = "XLS OHCI Host Controller", | ||
| 101 | .hcd_priv_size = sizeof(struct ohci_hcd), | ||
| 102 | .irq = ohci_irq, | ||
| 103 | .flags = HCD_MEMORY | HCD_USB11, | ||
| 104 | .reset = ohci_xls_reset, | ||
| 105 | .start = ohci_xls_start, | ||
| 106 | .stop = ohci_stop, | ||
| 107 | .shutdown = ohci_shutdown, | ||
| 108 | .urb_enqueue = ohci_urb_enqueue, | ||
| 109 | .urb_dequeue = ohci_urb_dequeue, | ||
| 110 | .endpoint_disable = ohci_endpoint_disable, | ||
| 111 | .get_frame_number = ohci_get_frame, | ||
| 112 | .hub_status_data = ohci_hub_status_data, | ||
| 113 | .hub_control = ohci_hub_control, | ||
| 114 | #ifdef CONFIG_PM | ||
| 115 | .bus_suspend = ohci_bus_suspend, | ||
| 116 | .bus_resume = ohci_bus_resume, | ||
| 117 | #endif | ||
| 118 | .start_port_reset = ohci_start_port_reset, | ||
| 119 | }; | ||
| 120 | |||
| 121 | static int ohci_xls_probe(struct platform_device *dev) | ||
| 122 | { | ||
| 123 | int ret; | ||
| 124 | |||
| 125 | pr_debug("In ohci_xls_probe"); | ||
| 126 | if (usb_disabled()) | ||
| 127 | return -ENODEV; | ||
| 128 | ret = ohci_xls_probe_internal(&ohci_xls_hc_driver, dev); | ||
| 129 | return ret; | ||
| 130 | } | ||
| 131 | |||
| 132 | static int ohci_xls_remove(struct platform_device *dev) | ||
| 133 | { | ||
| 134 | struct usb_hcd *hcd = platform_get_drvdata(dev); | ||
| 135 | |||
| 136 | usb_remove_hcd(hcd); | ||
| 137 | iounmap(hcd->regs); | ||
| 138 | release_mem_region(hcd->rsrc_start, hcd->rsrc_len); | ||
| 139 | usb_put_hcd(hcd); | ||
| 140 | return 0; | ||
| 141 | } | ||
| 142 | |||
| 143 | static struct platform_driver ohci_xls_driver = { | ||
| 144 | .probe = ohci_xls_probe, | ||
| 145 | .remove = ohci_xls_remove, | ||
| 146 | .shutdown = usb_hcd_platform_shutdown, | ||
| 147 | .driver = { | ||
| 148 | .name = "ohci-xls-0", | ||
| 149 | .owner = THIS_MODULE, | ||
| 150 | }, | ||
| 151 | }; | ||
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h index 35e5fd640ce7..0795b934d00c 100644 --- a/drivers/usb/host/ohci.h +++ b/drivers/usb/host/ohci.h | |||
| @@ -403,7 +403,6 @@ struct ohci_hcd { | |||
| 403 | #define OHCI_QUIRK_HUB_POWER 0x100 /* distrust firmware power/oc setup */ | 403 | #define OHCI_QUIRK_HUB_POWER 0x100 /* distrust firmware power/oc setup */ |
| 404 | #define OHCI_QUIRK_AMD_PLL 0x200 /* AMD PLL quirk*/ | 404 | #define OHCI_QUIRK_AMD_PLL 0x200 /* AMD PLL quirk*/ |
| 405 | #define OHCI_QUIRK_AMD_PREFETCH 0x400 /* pre-fetch for ISO transfer */ | 405 | #define OHCI_QUIRK_AMD_PREFETCH 0x400 /* pre-fetch for ISO transfer */ |
| 406 | #define OHCI_QUIRK_SHUTDOWN 0x800 /* nVidia power bug */ | ||
| 407 | // there are also chip quirks/bugs in init logic | 406 | // there are also chip quirks/bugs in init logic |
| 408 | 407 | ||
| 409 | struct work_struct nec_work; /* Worker for NEC quirk */ | 408 | struct work_struct nec_work; /* Worker for NEC quirk */ |
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c index 629a96813fd6..caf87428ca43 100644 --- a/drivers/usb/host/pci-quirks.c +++ b/drivers/usb/host/pci-quirks.c | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include <linux/pci.h> | 13 | #include <linux/pci.h> |
| 14 | #include <linux/init.h> | 14 | #include <linux/init.h> |
| 15 | #include <linux/delay.h> | 15 | #include <linux/delay.h> |
| 16 | #include <linux/export.h> | ||
| 16 | #include <linux/acpi.h> | 17 | #include <linux/acpi.h> |
| 17 | #include <linux/dmi.h> | 18 | #include <linux/dmi.h> |
| 18 | #include "pci-quirks.h" | 19 | #include "pci-quirks.h" |
| @@ -36,6 +37,7 @@ | |||
| 36 | #define OHCI_INTRENABLE 0x10 | 37 | #define OHCI_INTRENABLE 0x10 |
| 37 | #define OHCI_INTRDISABLE 0x14 | 38 | #define OHCI_INTRDISABLE 0x14 |
| 38 | #define OHCI_FMINTERVAL 0x34 | 39 | #define OHCI_FMINTERVAL 0x34 |
| 40 | #define OHCI_HCFS (3 << 6) /* hc functional state */ | ||
| 39 | #define OHCI_HCR (1 << 0) /* host controller reset */ | 41 | #define OHCI_HCR (1 << 0) /* host controller reset */ |
| 40 | #define OHCI_OCR (1 << 3) /* ownership change request */ | 42 | #define OHCI_OCR (1 << 3) /* ownership change request */ |
| 41 | #define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */ | 43 | #define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */ |
| @@ -465,6 +467,8 @@ static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev) | |||
| 465 | { | 467 | { |
| 466 | void __iomem *base; | 468 | void __iomem *base; |
| 467 | u32 control; | 469 | u32 control; |
| 470 | u32 fminterval; | ||
| 471 | int cnt; | ||
| 468 | 472 | ||
| 469 | if (!mmio_resource_enabled(pdev, 0)) | 473 | if (!mmio_resource_enabled(pdev, 0)) |
| 470 | return; | 474 | return; |
| @@ -497,41 +501,32 @@ static void __devinit quirk_usb_handoff_ohci(struct pci_dev *pdev) | |||
| 497 | } | 501 | } |
| 498 | #endif | 502 | #endif |
| 499 | 503 | ||
| 500 | /* reset controller, preserving RWC (and possibly IR) */ | 504 | /* disable interrupts */ |
| 501 | writel(control & OHCI_CTRL_MASK, base + OHCI_CONTROL); | 505 | writel((u32) ~0, base + OHCI_INTRDISABLE); |
| 502 | readl(base + OHCI_CONTROL); | ||
| 503 | 506 | ||
| 504 | /* Some NVIDIA controllers stop working if kept in RESET for too long */ | 507 | /* Reset the USB bus, if the controller isn't already in RESET */ |
| 505 | if (pdev->vendor == PCI_VENDOR_ID_NVIDIA) { | 508 | if (control & OHCI_HCFS) { |
| 506 | u32 fminterval; | 509 | /* Go into RESET, preserving RWC (and possibly IR) */ |
| 507 | int cnt; | 510 | writel(control & OHCI_CTRL_MASK, base + OHCI_CONTROL); |
| 511 | readl(base + OHCI_CONTROL); | ||
| 508 | 512 | ||
| 509 | /* drive reset for at least 50 ms (7.1.7.5) */ | 513 | /* drive bus reset for at least 50 ms (7.1.7.5) */ |
| 510 | msleep(50); | 514 | msleep(50); |
| 515 | } | ||
| 511 | 516 | ||
| 512 | /* software reset of the controller, preserving HcFmInterval */ | 517 | /* software reset of the controller, preserving HcFmInterval */ |
| 513 | fminterval = readl(base + OHCI_FMINTERVAL); | 518 | fminterval = readl(base + OHCI_FMINTERVAL); |
| 514 | writel(OHCI_HCR, base + OHCI_CMDSTATUS); | 519 | writel(OHCI_HCR, base + OHCI_CMDSTATUS); |
| 515 | 520 | ||
| 516 | /* reset requires max 10 us delay */ | 521 | /* reset requires max 10 us delay */ |
| 517 | for (cnt = 30; cnt > 0; --cnt) { /* ... allow extra time */ | 522 | for (cnt = 30; cnt > 0; --cnt) { /* ... allow extra time */ |
| 518 | if ((readl(base + OHCI_CMDSTATUS) & OHCI_HCR) == 0) | 523 | if ((readl(base + OHCI_CMDSTATUS) & OHCI_HCR) == 0) |
| 519 | break; | 524 | break; |
| 520 | udelay(1); | 525 | udelay(1); |
| 521 | } | ||
| 522 | writel(fminterval, base + OHCI_FMINTERVAL); | ||
| 523 | |||
| 524 | /* Now we're in the SUSPEND state with all devices reset | ||
| 525 | * and wakeups and interrupts disabled | ||
| 526 | */ | ||
| 527 | } | 526 | } |
| 527 | writel(fminterval, base + OHCI_FMINTERVAL); | ||
| 528 | 528 | ||
| 529 | /* | 529 | /* Now the controller is safely in SUSPEND and nothing can wake it up */ |
| 530 | * disable interrupts | ||
| 531 | */ | ||
| 532 | writel(~(u32)0, base + OHCI_INTRDISABLE); | ||
| 533 | writel(~(u32)0, base + OHCI_INTRSTATUS); | ||
| 534 | |||
| 535 | iounmap(base); | 530 | iounmap(base); |
| 536 | } | 531 | } |
| 537 | 532 | ||
| @@ -626,7 +621,7 @@ static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev) | |||
| 626 | void __iomem *base, *op_reg_base; | 621 | void __iomem *base, *op_reg_base; |
| 627 | u32 hcc_params, cap, val; | 622 | u32 hcc_params, cap, val; |
| 628 | u8 offset, cap_length; | 623 | u8 offset, cap_length; |
| 629 | int wait_time, delta, count = 256/4; | 624 | int wait_time, count = 256/4; |
| 630 | 625 | ||
| 631 | if (!mmio_resource_enabled(pdev, 0)) | 626 | if (!mmio_resource_enabled(pdev, 0)) |
| 632 | return; | 627 | return; |
| @@ -672,11 +667,10 @@ static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev) | |||
| 672 | writel(val, op_reg_base + EHCI_USBCMD); | 667 | writel(val, op_reg_base + EHCI_USBCMD); |
| 673 | 668 | ||
| 674 | wait_time = 2000; | 669 | wait_time = 2000; |
| 675 | delta = 100; | ||
| 676 | do { | 670 | do { |
| 677 | writel(0x3f, op_reg_base + EHCI_USBSTS); | 671 | writel(0x3f, op_reg_base + EHCI_USBSTS); |
| 678 | udelay(delta); | 672 | udelay(100); |
| 679 | wait_time -= delta; | 673 | wait_time -= 100; |
| 680 | val = readl(op_reg_base + EHCI_USBSTS); | 674 | val = readl(op_reg_base + EHCI_USBSTS); |
| 681 | if ((val == ~(u32)0) || (val & EHCI_USBSTS_HALTED)) { | 675 | if ((val == ~(u32)0) || (val & EHCI_USBSTS_HALTED)) { |
| 682 | break; | 676 | break; |
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c index 40a0d8b03ad7..e84ca1928dbf 100644 --- a/drivers/usb/host/r8a66597-hcd.c +++ b/drivers/usb/host/r8a66597-hcd.c | |||
| @@ -959,7 +959,7 @@ static void init_pipe_info(struct r8a66597 *r8a66597, struct urb *urb, | |||
| 959 | info.pipenum = get_empty_pipenum(r8a66597, ep); | 959 | info.pipenum = get_empty_pipenum(r8a66597, ep); |
| 960 | info.address = get_urb_to_r8a66597_addr(r8a66597, urb); | 960 | info.address = get_urb_to_r8a66597_addr(r8a66597, urb); |
| 961 | info.epnum = usb_endpoint_num(ep); | 961 | info.epnum = usb_endpoint_num(ep); |
| 962 | info.maxpacket = le16_to_cpu(ep->wMaxPacketSize); | 962 | info.maxpacket = usb_endpoint_maxp(ep); |
| 963 | info.type = get_r8a66597_type(usb_endpoint_type(ep)); | 963 | info.type = get_r8a66597_type(usb_endpoint_type(ep)); |
| 964 | info.bufnum = get_bufnum(info.pipenum); | 964 | info.bufnum = get_bufnum(info.pipenum); |
| 965 | info.buf_bsize = get_buf_bsize(info.pipenum); | 965 | info.buf_bsize = get_buf_bsize(info.pipenum); |
| @@ -2519,7 +2519,7 @@ static int __devinit r8a66597_probe(struct platform_device *pdev) | |||
| 2519 | hcd->rsrc_start = res->start; | 2519 | hcd->rsrc_start = res->start; |
| 2520 | hcd->has_tt = 1; | 2520 | hcd->has_tt = 1; |
| 2521 | 2521 | ||
| 2522 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | irq_trigger); | 2522 | ret = usb_add_hcd(hcd, irq, irq_trigger); |
| 2523 | if (ret != 0) { | 2523 | if (ret != 0) { |
| 2524 | dev_err(&pdev->dev, "Failed to add hcd\n"); | 2524 | dev_err(&pdev->dev, "Failed to add hcd\n"); |
| 2525 | goto clean_up3; | 2525 | goto clean_up3; |
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c index 1a996245ab98..961d6638d8f9 100644 --- a/drivers/usb/host/sl811-hcd.c +++ b/drivers/usb/host/sl811-hcd.c | |||
| @@ -1729,7 +1729,7 @@ sl811h_probe(struct platform_device *dev) | |||
| 1729 | * Use resource IRQ flags if set by platform device setup. | 1729 | * Use resource IRQ flags if set by platform device setup. |
| 1730 | */ | 1730 | */ |
| 1731 | irqflags |= IRQF_SHARED; | 1731 | irqflags |= IRQF_SHARED; |
| 1732 | retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | irqflags); | 1732 | retval = usb_add_hcd(hcd, irq, irqflags); |
| 1733 | if (retval != 0) | 1733 | if (retval != 0) |
| 1734 | goto err6; | 1734 | goto err6; |
| 1735 | 1735 | ||
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c index fba99b120588..c8ae199cfbb8 100644 --- a/drivers/usb/host/uhci-hcd.c +++ b/drivers/usb/host/uhci-hcd.c | |||
| @@ -294,50 +294,50 @@ __acquires(uhci->lock) | |||
| 294 | * and that remote wakeups should be enabled. | 294 | * and that remote wakeups should be enabled. |
| 295 | */ | 295 | */ |
| 296 | egsm_enable = USBCMD_EGSM; | 296 | egsm_enable = USBCMD_EGSM; |
| 297 | uhci->RD_enable = 1; | ||
| 298 | int_enable = USBINTR_RESUME; | 297 | int_enable = USBINTR_RESUME; |
| 299 | wakeup_enable = 1; | 298 | wakeup_enable = 1; |
| 300 | 299 | ||
| 301 | /* In auto-stop mode wakeups must always be detected, but | 300 | /* |
| 302 | * Resume-Detect interrupts may be prohibited. (In the absence | 301 | * In auto-stop mode, we must be able to detect new connections. |
| 303 | * of CONFIG_PM, they are always disallowed.) | 302 | * The user can force us to poll by disabling remote wakeup; |
| 303 | * otherwise we will use the EGSM/RD mechanism. | ||
| 304 | */ | 304 | */ |
| 305 | if (auto_stop) { | 305 | if (auto_stop) { |
| 306 | if (!device_may_wakeup(&rhdev->dev)) | 306 | if (!device_may_wakeup(&rhdev->dev)) |
| 307 | int_enable = 0; | 307 | egsm_enable = int_enable = 0; |
| 308 | } | ||
| 308 | 309 | ||
| 309 | /* In bus-suspend mode wakeups may be disabled, but if they are | ||
| 310 | * allowed then so are Resume-Detect interrupts. | ||
| 311 | */ | ||
| 312 | } else { | ||
| 313 | #ifdef CONFIG_PM | 310 | #ifdef CONFIG_PM |
| 311 | /* | ||
| 312 | * In bus-suspend mode, we use the wakeup setting specified | ||
| 313 | * for the root hub. | ||
| 314 | */ | ||
| 315 | else { | ||
| 314 | if (!rhdev->do_remote_wakeup) | 316 | if (!rhdev->do_remote_wakeup) |
| 315 | wakeup_enable = 0; | 317 | wakeup_enable = 0; |
| 316 | #endif | ||
| 317 | } | 318 | } |
| 319 | #endif | ||
| 318 | 320 | ||
| 319 | /* EGSM causes the root hub to echo a 'K' signal (resume) out any | 321 | /* |
| 320 | * port which requests a remote wakeup. According to the USB spec, | 322 | * UHCI doesn't distinguish between wakeup requests from downstream |
| 321 | * every hub is supposed to do this. But if we are ignoring | 323 | * devices and local connect/disconnect events. There's no way to |
| 322 | * remote-wakeup requests anyway then there's no point to it. | 324 | * enable one without the other; both are controlled by EGSM. Thus |
| 323 | * We also shouldn't enable EGSM if it's broken. | 325 | * if wakeups are disallowed then EGSM must be turned off -- in which |
| 324 | */ | 326 | * case remote wakeup requests from downstream during system sleep |
| 325 | if (!wakeup_enable || global_suspend_mode_is_broken(uhci)) | 327 | * will be lost. |
| 326 | egsm_enable = 0; | 328 | * |
| 327 | 329 | * In addition, if EGSM is broken then we can't use it. Likewise, | |
| 328 | /* If we're ignoring wakeup events then there's no reason to | 330 | * if Resume-Detect interrupts are broken then we can't use them. |
| 329 | * enable Resume-Detect interrupts. We also shouldn't enable | ||
| 330 | * them if they are broken or disallowed. | ||
| 331 | * | 331 | * |
| 332 | * This logic may lead us to enabling RD but not EGSM. The UHCI | 332 | * Finally, neither EGSM nor RD is useful by itself. Without EGSM, |
| 333 | * spec foolishly says that RD works only when EGSM is on, but | 333 | * the RD status bit will never get set. Without RD, the controller |
| 334 | * there's no harm in enabling it anyway -- perhaps some chips | 334 | * won't generate interrupts to tell the system about wakeup events. |
| 335 | * will implement it! | ||
| 336 | */ | 335 | */ |
| 337 | if (!wakeup_enable || resume_detect_interrupts_are_broken(uhci) || | 336 | if (!wakeup_enable || global_suspend_mode_is_broken(uhci) || |
| 338 | !int_enable) | 337 | resume_detect_interrupts_are_broken(uhci)) |
| 339 | uhci->RD_enable = int_enable = 0; | 338 | egsm_enable = int_enable = 0; |
| 340 | 339 | ||
| 340 | uhci->RD_enable = !!int_enable; | ||
| 341 | uhci_writew(uhci, int_enable, USBINTR); | 341 | uhci_writew(uhci, int_enable, USBINTR); |
| 342 | uhci_writew(uhci, egsm_enable | USBCMD_CF, USBCMD); | 342 | uhci_writew(uhci, egsm_enable | USBCMD_CF, USBCMD); |
| 343 | mb(); | 343 | mb(); |
| @@ -364,10 +364,12 @@ __acquires(uhci->lock) | |||
| 364 | uhci->rh_state = new_state; | 364 | uhci->rh_state = new_state; |
| 365 | uhci->is_stopped = UHCI_IS_STOPPED; | 365 | uhci->is_stopped = UHCI_IS_STOPPED; |
| 366 | 366 | ||
| 367 | /* If interrupts don't work and remote wakeup is enabled then | 367 | /* |
| 368 | * the suspended root hub needs to be polled. | 368 | * If remote wakeup is enabled but either EGSM or RD interrupts |
| 369 | * doesn't work, then we won't get an interrupt when a wakeup event | ||
| 370 | * occurs. Thus the suspended root hub needs to be polled. | ||
| 369 | */ | 371 | */ |
| 370 | if (!int_enable && wakeup_enable) | 372 | if (wakeup_enable && (!int_enable || !egsm_enable)) |
| 371 | set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags); | 373 | set_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags); |
| 372 | else | 374 | else |
| 373 | clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags); | 375 | clear_bit(HCD_FLAG_POLL_RH, &uhci_to_hcd(uhci)->flags); |
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c index 84ed28b34f93..f6ca80ee4cec 100644 --- a/drivers/usb/host/uhci-q.c +++ b/drivers/usb/host/uhci-q.c | |||
| @@ -280,7 +280,7 @@ static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci, | |||
| 280 | qh->load = usb_calc_bus_time(udev->speed, | 280 | qh->load = usb_calc_bus_time(udev->speed, |
| 281 | usb_endpoint_dir_in(&hep->desc), | 281 | usb_endpoint_dir_in(&hep->desc), |
| 282 | qh->type == USB_ENDPOINT_XFER_ISOC, | 282 | qh->type == USB_ENDPOINT_XFER_ISOC, |
| 283 | le16_to_cpu(hep->desc.wMaxPacketSize)) | 283 | usb_endpoint_maxp(&hep->desc)) |
| 284 | / 1000 + 1; | 284 | / 1000 + 1; |
| 285 | 285 | ||
| 286 | } else { /* Skeleton QH */ | 286 | } else { /* Skeleton QH */ |
| @@ -792,7 +792,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
| 792 | { | 792 | { |
| 793 | struct uhci_td *td; | 793 | struct uhci_td *td; |
| 794 | unsigned long destination, status; | 794 | unsigned long destination, status; |
| 795 | int maxsze = le16_to_cpu(qh->hep->desc.wMaxPacketSize); | 795 | int maxsze = usb_endpoint_maxp(&qh->hep->desc); |
| 796 | int len = urb->transfer_buffer_length; | 796 | int len = urb->transfer_buffer_length; |
| 797 | dma_addr_t data = urb->transfer_dma; | 797 | dma_addr_t data = urb->transfer_dma; |
| 798 | __hc32 *plink; | 798 | __hc32 *plink; |
| @@ -918,7 +918,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb, | |||
| 918 | { | 918 | { |
| 919 | struct uhci_td *td; | 919 | struct uhci_td *td; |
| 920 | unsigned long destination, status; | 920 | unsigned long destination, status; |
| 921 | int maxsze = le16_to_cpu(qh->hep->desc.wMaxPacketSize); | 921 | int maxsze = usb_endpoint_maxp(&qh->hep->desc); |
| 922 | int len = urb->transfer_buffer_length; | 922 | int len = urb->transfer_buffer_length; |
| 923 | int this_sg_len; | 923 | int this_sg_len; |
| 924 | dma_addr_t data; | 924 | dma_addr_t data; |
diff --git a/drivers/usb/host/whci/debug.c b/drivers/usb/host/whci/debug.c index 767af265e002..ba61dae9e4d2 100644 --- a/drivers/usb/host/whci/debug.c +++ b/drivers/usb/host/whci/debug.c | |||
| @@ -19,6 +19,7 @@ | |||
| 19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
| 20 | #include <linux/debugfs.h> | 20 | #include <linux/debugfs.h> |
| 21 | #include <linux/seq_file.h> | 21 | #include <linux/seq_file.h> |
| 22 | #include <linux/export.h> | ||
| 22 | 23 | ||
| 23 | #include "../../wusbcore/wusbhc.h" | 24 | #include "../../wusbcore/wusbhc.h" |
| 24 | 25 | ||
diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c index 9546f6cd01f0..1e141f755b26 100644 --- a/drivers/usb/host/whci/hcd.c +++ b/drivers/usb/host/whci/hcd.c | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | */ | 17 | */ |
| 18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
| 19 | #include <linux/init.h> | 19 | #include <linux/init.h> |
| 20 | #include <linux/module.h> | ||
| 20 | #include <linux/uwb/umc.h> | 21 | #include <linux/uwb/umc.h> |
| 21 | 22 | ||
| 22 | #include "../../wusbcore/wusbhc.h" | 23 | #include "../../wusbcore/wusbhc.h" |
diff --git a/drivers/usb/host/xhci-ext-caps.h b/drivers/usb/host/xhci-ext-caps.h index ce5c9e51748e..c7f33123d4c0 100644 --- a/drivers/usb/host/xhci-ext-caps.h +++ b/drivers/usb/host/xhci-ext-caps.h | |||
| @@ -65,6 +65,12 @@ | |||
| 65 | /* bits 1:2, 5:12, and 17:19 need to be preserved; bits 21:28 should be zero */ | 65 | /* bits 1:2, 5:12, and 17:19 need to be preserved; bits 21:28 should be zero */ |
| 66 | #define XHCI_LEGACY_DISABLE_SMI ((0x3 << 1) + (0xff << 5) + (0x7 << 17)) | 66 | #define XHCI_LEGACY_DISABLE_SMI ((0x3 << 1) + (0xff << 5) + (0x7 << 17)) |
| 67 | 67 | ||
| 68 | /* USB 2.0 xHCI 0.96 L1C capability - section 7.2.2.1.3.2 */ | ||
| 69 | #define XHCI_L1C (1 << 16) | ||
| 70 | |||
| 71 | /* USB 2.0 xHCI 1.0 hardware LMP capability - section 7.2.2.1.3.2 */ | ||
| 72 | #define XHCI_HLC (1 << 19) | ||
| 73 | |||
| 68 | /* command register values to disable interrupts and halt the HC */ | 74 | /* command register values to disable interrupts and halt the HC */ |
| 69 | /* start/stop HC execution - do not write unless HC is halted*/ | 75 | /* start/stop HC execution - do not write unless HC is halted*/ |
| 70 | #define XHCI_CMD_RUN (1 << 0) | 76 | #define XHCI_CMD_RUN (1 << 0) |
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 1e96d1f1fe6b..430e88fd3f6c 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 20 | * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ | 21 | */ |
| 22 | 22 | ||
| 23 | #include <linux/gfp.h> | ||
| 23 | #include <asm/unaligned.h> | 24 | #include <asm/unaligned.h> |
| 24 | 25 | ||
| 25 | #include "xhci.h" | 26 | #include "xhci.h" |
| @@ -28,6 +29,25 @@ | |||
| 28 | #define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \ | 29 | #define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \ |
| 29 | PORT_RC | PORT_PLC | PORT_PE) | 30 | PORT_RC | PORT_PLC | PORT_PE) |
| 30 | 31 | ||
| 32 | /* usb 1.1 root hub device descriptor */ | ||
| 33 | static u8 usb_bos_descriptor [] = { | ||
| 34 | USB_DT_BOS_SIZE, /* __u8 bLength, 5 bytes */ | ||
| 35 | USB_DT_BOS, /* __u8 bDescriptorType */ | ||
| 36 | 0x0F, 0x00, /* __le16 wTotalLength, 15 bytes */ | ||
| 37 | 0x1, /* __u8 bNumDeviceCaps */ | ||
| 38 | /* First device capability */ | ||
| 39 | USB_DT_USB_SS_CAP_SIZE, /* __u8 bLength, 10 bytes */ | ||
| 40 | USB_DT_DEVICE_CAPABILITY, /* Device Capability */ | ||
| 41 | USB_SS_CAP_TYPE, /* bDevCapabilityType, SUPERSPEED_USB */ | ||
| 42 | 0x00, /* bmAttributes, LTM off by default */ | ||
| 43 | USB_5GBPS_OPERATION, 0x00, /* wSpeedsSupported, 5Gbps only */ | ||
| 44 | 0x03, /* bFunctionalitySupport, | ||
| 45 | USB 3.0 speed only */ | ||
| 46 | 0x00, /* bU1DevExitLat, set later. */ | ||
| 47 | 0x00, 0x00 /* __le16 bU2DevExitLat, set later. */ | ||
| 48 | }; | ||
| 49 | |||
| 50 | |||
| 31 | static void xhci_common_hub_descriptor(struct xhci_hcd *xhci, | 51 | static void xhci_common_hub_descriptor(struct xhci_hcd *xhci, |
| 32 | struct usb_hub_descriptor *desc, int ports) | 52 | struct usb_hub_descriptor *desc, int ports) |
| 33 | { | 53 | { |
| @@ -232,7 +252,7 @@ int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci, | |||
| 232 | continue; | 252 | continue; |
| 233 | speed = xhci->devs[i]->udev->speed; | 253 | speed = xhci->devs[i]->udev->speed; |
| 234 | if (((speed == USB_SPEED_SUPER) == (hcd->speed == HCD_USB3)) | 254 | if (((speed == USB_SPEED_SUPER) == (hcd->speed == HCD_USB3)) |
| 235 | && xhci->devs[i]->port == port) { | 255 | && xhci->devs[i]->fake_port == port) { |
| 236 | slot_id = i; | 256 | slot_id = i; |
| 237 | break; | 257 | break; |
| 238 | } | 258 | } |
| @@ -392,13 +412,39 @@ static int xhci_get_ports(struct usb_hcd *hcd, __le32 __iomem ***port_array) | |||
| 392 | return max_ports; | 412 | return max_ports; |
| 393 | } | 413 | } |
| 394 | 414 | ||
| 415 | void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array, | ||
| 416 | int port_id, u32 link_state) | ||
| 417 | { | ||
| 418 | u32 temp; | ||
| 419 | |||
| 420 | temp = xhci_readl(xhci, port_array[port_id]); | ||
| 421 | temp = xhci_port_state_to_neutral(temp); | ||
| 422 | temp &= ~PORT_PLS_MASK; | ||
| 423 | temp |= PORT_LINK_STROBE | link_state; | ||
| 424 | xhci_writel(xhci, temp, port_array[port_id]); | ||
| 425 | } | ||
| 426 | |||
| 427 | /* Test and clear port RWC bit */ | ||
| 428 | void xhci_test_and_clear_bit(struct xhci_hcd *xhci, __le32 __iomem **port_array, | ||
| 429 | int port_id, u32 port_bit) | ||
| 430 | { | ||
| 431 | u32 temp; | ||
| 432 | |||
| 433 | temp = xhci_readl(xhci, port_array[port_id]); | ||
| 434 | if (temp & port_bit) { | ||
| 435 | temp = xhci_port_state_to_neutral(temp); | ||
| 436 | temp |= port_bit; | ||
| 437 | xhci_writel(xhci, temp, port_array[port_id]); | ||
| 438 | } | ||
| 439 | } | ||
| 440 | |||
| 395 | int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | 441 | int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, |
| 396 | u16 wIndex, char *buf, u16 wLength) | 442 | u16 wIndex, char *buf, u16 wLength) |
| 397 | { | 443 | { |
| 398 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 444 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 399 | int max_ports; | 445 | int max_ports; |
| 400 | unsigned long flags; | 446 | unsigned long flags; |
| 401 | u32 temp, temp1, status; | 447 | u32 temp, status; |
| 402 | int retval = 0; | 448 | int retval = 0; |
| 403 | __le32 __iomem **port_array; | 449 | __le32 __iomem **port_array; |
| 404 | int slot_id; | 450 | int slot_id; |
| @@ -429,6 +475,21 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
| 429 | xhci_hub_descriptor(hcd, xhci, | 475 | xhci_hub_descriptor(hcd, xhci, |
| 430 | (struct usb_hub_descriptor *) buf); | 476 | (struct usb_hub_descriptor *) buf); |
| 431 | break; | 477 | break; |
| 478 | case DeviceRequest | USB_REQ_GET_DESCRIPTOR: | ||
| 479 | if ((wValue & 0xff00) != (USB_DT_BOS << 8)) | ||
| 480 | goto error; | ||
| 481 | |||
| 482 | if (hcd->speed != HCD_USB3) | ||
| 483 | goto error; | ||
| 484 | |||
| 485 | memcpy(buf, &usb_bos_descriptor, | ||
| 486 | USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE); | ||
| 487 | temp = xhci_readl(xhci, &xhci->cap_regs->hcs_params3); | ||
| 488 | buf[12] = HCS_U1_LATENCY(temp); | ||
| 489 | put_unaligned_le16(HCS_U2_LATENCY(temp), &buf[13]); | ||
| 490 | |||
| 491 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
| 492 | return USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE; | ||
| 432 | case GetPortStatus: | 493 | case GetPortStatus: |
| 433 | if (!wIndex || wIndex > max_ports) | 494 | if (!wIndex || wIndex > max_ports) |
| 434 | goto error; | 495 | goto error; |
| @@ -472,11 +533,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
| 472 | xhci_dbg(xhci, "Resume USB2 port %d\n", | 533 | xhci_dbg(xhci, "Resume USB2 port %d\n", |
| 473 | wIndex + 1); | 534 | wIndex + 1); |
| 474 | bus_state->resume_done[wIndex] = 0; | 535 | bus_state->resume_done[wIndex] = 0; |
| 475 | temp1 = xhci_port_state_to_neutral(temp); | 536 | xhci_set_link_state(xhci, port_array, wIndex, |
| 476 | temp1 &= ~PORT_PLS_MASK; | 537 | XDEV_U0); |
| 477 | temp1 |= PORT_LINK_STROBE | XDEV_U0; | ||
| 478 | xhci_writel(xhci, temp1, port_array[wIndex]); | ||
| 479 | |||
| 480 | xhci_dbg(xhci, "set port %d resume\n", | 538 | xhci_dbg(xhci, "set port %d resume\n", |
| 481 | wIndex + 1); | 539 | wIndex + 1); |
| 482 | slot_id = xhci_find_slot_id_by_port(hcd, xhci, | 540 | slot_id = xhci_find_slot_id_by_port(hcd, xhci, |
| @@ -551,10 +609,19 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
| 551 | switch (wValue) { | 609 | switch (wValue) { |
| 552 | case USB_PORT_FEAT_SUSPEND: | 610 | case USB_PORT_FEAT_SUSPEND: |
| 553 | temp = xhci_readl(xhci, port_array[wIndex]); | 611 | temp = xhci_readl(xhci, port_array[wIndex]); |
| 612 | if ((temp & PORT_PLS_MASK) != XDEV_U0) { | ||
| 613 | /* Resume the port to U0 first */ | ||
| 614 | xhci_set_link_state(xhci, port_array, wIndex, | ||
| 615 | XDEV_U0); | ||
| 616 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
| 617 | msleep(10); | ||
| 618 | spin_lock_irqsave(&xhci->lock, flags); | ||
| 619 | } | ||
| 554 | /* In spec software should not attempt to suspend | 620 | /* In spec software should not attempt to suspend |
| 555 | * a port unless the port reports that it is in the | 621 | * a port unless the port reports that it is in the |
| 556 | * enabled (PED = ‘1’,PLS < ‘3’) state. | 622 | * enabled (PED = ‘1’,PLS < ‘3’) state. |
| 557 | */ | 623 | */ |
| 624 | temp = xhci_readl(xhci, port_array[wIndex]); | ||
| 558 | if ((temp & PORT_PE) == 0 || (temp & PORT_RESET) | 625 | if ((temp & PORT_PE) == 0 || (temp & PORT_RESET) |
| 559 | || (temp & PORT_PLS_MASK) >= XDEV_U3) { | 626 | || (temp & PORT_PLS_MASK) >= XDEV_U3) { |
| 560 | xhci_warn(xhci, "USB core suspending device " | 627 | xhci_warn(xhci, "USB core suspending device " |
| @@ -573,10 +640,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
| 573 | xhci_stop_device(xhci, slot_id, 1); | 640 | xhci_stop_device(xhci, slot_id, 1); |
| 574 | spin_lock_irqsave(&xhci->lock, flags); | 641 | spin_lock_irqsave(&xhci->lock, flags); |
| 575 | 642 | ||
| 576 | temp = xhci_port_state_to_neutral(temp); | 643 | xhci_set_link_state(xhci, port_array, wIndex, XDEV_U3); |
| 577 | temp &= ~PORT_PLS_MASK; | ||
| 578 | temp |= PORT_LINK_STROBE | XDEV_U3; | ||
| 579 | xhci_writel(xhci, temp, port_array[wIndex]); | ||
| 580 | 644 | ||
| 581 | spin_unlock_irqrestore(&xhci->lock, flags); | 645 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 582 | msleep(10); /* wait device to enter */ | 646 | msleep(10); /* wait device to enter */ |
| @@ -610,10 +674,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
| 610 | } | 674 | } |
| 611 | } | 675 | } |
| 612 | 676 | ||
| 613 | temp = xhci_port_state_to_neutral(temp); | 677 | xhci_set_link_state(xhci, port_array, wIndex, |
| 614 | temp &= ~PORT_PLS_MASK; | 678 | link_state); |
| 615 | temp |= PORT_LINK_STROBE | link_state; | ||
| 616 | xhci_writel(xhci, temp, port_array[wIndex]); | ||
| 617 | 679 | ||
| 618 | spin_unlock_irqrestore(&xhci->lock, flags); | 680 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 619 | msleep(20); /* wait device to enter */ | 681 | msleep(20); /* wait device to enter */ |
| @@ -677,24 +739,13 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, | |||
| 677 | if ((temp & PORT_PE) == 0) | 739 | if ((temp & PORT_PE) == 0) |
| 678 | goto error; | 740 | goto error; |
| 679 | 741 | ||
| 680 | temp = xhci_port_state_to_neutral(temp); | 742 | xhci_set_link_state(xhci, port_array, wIndex, |
| 681 | temp &= ~PORT_PLS_MASK; | 743 | XDEV_RESUME); |
| 682 | temp |= PORT_LINK_STROBE | XDEV_RESUME; | 744 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 683 | xhci_writel(xhci, temp, | ||
| 684 | port_array[wIndex]); | ||
| 685 | |||
| 686 | spin_unlock_irqrestore(&xhci->lock, | ||
| 687 | flags); | ||
| 688 | msleep(20); | 745 | msleep(20); |
| 689 | spin_lock_irqsave(&xhci->lock, flags); | 746 | spin_lock_irqsave(&xhci->lock, flags); |
| 690 | 747 | xhci_set_link_state(xhci, port_array, wIndex, | |
| 691 | temp = xhci_readl(xhci, | 748 | XDEV_U0); |
| 692 | port_array[wIndex]); | ||
| 693 | temp = xhci_port_state_to_neutral(temp); | ||
| 694 | temp &= ~PORT_PLS_MASK; | ||
| 695 | temp |= PORT_LINK_STROBE | XDEV_U0; | ||
| 696 | xhci_writel(xhci, temp, | ||
| 697 | port_array[wIndex]); | ||
| 698 | } | 749 | } |
| 699 | bus_state->port_c_suspend |= 1 << wIndex; | 750 | bus_state->port_c_suspend |= 1 << wIndex; |
| 700 | 751 | ||
| @@ -761,7 +812,7 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf) | |||
| 761 | memset(buf, 0, retval); | 812 | memset(buf, 0, retval); |
| 762 | status = 0; | 813 | status = 0; |
| 763 | 814 | ||
| 764 | mask = PORT_CSC | PORT_PEC | PORT_OCC | PORT_PLC; | 815 | mask = PORT_CSC | PORT_PEC | PORT_OCC | PORT_PLC | PORT_WRC; |
| 765 | 816 | ||
| 766 | spin_lock_irqsave(&xhci->lock, flags); | 817 | spin_lock_irqsave(&xhci->lock, flags); |
| 767 | /* For each port, did anything change? If so, set that bit in buf. */ | 818 | /* For each port, did anything change? If so, set that bit in buf. */ |
| @@ -910,25 +961,18 @@ int xhci_bus_resume(struct usb_hcd *hcd) | |||
| 910 | if (test_bit(port_index, &bus_state->bus_suspended) && | 961 | if (test_bit(port_index, &bus_state->bus_suspended) && |
| 911 | (temp & PORT_PLS_MASK)) { | 962 | (temp & PORT_PLS_MASK)) { |
| 912 | if (DEV_SUPERSPEED(temp)) { | 963 | if (DEV_SUPERSPEED(temp)) { |
| 913 | temp = xhci_port_state_to_neutral(temp); | 964 | xhci_set_link_state(xhci, port_array, |
| 914 | temp &= ~PORT_PLS_MASK; | 965 | port_index, XDEV_U0); |
| 915 | temp |= PORT_LINK_STROBE | XDEV_U0; | ||
| 916 | xhci_writel(xhci, temp, port_array[port_index]); | ||
| 917 | } else { | 966 | } else { |
| 918 | temp = xhci_port_state_to_neutral(temp); | 967 | xhci_set_link_state(xhci, port_array, |
| 919 | temp &= ~PORT_PLS_MASK; | 968 | port_index, XDEV_RESUME); |
| 920 | temp |= PORT_LINK_STROBE | XDEV_RESUME; | ||
| 921 | xhci_writel(xhci, temp, port_array[port_index]); | ||
| 922 | 969 | ||
| 923 | spin_unlock_irqrestore(&xhci->lock, flags); | 970 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 924 | msleep(20); | 971 | msleep(20); |
| 925 | spin_lock_irqsave(&xhci->lock, flags); | 972 | spin_lock_irqsave(&xhci->lock, flags); |
| 926 | 973 | ||
| 927 | temp = xhci_readl(xhci, port_array[port_index]); | 974 | xhci_set_link_state(xhci, port_array, |
| 928 | temp = xhci_port_state_to_neutral(temp); | 975 | port_index, XDEV_U0); |
| 929 | temp &= ~PORT_PLS_MASK; | ||
| 930 | temp |= PORT_LINK_STROBE | XDEV_U0; | ||
| 931 | xhci_writel(xhci, temp, port_array[port_index]); | ||
| 932 | } | 976 | } |
| 933 | /* wait for the port to enter U0 and report port link | 977 | /* wait for the port to enter U0 and report port link |
| 934 | * state change. | 978 | * state change. |
| @@ -938,12 +982,8 @@ int xhci_bus_resume(struct usb_hcd *hcd) | |||
| 938 | spin_lock_irqsave(&xhci->lock, flags); | 982 | spin_lock_irqsave(&xhci->lock, flags); |
| 939 | 983 | ||
| 940 | /* Clear PLC */ | 984 | /* Clear PLC */ |
| 941 | temp = xhci_readl(xhci, port_array[port_index]); | 985 | xhci_test_and_clear_bit(xhci, port_array, port_index, |
| 942 | if (temp & PORT_PLC) { | 986 | PORT_PLC); |
| 943 | temp = xhci_port_state_to_neutral(temp); | ||
| 944 | temp |= PORT_PLC; | ||
| 945 | xhci_writel(xhci, temp, port_array[port_index]); | ||
| 946 | } | ||
| 947 | 987 | ||
| 948 | slot_id = xhci_find_slot_id_by_port(hcd, | 988 | slot_id = xhci_find_slot_id_by_port(hcd, |
| 949 | xhci, port_index + 1); | 989 | xhci, port_index + 1); |
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index d446886b22b0..0e4b25fa3bcd 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c | |||
| @@ -61,8 +61,6 @@ static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci, gfp_t flag | |||
| 61 | 61 | ||
| 62 | static void xhci_segment_free(struct xhci_hcd *xhci, struct xhci_segment *seg) | 62 | static void xhci_segment_free(struct xhci_hcd *xhci, struct xhci_segment *seg) |
| 63 | { | 63 | { |
| 64 | if (!seg) | ||
| 65 | return; | ||
| 66 | if (seg->trbs) { | 64 | if (seg->trbs) { |
| 67 | xhci_dbg(xhci, "Freeing DMA segment at %p (virtual) 0x%llx (DMA)\n", | 65 | xhci_dbg(xhci, "Freeing DMA segment at %p (virtual) 0x%llx (DMA)\n", |
| 68 | seg->trbs, (unsigned long long)seg->dma); | 66 | seg->trbs, (unsigned long long)seg->dma); |
| @@ -81,7 +79,7 @@ static void xhci_segment_free(struct xhci_hcd *xhci, struct xhci_segment *seg) | |||
| 81 | * related flags, such as End TRB, Toggle Cycle, and no snoop. | 79 | * related flags, such as End TRB, Toggle Cycle, and no snoop. |
| 82 | */ | 80 | */ |
| 83 | static void xhci_link_segments(struct xhci_hcd *xhci, struct xhci_segment *prev, | 81 | static void xhci_link_segments(struct xhci_hcd *xhci, struct xhci_segment *prev, |
| 84 | struct xhci_segment *next, bool link_trbs) | 82 | struct xhci_segment *next, bool link_trbs, bool isoc) |
| 85 | { | 83 | { |
| 86 | u32 val; | 84 | u32 val; |
| 87 | 85 | ||
| @@ -97,7 +95,9 @@ static void xhci_link_segments(struct xhci_hcd *xhci, struct xhci_segment *prev, | |||
| 97 | val &= ~TRB_TYPE_BITMASK; | 95 | val &= ~TRB_TYPE_BITMASK; |
| 98 | val |= TRB_TYPE(TRB_LINK); | 96 | val |= TRB_TYPE(TRB_LINK); |
| 99 | /* Always set the chain bit with 0.95 hardware */ | 97 | /* Always set the chain bit with 0.95 hardware */ |
| 100 | if (xhci_link_trb_quirk(xhci)) | 98 | /* Set chain bit for isoc rings on AMD 0.96 host */ |
| 99 | if (xhci_link_trb_quirk(xhci) || | ||
| 100 | (isoc && (xhci->quirks & XHCI_AMD_0x96_HOST))) | ||
| 101 | val |= TRB_CHAIN; | 101 | val |= TRB_CHAIN; |
| 102 | prev->trbs[TRBS_PER_SEGMENT-1].link.control = cpu_to_le32(val); | 102 | prev->trbs[TRBS_PER_SEGMENT-1].link.control = cpu_to_le32(val); |
| 103 | } | 103 | } |
| @@ -112,18 +112,20 @@ void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring) | |||
| 112 | struct xhci_segment *seg; | 112 | struct xhci_segment *seg; |
| 113 | struct xhci_segment *first_seg; | 113 | struct xhci_segment *first_seg; |
| 114 | 114 | ||
| 115 | if (!ring || !ring->first_seg) | 115 | if (!ring) |
| 116 | return; | 116 | return; |
| 117 | first_seg = ring->first_seg; | 117 | if (ring->first_seg) { |
| 118 | seg = first_seg->next; | 118 | first_seg = ring->first_seg; |
| 119 | xhci_dbg(xhci, "Freeing ring at %p\n", ring); | 119 | seg = first_seg->next; |
| 120 | while (seg != first_seg) { | 120 | xhci_dbg(xhci, "Freeing ring at %p\n", ring); |
| 121 | struct xhci_segment *next = seg->next; | 121 | while (seg != first_seg) { |
| 122 | xhci_segment_free(xhci, seg); | 122 | struct xhci_segment *next = seg->next; |
| 123 | seg = next; | 123 | xhci_segment_free(xhci, seg); |
| 124 | seg = next; | ||
| 125 | } | ||
| 126 | xhci_segment_free(xhci, first_seg); | ||
| 127 | ring->first_seg = NULL; | ||
| 124 | } | 128 | } |
| 125 | xhci_segment_free(xhci, first_seg); | ||
| 126 | ring->first_seg = NULL; | ||
| 127 | kfree(ring); | 129 | kfree(ring); |
| 128 | } | 130 | } |
| 129 | 131 | ||
| @@ -152,7 +154,7 @@ static void xhci_initialize_ring_info(struct xhci_ring *ring) | |||
| 152 | * See section 4.9.1 and figures 15 and 16. | 154 | * See section 4.9.1 and figures 15 and 16. |
| 153 | */ | 155 | */ |
| 154 | static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, | 156 | static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, |
| 155 | unsigned int num_segs, bool link_trbs, gfp_t flags) | 157 | unsigned int num_segs, bool link_trbs, bool isoc, gfp_t flags) |
| 156 | { | 158 | { |
| 157 | struct xhci_ring *ring; | 159 | struct xhci_ring *ring; |
| 158 | struct xhci_segment *prev; | 160 | struct xhci_segment *prev; |
| @@ -178,12 +180,12 @@ static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, | |||
| 178 | next = xhci_segment_alloc(xhci, flags); | 180 | next = xhci_segment_alloc(xhci, flags); |
| 179 | if (!next) | 181 | if (!next) |
| 180 | goto fail; | 182 | goto fail; |
| 181 | xhci_link_segments(xhci, prev, next, link_trbs); | 183 | xhci_link_segments(xhci, prev, next, link_trbs, isoc); |
| 182 | 184 | ||
| 183 | prev = next; | 185 | prev = next; |
| 184 | num_segs--; | 186 | num_segs--; |
| 185 | } | 187 | } |
| 186 | xhci_link_segments(xhci, prev, ring->first_seg, link_trbs); | 188 | xhci_link_segments(xhci, prev, ring->first_seg, link_trbs, isoc); |
| 187 | 189 | ||
| 188 | if (link_trbs) { | 190 | if (link_trbs) { |
| 189 | /* See section 4.9.2.1 and 6.4.4.1 */ | 191 | /* See section 4.9.2.1 and 6.4.4.1 */ |
| @@ -229,14 +231,14 @@ void xhci_free_or_cache_endpoint_ring(struct xhci_hcd *xhci, | |||
| 229 | * pointers to the beginning of the ring. | 231 | * pointers to the beginning of the ring. |
| 230 | */ | 232 | */ |
| 231 | static void xhci_reinit_cached_ring(struct xhci_hcd *xhci, | 233 | static void xhci_reinit_cached_ring(struct xhci_hcd *xhci, |
| 232 | struct xhci_ring *ring) | 234 | struct xhci_ring *ring, bool isoc) |
| 233 | { | 235 | { |
| 234 | struct xhci_segment *seg = ring->first_seg; | 236 | struct xhci_segment *seg = ring->first_seg; |
| 235 | do { | 237 | do { |
| 236 | memset(seg->trbs, 0, | 238 | memset(seg->trbs, 0, |
| 237 | sizeof(union xhci_trb)*TRBS_PER_SEGMENT); | 239 | sizeof(union xhci_trb)*TRBS_PER_SEGMENT); |
| 238 | /* All endpoint rings have link TRBs */ | 240 | /* All endpoint rings have link TRBs */ |
| 239 | xhci_link_segments(xhci, seg, seg->next, 1); | 241 | xhci_link_segments(xhci, seg, seg->next, 1, isoc); |
| 240 | seg = seg->next; | 242 | seg = seg->next; |
| 241 | } while (seg != ring->first_seg); | 243 | } while (seg != ring->first_seg); |
| 242 | xhci_initialize_ring_info(ring); | 244 | xhci_initialize_ring_info(ring); |
| @@ -315,7 +317,7 @@ static void xhci_free_stream_ctx(struct xhci_hcd *xhci, | |||
| 315 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); | 317 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); |
| 316 | 318 | ||
| 317 | if (num_stream_ctxs > MEDIUM_STREAM_ARRAY_SIZE) | 319 | if (num_stream_ctxs > MEDIUM_STREAM_ARRAY_SIZE) |
| 318 | pci_free_consistent(pdev, | 320 | dma_free_coherent(&pdev->dev, |
| 319 | sizeof(struct xhci_stream_ctx)*num_stream_ctxs, | 321 | sizeof(struct xhci_stream_ctx)*num_stream_ctxs, |
| 320 | stream_ctx, dma); | 322 | stream_ctx, dma); |
| 321 | else if (num_stream_ctxs <= SMALL_STREAM_ARRAY_SIZE) | 323 | else if (num_stream_ctxs <= SMALL_STREAM_ARRAY_SIZE) |
| @@ -343,9 +345,9 @@ static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci, | |||
| 343 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); | 345 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); |
| 344 | 346 | ||
| 345 | if (num_stream_ctxs > MEDIUM_STREAM_ARRAY_SIZE) | 347 | if (num_stream_ctxs > MEDIUM_STREAM_ARRAY_SIZE) |
| 346 | return pci_alloc_consistent(pdev, | 348 | return dma_alloc_coherent(&pdev->dev, |
| 347 | sizeof(struct xhci_stream_ctx)*num_stream_ctxs, | 349 | sizeof(struct xhci_stream_ctx)*num_stream_ctxs, |
| 348 | dma); | 350 | dma, mem_flags); |
| 349 | else if (num_stream_ctxs <= SMALL_STREAM_ARRAY_SIZE) | 351 | else if (num_stream_ctxs <= SMALL_STREAM_ARRAY_SIZE) |
| 350 | return dma_pool_alloc(xhci->small_streams_pool, | 352 | return dma_pool_alloc(xhci->small_streams_pool, |
| 351 | mem_flags, dma); | 353 | mem_flags, dma); |
| @@ -540,7 +542,7 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci, | |||
| 540 | */ | 542 | */ |
| 541 | for (cur_stream = 1; cur_stream < num_streams; cur_stream++) { | 543 | for (cur_stream = 1; cur_stream < num_streams; cur_stream++) { |
| 542 | stream_info->stream_rings[cur_stream] = | 544 | stream_info->stream_rings[cur_stream] = |
| 543 | xhci_ring_alloc(xhci, 1, true, mem_flags); | 545 | xhci_ring_alloc(xhci, 1, true, false, mem_flags); |
| 544 | cur_ring = stream_info->stream_rings[cur_stream]; | 546 | cur_ring = stream_info->stream_rings[cur_stream]; |
| 545 | if (!cur_ring) | 547 | if (!cur_ring) |
| 546 | goto cleanup_rings; | 548 | goto cleanup_rings; |
| @@ -687,11 +689,103 @@ static void xhci_init_endpoint_timer(struct xhci_hcd *xhci, | |||
| 687 | ep->xhci = xhci; | 689 | ep->xhci = xhci; |
| 688 | } | 690 | } |
| 689 | 691 | ||
| 690 | /* All the xhci_tds in the ring's TD list should be freed at this point */ | 692 | static void xhci_free_tt_info(struct xhci_hcd *xhci, |
| 693 | struct xhci_virt_device *virt_dev, | ||
| 694 | int slot_id) | ||
| 695 | { | ||
| 696 | struct list_head *tt; | ||
| 697 | struct list_head *tt_list_head; | ||
| 698 | struct list_head *tt_next; | ||
| 699 | struct xhci_tt_bw_info *tt_info; | ||
| 700 | |||
| 701 | /* If the device never made it past the Set Address stage, | ||
| 702 | * it may not have the real_port set correctly. | ||
| 703 | */ | ||
| 704 | if (virt_dev->real_port == 0 || | ||
| 705 | virt_dev->real_port > HCS_MAX_PORTS(xhci->hcs_params1)) { | ||
| 706 | xhci_dbg(xhci, "Bad real port.\n"); | ||
| 707 | return; | ||
| 708 | } | ||
| 709 | |||
| 710 | tt_list_head = &(xhci->rh_bw[virt_dev->real_port - 1].tts); | ||
| 711 | if (list_empty(tt_list_head)) | ||
| 712 | return; | ||
| 713 | |||
| 714 | list_for_each(tt, tt_list_head) { | ||
| 715 | tt_info = list_entry(tt, struct xhci_tt_bw_info, tt_list); | ||
| 716 | if (tt_info->slot_id == slot_id) | ||
| 717 | break; | ||
| 718 | } | ||
| 719 | /* Cautionary measure in case the hub was disconnected before we | ||
| 720 | * stored the TT information. | ||
| 721 | */ | ||
| 722 | if (tt_info->slot_id != slot_id) | ||
| 723 | return; | ||
| 724 | |||
| 725 | tt_next = tt->next; | ||
| 726 | tt_info = list_entry(tt, struct xhci_tt_bw_info, | ||
| 727 | tt_list); | ||
| 728 | /* Multi-TT hubs will have more than one entry */ | ||
| 729 | do { | ||
| 730 | list_del(tt); | ||
| 731 | kfree(tt_info); | ||
| 732 | tt = tt_next; | ||
| 733 | if (list_empty(tt_list_head)) | ||
| 734 | break; | ||
| 735 | tt_next = tt->next; | ||
| 736 | tt_info = list_entry(tt, struct xhci_tt_bw_info, | ||
| 737 | tt_list); | ||
| 738 | } while (tt_info->slot_id == slot_id); | ||
| 739 | } | ||
| 740 | |||
| 741 | int xhci_alloc_tt_info(struct xhci_hcd *xhci, | ||
| 742 | struct xhci_virt_device *virt_dev, | ||
| 743 | struct usb_device *hdev, | ||
| 744 | struct usb_tt *tt, gfp_t mem_flags) | ||
| 745 | { | ||
| 746 | struct xhci_tt_bw_info *tt_info; | ||
| 747 | unsigned int num_ports; | ||
| 748 | int i, j; | ||
| 749 | |||
| 750 | if (!tt->multi) | ||
| 751 | num_ports = 1; | ||
| 752 | else | ||
| 753 | num_ports = hdev->maxchild; | ||
| 754 | |||
| 755 | for (i = 0; i < num_ports; i++, tt_info++) { | ||
| 756 | struct xhci_interval_bw_table *bw_table; | ||
| 757 | |||
| 758 | tt_info = kzalloc(sizeof(*tt_info), mem_flags); | ||
| 759 | if (!tt_info) | ||
| 760 | goto free_tts; | ||
| 761 | INIT_LIST_HEAD(&tt_info->tt_list); | ||
| 762 | list_add(&tt_info->tt_list, | ||
| 763 | &xhci->rh_bw[virt_dev->real_port - 1].tts); | ||
| 764 | tt_info->slot_id = virt_dev->udev->slot_id; | ||
| 765 | if (tt->multi) | ||
| 766 | tt_info->ttport = i+1; | ||
| 767 | bw_table = &tt_info->bw_table; | ||
| 768 | for (j = 0; j < XHCI_MAX_INTERVAL; j++) | ||
| 769 | INIT_LIST_HEAD(&bw_table->interval_bw[j].endpoints); | ||
| 770 | } | ||
| 771 | return 0; | ||
| 772 | |||
| 773 | free_tts: | ||
| 774 | xhci_free_tt_info(xhci, virt_dev, virt_dev->udev->slot_id); | ||
| 775 | return -ENOMEM; | ||
| 776 | } | ||
| 777 | |||
| 778 | |||
| 779 | /* All the xhci_tds in the ring's TD list should be freed at this point. | ||
| 780 | * Should be called with xhci->lock held if there is any chance the TT lists | ||
| 781 | * will be manipulated by the configure endpoint, allocate device, or update | ||
| 782 | * hub functions while this function is removing the TT entries from the list. | ||
| 783 | */ | ||
| 691 | void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id) | 784 | void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id) |
| 692 | { | 785 | { |
| 693 | struct xhci_virt_device *dev; | 786 | struct xhci_virt_device *dev; |
| 694 | int i; | 787 | int i; |
| 788 | int old_active_eps = 0; | ||
| 695 | 789 | ||
| 696 | /* Slot ID 0 is reserved */ | 790 | /* Slot ID 0 is reserved */ |
| 697 | if (slot_id == 0 || !xhci->devs[slot_id]) | 791 | if (slot_id == 0 || !xhci->devs[slot_id]) |
| @@ -702,13 +796,29 @@ void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id) | |||
| 702 | if (!dev) | 796 | if (!dev) |
| 703 | return; | 797 | return; |
| 704 | 798 | ||
| 799 | if (dev->tt_info) | ||
| 800 | old_active_eps = dev->tt_info->active_eps; | ||
| 801 | |||
| 705 | for (i = 0; i < 31; ++i) { | 802 | for (i = 0; i < 31; ++i) { |
| 706 | if (dev->eps[i].ring) | 803 | if (dev->eps[i].ring) |
| 707 | xhci_ring_free(xhci, dev->eps[i].ring); | 804 | xhci_ring_free(xhci, dev->eps[i].ring); |
| 708 | if (dev->eps[i].stream_info) | 805 | if (dev->eps[i].stream_info) |
| 709 | xhci_free_stream_info(xhci, | 806 | xhci_free_stream_info(xhci, |
| 710 | dev->eps[i].stream_info); | 807 | dev->eps[i].stream_info); |
| 808 | /* Endpoints on the TT/root port lists should have been removed | ||
| 809 | * when usb_disable_device() was called for the device. | ||
| 810 | * We can't drop them anyway, because the udev might have gone | ||
| 811 | * away by this point, and we can't tell what speed it was. | ||
| 812 | */ | ||
| 813 | if (!list_empty(&dev->eps[i].bw_endpoint_list)) | ||
| 814 | xhci_warn(xhci, "Slot %u endpoint %u " | ||
| 815 | "not removed from BW list!\n", | ||
| 816 | slot_id, i); | ||
| 711 | } | 817 | } |
| 818 | /* If this is a hub, free the TT(s) from the TT list */ | ||
| 819 | xhci_free_tt_info(xhci, dev, slot_id); | ||
| 820 | /* If necessary, update the number of active TTs on this root port */ | ||
| 821 | xhci_update_tt_active_eps(xhci, dev, old_active_eps); | ||
| 712 | 822 | ||
| 713 | if (dev->ring_cache) { | 823 | if (dev->ring_cache) { |
| 714 | for (i = 0; i < dev->num_rings_cached; i++) | 824 | for (i = 0; i < dev->num_rings_cached; i++) |
| @@ -762,10 +872,11 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, | |||
| 762 | for (i = 0; i < 31; i++) { | 872 | for (i = 0; i < 31; i++) { |
| 763 | xhci_init_endpoint_timer(xhci, &dev->eps[i]); | 873 | xhci_init_endpoint_timer(xhci, &dev->eps[i]); |
| 764 | INIT_LIST_HEAD(&dev->eps[i].cancelled_td_list); | 874 | INIT_LIST_HEAD(&dev->eps[i].cancelled_td_list); |
| 875 | INIT_LIST_HEAD(&dev->eps[i].bw_endpoint_list); | ||
| 765 | } | 876 | } |
| 766 | 877 | ||
| 767 | /* Allocate endpoint 0 ring */ | 878 | /* Allocate endpoint 0 ring */ |
| 768 | dev->eps[0].ring = xhci_ring_alloc(xhci, 1, true, flags); | 879 | dev->eps[0].ring = xhci_ring_alloc(xhci, 1, true, false, flags); |
| 769 | if (!dev->eps[0].ring) | 880 | if (!dev->eps[0].ring) |
| 770 | goto fail; | 881 | goto fail; |
| 771 | 882 | ||
| @@ -871,7 +982,6 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud | |||
| 871 | struct xhci_virt_device *dev; | 982 | struct xhci_virt_device *dev; |
| 872 | struct xhci_ep_ctx *ep0_ctx; | 983 | struct xhci_ep_ctx *ep0_ctx; |
| 873 | struct xhci_slot_ctx *slot_ctx; | 984 | struct xhci_slot_ctx *slot_ctx; |
| 874 | struct xhci_input_control_ctx *ctrl_ctx; | ||
| 875 | u32 port_num; | 985 | u32 port_num; |
| 876 | struct usb_device *top_dev; | 986 | struct usb_device *top_dev; |
| 877 | 987 | ||
| @@ -883,12 +993,8 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud | |||
| 883 | return -EINVAL; | 993 | return -EINVAL; |
| 884 | } | 994 | } |
| 885 | ep0_ctx = xhci_get_ep_ctx(xhci, dev->in_ctx, 0); | 995 | ep0_ctx = xhci_get_ep_ctx(xhci, dev->in_ctx, 0); |
| 886 | ctrl_ctx = xhci_get_input_control_ctx(xhci, dev->in_ctx); | ||
| 887 | slot_ctx = xhci_get_slot_ctx(xhci, dev->in_ctx); | 996 | slot_ctx = xhci_get_slot_ctx(xhci, dev->in_ctx); |
| 888 | 997 | ||
| 889 | /* 2) New slot context and endpoint 0 context are valid*/ | ||
| 890 | ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG); | ||
| 891 | |||
| 892 | /* 3) Only the control endpoint is valid - one endpoint context */ | 998 | /* 3) Only the control endpoint is valid - one endpoint context */ |
| 893 | slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1) | udev->route); | 999 | slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1) | udev->route); |
| 894 | switch (udev->speed) { | 1000 | switch (udev->speed) { |
| @@ -921,9 +1027,40 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud | |||
| 921 | for (top_dev = udev; top_dev->parent && top_dev->parent->parent; | 1027 | for (top_dev = udev; top_dev->parent && top_dev->parent->parent; |
| 922 | top_dev = top_dev->parent) | 1028 | top_dev = top_dev->parent) |
| 923 | /* Found device below root hub */; | 1029 | /* Found device below root hub */; |
| 924 | dev->port = top_dev->portnum; | 1030 | dev->fake_port = top_dev->portnum; |
| 1031 | dev->real_port = port_num; | ||
| 925 | xhci_dbg(xhci, "Set root hub portnum to %d\n", port_num); | 1032 | xhci_dbg(xhci, "Set root hub portnum to %d\n", port_num); |
| 926 | xhci_dbg(xhci, "Set fake root hub portnum to %d\n", dev->port); | 1033 | xhci_dbg(xhci, "Set fake root hub portnum to %d\n", dev->fake_port); |
| 1034 | |||
| 1035 | /* Find the right bandwidth table that this device will be a part of. | ||
| 1036 | * If this is a full speed device attached directly to a root port (or a | ||
| 1037 | * decendent of one), it counts as a primary bandwidth domain, not a | ||
| 1038 | * secondary bandwidth domain under a TT. An xhci_tt_info structure | ||
| 1039 | * will never be created for the HS root hub. | ||
| 1040 | */ | ||
| 1041 | if (!udev->tt || !udev->tt->hub->parent) { | ||
| 1042 | dev->bw_table = &xhci->rh_bw[port_num - 1].bw_table; | ||
| 1043 | } else { | ||
| 1044 | struct xhci_root_port_bw_info *rh_bw; | ||
| 1045 | struct xhci_tt_bw_info *tt_bw; | ||
| 1046 | |||
| 1047 | rh_bw = &xhci->rh_bw[port_num - 1]; | ||
| 1048 | /* Find the right TT. */ | ||
| 1049 | list_for_each_entry(tt_bw, &rh_bw->tts, tt_list) { | ||
| 1050 | if (tt_bw->slot_id != udev->tt->hub->slot_id) | ||
| 1051 | continue; | ||
| 1052 | |||
| 1053 | if (!dev->udev->tt->multi || | ||
| 1054 | (udev->tt->multi && | ||
| 1055 | tt_bw->ttport == dev->udev->ttport)) { | ||
| 1056 | dev->bw_table = &tt_bw->bw_table; | ||
| 1057 | dev->tt_info = tt_bw; | ||
| 1058 | break; | ||
| 1059 | } | ||
| 1060 | } | ||
| 1061 | if (!dev->tt_info) | ||
| 1062 | xhci_warn(xhci, "WARN: Didn't find a matching TT\n"); | ||
| 1063 | } | ||
| 927 | 1064 | ||
| 928 | /* Is this a LS/FS device under an external HS hub? */ | 1065 | /* Is this a LS/FS device under an external HS hub? */ |
| 929 | if (udev->tt && udev->tt->hub->parent) { | 1066 | if (udev->tt && udev->tt->hub->parent) { |
| @@ -1141,8 +1278,8 @@ static u32 xhci_get_max_esit_payload(struct xhci_hcd *xhci, | |||
| 1141 | if (udev->speed == USB_SPEED_SUPER) | 1278 | if (udev->speed == USB_SPEED_SUPER) |
| 1142 | return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval); | 1279 | return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval); |
| 1143 | 1280 | ||
| 1144 | max_packet = GET_MAX_PACKET(le16_to_cpu(ep->desc.wMaxPacketSize)); | 1281 | max_packet = GET_MAX_PACKET(usb_endpoint_maxp(&ep->desc)); |
| 1145 | max_burst = (le16_to_cpu(ep->desc.wMaxPacketSize) & 0x1800) >> 11; | 1282 | max_burst = (usb_endpoint_maxp(&ep->desc) & 0x1800) >> 11; |
| 1146 | /* A 0 in max burst means 1 transfer per ESIT */ | 1283 | /* A 0 in max burst means 1 transfer per ESIT */ |
| 1147 | return max_packet * (max_burst + 1); | 1284 | return max_packet * (max_burst + 1); |
| 1148 | } | 1285 | } |
| @@ -1175,10 +1312,10 @@ int xhci_endpoint_init(struct xhci_hcd *xhci, | |||
| 1175 | */ | 1312 | */ |
| 1176 | if (usb_endpoint_xfer_isoc(&ep->desc)) | 1313 | if (usb_endpoint_xfer_isoc(&ep->desc)) |
| 1177 | virt_dev->eps[ep_index].new_ring = | 1314 | virt_dev->eps[ep_index].new_ring = |
| 1178 | xhci_ring_alloc(xhci, 8, true, mem_flags); | 1315 | xhci_ring_alloc(xhci, 8, true, true, mem_flags); |
| 1179 | else | 1316 | else |
| 1180 | virt_dev->eps[ep_index].new_ring = | 1317 | virt_dev->eps[ep_index].new_ring = |
| 1181 | xhci_ring_alloc(xhci, 1, true, mem_flags); | 1318 | xhci_ring_alloc(xhci, 1, true, false, mem_flags); |
| 1182 | if (!virt_dev->eps[ep_index].new_ring) { | 1319 | if (!virt_dev->eps[ep_index].new_ring) { |
| 1183 | /* Attempt to use the ring cache */ | 1320 | /* Attempt to use the ring cache */ |
| 1184 | if (virt_dev->num_rings_cached == 0) | 1321 | if (virt_dev->num_rings_cached == 0) |
| @@ -1187,7 +1324,8 @@ int xhci_endpoint_init(struct xhci_hcd *xhci, | |||
| 1187 | virt_dev->ring_cache[virt_dev->num_rings_cached]; | 1324 | virt_dev->ring_cache[virt_dev->num_rings_cached]; |
| 1188 | virt_dev->ring_cache[virt_dev->num_rings_cached] = NULL; | 1325 | virt_dev->ring_cache[virt_dev->num_rings_cached] = NULL; |
| 1189 | virt_dev->num_rings_cached--; | 1326 | virt_dev->num_rings_cached--; |
| 1190 | xhci_reinit_cached_ring(xhci, virt_dev->eps[ep_index].new_ring); | 1327 | xhci_reinit_cached_ring(xhci, virt_dev->eps[ep_index].new_ring, |
| 1328 | usb_endpoint_xfer_isoc(&ep->desc) ? true : false); | ||
| 1191 | } | 1329 | } |
| 1192 | virt_dev->eps[ep_index].skip = false; | 1330 | virt_dev->eps[ep_index].skip = false; |
| 1193 | ep_ring = virt_dev->eps[ep_index].new_ring; | 1331 | ep_ring = virt_dev->eps[ep_index].new_ring; |
| @@ -1211,7 +1349,7 @@ int xhci_endpoint_init(struct xhci_hcd *xhci, | |||
| 1211 | /* Set the max packet size and max burst */ | 1349 | /* Set the max packet size and max burst */ |
| 1212 | switch (udev->speed) { | 1350 | switch (udev->speed) { |
| 1213 | case USB_SPEED_SUPER: | 1351 | case USB_SPEED_SUPER: |
| 1214 | max_packet = le16_to_cpu(ep->desc.wMaxPacketSize); | 1352 | max_packet = usb_endpoint_maxp(&ep->desc); |
| 1215 | ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet)); | 1353 | ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet)); |
| 1216 | /* dig out max burst from ep companion desc */ | 1354 | /* dig out max burst from ep companion desc */ |
| 1217 | max_packet = ep->ss_ep_comp.bMaxBurst; | 1355 | max_packet = ep->ss_ep_comp.bMaxBurst; |
| @@ -1223,14 +1361,14 @@ int xhci_endpoint_init(struct xhci_hcd *xhci, | |||
| 1223 | */ | 1361 | */ |
| 1224 | if (usb_endpoint_xfer_isoc(&ep->desc) || | 1362 | if (usb_endpoint_xfer_isoc(&ep->desc) || |
| 1225 | usb_endpoint_xfer_int(&ep->desc)) { | 1363 | usb_endpoint_xfer_int(&ep->desc)) { |
| 1226 | max_burst = (le16_to_cpu(ep->desc.wMaxPacketSize) | 1364 | max_burst = (usb_endpoint_maxp(&ep->desc) |
| 1227 | & 0x1800) >> 11; | 1365 | & 0x1800) >> 11; |
| 1228 | ep_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(max_burst)); | 1366 | ep_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(max_burst)); |
| 1229 | } | 1367 | } |
| 1230 | /* Fall through */ | 1368 | /* Fall through */ |
| 1231 | case USB_SPEED_FULL: | 1369 | case USB_SPEED_FULL: |
| 1232 | case USB_SPEED_LOW: | 1370 | case USB_SPEED_LOW: |
| 1233 | max_packet = GET_MAX_PACKET(le16_to_cpu(ep->desc.wMaxPacketSize)); | 1371 | max_packet = GET_MAX_PACKET(usb_endpoint_maxp(&ep->desc)); |
| 1234 | ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet)); | 1372 | ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet)); |
| 1235 | break; | 1373 | break; |
| 1236 | default: | 1374 | default: |
| @@ -1286,6 +1424,70 @@ void xhci_endpoint_zero(struct xhci_hcd *xhci, | |||
| 1286 | */ | 1424 | */ |
| 1287 | } | 1425 | } |
| 1288 | 1426 | ||
| 1427 | void xhci_clear_endpoint_bw_info(struct xhci_bw_info *bw_info) | ||
| 1428 | { | ||
| 1429 | bw_info->ep_interval = 0; | ||
| 1430 | bw_info->mult = 0; | ||
| 1431 | bw_info->num_packets = 0; | ||
| 1432 | bw_info->max_packet_size = 0; | ||
| 1433 | bw_info->type = 0; | ||
| 1434 | bw_info->max_esit_payload = 0; | ||
| 1435 | } | ||
| 1436 | |||
| 1437 | void xhci_update_bw_info(struct xhci_hcd *xhci, | ||
| 1438 | struct xhci_container_ctx *in_ctx, | ||
| 1439 | struct xhci_input_control_ctx *ctrl_ctx, | ||
| 1440 | struct xhci_virt_device *virt_dev) | ||
| 1441 | { | ||
| 1442 | struct xhci_bw_info *bw_info; | ||
| 1443 | struct xhci_ep_ctx *ep_ctx; | ||
| 1444 | unsigned int ep_type; | ||
| 1445 | int i; | ||
| 1446 | |||
| 1447 | for (i = 1; i < 31; ++i) { | ||
| 1448 | bw_info = &virt_dev->eps[i].bw_info; | ||
| 1449 | |||
| 1450 | /* We can't tell what endpoint type is being dropped, but | ||
| 1451 | * unconditionally clearing the bandwidth info for non-periodic | ||
| 1452 | * endpoints should be harmless because the info will never be | ||
| 1453 | * set in the first place. | ||
| 1454 | */ | ||
| 1455 | if (!EP_IS_ADDED(ctrl_ctx, i) && EP_IS_DROPPED(ctrl_ctx, i)) { | ||
| 1456 | /* Dropped endpoint */ | ||
| 1457 | xhci_clear_endpoint_bw_info(bw_info); | ||
| 1458 | continue; | ||
| 1459 | } | ||
| 1460 | |||
| 1461 | if (EP_IS_ADDED(ctrl_ctx, i)) { | ||
| 1462 | ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, i); | ||
| 1463 | ep_type = CTX_TO_EP_TYPE(le32_to_cpu(ep_ctx->ep_info2)); | ||
| 1464 | |||
| 1465 | /* Ignore non-periodic endpoints */ | ||
| 1466 | if (ep_type != ISOC_OUT_EP && ep_type != INT_OUT_EP && | ||
| 1467 | ep_type != ISOC_IN_EP && | ||
| 1468 | ep_type != INT_IN_EP) | ||
| 1469 | continue; | ||
| 1470 | |||
| 1471 | /* Added or changed endpoint */ | ||
| 1472 | bw_info->ep_interval = CTX_TO_EP_INTERVAL( | ||
| 1473 | le32_to_cpu(ep_ctx->ep_info)); | ||
| 1474 | /* Number of packets and mult are zero-based in the | ||
| 1475 | * input context, but we want one-based for the | ||
| 1476 | * interval table. | ||
| 1477 | */ | ||
| 1478 | bw_info->mult = CTX_TO_EP_MULT( | ||
| 1479 | le32_to_cpu(ep_ctx->ep_info)) + 1; | ||
| 1480 | bw_info->num_packets = CTX_TO_MAX_BURST( | ||
| 1481 | le32_to_cpu(ep_ctx->ep_info2)) + 1; | ||
| 1482 | bw_info->max_packet_size = MAX_PACKET_DECODED( | ||
| 1483 | le32_to_cpu(ep_ctx->ep_info2)); | ||
| 1484 | bw_info->type = ep_type; | ||
| 1485 | bw_info->max_esit_payload = CTX_TO_MAX_ESIT_PAYLOAD( | ||
| 1486 | le32_to_cpu(ep_ctx->tx_info)); | ||
| 1487 | } | ||
| 1488 | } | ||
| 1489 | } | ||
| 1490 | |||
| 1289 | /* Copy output xhci_ep_ctx to the input xhci_ep_ctx copy. | 1491 | /* Copy output xhci_ep_ctx to the input xhci_ep_ctx copy. |
| 1290 | * Useful when you want to change one particular aspect of the endpoint and then | 1492 | * Useful when you want to change one particular aspect of the endpoint and then |
| 1291 | * issue a configure endpoint command. | 1493 | * issue a configure endpoint command. |
| @@ -1344,10 +1546,9 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags) | |||
| 1344 | if (!xhci->scratchpad) | 1546 | if (!xhci->scratchpad) |
| 1345 | goto fail_sp; | 1547 | goto fail_sp; |
| 1346 | 1548 | ||
| 1347 | xhci->scratchpad->sp_array = | 1549 | xhci->scratchpad->sp_array = dma_alloc_coherent(dev, |
| 1348 | pci_alloc_consistent(to_pci_dev(dev), | ||
| 1349 | num_sp * sizeof(u64), | 1550 | num_sp * sizeof(u64), |
| 1350 | &xhci->scratchpad->sp_dma); | 1551 | &xhci->scratchpad->sp_dma, flags); |
| 1351 | if (!xhci->scratchpad->sp_array) | 1552 | if (!xhci->scratchpad->sp_array) |
| 1352 | goto fail_sp2; | 1553 | goto fail_sp2; |
| 1353 | 1554 | ||
| @@ -1364,8 +1565,8 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags) | |||
| 1364 | xhci->dcbaa->dev_context_ptrs[0] = cpu_to_le64(xhci->scratchpad->sp_dma); | 1565 | xhci->dcbaa->dev_context_ptrs[0] = cpu_to_le64(xhci->scratchpad->sp_dma); |
| 1365 | for (i = 0; i < num_sp; i++) { | 1566 | for (i = 0; i < num_sp; i++) { |
| 1366 | dma_addr_t dma; | 1567 | dma_addr_t dma; |
| 1367 | void *buf = pci_alloc_consistent(to_pci_dev(dev), | 1568 | void *buf = dma_alloc_coherent(dev, xhci->page_size, &dma, |
| 1368 | xhci->page_size, &dma); | 1569 | flags); |
| 1369 | if (!buf) | 1570 | if (!buf) |
| 1370 | goto fail_sp5; | 1571 | goto fail_sp5; |
| 1371 | 1572 | ||
| @@ -1378,7 +1579,7 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags) | |||
| 1378 | 1579 | ||
| 1379 | fail_sp5: | 1580 | fail_sp5: |
| 1380 | for (i = i - 1; i >= 0; i--) { | 1581 | for (i = i - 1; i >= 0; i--) { |
| 1381 | pci_free_consistent(to_pci_dev(dev), xhci->page_size, | 1582 | dma_free_coherent(dev, xhci->page_size, |
| 1382 | xhci->scratchpad->sp_buffers[i], | 1583 | xhci->scratchpad->sp_buffers[i], |
| 1383 | xhci->scratchpad->sp_dma_buffers[i]); | 1584 | xhci->scratchpad->sp_dma_buffers[i]); |
| 1384 | } | 1585 | } |
| @@ -1388,7 +1589,7 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags) | |||
| 1388 | kfree(xhci->scratchpad->sp_buffers); | 1589 | kfree(xhci->scratchpad->sp_buffers); |
| 1389 | 1590 | ||
| 1390 | fail_sp3: | 1591 | fail_sp3: |
| 1391 | pci_free_consistent(to_pci_dev(dev), num_sp * sizeof(u64), | 1592 | dma_free_coherent(dev, num_sp * sizeof(u64), |
| 1392 | xhci->scratchpad->sp_array, | 1593 | xhci->scratchpad->sp_array, |
| 1393 | xhci->scratchpad->sp_dma); | 1594 | xhci->scratchpad->sp_dma); |
| 1394 | 1595 | ||
| @@ -1412,13 +1613,13 @@ static void scratchpad_free(struct xhci_hcd *xhci) | |||
| 1412 | num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); | 1613 | num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2); |
| 1413 | 1614 | ||
| 1414 | for (i = 0; i < num_sp; i++) { | 1615 | for (i = 0; i < num_sp; i++) { |
| 1415 | pci_free_consistent(pdev, xhci->page_size, | 1616 | dma_free_coherent(&pdev->dev, xhci->page_size, |
| 1416 | xhci->scratchpad->sp_buffers[i], | 1617 | xhci->scratchpad->sp_buffers[i], |
| 1417 | xhci->scratchpad->sp_dma_buffers[i]); | 1618 | xhci->scratchpad->sp_dma_buffers[i]); |
| 1418 | } | 1619 | } |
| 1419 | kfree(xhci->scratchpad->sp_dma_buffers); | 1620 | kfree(xhci->scratchpad->sp_dma_buffers); |
| 1420 | kfree(xhci->scratchpad->sp_buffers); | 1621 | kfree(xhci->scratchpad->sp_buffers); |
| 1421 | pci_free_consistent(pdev, num_sp * sizeof(u64), | 1622 | dma_free_coherent(&pdev->dev, num_sp * sizeof(u64), |
| 1422 | xhci->scratchpad->sp_array, | 1623 | xhci->scratchpad->sp_array, |
| 1423 | xhci->scratchpad->sp_dma); | 1624 | xhci->scratchpad->sp_dma); |
| 1424 | kfree(xhci->scratchpad); | 1625 | kfree(xhci->scratchpad); |
| @@ -1463,18 +1664,10 @@ struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci, | |||
| 1463 | 1664 | ||
| 1464 | void xhci_urb_free_priv(struct xhci_hcd *xhci, struct urb_priv *urb_priv) | 1665 | void xhci_urb_free_priv(struct xhci_hcd *xhci, struct urb_priv *urb_priv) |
| 1465 | { | 1666 | { |
| 1466 | int last; | 1667 | if (urb_priv) { |
| 1467 | 1668 | kfree(urb_priv->td[0]); | |
| 1468 | if (!urb_priv) | 1669 | kfree(urb_priv); |
| 1469 | return; | ||
| 1470 | |||
| 1471 | last = urb_priv->length - 1; | ||
| 1472 | if (last >= 0) { | ||
| 1473 | int i; | ||
| 1474 | for (i = 0; i <= last; i++) | ||
| 1475 | kfree(urb_priv->td[i]); | ||
| 1476 | } | 1670 | } |
| 1477 | kfree(urb_priv); | ||
| 1478 | } | 1671 | } |
| 1479 | 1672 | ||
| 1480 | void xhci_free_command(struct xhci_hcd *xhci, | 1673 | void xhci_free_command(struct xhci_hcd *xhci, |
| @@ -1489,6 +1682,8 @@ void xhci_free_command(struct xhci_hcd *xhci, | |||
| 1489 | void xhci_mem_cleanup(struct xhci_hcd *xhci) | 1682 | void xhci_mem_cleanup(struct xhci_hcd *xhci) |
| 1490 | { | 1683 | { |
| 1491 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); | 1684 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); |
| 1685 | struct dev_info *dev_info, *next; | ||
| 1686 | unsigned long flags; | ||
| 1492 | int size; | 1687 | int size; |
| 1493 | int i; | 1688 | int i; |
| 1494 | 1689 | ||
| @@ -1500,7 +1695,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) | |||
| 1500 | } | 1695 | } |
| 1501 | size = sizeof(struct xhci_erst_entry)*(xhci->erst.num_entries); | 1696 | size = sizeof(struct xhci_erst_entry)*(xhci->erst.num_entries); |
| 1502 | if (xhci->erst.entries) | 1697 | if (xhci->erst.entries) |
| 1503 | pci_free_consistent(pdev, size, | 1698 | dma_free_coherent(&pdev->dev, size, |
| 1504 | xhci->erst.entries, xhci->erst.erst_dma_addr); | 1699 | xhci->erst.entries, xhci->erst.erst_dma_addr); |
| 1505 | xhci->erst.entries = NULL; | 1700 | xhci->erst.entries = NULL; |
| 1506 | xhci_dbg(xhci, "Freed ERST\n"); | 1701 | xhci_dbg(xhci, "Freed ERST\n"); |
| @@ -1540,17 +1735,25 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) | |||
| 1540 | 1735 | ||
| 1541 | xhci_write_64(xhci, 0, &xhci->op_regs->dcbaa_ptr); | 1736 | xhci_write_64(xhci, 0, &xhci->op_regs->dcbaa_ptr); |
| 1542 | if (xhci->dcbaa) | 1737 | if (xhci->dcbaa) |
| 1543 | pci_free_consistent(pdev, sizeof(*xhci->dcbaa), | 1738 | dma_free_coherent(&pdev->dev, sizeof(*xhci->dcbaa), |
| 1544 | xhci->dcbaa, xhci->dcbaa->dma); | 1739 | xhci->dcbaa, xhci->dcbaa->dma); |
| 1545 | xhci->dcbaa = NULL; | 1740 | xhci->dcbaa = NULL; |
| 1546 | 1741 | ||
| 1547 | scratchpad_free(xhci); | 1742 | scratchpad_free(xhci); |
| 1548 | 1743 | ||
| 1744 | spin_lock_irqsave(&xhci->lock, flags); | ||
| 1745 | list_for_each_entry_safe(dev_info, next, &xhci->lpm_failed_devs, list) { | ||
| 1746 | list_del(&dev_info->list); | ||
| 1747 | kfree(dev_info); | ||
| 1748 | } | ||
| 1749 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
| 1750 | |||
| 1549 | xhci->num_usb2_ports = 0; | 1751 | xhci->num_usb2_ports = 0; |
| 1550 | xhci->num_usb3_ports = 0; | 1752 | xhci->num_usb3_ports = 0; |
| 1551 | kfree(xhci->usb2_ports); | 1753 | kfree(xhci->usb2_ports); |
| 1552 | kfree(xhci->usb3_ports); | 1754 | kfree(xhci->usb3_ports); |
| 1553 | kfree(xhci->port_array); | 1755 | kfree(xhci->port_array); |
| 1756 | kfree(xhci->rh_bw); | ||
| 1554 | 1757 | ||
| 1555 | xhci->page_size = 0; | 1758 | xhci->page_size = 0; |
| 1556 | xhci->page_shift = 0; | 1759 | xhci->page_shift = 0; |
| @@ -1762,6 +1965,23 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports, | |||
| 1762 | if (port_offset == 0 || (port_offset + port_count - 1) > num_ports) | 1965 | if (port_offset == 0 || (port_offset + port_count - 1) > num_ports) |
| 1763 | /* WTF? "Valid values are ‘1’ to MaxPorts" */ | 1966 | /* WTF? "Valid values are ‘1’ to MaxPorts" */ |
| 1764 | return; | 1967 | return; |
| 1968 | |||
| 1969 | /* Check the host's USB2 LPM capability */ | ||
| 1970 | if ((xhci->hci_version == 0x96) && (major_revision != 0x03) && | ||
| 1971 | (temp & XHCI_L1C)) { | ||
| 1972 | xhci_dbg(xhci, "xHCI 0.96: support USB2 software lpm\n"); | ||
| 1973 | xhci->sw_lpm_support = 1; | ||
| 1974 | } | ||
| 1975 | |||
| 1976 | if ((xhci->hci_version >= 0x100) && (major_revision != 0x03)) { | ||
| 1977 | xhci_dbg(xhci, "xHCI 1.0: support USB2 software lpm\n"); | ||
| 1978 | xhci->sw_lpm_support = 1; | ||
| 1979 | if (temp & XHCI_HLC) { | ||
| 1980 | xhci_dbg(xhci, "xHCI 1.0: support USB2 hardware lpm\n"); | ||
| 1981 | xhci->hw_lpm_support = 1; | ||
| 1982 | } | ||
| 1983 | } | ||
| 1984 | |||
| 1765 | port_offset--; | 1985 | port_offset--; |
| 1766 | for (i = port_offset; i < (port_offset + port_count); i++) { | 1986 | for (i = port_offset; i < (port_offset + port_count); i++) { |
| 1767 | /* Duplicate entry. Ignore the port if the revisions differ. */ | 1987 | /* Duplicate entry. Ignore the port if the revisions differ. */ |
| @@ -1806,7 +2026,7 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags) | |||
| 1806 | __le32 __iomem *addr; | 2026 | __le32 __iomem *addr; |
| 1807 | u32 offset; | 2027 | u32 offset; |
| 1808 | unsigned int num_ports; | 2028 | unsigned int num_ports; |
| 1809 | int i, port_index; | 2029 | int i, j, port_index; |
| 1810 | 2030 | ||
| 1811 | addr = &xhci->cap_regs->hcc_params; | 2031 | addr = &xhci->cap_regs->hcc_params; |
| 1812 | offset = XHCI_HCC_EXT_CAPS(xhci_readl(xhci, addr)); | 2032 | offset = XHCI_HCC_EXT_CAPS(xhci_readl(xhci, addr)); |
| @@ -1821,6 +2041,18 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags) | |||
| 1821 | if (!xhci->port_array) | 2041 | if (!xhci->port_array) |
| 1822 | return -ENOMEM; | 2042 | return -ENOMEM; |
| 1823 | 2043 | ||
| 2044 | xhci->rh_bw = kzalloc(sizeof(*xhci->rh_bw)*num_ports, flags); | ||
| 2045 | if (!xhci->rh_bw) | ||
| 2046 | return -ENOMEM; | ||
| 2047 | for (i = 0; i < num_ports; i++) { | ||
| 2048 | struct xhci_interval_bw_table *bw_table; | ||
| 2049 | |||
| 2050 | INIT_LIST_HEAD(&xhci->rh_bw[i].tts); | ||
| 2051 | bw_table = &xhci->rh_bw[i].bw_table; | ||
| 2052 | for (j = 0; j < XHCI_MAX_INTERVAL; j++) | ||
| 2053 | INIT_LIST_HEAD(&bw_table->interval_bw[j].endpoints); | ||
| 2054 | } | ||
| 2055 | |||
| 1824 | /* | 2056 | /* |
| 1825 | * For whatever reason, the first capability offset is from the | 2057 | * For whatever reason, the first capability offset is from the |
| 1826 | * capability register base, not from the HCCPARAMS register. | 2058 | * capability register base, not from the HCCPARAMS register. |
| @@ -1959,8 +2191,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
| 1959 | * Section 5.4.8 - doorbell array must be | 2191 | * Section 5.4.8 - doorbell array must be |
| 1960 | * "physically contiguous and 64-byte (cache line) aligned". | 2192 | * "physically contiguous and 64-byte (cache line) aligned". |
| 1961 | */ | 2193 | */ |
| 1962 | xhci->dcbaa = pci_alloc_consistent(to_pci_dev(dev), | 2194 | xhci->dcbaa = dma_alloc_coherent(dev, sizeof(*xhci->dcbaa), &dma, |
| 1963 | sizeof(*xhci->dcbaa), &dma); | 2195 | GFP_KERNEL); |
| 1964 | if (!xhci->dcbaa) | 2196 | if (!xhci->dcbaa) |
| 1965 | goto fail; | 2197 | goto fail; |
| 1966 | memset(xhci->dcbaa, 0, sizeof *(xhci->dcbaa)); | 2198 | memset(xhci->dcbaa, 0, sizeof *(xhci->dcbaa)); |
| @@ -1994,14 +2226,14 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
| 1994 | dma_pool_create("xHCI 1KB stream ctx arrays", | 2226 | dma_pool_create("xHCI 1KB stream ctx arrays", |
| 1995 | dev, MEDIUM_STREAM_ARRAY_SIZE, 16, 0); | 2227 | dev, MEDIUM_STREAM_ARRAY_SIZE, 16, 0); |
| 1996 | /* Any stream context array bigger than MEDIUM_STREAM_ARRAY_SIZE | 2228 | /* Any stream context array bigger than MEDIUM_STREAM_ARRAY_SIZE |
| 1997 | * will be allocated with pci_alloc_consistent() | 2229 | * will be allocated with dma_alloc_coherent() |
| 1998 | */ | 2230 | */ |
| 1999 | 2231 | ||
| 2000 | if (!xhci->small_streams_pool || !xhci->medium_streams_pool) | 2232 | if (!xhci->small_streams_pool || !xhci->medium_streams_pool) |
| 2001 | goto fail; | 2233 | goto fail; |
| 2002 | 2234 | ||
| 2003 | /* Set up the command ring to have one segments for now. */ | 2235 | /* Set up the command ring to have one segments for now. */ |
| 2004 | xhci->cmd_ring = xhci_ring_alloc(xhci, 1, true, flags); | 2236 | xhci->cmd_ring = xhci_ring_alloc(xhci, 1, true, false, flags); |
| 2005 | if (!xhci->cmd_ring) | 2237 | if (!xhci->cmd_ring) |
| 2006 | goto fail; | 2238 | goto fail; |
| 2007 | xhci_dbg(xhci, "Allocated command ring at %p\n", xhci->cmd_ring); | 2239 | xhci_dbg(xhci, "Allocated command ring at %p\n", xhci->cmd_ring); |
| @@ -2032,14 +2264,16 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
| 2032 | * the event ring segment table (ERST). Section 4.9.3. | 2264 | * the event ring segment table (ERST). Section 4.9.3. |
| 2033 | */ | 2265 | */ |
| 2034 | xhci_dbg(xhci, "// Allocating event ring\n"); | 2266 | xhci_dbg(xhci, "// Allocating event ring\n"); |
| 2035 | xhci->event_ring = xhci_ring_alloc(xhci, ERST_NUM_SEGS, false, flags); | 2267 | xhci->event_ring = xhci_ring_alloc(xhci, ERST_NUM_SEGS, false, false, |
| 2268 | flags); | ||
| 2036 | if (!xhci->event_ring) | 2269 | if (!xhci->event_ring) |
| 2037 | goto fail; | 2270 | goto fail; |
| 2038 | if (xhci_check_trb_in_td_math(xhci, flags) < 0) | 2271 | if (xhci_check_trb_in_td_math(xhci, flags) < 0) |
| 2039 | goto fail; | 2272 | goto fail; |
| 2040 | 2273 | ||
| 2041 | xhci->erst.entries = pci_alloc_consistent(to_pci_dev(dev), | 2274 | xhci->erst.entries = dma_alloc_coherent(dev, |
| 2042 | sizeof(struct xhci_erst_entry)*ERST_NUM_SEGS, &dma); | 2275 | sizeof(struct xhci_erst_entry) * ERST_NUM_SEGS, &dma, |
| 2276 | GFP_KERNEL); | ||
| 2043 | if (!xhci->erst.entries) | 2277 | if (!xhci->erst.entries) |
| 2044 | goto fail; | 2278 | goto fail; |
| 2045 | xhci_dbg(xhci, "// Allocated event ring segment table at 0x%llx\n", | 2279 | xhci_dbg(xhci, "// Allocated event ring segment table at 0x%llx\n", |
| @@ -2102,6 +2336,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) | |||
| 2102 | if (xhci_setup_port_arrays(xhci, flags)) | 2336 | if (xhci_setup_port_arrays(xhci, flags)) |
| 2103 | goto fail; | 2337 | goto fail; |
| 2104 | 2338 | ||
| 2339 | INIT_LIST_HEAD(&xhci->lpm_failed_devs); | ||
| 2340 | |||
| 2105 | return 0; | 2341 | return 0; |
| 2106 | 2342 | ||
| 2107 | fail: | 2343 | fail: |
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index cb16de213f64..ef98b38626fb 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c | |||
| @@ -22,6 +22,7 @@ | |||
| 22 | 22 | ||
| 23 | #include <linux/pci.h> | 23 | #include <linux/pci.h> |
| 24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
| 25 | #include <linux/module.h> | ||
| 25 | 26 | ||
| 26 | #include "xhci.h" | 27 | #include "xhci.h" |
| 27 | 28 | ||
| @@ -51,61 +52,9 @@ static int xhci_pci_reinit(struct xhci_hcd *xhci, struct pci_dev *pdev) | |||
| 51 | return 0; | 52 | return 0; |
| 52 | } | 53 | } |
| 53 | 54 | ||
| 54 | /* called during probe() after chip reset completes */ | 55 | static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) |
| 55 | static int xhci_pci_setup(struct usb_hcd *hcd) | ||
| 56 | { | 56 | { |
| 57 | struct xhci_hcd *xhci; | 57 | struct pci_dev *pdev = to_pci_dev(dev); |
| 58 | struct pci_dev *pdev = to_pci_dev(hcd->self.controller); | ||
| 59 | int retval; | ||
| 60 | u32 temp; | ||
| 61 | |||
| 62 | hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2; | ||
| 63 | |||
| 64 | if (usb_hcd_is_primary_hcd(hcd)) { | ||
| 65 | xhci = kzalloc(sizeof(struct xhci_hcd), GFP_KERNEL); | ||
| 66 | if (!xhci) | ||
| 67 | return -ENOMEM; | ||
| 68 | *((struct xhci_hcd **) hcd->hcd_priv) = xhci; | ||
| 69 | xhci->main_hcd = hcd; | ||
| 70 | /* Mark the first roothub as being USB 2.0. | ||
| 71 | * The xHCI driver will register the USB 3.0 roothub. | ||
| 72 | */ | ||
| 73 | hcd->speed = HCD_USB2; | ||
| 74 | hcd->self.root_hub->speed = USB_SPEED_HIGH; | ||
| 75 | /* | ||
| 76 | * USB 2.0 roothub under xHCI has an integrated TT, | ||
| 77 | * (rate matching hub) as opposed to having an OHCI/UHCI | ||
| 78 | * companion controller. | ||
| 79 | */ | ||
| 80 | hcd->has_tt = 1; | ||
| 81 | } else { | ||
| 82 | /* xHCI private pointer was set in xhci_pci_probe for the second | ||
| 83 | * registered roothub. | ||
| 84 | */ | ||
| 85 | xhci = hcd_to_xhci(hcd); | ||
| 86 | temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params); | ||
| 87 | if (HCC_64BIT_ADDR(temp)) { | ||
| 88 | xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); | ||
| 89 | dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)); | ||
| 90 | } else { | ||
| 91 | dma_set_mask(hcd->self.controller, DMA_BIT_MASK(32)); | ||
| 92 | } | ||
| 93 | return 0; | ||
| 94 | } | ||
| 95 | |||
| 96 | xhci->cap_regs = hcd->regs; | ||
| 97 | xhci->op_regs = hcd->regs + | ||
| 98 | HC_LENGTH(xhci_readl(xhci, &xhci->cap_regs->hc_capbase)); | ||
| 99 | xhci->run_regs = hcd->regs + | ||
| 100 | (xhci_readl(xhci, &xhci->cap_regs->run_regs_off) & RTSOFF_MASK); | ||
| 101 | /* Cache read-only capability registers */ | ||
| 102 | xhci->hcs_params1 = xhci_readl(xhci, &xhci->cap_regs->hcs_params1); | ||
| 103 | xhci->hcs_params2 = xhci_readl(xhci, &xhci->cap_regs->hcs_params2); | ||
| 104 | xhci->hcs_params3 = xhci_readl(xhci, &xhci->cap_regs->hcs_params3); | ||
| 105 | xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hc_capbase); | ||
| 106 | xhci->hci_version = HC_VERSION(xhci->hcc_params); | ||
| 107 | xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hcc_params); | ||
| 108 | xhci_print_registers(xhci); | ||
| 109 | 58 | ||
| 110 | /* Look for vendor-specific quirks */ | 59 | /* Look for vendor-specific quirks */ |
| 111 | if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC && | 60 | if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC && |
| @@ -128,6 +77,9 @@ static int xhci_pci_setup(struct usb_hcd *hcd) | |||
| 128 | if (pdev->vendor == PCI_VENDOR_ID_NEC) | 77 | if (pdev->vendor == PCI_VENDOR_ID_NEC) |
| 129 | xhci->quirks |= XHCI_NEC_HOST; | 78 | xhci->quirks |= XHCI_NEC_HOST; |
| 130 | 79 | ||
| 80 | if (pdev->vendor == PCI_VENDOR_ID_AMD && xhci->hci_version == 0x96) | ||
| 81 | xhci->quirks |= XHCI_AMD_0x96_HOST; | ||
| 82 | |||
| 131 | /* AMD PLL quirk */ | 83 | /* AMD PLL quirk */ |
| 132 | if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info()) | 84 | if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info()) |
| 133 | xhci->quirks |= XHCI_AMD_PLL_FIX; | 85 | xhci->quirks |= XHCI_AMD_PLL_FIX; |
| @@ -136,39 +88,29 @@ static int xhci_pci_setup(struct usb_hcd *hcd) | |||
| 136 | xhci->quirks |= XHCI_SPURIOUS_SUCCESS; | 88 | xhci->quirks |= XHCI_SPURIOUS_SUCCESS; |
| 137 | xhci->quirks |= XHCI_EP_LIMIT_QUIRK; | 89 | xhci->quirks |= XHCI_EP_LIMIT_QUIRK; |
| 138 | xhci->limit_active_eps = 64; | 90 | xhci->limit_active_eps = 64; |
| 91 | xhci->quirks |= XHCI_SW_BW_CHECKING; | ||
| 139 | } | 92 | } |
| 140 | if (pdev->vendor == PCI_VENDOR_ID_ETRON && | 93 | if (pdev->vendor == PCI_VENDOR_ID_ETRON && |
| 141 | pdev->device == PCI_DEVICE_ID_ASROCK_P67) { | 94 | pdev->device == PCI_DEVICE_ID_ASROCK_P67) { |
| 142 | xhci->quirks |= XHCI_RESET_ON_RESUME; | 95 | xhci->quirks |= XHCI_RESET_ON_RESUME; |
| 143 | xhci_dbg(xhci, "QUIRK: Resetting on resume\n"); | 96 | xhci_dbg(xhci, "QUIRK: Resetting on resume\n"); |
| 144 | } | 97 | } |
| 98 | } | ||
| 145 | 99 | ||
| 146 | /* Make sure the HC is halted. */ | 100 | /* called during probe() after chip reset completes */ |
| 147 | retval = xhci_halt(xhci); | 101 | static int xhci_pci_setup(struct usb_hcd *hcd) |
| 148 | if (retval) | 102 | { |
| 149 | goto error; | 103 | struct xhci_hcd *xhci; |
| 104 | struct pci_dev *pdev = to_pci_dev(hcd->self.controller); | ||
| 105 | int retval; | ||
| 150 | 106 | ||
| 151 | xhci_dbg(xhci, "Resetting HCD\n"); | 107 | retval = xhci_gen_setup(hcd, xhci_pci_quirks); |
| 152 | /* Reset the internal HC memory state and registers. */ | ||
| 153 | retval = xhci_reset(xhci); | ||
| 154 | if (retval) | 108 | if (retval) |
| 155 | goto error; | 109 | return retval; |
| 156 | xhci_dbg(xhci, "Reset complete\n"); | ||
| 157 | |||
| 158 | temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params); | ||
| 159 | if (HCC_64BIT_ADDR(temp)) { | ||
| 160 | xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); | ||
| 161 | dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)); | ||
| 162 | } else { | ||
| 163 | dma_set_mask(hcd->self.controller, DMA_BIT_MASK(32)); | ||
| 164 | } | ||
| 165 | 110 | ||
| 166 | xhci_dbg(xhci, "Calling HCD init\n"); | 111 | xhci = hcd_to_xhci(hcd); |
| 167 | /* Initialize HCD and host controller data structures. */ | 112 | if (!usb_hcd_is_primary_hcd(hcd)) |
| 168 | retval = xhci_init(hcd); | 113 | return 0; |
| 169 | if (retval) | ||
| 170 | goto error; | ||
| 171 | xhci_dbg(xhci, "Called HCD init\n"); | ||
| 172 | 114 | ||
| 173 | pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn); | 115 | pci_read_config_byte(pdev, XHCI_SBRN_OFFSET, &xhci->sbrn); |
| 174 | xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn); | 116 | xhci_dbg(xhci, "Got SBRN %u\n", (unsigned int) xhci->sbrn); |
| @@ -178,7 +120,6 @@ static int xhci_pci_setup(struct usb_hcd *hcd) | |||
| 178 | if (!retval) | 120 | if (!retval) |
| 179 | return retval; | 121 | return retval; |
| 180 | 122 | ||
| 181 | error: | ||
| 182 | kfree(xhci); | 123 | kfree(xhci); |
| 183 | return retval; | 124 | return retval; |
| 184 | } | 125 | } |
| @@ -222,7 +163,7 @@ static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | |||
| 222 | *((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci; | 163 | *((struct xhci_hcd **) xhci->shared_hcd->hcd_priv) = xhci; |
| 223 | 164 | ||
| 224 | retval = usb_add_hcd(xhci->shared_hcd, dev->irq, | 165 | retval = usb_add_hcd(xhci->shared_hcd, dev->irq, |
| 225 | IRQF_DISABLED | IRQF_SHARED); | 166 | IRQF_SHARED); |
| 226 | if (retval) | 167 | if (retval) |
| 227 | goto put_usb3_hcd; | 168 | goto put_usb3_hcd; |
| 228 | /* Roothub already marked as USB 3.0 speed */ | 169 | /* Roothub already marked as USB 3.0 speed */ |
| @@ -344,6 +285,11 @@ static const struct hc_driver xhci_pci_hc_driver = { | |||
| 344 | .hub_status_data = xhci_hub_status_data, | 285 | .hub_status_data = xhci_hub_status_data, |
| 345 | .bus_suspend = xhci_bus_suspend, | 286 | .bus_suspend = xhci_bus_suspend, |
| 346 | .bus_resume = xhci_bus_resume, | 287 | .bus_resume = xhci_bus_resume, |
| 288 | /* | ||
| 289 | * call back when device connected and addressed | ||
| 290 | */ | ||
| 291 | .update_device = xhci_update_device, | ||
| 292 | .set_usb2_hw_lpm = xhci_set_usb2_hardware_lpm, | ||
| 347 | }; | 293 | }; |
| 348 | 294 | ||
| 349 | /*-------------------------------------------------------------------------*/ | 295 | /*-------------------------------------------------------------------------*/ |
| @@ -375,12 +321,12 @@ static struct pci_driver xhci_pci_driver = { | |||
| 375 | #endif | 321 | #endif |
| 376 | }; | 322 | }; |
| 377 | 323 | ||
| 378 | int xhci_register_pci(void) | 324 | int __init xhci_register_pci(void) |
| 379 | { | 325 | { |
| 380 | return pci_register_driver(&xhci_pci_driver); | 326 | return pci_register_driver(&xhci_pci_driver); |
| 381 | } | 327 | } |
| 382 | 328 | ||
| 383 | void xhci_unregister_pci(void) | 329 | void __exit xhci_unregister_pci(void) |
| 384 | { | 330 | { |
| 385 | pci_unregister_driver(&xhci_pci_driver); | 331 | pci_unregister_driver(&xhci_pci_driver); |
| 386 | } | 332 | } |
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 54139a2f06ce..9f1d4b15d818 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c | |||
| @@ -185,7 +185,7 @@ static void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring, bool consumer | |||
| 185 | * prepare_transfer()? | 185 | * prepare_transfer()? |
| 186 | */ | 186 | */ |
| 187 | static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, | 187 | static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, |
| 188 | bool consumer, bool more_trbs_coming) | 188 | bool consumer, bool more_trbs_coming, bool isoc) |
| 189 | { | 189 | { |
| 190 | u32 chain; | 190 | u32 chain; |
| 191 | union xhci_trb *next; | 191 | union xhci_trb *next; |
| @@ -212,11 +212,13 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, | |||
| 212 | if (!chain && !more_trbs_coming) | 212 | if (!chain && !more_trbs_coming) |
| 213 | break; | 213 | break; |
| 214 | 214 | ||
| 215 | /* If we're not dealing with 0.95 hardware, | 215 | /* If we're not dealing with 0.95 hardware or |
| 216 | * isoc rings on AMD 0.96 host, | ||
| 216 | * carry over the chain bit of the previous TRB | 217 | * carry over the chain bit of the previous TRB |
| 217 | * (which may mean the chain bit is cleared). | 218 | * (which may mean the chain bit is cleared). |
| 218 | */ | 219 | */ |
| 219 | if (!xhci_link_trb_quirk(xhci)) { | 220 | if (!(isoc && (xhci->quirks & XHCI_AMD_0x96_HOST)) |
| 221 | && !xhci_link_trb_quirk(xhci)) { | ||
| 220 | next->link.control &= | 222 | next->link.control &= |
| 221 | cpu_to_le32(~TRB_CHAIN); | 223 | cpu_to_le32(~TRB_CHAIN); |
| 222 | next->link.control |= | 224 | next->link.control |= |
| @@ -814,23 +816,24 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg) | |||
| 814 | struct xhci_ring *ring; | 816 | struct xhci_ring *ring; |
| 815 | struct xhci_td *cur_td; | 817 | struct xhci_td *cur_td; |
| 816 | int ret, i, j; | 818 | int ret, i, j; |
| 819 | unsigned long flags; | ||
| 817 | 820 | ||
| 818 | ep = (struct xhci_virt_ep *) arg; | 821 | ep = (struct xhci_virt_ep *) arg; |
| 819 | xhci = ep->xhci; | 822 | xhci = ep->xhci; |
| 820 | 823 | ||
| 821 | spin_lock(&xhci->lock); | 824 | spin_lock_irqsave(&xhci->lock, flags); |
| 822 | 825 | ||
| 823 | ep->stop_cmds_pending--; | 826 | ep->stop_cmds_pending--; |
| 824 | if (xhci->xhc_state & XHCI_STATE_DYING) { | 827 | if (xhci->xhc_state & XHCI_STATE_DYING) { |
| 825 | xhci_dbg(xhci, "Stop EP timer ran, but another timer marked " | 828 | xhci_dbg(xhci, "Stop EP timer ran, but another timer marked " |
| 826 | "xHCI as DYING, exiting.\n"); | 829 | "xHCI as DYING, exiting.\n"); |
| 827 | spin_unlock(&xhci->lock); | 830 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 828 | return; | 831 | return; |
| 829 | } | 832 | } |
| 830 | if (!(ep->stop_cmds_pending == 0 && (ep->ep_state & EP_HALT_PENDING))) { | 833 | if (!(ep->stop_cmds_pending == 0 && (ep->ep_state & EP_HALT_PENDING))) { |
| 831 | xhci_dbg(xhci, "Stop EP timer ran, but no command pending, " | 834 | xhci_dbg(xhci, "Stop EP timer ran, but no command pending, " |
| 832 | "exiting.\n"); | 835 | "exiting.\n"); |
| 833 | spin_unlock(&xhci->lock); | 836 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 834 | return; | 837 | return; |
| 835 | } | 838 | } |
| 836 | 839 | ||
| @@ -842,11 +845,11 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg) | |||
| 842 | xhci->xhc_state |= XHCI_STATE_DYING; | 845 | xhci->xhc_state |= XHCI_STATE_DYING; |
| 843 | /* Disable interrupts from the host controller and start halting it */ | 846 | /* Disable interrupts from the host controller and start halting it */ |
| 844 | xhci_quiesce(xhci); | 847 | xhci_quiesce(xhci); |
| 845 | spin_unlock(&xhci->lock); | 848 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 846 | 849 | ||
| 847 | ret = xhci_halt(xhci); | 850 | ret = xhci_halt(xhci); |
| 848 | 851 | ||
| 849 | spin_lock(&xhci->lock); | 852 | spin_lock_irqsave(&xhci->lock, flags); |
| 850 | if (ret < 0) { | 853 | if (ret < 0) { |
| 851 | /* This is bad; the host is not responding to commands and it's | 854 | /* This is bad; the host is not responding to commands and it's |
| 852 | * not allowing itself to be halted. At least interrupts are | 855 | * not allowing itself to be halted. At least interrupts are |
| @@ -894,7 +897,7 @@ void xhci_stop_endpoint_command_watchdog(unsigned long arg) | |||
| 894 | } | 897 | } |
| 895 | } | 898 | } |
| 896 | } | 899 | } |
| 897 | spin_unlock(&xhci->lock); | 900 | spin_unlock_irqrestore(&xhci->lock, flags); |
| 898 | xhci_dbg(xhci, "Calling usb_hc_died()\n"); | 901 | xhci_dbg(xhci, "Calling usb_hc_died()\n"); |
| 899 | usb_hc_died(xhci_to_hcd(xhci)->primary_hcd); | 902 | usb_hc_died(xhci_to_hcd(xhci)->primary_hcd); |
| 900 | xhci_dbg(xhci, "xHCI host controller is dead.\n"); | 903 | xhci_dbg(xhci, "xHCI host controller is dead.\n"); |
| @@ -1329,10 +1332,8 @@ static void handle_port_status(struct xhci_hcd *xhci, | |||
| 1329 | 1332 | ||
| 1330 | if (DEV_SUPERSPEED(temp)) { | 1333 | if (DEV_SUPERSPEED(temp)) { |
| 1331 | xhci_dbg(xhci, "resume SS port %d\n", port_id); | 1334 | xhci_dbg(xhci, "resume SS port %d\n", port_id); |
| 1332 | temp = xhci_port_state_to_neutral(temp); | 1335 | xhci_set_link_state(xhci, port_array, faked_port_index, |
| 1333 | temp &= ~PORT_PLS_MASK; | 1336 | XDEV_U0); |
| 1334 | temp |= PORT_LINK_STROBE | XDEV_U0; | ||
| 1335 | xhci_writel(xhci, temp, port_array[faked_port_index]); | ||
| 1336 | slot_id = xhci_find_slot_id_by_port(hcd, xhci, | 1337 | slot_id = xhci_find_slot_id_by_port(hcd, xhci, |
| 1337 | faked_port_index); | 1338 | faked_port_index); |
| 1338 | if (!slot_id) { | 1339 | if (!slot_id) { |
| @@ -1342,10 +1343,8 @@ static void handle_port_status(struct xhci_hcd *xhci, | |||
| 1342 | xhci_ring_device(xhci, slot_id); | 1343 | xhci_ring_device(xhci, slot_id); |
| 1343 | xhci_dbg(xhci, "resume SS port %d finished\n", port_id); | 1344 | xhci_dbg(xhci, "resume SS port %d finished\n", port_id); |
| 1344 | /* Clear PORT_PLC */ | 1345 | /* Clear PORT_PLC */ |
| 1345 | temp = xhci_readl(xhci, port_array[faked_port_index]); | 1346 | xhci_test_and_clear_bit(xhci, port_array, |
| 1346 | temp = xhci_port_state_to_neutral(temp); | 1347 | faked_port_index, PORT_PLC); |
| 1347 | temp |= PORT_PLC; | ||
| 1348 | xhci_writel(xhci, temp, port_array[faked_port_index]); | ||
| 1349 | } else { | 1348 | } else { |
| 1350 | xhci_dbg(xhci, "resume HS port %d\n", port_id); | 1349 | xhci_dbg(xhci, "resume HS port %d\n", port_id); |
| 1351 | bus_state->resume_done[faked_port_index] = jiffies + | 1350 | bus_state->resume_done[faked_port_index] = jiffies + |
| @@ -1356,6 +1355,10 @@ static void handle_port_status(struct xhci_hcd *xhci, | |||
| 1356 | } | 1355 | } |
| 1357 | } | 1356 | } |
| 1358 | 1357 | ||
| 1358 | if (hcd->speed != HCD_USB3) | ||
| 1359 | xhci_test_and_clear_bit(xhci, port_array, faked_port_index, | ||
| 1360 | PORT_PLC); | ||
| 1361 | |||
| 1359 | cleanup: | 1362 | cleanup: |
| 1360 | /* Update event ring dequeue pointer before dropping the lock */ | 1363 | /* Update event ring dequeue pointer before dropping the lock */ |
| 1361 | inc_deq(xhci, xhci->event_ring, true); | 1364 | inc_deq(xhci, xhci->event_ring, true); |
| @@ -1934,8 +1937,10 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
| 1934 | int status = -EINPROGRESS; | 1937 | int status = -EINPROGRESS; |
| 1935 | struct urb_priv *urb_priv; | 1938 | struct urb_priv *urb_priv; |
| 1936 | struct xhci_ep_ctx *ep_ctx; | 1939 | struct xhci_ep_ctx *ep_ctx; |
| 1940 | struct list_head *tmp; | ||
| 1937 | u32 trb_comp_code; | 1941 | u32 trb_comp_code; |
| 1938 | int ret = 0; | 1942 | int ret = 0; |
| 1943 | int td_num = 0; | ||
| 1939 | 1944 | ||
| 1940 | slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); | 1945 | slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags)); |
| 1941 | xdev = xhci->devs[slot_id]; | 1946 | xdev = xhci->devs[slot_id]; |
| @@ -1957,6 +1962,12 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
| 1957 | return -ENODEV; | 1962 | return -ENODEV; |
| 1958 | } | 1963 | } |
| 1959 | 1964 | ||
| 1965 | /* Count current td numbers if ep->skip is set */ | ||
| 1966 | if (ep->skip) { | ||
| 1967 | list_for_each(tmp, &ep_ring->td_list) | ||
| 1968 | td_num++; | ||
| 1969 | } | ||
| 1970 | |||
| 1960 | event_dma = le64_to_cpu(event->buffer); | 1971 | event_dma = le64_to_cpu(event->buffer); |
| 1961 | trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); | 1972 | trb_comp_code = GET_COMP_CODE(le32_to_cpu(event->transfer_len)); |
| 1962 | /* Look for common error cases */ | 1973 | /* Look for common error cases */ |
| @@ -2068,7 +2079,18 @@ static int handle_tx_event(struct xhci_hcd *xhci, | |||
| 2068 | goto cleanup; | 2079 | goto cleanup; |
| 2069 | } | 2080 | } |
| 2070 | 2081 | ||
| 2082 | /* We've skipped all the TDs on the ep ring when ep->skip set */ | ||
| 2083 | if (ep->skip && td_num == 0) { | ||
| 2084 | ep->skip = false; | ||
| 2085 | xhci_dbg(xhci, "All tds on the ep_ring skipped. " | ||
| 2086 | "Clear skip flag.\n"); | ||
| 2087 | ret = 0; | ||
| 2088 | goto cleanup; | ||
| 2089 | } | ||
| 2090 | |||
| 2071 | td = list_entry(ep_ring->td_list.next, struct xhci_td, td_list); | 2091 | td = list_entry(ep_ring->td_list.next, struct xhci_td, td_list); |
| 2092 | if (ep->skip) | ||
| 2093 | td_num--; | ||
| 2072 | 2094 | ||
| 2073 | /* Is this a TRB in the currently executing TD? */ | 2095 | /* Is this a TRB in the currently executing TD? */ |
| 2074 | event_seg = trb_in_td(ep_ring->deq_seg, ep_ring->dequeue, | 2096 | event_seg = trb_in_td(ep_ring->deq_seg, ep_ring->dequeue, |
| @@ -2173,7 +2195,8 @@ cleanup: | |||
| 2173 | if ((urb->actual_length != urb->transfer_buffer_length && | 2195 | if ((urb->actual_length != urb->transfer_buffer_length && |
| 2174 | (urb->transfer_flags & | 2196 | (urb->transfer_flags & |
| 2175 | URB_SHORT_NOT_OK)) || | 2197 | URB_SHORT_NOT_OK)) || |
| 2176 | status != 0) | 2198 | (status != 0 && |
| 2199 | !usb_endpoint_xfer_isoc(&urb->ep->desc))) | ||
| 2177 | xhci_dbg(xhci, "Giveback URB %p, len = %d, " | 2200 | xhci_dbg(xhci, "Giveback URB %p, len = %d, " |
| 2178 | "expected = %x, status = %d\n", | 2201 | "expected = %x, status = %d\n", |
| 2179 | urb, urb->actual_length, | 2202 | urb, urb->actual_length, |
| @@ -2390,7 +2413,7 @@ irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd) | |||
| 2390 | * prepare_transfer()? | 2413 | * prepare_transfer()? |
| 2391 | */ | 2414 | */ |
| 2392 | static void queue_trb(struct xhci_hcd *xhci, struct xhci_ring *ring, | 2415 | static void queue_trb(struct xhci_hcd *xhci, struct xhci_ring *ring, |
| 2393 | bool consumer, bool more_trbs_coming, | 2416 | bool consumer, bool more_trbs_coming, bool isoc, |
| 2394 | u32 field1, u32 field2, u32 field3, u32 field4) | 2417 | u32 field1, u32 field2, u32 field3, u32 field4) |
| 2395 | { | 2418 | { |
| 2396 | struct xhci_generic_trb *trb; | 2419 | struct xhci_generic_trb *trb; |
| @@ -2400,7 +2423,7 @@ static void queue_trb(struct xhci_hcd *xhci, struct xhci_ring *ring, | |||
| 2400 | trb->field[1] = cpu_to_le32(field2); | 2423 | trb->field[1] = cpu_to_le32(field2); |
| 2401 | trb->field[2] = cpu_to_le32(field3); | 2424 | trb->field[2] = cpu_to_le32(field3); |
| 2402 | trb->field[3] = cpu_to_le32(field4); | 2425 | trb->field[3] = cpu_to_le32(field4); |
| 2403 | inc_enq(xhci, ring, consumer, more_trbs_coming); | 2426 | inc_enq(xhci, ring, consumer, more_trbs_coming, isoc); |
| 2404 | } | 2427 | } |
| 2405 | 2428 | ||
| 2406 | /* | 2429 | /* |
| @@ -2408,7 +2431,7 @@ static void queue_trb(struct xhci_hcd *xhci, struct xhci_ring *ring, | |||
| 2408 | * FIXME allocate segments if the ring is full. | 2431 | * FIXME allocate segments if the ring is full. |
| 2409 | */ | 2432 | */ |
| 2410 | static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, | 2433 | static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, |
| 2411 | u32 ep_state, unsigned int num_trbs, gfp_t mem_flags) | 2434 | u32 ep_state, unsigned int num_trbs, bool isoc, gfp_t mem_flags) |
| 2412 | { | 2435 | { |
| 2413 | /* Make sure the endpoint has been added to xHC schedule */ | 2436 | /* Make sure the endpoint has been added to xHC schedule */ |
| 2414 | switch (ep_state) { | 2437 | switch (ep_state) { |
| @@ -2450,10 +2473,11 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring, | |||
| 2450 | next = ring->enqueue; | 2473 | next = ring->enqueue; |
| 2451 | 2474 | ||
| 2452 | while (last_trb(xhci, ring, ring->enq_seg, next)) { | 2475 | while (last_trb(xhci, ring, ring->enq_seg, next)) { |
| 2453 | /* If we're not dealing with 0.95 hardware, | 2476 | /* If we're not dealing with 0.95 hardware or isoc rings |
| 2454 | * clear the chain bit. | 2477 | * on AMD 0.96 host, clear the chain bit. |
| 2455 | */ | 2478 | */ |
| 2456 | if (!xhci_link_trb_quirk(xhci)) | 2479 | if (!xhci_link_trb_quirk(xhci) && !(isoc && |
| 2480 | (xhci->quirks & XHCI_AMD_0x96_HOST))) | ||
| 2457 | next->link.control &= cpu_to_le32(~TRB_CHAIN); | 2481 | next->link.control &= cpu_to_le32(~TRB_CHAIN); |
| 2458 | else | 2482 | else |
| 2459 | next->link.control |= cpu_to_le32(TRB_CHAIN); | 2483 | next->link.control |= cpu_to_le32(TRB_CHAIN); |
| @@ -2486,6 +2510,7 @@ static int prepare_transfer(struct xhci_hcd *xhci, | |||
| 2486 | unsigned int num_trbs, | 2510 | unsigned int num_trbs, |
| 2487 | struct urb *urb, | 2511 | struct urb *urb, |
| 2488 | unsigned int td_index, | 2512 | unsigned int td_index, |
| 2513 | bool isoc, | ||
| 2489 | gfp_t mem_flags) | 2514 | gfp_t mem_flags) |
| 2490 | { | 2515 | { |
| 2491 | int ret; | 2516 | int ret; |
| @@ -2503,7 +2528,7 @@ static int prepare_transfer(struct xhci_hcd *xhci, | |||
| 2503 | 2528 | ||
| 2504 | ret = prepare_ring(xhci, ep_ring, | 2529 | ret = prepare_ring(xhci, ep_ring, |
| 2505 | le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK, | 2530 | le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK, |
| 2506 | num_trbs, mem_flags); | 2531 | num_trbs, isoc, mem_flags); |
| 2507 | if (ret) | 2532 | if (ret) |
| 2508 | return ret; | 2533 | return ret; |
| 2509 | 2534 | ||
| @@ -2692,7 +2717,7 @@ static u32 xhci_v1_0_td_remainder(int running_total, int trb_buff_len, | |||
| 2692 | * running_total. | 2717 | * running_total. |
| 2693 | */ | 2718 | */ |
| 2694 | packets_transferred = (running_total + trb_buff_len) / | 2719 | packets_transferred = (running_total + trb_buff_len) / |
| 2695 | le16_to_cpu(urb->ep->desc.wMaxPacketSize); | 2720 | usb_endpoint_maxp(&urb->ep->desc); |
| 2696 | 2721 | ||
| 2697 | return xhci_td_remainder(total_packet_count - packets_transferred); | 2722 | return xhci_td_remainder(total_packet_count - packets_transferred); |
| 2698 | } | 2723 | } |
| @@ -2722,11 +2747,11 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
| 2722 | num_trbs = count_sg_trbs_needed(xhci, urb); | 2747 | num_trbs = count_sg_trbs_needed(xhci, urb); |
| 2723 | num_sgs = urb->num_sgs; | 2748 | num_sgs = urb->num_sgs; |
| 2724 | total_packet_count = roundup(urb->transfer_buffer_length, | 2749 | total_packet_count = roundup(urb->transfer_buffer_length, |
| 2725 | le16_to_cpu(urb->ep->desc.wMaxPacketSize)); | 2750 | usb_endpoint_maxp(&urb->ep->desc)); |
| 2726 | 2751 | ||
| 2727 | trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id], | 2752 | trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id], |
| 2728 | ep_index, urb->stream_id, | 2753 | ep_index, urb->stream_id, |
| 2729 | num_trbs, urb, 0, mem_flags); | 2754 | num_trbs, urb, 0, false, mem_flags); |
| 2730 | if (trb_buff_len < 0) | 2755 | if (trb_buff_len < 0) |
| 2731 | return trb_buff_len; | 2756 | return trb_buff_len; |
| 2732 | 2757 | ||
| @@ -2821,7 +2846,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
| 2821 | more_trbs_coming = true; | 2846 | more_trbs_coming = true; |
| 2822 | else | 2847 | else |
| 2823 | more_trbs_coming = false; | 2848 | more_trbs_coming = false; |
| 2824 | queue_trb(xhci, ep_ring, false, more_trbs_coming, | 2849 | queue_trb(xhci, ep_ring, false, more_trbs_coming, false, |
| 2825 | lower_32_bits(addr), | 2850 | lower_32_bits(addr), |
| 2826 | upper_32_bits(addr), | 2851 | upper_32_bits(addr), |
| 2827 | length_field, | 2852 | length_field, |
| @@ -2912,7 +2937,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
| 2912 | 2937 | ||
| 2913 | ret = prepare_transfer(xhci, xhci->devs[slot_id], | 2938 | ret = prepare_transfer(xhci, xhci->devs[slot_id], |
| 2914 | ep_index, urb->stream_id, | 2939 | ep_index, urb->stream_id, |
| 2915 | num_trbs, urb, 0, mem_flags); | 2940 | num_trbs, urb, 0, false, mem_flags); |
| 2916 | if (ret < 0) | 2941 | if (ret < 0) |
| 2917 | return ret; | 2942 | return ret; |
| 2918 | 2943 | ||
| @@ -2929,7 +2954,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
| 2929 | 2954 | ||
| 2930 | running_total = 0; | 2955 | running_total = 0; |
| 2931 | total_packet_count = roundup(urb->transfer_buffer_length, | 2956 | total_packet_count = roundup(urb->transfer_buffer_length, |
| 2932 | le16_to_cpu(urb->ep->desc.wMaxPacketSize)); | 2957 | usb_endpoint_maxp(&urb->ep->desc)); |
| 2933 | /* How much data is in the first TRB? */ | 2958 | /* How much data is in the first TRB? */ |
| 2934 | addr = (u64) urb->transfer_dma; | 2959 | addr = (u64) urb->transfer_dma; |
| 2935 | trb_buff_len = TRB_MAX_BUFF_SIZE - | 2960 | trb_buff_len = TRB_MAX_BUFF_SIZE - |
| @@ -2984,7 +3009,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
| 2984 | more_trbs_coming = true; | 3009 | more_trbs_coming = true; |
| 2985 | else | 3010 | else |
| 2986 | more_trbs_coming = false; | 3011 | more_trbs_coming = false; |
| 2987 | queue_trb(xhci, ep_ring, false, more_trbs_coming, | 3012 | queue_trb(xhci, ep_ring, false, more_trbs_coming, false, |
| 2988 | lower_32_bits(addr), | 3013 | lower_32_bits(addr), |
| 2989 | upper_32_bits(addr), | 3014 | upper_32_bits(addr), |
| 2990 | length_field, | 3015 | length_field, |
| @@ -3044,7 +3069,7 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
| 3044 | num_trbs++; | 3069 | num_trbs++; |
| 3045 | ret = prepare_transfer(xhci, xhci->devs[slot_id], | 3070 | ret = prepare_transfer(xhci, xhci->devs[slot_id], |
| 3046 | ep_index, urb->stream_id, | 3071 | ep_index, urb->stream_id, |
| 3047 | num_trbs, urb, 0, mem_flags); | 3072 | num_trbs, urb, 0, false, mem_flags); |
| 3048 | if (ret < 0) | 3073 | if (ret < 0) |
| 3049 | return ret; | 3074 | return ret; |
| 3050 | 3075 | ||
| @@ -3077,7 +3102,7 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
| 3077 | } | 3102 | } |
| 3078 | } | 3103 | } |
| 3079 | 3104 | ||
| 3080 | queue_trb(xhci, ep_ring, false, true, | 3105 | queue_trb(xhci, ep_ring, false, true, false, |
| 3081 | setup->bRequestType | setup->bRequest << 8 | le16_to_cpu(setup->wValue) << 16, | 3106 | setup->bRequestType | setup->bRequest << 8 | le16_to_cpu(setup->wValue) << 16, |
| 3082 | le16_to_cpu(setup->wIndex) | le16_to_cpu(setup->wLength) << 16, | 3107 | le16_to_cpu(setup->wIndex) | le16_to_cpu(setup->wLength) << 16, |
| 3083 | TRB_LEN(8) | TRB_INTR_TARGET(0), | 3108 | TRB_LEN(8) | TRB_INTR_TARGET(0), |
| @@ -3097,7 +3122,7 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
| 3097 | if (urb->transfer_buffer_length > 0) { | 3122 | if (urb->transfer_buffer_length > 0) { |
| 3098 | if (setup->bRequestType & USB_DIR_IN) | 3123 | if (setup->bRequestType & USB_DIR_IN) |
| 3099 | field |= TRB_DIR_IN; | 3124 | field |= TRB_DIR_IN; |
| 3100 | queue_trb(xhci, ep_ring, false, true, | 3125 | queue_trb(xhci, ep_ring, false, true, false, |
| 3101 | lower_32_bits(urb->transfer_dma), | 3126 | lower_32_bits(urb->transfer_dma), |
| 3102 | upper_32_bits(urb->transfer_dma), | 3127 | upper_32_bits(urb->transfer_dma), |
| 3103 | length_field, | 3128 | length_field, |
| @@ -3113,7 +3138,7 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
| 3113 | field = 0; | 3138 | field = 0; |
| 3114 | else | 3139 | else |
| 3115 | field = TRB_DIR_IN; | 3140 | field = TRB_DIR_IN; |
| 3116 | queue_trb(xhci, ep_ring, false, false, | 3141 | queue_trb(xhci, ep_ring, false, false, false, |
| 3117 | 0, | 3142 | 0, |
| 3118 | 0, | 3143 | 0, |
| 3119 | TRB_INTR_TARGET(0), | 3144 | TRB_INTR_TARGET(0), |
| @@ -3250,7 +3275,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
| 3250 | td_len = urb->iso_frame_desc[i].length; | 3275 | td_len = urb->iso_frame_desc[i].length; |
| 3251 | td_remain_len = td_len; | 3276 | td_remain_len = td_len; |
| 3252 | total_packet_count = roundup(td_len, | 3277 | total_packet_count = roundup(td_len, |
| 3253 | le16_to_cpu(urb->ep->desc.wMaxPacketSize)); | 3278 | usb_endpoint_maxp(&urb->ep->desc)); |
| 3254 | /* A zero-length transfer still involves at least one packet. */ | 3279 | /* A zero-length transfer still involves at least one packet. */ |
| 3255 | if (total_packet_count == 0) | 3280 | if (total_packet_count == 0) |
| 3256 | total_packet_count++; | 3281 | total_packet_count++; |
| @@ -3262,7 +3287,8 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
| 3262 | trbs_per_td = count_isoc_trbs_needed(xhci, urb, i); | 3287 | trbs_per_td = count_isoc_trbs_needed(xhci, urb, i); |
| 3263 | 3288 | ||
| 3264 | ret = prepare_transfer(xhci, xhci->devs[slot_id], ep_index, | 3289 | ret = prepare_transfer(xhci, xhci->devs[slot_id], ep_index, |
| 3265 | urb->stream_id, trbs_per_td, urb, i, mem_flags); | 3290 | urb->stream_id, trbs_per_td, urb, i, true, |
| 3291 | mem_flags); | ||
| 3266 | if (ret < 0) { | 3292 | if (ret < 0) { |
| 3267 | if (i == 0) | 3293 | if (i == 0) |
| 3268 | return ret; | 3294 | return ret; |
| @@ -3332,7 +3358,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
| 3332 | remainder | | 3358 | remainder | |
| 3333 | TRB_INTR_TARGET(0); | 3359 | TRB_INTR_TARGET(0); |
| 3334 | 3360 | ||
| 3335 | queue_trb(xhci, ep_ring, false, more_trbs_coming, | 3361 | queue_trb(xhci, ep_ring, false, more_trbs_coming, true, |
| 3336 | lower_32_bits(addr), | 3362 | lower_32_bits(addr), |
| 3337 | upper_32_bits(addr), | 3363 | upper_32_bits(addr), |
| 3338 | length_field, | 3364 | length_field, |
| @@ -3414,7 +3440,7 @@ int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags, | |||
| 3414 | * Do not insert any td of the urb to the ring if the check failed. | 3440 | * Do not insert any td of the urb to the ring if the check failed. |
| 3415 | */ | 3441 | */ |
| 3416 | ret = prepare_ring(xhci, ep_ring, le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK, | 3442 | ret = prepare_ring(xhci, ep_ring, le32_to_cpu(ep_ctx->ep_info) & EP_STATE_MASK, |
| 3417 | num_trbs, mem_flags); | 3443 | num_trbs, true, mem_flags); |
| 3418 | if (ret) | 3444 | if (ret) |
| 3419 | return ret; | 3445 | return ret; |
| 3420 | 3446 | ||
| @@ -3473,7 +3499,7 @@ static int queue_command(struct xhci_hcd *xhci, u32 field1, u32 field2, | |||
| 3473 | reserved_trbs++; | 3499 | reserved_trbs++; |
| 3474 | 3500 | ||
| 3475 | ret = prepare_ring(xhci, xhci->cmd_ring, EP_STATE_RUNNING, | 3501 | ret = prepare_ring(xhci, xhci->cmd_ring, EP_STATE_RUNNING, |
| 3476 | reserved_trbs, GFP_ATOMIC); | 3502 | reserved_trbs, false, GFP_ATOMIC); |
| 3477 | if (ret < 0) { | 3503 | if (ret < 0) { |
| 3478 | xhci_err(xhci, "ERR: No room for command on command ring\n"); | 3504 | xhci_err(xhci, "ERR: No room for command on command ring\n"); |
| 3479 | if (command_must_succeed) | 3505 | if (command_must_succeed) |
| @@ -3481,8 +3507,8 @@ static int queue_command(struct xhci_hcd *xhci, u32 field1, u32 field2, | |||
| 3481 | "unfailable commands failed.\n"); | 3507 | "unfailable commands failed.\n"); |
| 3482 | return ret; | 3508 | return ret; |
| 3483 | } | 3509 | } |
| 3484 | queue_trb(xhci, xhci->cmd_ring, false, false, field1, field2, field3, | 3510 | queue_trb(xhci, xhci->cmd_ring, false, false, false, field1, field2, |
| 3485 | field4 | xhci->cmd_ring->cycle_state); | 3511 | field3, field4 | xhci->cmd_ring->cycle_state); |
| 3486 | return 0; | 3512 | return 0; |
| 3487 | } | 3513 | } |
| 3488 | 3514 | ||
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 3a0f695138f4..aa94c0195791 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c | |||
| @@ -175,28 +175,19 @@ int xhci_reset(struct xhci_hcd *xhci) | |||
| 175 | return handshake(xhci, &xhci->op_regs->status, STS_CNR, 0, 250 * 1000); | 175 | return handshake(xhci, &xhci->op_regs->status, STS_CNR, 0, 250 * 1000); |
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | /* | 178 | #ifdef CONFIG_PCI |
| 179 | * Free IRQs | 179 | static int xhci_free_msi(struct xhci_hcd *xhci) |
| 180 | * free all IRQs request | ||
| 181 | */ | ||
| 182 | static void xhci_free_irq(struct xhci_hcd *xhci) | ||
| 183 | { | 180 | { |
| 184 | int i; | 181 | int i; |
| 185 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); | ||
| 186 | 182 | ||
| 187 | /* return if using legacy interrupt */ | 183 | if (!xhci->msix_entries) |
| 188 | if (xhci_to_hcd(xhci)->irq >= 0) | 184 | return -EINVAL; |
| 189 | return; | ||
| 190 | |||
| 191 | if (xhci->msix_entries) { | ||
| 192 | for (i = 0; i < xhci->msix_count; i++) | ||
| 193 | if (xhci->msix_entries[i].vector) | ||
| 194 | free_irq(xhci->msix_entries[i].vector, | ||
| 195 | xhci_to_hcd(xhci)); | ||
| 196 | } else if (pdev->irq >= 0) | ||
| 197 | free_irq(pdev->irq, xhci_to_hcd(xhci)); | ||
| 198 | 185 | ||
| 199 | return; | 186 | for (i = 0; i < xhci->msix_count; i++) |
| 187 | if (xhci->msix_entries[i].vector) | ||
| 188 | free_irq(xhci->msix_entries[i].vector, | ||
| 189 | xhci_to_hcd(xhci)); | ||
| 190 | return 0; | ||
| 200 | } | 191 | } |
| 201 | 192 | ||
| 202 | /* | 193 | /* |
| @@ -224,6 +215,28 @@ static int xhci_setup_msi(struct xhci_hcd *xhci) | |||
| 224 | } | 215 | } |
| 225 | 216 | ||
| 226 | /* | 217 | /* |
| 218 | * Free IRQs | ||
| 219 | * free all IRQs request | ||
| 220 | */ | ||
| 221 | static void xhci_free_irq(struct xhci_hcd *xhci) | ||
| 222 | { | ||
| 223 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); | ||
| 224 | int ret; | ||
| 225 | |||
| 226 | /* return if using legacy interrupt */ | ||
| 227 | if (xhci_to_hcd(xhci)->irq >= 0) | ||
| 228 | return; | ||
| 229 | |||
| 230 | ret = xhci_free_msi(xhci); | ||
| 231 | if (!ret) | ||
| 232 | return; | ||
| 233 | if (pdev->irq >= 0) | ||
| 234 | free_irq(pdev->irq, xhci_to_hcd(xhci)); | ||
| 235 | |||
| 236 | return; | ||
| 237 | } | ||
| 238 | |||
| 239 | /* | ||
| 227 | * Set up MSI-X | 240 | * Set up MSI-X |
| 228 | */ | 241 | */ |
| 229 | static int xhci_setup_msix(struct xhci_hcd *xhci) | 242 | static int xhci_setup_msix(struct xhci_hcd *xhci) |
| @@ -302,6 +315,72 @@ static void xhci_cleanup_msix(struct xhci_hcd *xhci) | |||
| 302 | return; | 315 | return; |
| 303 | } | 316 | } |
| 304 | 317 | ||
| 318 | static void xhci_msix_sync_irqs(struct xhci_hcd *xhci) | ||
| 319 | { | ||
| 320 | int i; | ||
| 321 | |||
| 322 | if (xhci->msix_entries) { | ||
| 323 | for (i = 0; i < xhci->msix_count; i++) | ||
| 324 | synchronize_irq(xhci->msix_entries[i].vector); | ||
| 325 | } | ||
| 326 | } | ||
| 327 | |||
| 328 | static int xhci_try_enable_msi(struct usb_hcd *hcd) | ||
| 329 | { | ||
| 330 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | ||
| 331 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); | ||
| 332 | int ret; | ||
| 333 | |||
| 334 | /* | ||
| 335 | * Some Fresco Logic host controllers advertise MSI, but fail to | ||
| 336 | * generate interrupts. Don't even try to enable MSI. | ||
| 337 | */ | ||
| 338 | if (xhci->quirks & XHCI_BROKEN_MSI) | ||
| 339 | return 0; | ||
| 340 | |||
| 341 | /* unregister the legacy interrupt */ | ||
| 342 | if (hcd->irq) | ||
| 343 | free_irq(hcd->irq, hcd); | ||
| 344 | hcd->irq = -1; | ||
| 345 | |||
| 346 | ret = xhci_setup_msix(xhci); | ||
| 347 | if (ret) | ||
| 348 | /* fall back to msi*/ | ||
| 349 | ret = xhci_setup_msi(xhci); | ||
| 350 | |||
| 351 | if (!ret) | ||
| 352 | /* hcd->irq is -1, we have MSI */ | ||
| 353 | return 0; | ||
| 354 | |||
| 355 | /* fall back to legacy interrupt*/ | ||
| 356 | ret = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED, | ||
| 357 | hcd->irq_descr, hcd); | ||
| 358 | if (ret) { | ||
| 359 | xhci_err(xhci, "request interrupt %d failed\n", | ||
| 360 | pdev->irq); | ||
| 361 | return ret; | ||
| 362 | } | ||
| 363 | hcd->irq = pdev->irq; | ||
| 364 | return 0; | ||
| 365 | } | ||
| 366 | |||
| 367 | #else | ||
| 368 | |||
| 369 | static int xhci_try_enable_msi(struct usb_hcd *hcd) | ||
| 370 | { | ||
| 371 | return 0; | ||
| 372 | } | ||
| 373 | |||
| 374 | static void xhci_cleanup_msix(struct xhci_hcd *xhci) | ||
| 375 | { | ||
| 376 | } | ||
| 377 | |||
| 378 | static void xhci_msix_sync_irqs(struct xhci_hcd *xhci) | ||
| 379 | { | ||
| 380 | } | ||
| 381 | |||
| 382 | #endif | ||
| 383 | |||
| 305 | /* | 384 | /* |
| 306 | * Initialize memory for HCD and xHC (one-time init). | 385 | * Initialize memory for HCD and xHC (one-time init). |
| 307 | * | 386 | * |
| @@ -316,7 +395,7 @@ int xhci_init(struct usb_hcd *hcd) | |||
| 316 | 395 | ||
| 317 | xhci_dbg(xhci, "xhci_init\n"); | 396 | xhci_dbg(xhci, "xhci_init\n"); |
| 318 | spin_lock_init(&xhci->lock); | 397 | spin_lock_init(&xhci->lock); |
| 319 | if (link_quirk) { | 398 | if (xhci->hci_version == 0x95 && link_quirk) { |
| 320 | xhci_dbg(xhci, "QUIRK: Not clearing Link TRB chain bits.\n"); | 399 | xhci_dbg(xhci, "QUIRK: Not clearing Link TRB chain bits.\n"); |
| 321 | xhci->quirks |= XHCI_LINK_TRB_QUIRK; | 400 | xhci->quirks |= XHCI_LINK_TRB_QUIRK; |
| 322 | } else { | 401 | } else { |
| @@ -413,9 +492,8 @@ int xhci_run(struct usb_hcd *hcd) | |||
| 413 | { | 492 | { |
| 414 | u32 temp; | 493 | u32 temp; |
| 415 | u64 temp_64; | 494 | u64 temp_64; |
| 416 | u32 ret; | 495 | int ret; |
| 417 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 496 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 418 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); | ||
| 419 | 497 | ||
| 420 | /* Start the xHCI host controller running only after the USB 2.0 roothub | 498 | /* Start the xHCI host controller running only after the USB 2.0 roothub |
| 421 | * is setup. | 499 | * is setup. |
| @@ -426,34 +504,10 @@ int xhci_run(struct usb_hcd *hcd) | |||
| 426 | return xhci_run_finished(xhci); | 504 | return xhci_run_finished(xhci); |
| 427 | 505 | ||
| 428 | xhci_dbg(xhci, "xhci_run\n"); | 506 | xhci_dbg(xhci, "xhci_run\n"); |
| 429 | /* unregister the legacy interrupt */ | ||
| 430 | if (hcd->irq) | ||
| 431 | free_irq(hcd->irq, hcd); | ||
| 432 | hcd->irq = -1; | ||
| 433 | 507 | ||
| 434 | /* Some Fresco Logic host controllers advertise MSI, but fail to | 508 | ret = xhci_try_enable_msi(hcd); |
| 435 | * generate interrupts. Don't even try to enable MSI. | ||
| 436 | */ | ||
| 437 | if (xhci->quirks & XHCI_BROKEN_MSI) | ||
| 438 | goto legacy_irq; | ||
| 439 | |||
| 440 | ret = xhci_setup_msix(xhci); | ||
| 441 | if (ret) | 509 | if (ret) |
| 442 | /* fall back to msi*/ | 510 | return ret; |
| 443 | ret = xhci_setup_msi(xhci); | ||
| 444 | |||
| 445 | if (ret) { | ||
| 446 | legacy_irq: | ||
| 447 | /* fall back to legacy interrupt*/ | ||
| 448 | ret = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED, | ||
| 449 | hcd->irq_descr, hcd); | ||
| 450 | if (ret) { | ||
| 451 | xhci_err(xhci, "request interrupt %d failed\n", | ||
| 452 | pdev->irq); | ||
| 453 | return ret; | ||
| 454 | } | ||
| 455 | hcd->irq = pdev->irq; | ||
| 456 | } | ||
| 457 | 511 | ||
| 458 | #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING | 512 | #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING |
| 459 | init_timer(&xhci->event_ring_timer); | 513 | init_timer(&xhci->event_ring_timer); |
| @@ -694,7 +748,6 @@ int xhci_suspend(struct xhci_hcd *xhci) | |||
| 694 | int rc = 0; | 748 | int rc = 0; |
| 695 | struct usb_hcd *hcd = xhci_to_hcd(xhci); | 749 | struct usb_hcd *hcd = xhci_to_hcd(xhci); |
| 696 | u32 command; | 750 | u32 command; |
| 697 | int i; | ||
| 698 | 751 | ||
| 699 | spin_lock_irq(&xhci->lock); | 752 | spin_lock_irq(&xhci->lock); |
| 700 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 753 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
| @@ -730,10 +783,7 @@ int xhci_suspend(struct xhci_hcd *xhci) | |||
| 730 | 783 | ||
| 731 | /* step 5: remove core well power */ | 784 | /* step 5: remove core well power */ |
| 732 | /* synchronize irq when using MSI-X */ | 785 | /* synchronize irq when using MSI-X */ |
| 733 | if (xhci->msix_entries) { | 786 | xhci_msix_sync_irqs(xhci); |
| 734 | for (i = 0; i < xhci->msix_count; i++) | ||
| 735 | synchronize_irq(xhci->msix_entries[i].vector); | ||
| 736 | } | ||
| 737 | 787 | ||
| 738 | return rc; | 788 | return rc; |
| 739 | } | 789 | } |
| @@ -749,7 +799,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) | |||
| 749 | u32 command, temp = 0; | 799 | u32 command, temp = 0; |
| 750 | struct usb_hcd *hcd = xhci_to_hcd(xhci); | 800 | struct usb_hcd *hcd = xhci_to_hcd(xhci); |
| 751 | struct usb_hcd *secondary_hcd; | 801 | struct usb_hcd *secondary_hcd; |
| 752 | int retval; | 802 | int retval = 0; |
| 753 | 803 | ||
| 754 | /* Wait a bit if either of the roothubs need to settle from the | 804 | /* Wait a bit if either of the roothubs need to settle from the |
| 755 | * transition into bus suspend. | 805 | * transition into bus suspend. |
| @@ -759,6 +809,9 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) | |||
| 759 | xhci->bus_state[1].next_statechange)) | 809 | xhci->bus_state[1].next_statechange)) |
| 760 | msleep(100); | 810 | msleep(100); |
| 761 | 811 | ||
| 812 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | ||
| 813 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); | ||
| 814 | |||
| 762 | spin_lock_irq(&xhci->lock); | 815 | spin_lock_irq(&xhci->lock); |
| 763 | if (xhci->quirks & XHCI_RESET_ON_RESUME) | 816 | if (xhci->quirks & XHCI_RESET_ON_RESUME) |
| 764 | hibernated = true; | 817 | hibernated = true; |
| @@ -828,20 +881,13 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) | |||
| 828 | return retval; | 881 | return retval; |
| 829 | xhci_dbg(xhci, "Start the primary HCD\n"); | 882 | xhci_dbg(xhci, "Start the primary HCD\n"); |
| 830 | retval = xhci_run(hcd->primary_hcd); | 883 | retval = xhci_run(hcd->primary_hcd); |
| 831 | if (retval) | ||
| 832 | goto failed_restart; | ||
| 833 | |||
| 834 | xhci_dbg(xhci, "Start the secondary HCD\n"); | ||
| 835 | retval = xhci_run(secondary_hcd); | ||
| 836 | if (!retval) { | 884 | if (!retval) { |
| 837 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 885 | xhci_dbg(xhci, "Start the secondary HCD\n"); |
| 838 | set_bit(HCD_FLAG_HW_ACCESSIBLE, | 886 | retval = xhci_run(secondary_hcd); |
| 839 | &xhci->shared_hcd->flags); | ||
| 840 | } | 887 | } |
| 841 | failed_restart: | ||
| 842 | hcd->state = HC_STATE_SUSPENDED; | 888 | hcd->state = HC_STATE_SUSPENDED; |
| 843 | xhci->shared_hcd->state = HC_STATE_SUSPENDED; | 889 | xhci->shared_hcd->state = HC_STATE_SUSPENDED; |
| 844 | return retval; | 890 | goto done; |
| 845 | } | 891 | } |
| 846 | 892 | ||
| 847 | /* step 4: set Run/Stop bit */ | 893 | /* step 4: set Run/Stop bit */ |
| @@ -860,11 +906,14 @@ failed_restart: | |||
| 860 | * Running endpoints by ringing their doorbells | 906 | * Running endpoints by ringing their doorbells |
| 861 | */ | 907 | */ |
| 862 | 908 | ||
| 863 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | ||
| 864 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &xhci->shared_hcd->flags); | ||
| 865 | |||
| 866 | spin_unlock_irq(&xhci->lock); | 909 | spin_unlock_irq(&xhci->lock); |
| 867 | return 0; | 910 | |
| 911 | done: | ||
| 912 | if (retval == 0) { | ||
| 913 | usb_hcd_resume_root_hub(hcd); | ||
| 914 | usb_hcd_resume_root_hub(xhci->shared_hcd); | ||
| 915 | } | ||
| 916 | return retval; | ||
| 868 | } | 917 | } |
| 869 | #endif /* CONFIG_PM */ | 918 | #endif /* CONFIG_PM */ |
| 870 | 919 | ||
| @@ -945,8 +994,7 @@ static int xhci_check_args(struct usb_hcd *hcd, struct usb_device *udev, | |||
| 945 | return -ENODEV; | 994 | return -ENODEV; |
| 946 | 995 | ||
| 947 | if (check_virt_dev) { | 996 | if (check_virt_dev) { |
| 948 | if (!udev->slot_id || !xhci->devs | 997 | if (!udev->slot_id || !xhci->devs[udev->slot_id]) { |
| 949 | || !xhci->devs[udev->slot_id]) { | ||
| 950 | printk(KERN_DEBUG "xHCI %s called with unaddressed " | 998 | printk(KERN_DEBUG "xHCI %s called with unaddressed " |
| 951 | "device\n", func); | 999 | "device\n", func); |
| 952 | return -EINVAL; | 1000 | return -EINVAL; |
| @@ -987,7 +1035,7 @@ static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id, | |||
| 987 | out_ctx = xhci->devs[slot_id]->out_ctx; | 1035 | out_ctx = xhci->devs[slot_id]->out_ctx; |
| 988 | ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); | 1036 | ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); |
| 989 | hw_max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2)); | 1037 | hw_max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2)); |
| 990 | max_packet_size = le16_to_cpu(urb->dev->ep0.desc.wMaxPacketSize); | 1038 | max_packet_size = usb_endpoint_maxp(&urb->dev->ep0.desc); |
| 991 | if (hw_max_packet_size != max_packet_size) { | 1039 | if (hw_max_packet_size != max_packet_size) { |
| 992 | xhci_dbg(xhci, "Max Packet Size for ep 0 changed.\n"); | 1040 | xhci_dbg(xhci, "Max Packet Size for ep 0 changed.\n"); |
| 993 | xhci_dbg(xhci, "Max packet size in usb_device = %d\n", | 1041 | xhci_dbg(xhci, "Max packet size in usb_device = %d\n", |
| @@ -1035,6 +1083,7 @@ static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id, | |||
| 1035 | int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) | 1083 | int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) |
| 1036 | { | 1084 | { |
| 1037 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | 1085 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); |
| 1086 | struct xhci_td *buffer; | ||
| 1038 | unsigned long flags; | 1087 | unsigned long flags; |
| 1039 | int ret = 0; | 1088 | int ret = 0; |
| 1040 | unsigned int slot_id, ep_index; | 1089 | unsigned int slot_id, ep_index; |
| @@ -1065,13 +1114,15 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) | |||
| 1065 | if (!urb_priv) | 1114 | if (!urb_priv) |
| 1066 | return -ENOMEM; | 1115 | return -ENOMEM; |
| 1067 | 1116 | ||
| 1117 | buffer = kzalloc(size * sizeof(struct xhci_td), mem_flags); | ||
| 1118 | if (!buffer) { | ||
| 1119 | kfree(urb_priv); | ||
| 1120 | return -ENOMEM; | ||
| 1121 | } | ||
| 1122 | |||
| 1068 | for (i = 0; i < size; i++) { | 1123 | for (i = 0; i < size; i++) { |
| 1069 | urb_priv->td[i] = kzalloc(sizeof(struct xhci_td), mem_flags); | 1124 | urb_priv->td[i] = buffer; |
| 1070 | if (!urb_priv->td[i]) { | 1125 | buffer++; |
| 1071 | urb_priv->length = i; | ||
| 1072 | xhci_urb_free_priv(xhci, urb_priv); | ||
| 1073 | return -ENOMEM; | ||
| 1074 | } | ||
| 1075 | } | 1126 | } |
| 1076 | 1127 | ||
| 1077 | urb_priv->length = size; | 1128 | urb_priv->length = size; |
| @@ -1747,6 +1798,564 @@ static void xhci_finish_resource_reservation(struct xhci_hcd *xhci, | |||
| 1747 | xhci->num_active_eps); | 1798 | xhci->num_active_eps); |
| 1748 | } | 1799 | } |
| 1749 | 1800 | ||
| 1801 | unsigned int xhci_get_block_size(struct usb_device *udev) | ||
| 1802 | { | ||
| 1803 | switch (udev->speed) { | ||
| 1804 | case USB_SPEED_LOW: | ||
| 1805 | case USB_SPEED_FULL: | ||
| 1806 | return FS_BLOCK; | ||
| 1807 | case USB_SPEED_HIGH: | ||
| 1808 | return HS_BLOCK; | ||
| 1809 | case USB_SPEED_SUPER: | ||
| 1810 | return SS_BLOCK; | ||
| 1811 | case USB_SPEED_UNKNOWN: | ||
| 1812 | case USB_SPEED_WIRELESS: | ||
| 1813 | default: | ||
| 1814 | /* Should never happen */ | ||
| 1815 | return 1; | ||
| 1816 | } | ||
| 1817 | } | ||
| 1818 | |||
| 1819 | unsigned int xhci_get_largest_overhead(struct xhci_interval_bw *interval_bw) | ||
| 1820 | { | ||
| 1821 | if (interval_bw->overhead[LS_OVERHEAD_TYPE]) | ||
| 1822 | return LS_OVERHEAD; | ||
| 1823 | if (interval_bw->overhead[FS_OVERHEAD_TYPE]) | ||
| 1824 | return FS_OVERHEAD; | ||
| 1825 | return HS_OVERHEAD; | ||
| 1826 | } | ||
| 1827 | |||
| 1828 | /* If we are changing a LS/FS device under a HS hub, | ||
| 1829 | * make sure (if we are activating a new TT) that the HS bus has enough | ||
| 1830 | * bandwidth for this new TT. | ||
| 1831 | */ | ||
| 1832 | static int xhci_check_tt_bw_table(struct xhci_hcd *xhci, | ||
| 1833 | struct xhci_virt_device *virt_dev, | ||
| 1834 | int old_active_eps) | ||
| 1835 | { | ||
| 1836 | struct xhci_interval_bw_table *bw_table; | ||
| 1837 | struct xhci_tt_bw_info *tt_info; | ||
| 1838 | |||
| 1839 | /* Find the bandwidth table for the root port this TT is attached to. */ | ||
| 1840 | bw_table = &xhci->rh_bw[virt_dev->real_port - 1].bw_table; | ||
| 1841 | tt_info = virt_dev->tt_info; | ||
| 1842 | /* If this TT already had active endpoints, the bandwidth for this TT | ||
| 1843 | * has already been added. Removing all periodic endpoints (and thus | ||
| 1844 | * making the TT enactive) will only decrease the bandwidth used. | ||
| 1845 | */ | ||
| 1846 | if (old_active_eps) | ||
| 1847 | return 0; | ||
| 1848 | if (old_active_eps == 0 && tt_info->active_eps != 0) { | ||
| 1849 | if (bw_table->bw_used + TT_HS_OVERHEAD > HS_BW_LIMIT) | ||
| 1850 | return -ENOMEM; | ||
| 1851 | return 0; | ||
| 1852 | } | ||
| 1853 | /* Not sure why we would have no new active endpoints... | ||
| 1854 | * | ||
| 1855 | * Maybe because of an Evaluate Context change for a hub update or a | ||
| 1856 | * control endpoint 0 max packet size change? | ||
| 1857 | * FIXME: skip the bandwidth calculation in that case. | ||
| 1858 | */ | ||
| 1859 | return 0; | ||
| 1860 | } | ||
| 1861 | |||
| 1862 | static int xhci_check_ss_bw(struct xhci_hcd *xhci, | ||
| 1863 | struct xhci_virt_device *virt_dev) | ||
| 1864 | { | ||
| 1865 | unsigned int bw_reserved; | ||
| 1866 | |||
| 1867 | bw_reserved = DIV_ROUND_UP(SS_BW_RESERVED*SS_BW_LIMIT_IN, 100); | ||
| 1868 | if (virt_dev->bw_table->ss_bw_in > (SS_BW_LIMIT_IN - bw_reserved)) | ||
| 1869 | return -ENOMEM; | ||
| 1870 | |||
| 1871 | bw_reserved = DIV_ROUND_UP(SS_BW_RESERVED*SS_BW_LIMIT_OUT, 100); | ||
| 1872 | if (virt_dev->bw_table->ss_bw_out > (SS_BW_LIMIT_OUT - bw_reserved)) | ||
| 1873 | return -ENOMEM; | ||
| 1874 | |||
| 1875 | return 0; | ||
| 1876 | } | ||
| 1877 | |||
| 1878 | /* | ||
| 1879 | * This algorithm is a very conservative estimate of the worst-case scheduling | ||
| 1880 | * scenario for any one interval. The hardware dynamically schedules the | ||
| 1881 | * packets, so we can't tell which microframe could be the limiting factor in | ||
| 1882 | * the bandwidth scheduling. This only takes into account periodic endpoints. | ||
| 1883 | * | ||
| 1884 | * Obviously, we can't solve an NP complete problem to find the minimum worst | ||
| 1885 | * case scenario. Instead, we come up with an estimate that is no less than | ||
| 1886 | * the worst case bandwidth used for any one microframe, but may be an | ||
| 1887 | * over-estimate. | ||
| 1888 | * | ||
| 1889 | * We walk the requirements for each endpoint by interval, starting with the | ||
| 1890 | * smallest interval, and place packets in the schedule where there is only one | ||
| 1891 | * possible way to schedule packets for that interval. In order to simplify | ||
| 1892 | * this algorithm, we record the largest max packet size for each interval, and | ||
| 1893 | * assume all packets will be that size. | ||
| 1894 | * | ||
| 1895 | * For interval 0, we obviously must schedule all packets for each interval. | ||
| 1896 | * The bandwidth for interval 0 is just the amount of data to be transmitted | ||
| 1897 | * (the sum of all max ESIT payload sizes, plus any overhead per packet times | ||
| 1898 | * the number of packets). | ||
| 1899 | * | ||
| 1900 | * For interval 1, we have two possible microframes to schedule those packets | ||
| 1901 | * in. For this algorithm, if we can schedule the same number of packets for | ||
| 1902 | * each possible scheduling opportunity (each microframe), we will do so. The | ||
| 1903 | * remaining number of packets will be saved to be transmitted in the gaps in | ||
| 1904 | * the next interval's scheduling sequence. | ||
| 1905 | * | ||
| 1906 | * As we move those remaining packets to be scheduled with interval 2 packets, | ||
| 1907 | * we have to double the number of remaining packets to transmit. This is | ||
| 1908 | * because the intervals are actually powers of 2, and we would be transmitting | ||
| 1909 | * the previous interval's packets twice in this interval. We also have to be | ||
| 1910 | * sure that when we look at the largest max packet size for this interval, we | ||
| 1911 | * also look at the largest max packet size for the remaining packets and take | ||
| 1912 | * the greater of the two. | ||
| 1913 | * | ||
| 1914 | * The algorithm continues to evenly distribute packets in each scheduling | ||
| 1915 | * opportunity, and push the remaining packets out, until we get to the last | ||
| 1916 | * interval. Then those packets and their associated overhead are just added | ||
| 1917 | * to the bandwidth used. | ||
| 1918 | */ | ||
| 1919 | static int xhci_check_bw_table(struct xhci_hcd *xhci, | ||
| 1920 | struct xhci_virt_device *virt_dev, | ||
| 1921 | int old_active_eps) | ||
| 1922 | { | ||
| 1923 | unsigned int bw_reserved; | ||
| 1924 | unsigned int max_bandwidth; | ||
| 1925 | unsigned int bw_used; | ||
| 1926 | unsigned int block_size; | ||
| 1927 | struct xhci_interval_bw_table *bw_table; | ||
| 1928 | unsigned int packet_size = 0; | ||
| 1929 | unsigned int overhead = 0; | ||
| 1930 | unsigned int packets_transmitted = 0; | ||
| 1931 | unsigned int packets_remaining = 0; | ||
| 1932 | unsigned int i; | ||
| 1933 | |||
| 1934 | if (virt_dev->udev->speed == USB_SPEED_SUPER) | ||
| 1935 | return xhci_check_ss_bw(xhci, virt_dev); | ||
| 1936 | |||
| 1937 | if (virt_dev->udev->speed == USB_SPEED_HIGH) { | ||
| 1938 | max_bandwidth = HS_BW_LIMIT; | ||
| 1939 | /* Convert percent of bus BW reserved to blocks reserved */ | ||
| 1940 | bw_reserved = DIV_ROUND_UP(HS_BW_RESERVED * max_bandwidth, 100); | ||
| 1941 | } else { | ||
| 1942 | max_bandwidth = FS_BW_LIMIT; | ||
| 1943 | bw_reserved = DIV_ROUND_UP(FS_BW_RESERVED * max_bandwidth, 100); | ||
| 1944 | } | ||
| 1945 | |||
| 1946 | bw_table = virt_dev->bw_table; | ||
| 1947 | /* We need to translate the max packet size and max ESIT payloads into | ||
| 1948 | * the units the hardware uses. | ||
| 1949 | */ | ||
| 1950 | block_size = xhci_get_block_size(virt_dev->udev); | ||
| 1951 | |||
| 1952 | /* If we are manipulating a LS/FS device under a HS hub, double check | ||
| 1953 | * that the HS bus has enough bandwidth if we are activing a new TT. | ||
| 1954 | */ | ||
| 1955 | if (virt_dev->tt_info) { | ||
| 1956 | xhci_dbg(xhci, "Recalculating BW for rootport %u\n", | ||
| 1957 | virt_dev->real_port); | ||
| 1958 | if (xhci_check_tt_bw_table(xhci, virt_dev, old_active_eps)) { | ||
| 1959 | xhci_warn(xhci, "Not enough bandwidth on HS bus for " | ||
| 1960 | "newly activated TT.\n"); | ||
| 1961 | return -ENOMEM; | ||
| 1962 | } | ||
| 1963 | xhci_dbg(xhci, "Recalculating BW for TT slot %u port %u\n", | ||
| 1964 | virt_dev->tt_info->slot_id, | ||
| 1965 | virt_dev->tt_info->ttport); | ||
| 1966 | } else { | ||
| 1967 | xhci_dbg(xhci, "Recalculating BW for rootport %u\n", | ||
| 1968 | virt_dev->real_port); | ||
| 1969 | } | ||
| 1970 | |||
| 1971 | /* Add in how much bandwidth will be used for interval zero, or the | ||
| 1972 | * rounded max ESIT payload + number of packets * largest overhead. | ||
| 1973 | */ | ||
| 1974 | bw_used = DIV_ROUND_UP(bw_table->interval0_esit_payload, block_size) + | ||
| 1975 | bw_table->interval_bw[0].num_packets * | ||
| 1976 | xhci_get_largest_overhead(&bw_table->interval_bw[0]); | ||
| 1977 | |||
| 1978 | for (i = 1; i < XHCI_MAX_INTERVAL; i++) { | ||
| 1979 | unsigned int bw_added; | ||
| 1980 | unsigned int largest_mps; | ||
| 1981 | unsigned int interval_overhead; | ||
| 1982 | |||
| 1983 | /* | ||
| 1984 | * How many packets could we transmit in this interval? | ||
| 1985 | * If packets didn't fit in the previous interval, we will need | ||
| 1986 | * to transmit that many packets twice within this interval. | ||
| 1987 | */ | ||
| 1988 | packets_remaining = 2 * packets_remaining + | ||
| 1989 | bw_table->interval_bw[i].num_packets; | ||
| 1990 | |||
| 1991 | /* Find the largest max packet size of this or the previous | ||
| 1992 | * interval. | ||
| 1993 | */ | ||
| 1994 | if (list_empty(&bw_table->interval_bw[i].endpoints)) | ||
| 1995 | largest_mps = 0; | ||
| 1996 | else { | ||
| 1997 | struct xhci_virt_ep *virt_ep; | ||
| 1998 | struct list_head *ep_entry; | ||
| 1999 | |||
| 2000 | ep_entry = bw_table->interval_bw[i].endpoints.next; | ||
| 2001 | virt_ep = list_entry(ep_entry, | ||
| 2002 | struct xhci_virt_ep, bw_endpoint_list); | ||
| 2003 | /* Convert to blocks, rounding up */ | ||
| 2004 | largest_mps = DIV_ROUND_UP( | ||
| 2005 | virt_ep->bw_info.max_packet_size, | ||
| 2006 | block_size); | ||
| 2007 | } | ||
| 2008 | if (largest_mps > packet_size) | ||
| 2009 | packet_size = largest_mps; | ||
| 2010 | |||
| 2011 | /* Use the larger overhead of this or the previous interval. */ | ||
| 2012 | interval_overhead = xhci_get_largest_overhead( | ||
| 2013 | &bw_table->interval_bw[i]); | ||
| 2014 | if (interval_overhead > overhead) | ||
| 2015 | overhead = interval_overhead; | ||
| 2016 | |||
| 2017 | /* How many packets can we evenly distribute across | ||
| 2018 | * (1 << (i + 1)) possible scheduling opportunities? | ||
| 2019 | */ | ||
| 2020 | packets_transmitted = packets_remaining >> (i + 1); | ||
| 2021 | |||
| 2022 | /* Add in the bandwidth used for those scheduled packets */ | ||
| 2023 | bw_added = packets_transmitted * (overhead + packet_size); | ||
| 2024 | |||
| 2025 | /* How many packets do we have remaining to transmit? */ | ||
| 2026 | packets_remaining = packets_remaining % (1 << (i + 1)); | ||
| 2027 | |||
| 2028 | /* What largest max packet size should those packets have? */ | ||
| 2029 | /* If we've transmitted all packets, don't carry over the | ||
| 2030 | * largest packet size. | ||
| 2031 | */ | ||
| 2032 | if (packets_remaining == 0) { | ||
| 2033 | packet_size = 0; | ||
| 2034 | overhead = 0; | ||
| 2035 | } else if (packets_transmitted > 0) { | ||
| 2036 | /* Otherwise if we do have remaining packets, and we've | ||
| 2037 | * scheduled some packets in this interval, take the | ||
| 2038 | * largest max packet size from endpoints with this | ||
| 2039 | * interval. | ||
| 2040 | */ | ||
| 2041 | packet_size = largest_mps; | ||
| 2042 | overhead = interval_overhead; | ||
| 2043 | } | ||
| 2044 | /* Otherwise carry over packet_size and overhead from the last | ||
| 2045 | * time we had a remainder. | ||
| 2046 | */ | ||
| 2047 | bw_used += bw_added; | ||
| 2048 | if (bw_used > max_bandwidth) { | ||
| 2049 | xhci_warn(xhci, "Not enough bandwidth. " | ||
| 2050 | "Proposed: %u, Max: %u\n", | ||
| 2051 | bw_used, max_bandwidth); | ||
| 2052 | return -ENOMEM; | ||
| 2053 | } | ||
| 2054 | } | ||
| 2055 | /* | ||
| 2056 | * Ok, we know we have some packets left over after even-handedly | ||
| 2057 | * scheduling interval 15. We don't know which microframes they will | ||
| 2058 | * fit into, so we over-schedule and say they will be scheduled every | ||
| 2059 | * microframe. | ||
| 2060 | */ | ||
| 2061 | if (packets_remaining > 0) | ||
| 2062 | bw_used += overhead + packet_size; | ||
| 2063 | |||
| 2064 | if (!virt_dev->tt_info && virt_dev->udev->speed == USB_SPEED_HIGH) { | ||
| 2065 | unsigned int port_index = virt_dev->real_port - 1; | ||
| 2066 | |||
| 2067 | /* OK, we're manipulating a HS device attached to a | ||
| 2068 | * root port bandwidth domain. Include the number of active TTs | ||
| 2069 | * in the bandwidth used. | ||
| 2070 | */ | ||
| 2071 | bw_used += TT_HS_OVERHEAD * | ||
| 2072 | xhci->rh_bw[port_index].num_active_tts; | ||
| 2073 | } | ||
| 2074 | |||
| 2075 | xhci_dbg(xhci, "Final bandwidth: %u, Limit: %u, Reserved: %u, " | ||
| 2076 | "Available: %u " "percent\n", | ||
| 2077 | bw_used, max_bandwidth, bw_reserved, | ||
| 2078 | (max_bandwidth - bw_used - bw_reserved) * 100 / | ||
| 2079 | max_bandwidth); | ||
| 2080 | |||
| 2081 | bw_used += bw_reserved; | ||
| 2082 | if (bw_used > max_bandwidth) { | ||
| 2083 | xhci_warn(xhci, "Not enough bandwidth. Proposed: %u, Max: %u\n", | ||
| 2084 | bw_used, max_bandwidth); | ||
| 2085 | return -ENOMEM; | ||
| 2086 | } | ||
| 2087 | |||
| 2088 | bw_table->bw_used = bw_used; | ||
| 2089 | return 0; | ||
| 2090 | } | ||
| 2091 | |||
| 2092 | static bool xhci_is_async_ep(unsigned int ep_type) | ||
| 2093 | { | ||
| 2094 | return (ep_type != ISOC_OUT_EP && ep_type != INT_OUT_EP && | ||
| 2095 | ep_type != ISOC_IN_EP && | ||
| 2096 | ep_type != INT_IN_EP); | ||
| 2097 | } | ||
| 2098 | |||
| 2099 | static bool xhci_is_sync_in_ep(unsigned int ep_type) | ||
| 2100 | { | ||
| 2101 | return (ep_type == ISOC_IN_EP || ep_type != INT_IN_EP); | ||
| 2102 | } | ||
| 2103 | |||
| 2104 | static unsigned int xhci_get_ss_bw_consumed(struct xhci_bw_info *ep_bw) | ||
| 2105 | { | ||
| 2106 | unsigned int mps = DIV_ROUND_UP(ep_bw->max_packet_size, SS_BLOCK); | ||
| 2107 | |||
| 2108 | if (ep_bw->ep_interval == 0) | ||
| 2109 | return SS_OVERHEAD_BURST + | ||
| 2110 | (ep_bw->mult * ep_bw->num_packets * | ||
| 2111 | (SS_OVERHEAD + mps)); | ||
| 2112 | return DIV_ROUND_UP(ep_bw->mult * ep_bw->num_packets * | ||
| 2113 | (SS_OVERHEAD + mps + SS_OVERHEAD_BURST), | ||
| 2114 | 1 << ep_bw->ep_interval); | ||
| 2115 | |||
| 2116 | } | ||
| 2117 | |||
| 2118 | void xhci_drop_ep_from_interval_table(struct xhci_hcd *xhci, | ||
| 2119 | struct xhci_bw_info *ep_bw, | ||
| 2120 | struct xhci_interval_bw_table *bw_table, | ||
| 2121 | struct usb_device *udev, | ||
| 2122 | struct xhci_virt_ep *virt_ep, | ||
| 2123 | struct xhci_tt_bw_info *tt_info) | ||
| 2124 | { | ||
| 2125 | struct xhci_interval_bw *interval_bw; | ||
| 2126 | int normalized_interval; | ||
| 2127 | |||
| 2128 | if (xhci_is_async_ep(ep_bw->type)) | ||
| 2129 | return; | ||
| 2130 | |||
| 2131 | if (udev->speed == USB_SPEED_SUPER) { | ||
| 2132 | if (xhci_is_sync_in_ep(ep_bw->type)) | ||
| 2133 | xhci->devs[udev->slot_id]->bw_table->ss_bw_in -= | ||
| 2134 | xhci_get_ss_bw_consumed(ep_bw); | ||
| 2135 | else | ||
| 2136 | xhci->devs[udev->slot_id]->bw_table->ss_bw_out -= | ||
| 2137 | xhci_get_ss_bw_consumed(ep_bw); | ||
| 2138 | return; | ||
| 2139 | } | ||
| 2140 | |||
| 2141 | /* SuperSpeed endpoints never get added to intervals in the table, so | ||
| 2142 | * this check is only valid for HS/FS/LS devices. | ||
| 2143 | */ | ||
| 2144 | if (list_empty(&virt_ep->bw_endpoint_list)) | ||
| 2145 | return; | ||
| 2146 | /* For LS/FS devices, we need to translate the interval expressed in | ||
| 2147 | * microframes to frames. | ||
| 2148 | */ | ||
| 2149 | if (udev->speed == USB_SPEED_HIGH) | ||
| 2150 | normalized_interval = ep_bw->ep_interval; | ||
| 2151 | else | ||
| 2152 | normalized_interval = ep_bw->ep_interval - 3; | ||
| 2153 | |||
| 2154 | if (normalized_interval == 0) | ||
| 2155 | bw_table->interval0_esit_payload -= ep_bw->max_esit_payload; | ||
| 2156 | interval_bw = &bw_table->interval_bw[normalized_interval]; | ||
| 2157 | interval_bw->num_packets -= ep_bw->num_packets; | ||
| 2158 | switch (udev->speed) { | ||
| 2159 | case USB_SPEED_LOW: | ||
| 2160 | interval_bw->overhead[LS_OVERHEAD_TYPE] -= 1; | ||
| 2161 | break; | ||
| 2162 | case USB_SPEED_FULL: | ||
| 2163 | interval_bw->overhead[FS_OVERHEAD_TYPE] -= 1; | ||
| 2164 | break; | ||
| 2165 | case USB_SPEED_HIGH: | ||
| 2166 | interval_bw->overhead[HS_OVERHEAD_TYPE] -= 1; | ||
| 2167 | break; | ||
| 2168 | case USB_SPEED_SUPER: | ||
| 2169 | case USB_SPEED_UNKNOWN: | ||
| 2170 | case USB_SPEED_WIRELESS: | ||
| 2171 | /* Should never happen because only LS/FS/HS endpoints will get | ||
| 2172 | * added to the endpoint list. | ||
| 2173 | */ | ||
| 2174 | return; | ||
| 2175 | } | ||
| 2176 | if (tt_info) | ||
| 2177 | tt_info->active_eps -= 1; | ||
| 2178 | list_del_init(&virt_ep->bw_endpoint_list); | ||
| 2179 | } | ||
| 2180 | |||
| 2181 | static void xhci_add_ep_to_interval_table(struct xhci_hcd *xhci, | ||
| 2182 | struct xhci_bw_info *ep_bw, | ||
| 2183 | struct xhci_interval_bw_table *bw_table, | ||
| 2184 | struct usb_device *udev, | ||
| 2185 | struct xhci_virt_ep *virt_ep, | ||
| 2186 | struct xhci_tt_bw_info *tt_info) | ||
| 2187 | { | ||
| 2188 | struct xhci_interval_bw *interval_bw; | ||
| 2189 | struct xhci_virt_ep *smaller_ep; | ||
| 2190 | int normalized_interval; | ||
| 2191 | |||
| 2192 | if (xhci_is_async_ep(ep_bw->type)) | ||
| 2193 | return; | ||
| 2194 | |||
| 2195 | if (udev->speed == USB_SPEED_SUPER) { | ||
| 2196 | if (xhci_is_sync_in_ep(ep_bw->type)) | ||
| 2197 | xhci->devs[udev->slot_id]->bw_table->ss_bw_in += | ||
| 2198 | xhci_get_ss_bw_consumed(ep_bw); | ||
| 2199 | else | ||
| 2200 | xhci->devs[udev->slot_id]->bw_table->ss_bw_out += | ||
| 2201 | xhci_get_ss_bw_consumed(ep_bw); | ||
| 2202 | return; | ||
| 2203 | } | ||
| 2204 | |||
| 2205 | /* For LS/FS devices, we need to translate the interval expressed in | ||
| 2206 | * microframes to frames. | ||
| 2207 | */ | ||
| 2208 | if (udev->speed == USB_SPEED_HIGH) | ||
| 2209 | normalized_interval = ep_bw->ep_interval; | ||
| 2210 | else | ||
| 2211 | normalized_interval = ep_bw->ep_interval - 3; | ||
| 2212 | |||
| 2213 | if (normalized_interval == 0) | ||
| 2214 | bw_table->interval0_esit_payload += ep_bw->max_esit_payload; | ||
| 2215 | interval_bw = &bw_table->interval_bw[normalized_interval]; | ||
| 2216 | interval_bw->num_packets += ep_bw->num_packets; | ||
| 2217 | switch (udev->speed) { | ||
| 2218 | case USB_SPEED_LOW: | ||
| 2219 | interval_bw->overhead[LS_OVERHEAD_TYPE] += 1; | ||
| 2220 | break; | ||
| 2221 | case USB_SPEED_FULL: | ||
| 2222 | interval_bw->overhead[FS_OVERHEAD_TYPE] += 1; | ||
| 2223 | break; | ||
| 2224 | case USB_SPEED_HIGH: | ||
| 2225 | interval_bw->overhead[HS_OVERHEAD_TYPE] += 1; | ||
| 2226 | break; | ||
| 2227 | case USB_SPEED_SUPER: | ||
| 2228 | case USB_SPEED_UNKNOWN: | ||
| 2229 | case USB_SPEED_WIRELESS: | ||
| 2230 | /* Should never happen because only LS/FS/HS endpoints will get | ||
| 2231 | * added to the endpoint list. | ||
| 2232 | */ | ||
| 2233 | return; | ||
| 2234 | } | ||
| 2235 | |||
| 2236 | if (tt_info) | ||
| 2237 | tt_info->active_eps += 1; | ||
| 2238 | /* Insert the endpoint into the list, largest max packet size first. */ | ||
| 2239 | list_for_each_entry(smaller_ep, &interval_bw->endpoints, | ||
| 2240 | bw_endpoint_list) { | ||
| 2241 | if (ep_bw->max_packet_size >= | ||
| 2242 | smaller_ep->bw_info.max_packet_size) { | ||
| 2243 | /* Add the new ep before the smaller endpoint */ | ||
| 2244 | list_add_tail(&virt_ep->bw_endpoint_list, | ||
| 2245 | &smaller_ep->bw_endpoint_list); | ||
| 2246 | return; | ||
| 2247 | } | ||
| 2248 | } | ||
| 2249 | /* Add the new endpoint at the end of the list. */ | ||
| 2250 | list_add_tail(&virt_ep->bw_endpoint_list, | ||
| 2251 | &interval_bw->endpoints); | ||
| 2252 | } | ||
| 2253 | |||
| 2254 | void xhci_update_tt_active_eps(struct xhci_hcd *xhci, | ||
| 2255 | struct xhci_virt_device *virt_dev, | ||
| 2256 | int old_active_eps) | ||
| 2257 | { | ||
| 2258 | struct xhci_root_port_bw_info *rh_bw_info; | ||
| 2259 | if (!virt_dev->tt_info) | ||
| 2260 | return; | ||
| 2261 | |||
| 2262 | rh_bw_info = &xhci->rh_bw[virt_dev->real_port - 1]; | ||
| 2263 | if (old_active_eps == 0 && | ||
| 2264 | virt_dev->tt_info->active_eps != 0) { | ||
| 2265 | rh_bw_info->num_active_tts += 1; | ||
| 2266 | rh_bw_info->bw_table.bw_used += TT_HS_OVERHEAD; | ||
| 2267 | } else if (old_active_eps != 0 && | ||
| 2268 | virt_dev->tt_info->active_eps == 0) { | ||
| 2269 | rh_bw_info->num_active_tts -= 1; | ||
| 2270 | rh_bw_info->bw_table.bw_used -= TT_HS_OVERHEAD; | ||
| 2271 | } | ||
| 2272 | } | ||
| 2273 | |||
| 2274 | static int xhci_reserve_bandwidth(struct xhci_hcd *xhci, | ||
| 2275 | struct xhci_virt_device *virt_dev, | ||
| 2276 | struct xhci_container_ctx *in_ctx) | ||
| 2277 | { | ||
| 2278 | struct xhci_bw_info ep_bw_info[31]; | ||
| 2279 | int i; | ||
| 2280 | struct xhci_input_control_ctx *ctrl_ctx; | ||
| 2281 | int old_active_eps = 0; | ||
| 2282 | |||
| 2283 | if (virt_dev->tt_info) | ||
| 2284 | old_active_eps = virt_dev->tt_info->active_eps; | ||
| 2285 | |||
| 2286 | ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx); | ||
| 2287 | |||
| 2288 | for (i = 0; i < 31; i++) { | ||
| 2289 | if (!EP_IS_ADDED(ctrl_ctx, i) && !EP_IS_DROPPED(ctrl_ctx, i)) | ||
| 2290 | continue; | ||
| 2291 | |||
| 2292 | /* Make a copy of the BW info in case we need to revert this */ | ||
| 2293 | memcpy(&ep_bw_info[i], &virt_dev->eps[i].bw_info, | ||
| 2294 | sizeof(ep_bw_info[i])); | ||
| 2295 | /* Drop the endpoint from the interval table if the endpoint is | ||
| 2296 | * being dropped or changed. | ||
| 2297 | */ | ||
| 2298 | if (EP_IS_DROPPED(ctrl_ctx, i)) | ||
| 2299 | xhci_drop_ep_from_interval_table(xhci, | ||
| 2300 | &virt_dev->eps[i].bw_info, | ||
| 2301 | virt_dev->bw_table, | ||
| 2302 | virt_dev->udev, | ||
| 2303 | &virt_dev->eps[i], | ||
| 2304 | virt_dev->tt_info); | ||
| 2305 | } | ||
| 2306 | /* Overwrite the information stored in the endpoints' bw_info */ | ||
| 2307 | xhci_update_bw_info(xhci, virt_dev->in_ctx, ctrl_ctx, virt_dev); | ||
| 2308 | for (i = 0; i < 31; i++) { | ||
| 2309 | /* Add any changed or added endpoints to the interval table */ | ||
| 2310 | if (EP_IS_ADDED(ctrl_ctx, i)) | ||
| 2311 | xhci_add_ep_to_interval_table(xhci, | ||
| 2312 | &virt_dev->eps[i].bw_info, | ||
| 2313 | virt_dev->bw_table, | ||
| 2314 | virt_dev->udev, | ||
| 2315 | &virt_dev->eps[i], | ||
| 2316 | virt_dev->tt_info); | ||
| 2317 | } | ||
| 2318 | |||
| 2319 | if (!xhci_check_bw_table(xhci, virt_dev, old_active_eps)) { | ||
| 2320 | /* Ok, this fits in the bandwidth we have. | ||
| 2321 | * Update the number of active TTs. | ||
| 2322 | */ | ||
| 2323 | xhci_update_tt_active_eps(xhci, virt_dev, old_active_eps); | ||
| 2324 | return 0; | ||
| 2325 | } | ||
| 2326 | |||
| 2327 | /* We don't have enough bandwidth for this, revert the stored info. */ | ||
| 2328 | for (i = 0; i < 31; i++) { | ||
| 2329 | if (!EP_IS_ADDED(ctrl_ctx, i) && !EP_IS_DROPPED(ctrl_ctx, i)) | ||
| 2330 | continue; | ||
| 2331 | |||
| 2332 | /* Drop the new copies of any added or changed endpoints from | ||
| 2333 | * the interval table. | ||
| 2334 | */ | ||
| 2335 | if (EP_IS_ADDED(ctrl_ctx, i)) { | ||
| 2336 | xhci_drop_ep_from_interval_table(xhci, | ||
| 2337 | &virt_dev->eps[i].bw_info, | ||
| 2338 | virt_dev->bw_table, | ||
| 2339 | virt_dev->udev, | ||
| 2340 | &virt_dev->eps[i], | ||
| 2341 | virt_dev->tt_info); | ||
| 2342 | } | ||
| 2343 | /* Revert the endpoint back to its old information */ | ||
| 2344 | memcpy(&virt_dev->eps[i].bw_info, &ep_bw_info[i], | ||
| 2345 | sizeof(ep_bw_info[i])); | ||
| 2346 | /* Add any changed or dropped endpoints back into the table */ | ||
| 2347 | if (EP_IS_DROPPED(ctrl_ctx, i)) | ||
| 2348 | xhci_add_ep_to_interval_table(xhci, | ||
| 2349 | &virt_dev->eps[i].bw_info, | ||
| 2350 | virt_dev->bw_table, | ||
| 2351 | virt_dev->udev, | ||
| 2352 | &virt_dev->eps[i], | ||
| 2353 | virt_dev->tt_info); | ||
| 2354 | } | ||
| 2355 | return -ENOMEM; | ||
| 2356 | } | ||
| 2357 | |||
| 2358 | |||
| 1750 | /* Issue a configure endpoint command or evaluate context command | 2359 | /* Issue a configure endpoint command or evaluate context command |
| 1751 | * and wait for it to finish. | 2360 | * and wait for it to finish. |
| 1752 | */ | 2361 | */ |
| @@ -1765,17 +2374,30 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, | |||
| 1765 | 2374 | ||
| 1766 | spin_lock_irqsave(&xhci->lock, flags); | 2375 | spin_lock_irqsave(&xhci->lock, flags); |
| 1767 | virt_dev = xhci->devs[udev->slot_id]; | 2376 | virt_dev = xhci->devs[udev->slot_id]; |
| 1768 | if (command) { | 2377 | |
| 2378 | if (command) | ||
| 1769 | in_ctx = command->in_ctx; | 2379 | in_ctx = command->in_ctx; |
| 1770 | if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) && | 2380 | else |
| 1771 | xhci_reserve_host_resources(xhci, in_ctx)) { | 2381 | in_ctx = virt_dev->in_ctx; |
| 1772 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
| 1773 | xhci_warn(xhci, "Not enough host resources, " | ||
| 1774 | "active endpoint contexts = %u\n", | ||
| 1775 | xhci->num_active_eps); | ||
| 1776 | return -ENOMEM; | ||
| 1777 | } | ||
| 1778 | 2382 | ||
| 2383 | if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) && | ||
| 2384 | xhci_reserve_host_resources(xhci, in_ctx)) { | ||
| 2385 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
| 2386 | xhci_warn(xhci, "Not enough host resources, " | ||
| 2387 | "active endpoint contexts = %u\n", | ||
| 2388 | xhci->num_active_eps); | ||
| 2389 | return -ENOMEM; | ||
| 2390 | } | ||
| 2391 | if ((xhci->quirks & XHCI_SW_BW_CHECKING) && | ||
| 2392 | xhci_reserve_bandwidth(xhci, virt_dev, in_ctx)) { | ||
| 2393 | if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) | ||
| 2394 | xhci_free_host_resources(xhci, in_ctx); | ||
| 2395 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
| 2396 | xhci_warn(xhci, "Not enough bandwidth\n"); | ||
| 2397 | return -ENOMEM; | ||
| 2398 | } | ||
| 2399 | |||
| 2400 | if (command) { | ||
| 1779 | cmd_completion = command->completion; | 2401 | cmd_completion = command->completion; |
| 1780 | cmd_status = &command->status; | 2402 | cmd_status = &command->status; |
| 1781 | command->command_trb = xhci->cmd_ring->enqueue; | 2403 | command->command_trb = xhci->cmd_ring->enqueue; |
| @@ -1789,15 +2411,6 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, | |||
| 1789 | 2411 | ||
| 1790 | list_add_tail(&command->cmd_list, &virt_dev->cmd_list); | 2412 | list_add_tail(&command->cmd_list, &virt_dev->cmd_list); |
| 1791 | } else { | 2413 | } else { |
| 1792 | in_ctx = virt_dev->in_ctx; | ||
| 1793 | if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) && | ||
| 1794 | xhci_reserve_host_resources(xhci, in_ctx)) { | ||
| 1795 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
| 1796 | xhci_warn(xhci, "Not enough host resources, " | ||
| 1797 | "active endpoint contexts = %u\n", | ||
| 1798 | xhci->num_active_eps); | ||
| 1799 | return -ENOMEM; | ||
| 1800 | } | ||
| 1801 | cmd_completion = &virt_dev->cmd_completion; | 2414 | cmd_completion = &virt_dev->cmd_completion; |
| 1802 | cmd_status = &virt_dev->cmd_status; | 2415 | cmd_status = &virt_dev->cmd_status; |
| 1803 | } | 2416 | } |
| @@ -1888,6 +2501,12 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) | |||
| 1888 | ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); | 2501 | ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); |
| 1889 | ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG); | 2502 | ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG); |
| 1890 | ctrl_ctx->drop_flags &= cpu_to_le32(~(SLOT_FLAG | EP0_FLAG)); | 2503 | ctrl_ctx->drop_flags &= cpu_to_le32(~(SLOT_FLAG | EP0_FLAG)); |
| 2504 | |||
| 2505 | /* Don't issue the command if there's no endpoints to update. */ | ||
| 2506 | if (ctrl_ctx->add_flags == cpu_to_le32(SLOT_FLAG) && | ||
| 2507 | ctrl_ctx->drop_flags == 0) | ||
| 2508 | return 0; | ||
| 2509 | |||
| 1891 | xhci_dbg(xhci, "New Input Control Context:\n"); | 2510 | xhci_dbg(xhci, "New Input Control Context:\n"); |
| 1892 | slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); | 2511 | slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); |
| 1893 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, | 2512 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, |
| @@ -2525,6 +3144,7 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
| 2525 | int timeleft; | 3144 | int timeleft; |
| 2526 | int last_freed_endpoint; | 3145 | int last_freed_endpoint; |
| 2527 | struct xhci_slot_ctx *slot_ctx; | 3146 | struct xhci_slot_ctx *slot_ctx; |
| 3147 | int old_active_eps = 0; | ||
| 2528 | 3148 | ||
| 2529 | ret = xhci_check_args(hcd, udev, NULL, 0, false, __func__); | 3149 | ret = xhci_check_args(hcd, udev, NULL, 0, false, __func__); |
| 2530 | if (ret <= 0) | 3150 | if (ret <= 0) |
| @@ -2666,7 +3286,18 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
| 2666 | xhci_free_or_cache_endpoint_ring(xhci, virt_dev, i); | 3286 | xhci_free_or_cache_endpoint_ring(xhci, virt_dev, i); |
| 2667 | last_freed_endpoint = i; | 3287 | last_freed_endpoint = i; |
| 2668 | } | 3288 | } |
| 2669 | } | 3289 | if (!list_empty(&virt_dev->eps[i].bw_endpoint_list)) |
| 3290 | xhci_drop_ep_from_interval_table(xhci, | ||
| 3291 | &virt_dev->eps[i].bw_info, | ||
| 3292 | virt_dev->bw_table, | ||
| 3293 | udev, | ||
| 3294 | &virt_dev->eps[i], | ||
| 3295 | virt_dev->tt_info); | ||
| 3296 | xhci_clear_endpoint_bw_info(&virt_dev->eps[i].bw_info); | ||
| 3297 | } | ||
| 3298 | /* If necessary, update the number of active TTs on this root port */ | ||
| 3299 | xhci_update_tt_active_eps(xhci, virt_dev, old_active_eps); | ||
| 3300 | |||
| 2670 | xhci_dbg(xhci, "Output context after successful reset device cmd:\n"); | 3301 | xhci_dbg(xhci, "Output context after successful reset device cmd:\n"); |
| 2671 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, last_freed_endpoint); | 3302 | xhci_dbg_ctx(xhci, virt_dev->out_ctx, last_freed_endpoint); |
| 2672 | ret = 0; | 3303 | ret = 0; |
| @@ -2704,6 +3335,11 @@ void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev) | |||
| 2704 | del_timer_sync(&virt_dev->eps[i].stop_cmd_timer); | 3335 | del_timer_sync(&virt_dev->eps[i].stop_cmd_timer); |
| 2705 | } | 3336 | } |
| 2706 | 3337 | ||
| 3338 | if (udev->usb2_hw_lpm_enabled) { | ||
| 3339 | xhci_set_usb2_hardware_lpm(hcd, udev, 0); | ||
| 3340 | udev->usb2_hw_lpm_enabled = 0; | ||
| 3341 | } | ||
| 3342 | |||
| 2707 | spin_lock_irqsave(&xhci->lock, flags); | 3343 | spin_lock_irqsave(&xhci->lock, flags); |
| 2708 | /* Don't disable the slot if the host controller is dead. */ | 3344 | /* Don't disable the slot if the host controller is dead. */ |
| 2709 | state = xhci_readl(xhci, &xhci->op_regs->status); | 3345 | state = xhci_readl(xhci, &xhci->op_regs->status); |
| @@ -2867,6 +3503,10 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
| 2867 | /* Otherwise, update the control endpoint ring enqueue pointer. */ | 3503 | /* Otherwise, update the control endpoint ring enqueue pointer. */ |
| 2868 | else | 3504 | else |
| 2869 | xhci_copy_ep0_dequeue_into_input_ctx(xhci, udev); | 3505 | xhci_copy_ep0_dequeue_into_input_ctx(xhci, udev); |
| 3506 | ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx); | ||
| 3507 | ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG | EP0_FLAG); | ||
| 3508 | ctrl_ctx->drop_flags = 0; | ||
| 3509 | |||
| 2870 | xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); | 3510 | xhci_dbg(xhci, "Slot ID %d Input Context:\n", udev->slot_id); |
| 2871 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2); | 3511 | xhci_dbg_ctx(xhci, virt_dev->in_ctx, 2); |
| 2872 | 3512 | ||
| @@ -2889,7 +3529,7 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
| 2889 | * command on a timeout. | 3529 | * command on a timeout. |
| 2890 | */ | 3530 | */ |
| 2891 | if (timeleft <= 0) { | 3531 | if (timeleft <= 0) { |
| 2892 | xhci_warn(xhci, "%s while waiting for a slot\n", | 3532 | xhci_warn(xhci, "%s while waiting for address device command\n", |
| 2893 | timeleft == 0 ? "Timeout" : "Signal"); | 3533 | timeleft == 0 ? "Timeout" : "Signal"); |
| 2894 | /* FIXME cancel the address device command */ | 3534 | /* FIXME cancel the address device command */ |
| 2895 | return -ETIME; | 3535 | return -ETIME; |
| @@ -2948,7 +3588,6 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
| 2948 | virt_dev->address = (le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK) | 3588 | virt_dev->address = (le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK) |
| 2949 | + 1; | 3589 | + 1; |
| 2950 | /* Zero the input context control for later use */ | 3590 | /* Zero the input context control for later use */ |
| 2951 | ctrl_ctx = xhci_get_input_control_ctx(xhci, virt_dev->in_ctx); | ||
| 2952 | ctrl_ctx->add_flags = 0; | 3591 | ctrl_ctx->add_flags = 0; |
| 2953 | ctrl_ctx->drop_flags = 0; | 3592 | ctrl_ctx->drop_flags = 0; |
| 2954 | 3593 | ||
| @@ -2957,6 +3596,254 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev) | |||
| 2957 | return 0; | 3596 | return 0; |
| 2958 | } | 3597 | } |
| 2959 | 3598 | ||
| 3599 | #ifdef CONFIG_USB_SUSPEND | ||
| 3600 | |||
| 3601 | /* BESL to HIRD Encoding array for USB2 LPM */ | ||
| 3602 | static int xhci_besl_encoding[16] = {125, 150, 200, 300, 400, 500, 1000, 2000, | ||
| 3603 | 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000}; | ||
| 3604 | |||
| 3605 | /* Calculate HIRD/BESL for USB2 PORTPMSC*/ | ||
| 3606 | static int xhci_calculate_hird_besl(int u2del, bool use_besl) | ||
| 3607 | { | ||
| 3608 | int hird; | ||
| 3609 | |||
| 3610 | if (use_besl) { | ||
| 3611 | for (hird = 0; hird < 16; hird++) { | ||
| 3612 | if (xhci_besl_encoding[hird] >= u2del) | ||
| 3613 | break; | ||
| 3614 | } | ||
| 3615 | } else { | ||
| 3616 | if (u2del <= 50) | ||
| 3617 | hird = 0; | ||
| 3618 | else | ||
| 3619 | hird = (u2del - 51) / 75 + 1; | ||
| 3620 | |||
| 3621 | if (hird > 15) | ||
| 3622 | hird = 15; | ||
| 3623 | } | ||
| 3624 | |||
| 3625 | return hird; | ||
| 3626 | } | ||
| 3627 | |||
| 3628 | static int xhci_usb2_software_lpm_test(struct usb_hcd *hcd, | ||
| 3629 | struct usb_device *udev) | ||
| 3630 | { | ||
| 3631 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | ||
| 3632 | struct dev_info *dev_info; | ||
| 3633 | __le32 __iomem **port_array; | ||
| 3634 | __le32 __iomem *addr, *pm_addr; | ||
| 3635 | u32 temp, dev_id; | ||
| 3636 | unsigned int port_num; | ||
| 3637 | unsigned long flags; | ||
| 3638 | int u2del, hird; | ||
| 3639 | int ret; | ||
| 3640 | |||
| 3641 | if (hcd->speed == HCD_USB3 || !xhci->sw_lpm_support || | ||
| 3642 | !udev->lpm_capable) | ||
| 3643 | return -EINVAL; | ||
| 3644 | |||
| 3645 | /* we only support lpm for non-hub device connected to root hub yet */ | ||
| 3646 | if (!udev->parent || udev->parent->parent || | ||
| 3647 | udev->descriptor.bDeviceClass == USB_CLASS_HUB) | ||
| 3648 | return -EINVAL; | ||
| 3649 | |||
| 3650 | spin_lock_irqsave(&xhci->lock, flags); | ||
| 3651 | |||
| 3652 | /* Look for devices in lpm_failed_devs list */ | ||
| 3653 | dev_id = le16_to_cpu(udev->descriptor.idVendor) << 16 | | ||
| 3654 | le16_to_cpu(udev->descriptor.idProduct); | ||
| 3655 | list_for_each_entry(dev_info, &xhci->lpm_failed_devs, list) { | ||
| 3656 | if (dev_info->dev_id == dev_id) { | ||
| 3657 | ret = -EINVAL; | ||
| 3658 | goto finish; | ||
| 3659 | } | ||
| 3660 | } | ||
| 3661 | |||
| 3662 | port_array = xhci->usb2_ports; | ||
| 3663 | port_num = udev->portnum - 1; | ||
| 3664 | |||
| 3665 | if (port_num > HCS_MAX_PORTS(xhci->hcs_params1)) { | ||
| 3666 | xhci_dbg(xhci, "invalid port number %d\n", udev->portnum); | ||
| 3667 | ret = -EINVAL; | ||
| 3668 | goto finish; | ||
| 3669 | } | ||
| 3670 | |||
| 3671 | /* | ||
| 3672 | * Test USB 2.0 software LPM. | ||
| 3673 | * FIXME: some xHCI 1.0 hosts may implement a new register to set up | ||
| 3674 | * hardware-controlled USB 2.0 LPM. See section 5.4.11 and 4.23.5.1.1.1 | ||
| 3675 | * in the June 2011 errata release. | ||
| 3676 | */ | ||
| 3677 | xhci_dbg(xhci, "test port %d software LPM\n", port_num); | ||
| 3678 | /* | ||
| 3679 | * Set L1 Device Slot and HIRD/BESL. | ||
| 3680 | * Check device's USB 2.0 extension descriptor to determine whether | ||
| 3681 | * HIRD or BESL shoule be used. See USB2.0 LPM errata. | ||
| 3682 | */ | ||
| 3683 | pm_addr = port_array[port_num] + 1; | ||
| 3684 | u2del = HCS_U2_LATENCY(xhci->hcs_params3); | ||
| 3685 | if (le32_to_cpu(udev->bos->ext_cap->bmAttributes) & (1 << 2)) | ||
| 3686 | hird = xhci_calculate_hird_besl(u2del, 1); | ||
| 3687 | else | ||
| 3688 | hird = xhci_calculate_hird_besl(u2del, 0); | ||
| 3689 | |||
| 3690 | temp = PORT_L1DS(udev->slot_id) | PORT_HIRD(hird); | ||
| 3691 | xhci_writel(xhci, temp, pm_addr); | ||
| 3692 | |||
| 3693 | /* Set port link state to U2(L1) */ | ||
| 3694 | addr = port_array[port_num]; | ||
| 3695 | xhci_set_link_state(xhci, port_array, port_num, XDEV_U2); | ||
| 3696 | |||
| 3697 | /* wait for ACK */ | ||
| 3698 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
| 3699 | msleep(10); | ||
| 3700 | spin_lock_irqsave(&xhci->lock, flags); | ||
| 3701 | |||
| 3702 | /* Check L1 Status */ | ||
| 3703 | ret = handshake(xhci, pm_addr, PORT_L1S_MASK, PORT_L1S_SUCCESS, 125); | ||
| 3704 | if (ret != -ETIMEDOUT) { | ||
| 3705 | /* enter L1 successfully */ | ||
| 3706 | temp = xhci_readl(xhci, addr); | ||
| 3707 | xhci_dbg(xhci, "port %d entered L1 state, port status 0x%x\n", | ||
| 3708 | port_num, temp); | ||
| 3709 | ret = 0; | ||
| 3710 | } else { | ||
| 3711 | temp = xhci_readl(xhci, pm_addr); | ||
| 3712 | xhci_dbg(xhci, "port %d software lpm failed, L1 status %d\n", | ||
| 3713 | port_num, temp & PORT_L1S_MASK); | ||
| 3714 | ret = -EINVAL; | ||
| 3715 | } | ||
| 3716 | |||
| 3717 | /* Resume the port */ | ||
| 3718 | xhci_set_link_state(xhci, port_array, port_num, XDEV_U0); | ||
| 3719 | |||
| 3720 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
| 3721 | msleep(10); | ||
| 3722 | spin_lock_irqsave(&xhci->lock, flags); | ||
| 3723 | |||
| 3724 | /* Clear PLC */ | ||
| 3725 | xhci_test_and_clear_bit(xhci, port_array, port_num, PORT_PLC); | ||
| 3726 | |||
| 3727 | /* Check PORTSC to make sure the device is in the right state */ | ||
| 3728 | if (!ret) { | ||
| 3729 | temp = xhci_readl(xhci, addr); | ||
| 3730 | xhci_dbg(xhci, "resumed port %d status 0x%x\n", port_num, temp); | ||
| 3731 | if (!(temp & PORT_CONNECT) || !(temp & PORT_PE) || | ||
| 3732 | (temp & PORT_PLS_MASK) != XDEV_U0) { | ||
| 3733 | xhci_dbg(xhci, "port L1 resume fail\n"); | ||
| 3734 | ret = -EINVAL; | ||
| 3735 | } | ||
| 3736 | } | ||
| 3737 | |||
| 3738 | if (ret) { | ||
| 3739 | /* Insert dev to lpm_failed_devs list */ | ||
| 3740 | xhci_warn(xhci, "device LPM test failed, may disconnect and " | ||
| 3741 | "re-enumerate\n"); | ||
| 3742 | dev_info = kzalloc(sizeof(struct dev_info), GFP_ATOMIC); | ||
| 3743 | if (!dev_info) { | ||
| 3744 | ret = -ENOMEM; | ||
| 3745 | goto finish; | ||
| 3746 | } | ||
| 3747 | dev_info->dev_id = dev_id; | ||
| 3748 | INIT_LIST_HEAD(&dev_info->list); | ||
| 3749 | list_add(&dev_info->list, &xhci->lpm_failed_devs); | ||
| 3750 | } else { | ||
| 3751 | xhci_ring_device(xhci, udev->slot_id); | ||
| 3752 | } | ||
| 3753 | |||
| 3754 | finish: | ||
| 3755 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
| 3756 | return ret; | ||
| 3757 | } | ||
| 3758 | |||
| 3759 | int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, | ||
| 3760 | struct usb_device *udev, int enable) | ||
| 3761 | { | ||
| 3762 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | ||
| 3763 | __le32 __iomem **port_array; | ||
| 3764 | __le32 __iomem *pm_addr; | ||
| 3765 | u32 temp; | ||
| 3766 | unsigned int port_num; | ||
| 3767 | unsigned long flags; | ||
| 3768 | int u2del, hird; | ||
| 3769 | |||
| 3770 | if (hcd->speed == HCD_USB3 || !xhci->hw_lpm_support || | ||
| 3771 | !udev->lpm_capable) | ||
| 3772 | return -EPERM; | ||
| 3773 | |||
| 3774 | if (!udev->parent || udev->parent->parent || | ||
| 3775 | udev->descriptor.bDeviceClass == USB_CLASS_HUB) | ||
| 3776 | return -EPERM; | ||
| 3777 | |||
| 3778 | if (udev->usb2_hw_lpm_capable != 1) | ||
| 3779 | return -EPERM; | ||
| 3780 | |||
| 3781 | spin_lock_irqsave(&xhci->lock, flags); | ||
| 3782 | |||
| 3783 | port_array = xhci->usb2_ports; | ||
| 3784 | port_num = udev->portnum - 1; | ||
| 3785 | pm_addr = port_array[port_num] + 1; | ||
| 3786 | temp = xhci_readl(xhci, pm_addr); | ||
| 3787 | |||
| 3788 | xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n", | ||
| 3789 | enable ? "enable" : "disable", port_num); | ||
| 3790 | |||
| 3791 | u2del = HCS_U2_LATENCY(xhci->hcs_params3); | ||
| 3792 | if (le32_to_cpu(udev->bos->ext_cap->bmAttributes) & (1 << 2)) | ||
| 3793 | hird = xhci_calculate_hird_besl(u2del, 1); | ||
| 3794 | else | ||
| 3795 | hird = xhci_calculate_hird_besl(u2del, 0); | ||
| 3796 | |||
| 3797 | if (enable) { | ||
| 3798 | temp &= ~PORT_HIRD_MASK; | ||
| 3799 | temp |= PORT_HIRD(hird) | PORT_RWE; | ||
| 3800 | xhci_writel(xhci, temp, pm_addr); | ||
| 3801 | temp = xhci_readl(xhci, pm_addr); | ||
| 3802 | temp |= PORT_HLE; | ||
| 3803 | xhci_writel(xhci, temp, pm_addr); | ||
| 3804 | } else { | ||
| 3805 | temp &= ~(PORT_HLE | PORT_RWE | PORT_HIRD_MASK); | ||
| 3806 | xhci_writel(xhci, temp, pm_addr); | ||
| 3807 | } | ||
| 3808 | |||
| 3809 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
| 3810 | return 0; | ||
| 3811 | } | ||
| 3812 | |||
| 3813 | int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev) | ||
| 3814 | { | ||
| 3815 | struct xhci_hcd *xhci = hcd_to_xhci(hcd); | ||
| 3816 | int ret; | ||
| 3817 | |||
| 3818 | ret = xhci_usb2_software_lpm_test(hcd, udev); | ||
| 3819 | if (!ret) { | ||
| 3820 | xhci_dbg(xhci, "software LPM test succeed\n"); | ||
| 3821 | if (xhci->hw_lpm_support == 1) { | ||
| 3822 | udev->usb2_hw_lpm_capable = 1; | ||
| 3823 | ret = xhci_set_usb2_hardware_lpm(hcd, udev, 1); | ||
| 3824 | if (!ret) | ||
| 3825 | udev->usb2_hw_lpm_enabled = 1; | ||
| 3826 | } | ||
| 3827 | } | ||
| 3828 | |||
| 3829 | return 0; | ||
| 3830 | } | ||
| 3831 | |||
| 3832 | #else | ||
| 3833 | |||
| 3834 | int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, | ||
| 3835 | struct usb_device *udev, int enable) | ||
| 3836 | { | ||
| 3837 | return 0; | ||
| 3838 | } | ||
| 3839 | |||
| 3840 | int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev) | ||
| 3841 | { | ||
| 3842 | return 0; | ||
| 3843 | } | ||
| 3844 | |||
| 3845 | #endif /* CONFIG_USB_SUSPEND */ | ||
| 3846 | |||
| 2960 | /* Once a hub descriptor is fetched for a device, we need to update the xHC's | 3847 | /* Once a hub descriptor is fetched for a device, we need to update the xHC's |
| 2961 | * internal data structures for the device. | 3848 | * internal data structures for the device. |
| 2962 | */ | 3849 | */ |
| @@ -2988,6 +3875,14 @@ int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev, | |||
| 2988 | } | 3875 | } |
| 2989 | 3876 | ||
| 2990 | spin_lock_irqsave(&xhci->lock, flags); | 3877 | spin_lock_irqsave(&xhci->lock, flags); |
| 3878 | if (hdev->speed == USB_SPEED_HIGH && | ||
| 3879 | xhci_alloc_tt_info(xhci, vdev, hdev, tt, GFP_ATOMIC)) { | ||
| 3880 | xhci_dbg(xhci, "Could not allocate xHCI TT structure.\n"); | ||
| 3881 | xhci_free_command(xhci, config_cmd); | ||
| 3882 | spin_unlock_irqrestore(&xhci->lock, flags); | ||
| 3883 | return -ENOMEM; | ||
| 3884 | } | ||
| 3885 | |||
| 2991 | xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx); | 3886 | xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx); |
| 2992 | ctrl_ctx = xhci_get_input_control_ctx(xhci, config_cmd->in_ctx); | 3887 | ctrl_ctx = xhci_get_input_control_ctx(xhci, config_cmd->in_ctx); |
| 2993 | ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); | 3888 | ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); |
| @@ -3051,22 +3946,108 @@ int xhci_get_frame(struct usb_hcd *hcd) | |||
| 3051 | return xhci_readl(xhci, &xhci->run_regs->microframe_index) >> 3; | 3946 | return xhci_readl(xhci, &xhci->run_regs->microframe_index) >> 3; |
| 3052 | } | 3947 | } |
| 3053 | 3948 | ||
| 3949 | int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks) | ||
| 3950 | { | ||
| 3951 | struct xhci_hcd *xhci; | ||
| 3952 | struct device *dev = hcd->self.controller; | ||
| 3953 | int retval; | ||
| 3954 | u32 temp; | ||
| 3955 | |||
| 3956 | hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2; | ||
| 3957 | |||
| 3958 | if (usb_hcd_is_primary_hcd(hcd)) { | ||
| 3959 | xhci = kzalloc(sizeof(struct xhci_hcd), GFP_KERNEL); | ||
| 3960 | if (!xhci) | ||
| 3961 | return -ENOMEM; | ||
| 3962 | *((struct xhci_hcd **) hcd->hcd_priv) = xhci; | ||
| 3963 | xhci->main_hcd = hcd; | ||
| 3964 | /* Mark the first roothub as being USB 2.0. | ||
| 3965 | * The xHCI driver will register the USB 3.0 roothub. | ||
| 3966 | */ | ||
| 3967 | hcd->speed = HCD_USB2; | ||
| 3968 | hcd->self.root_hub->speed = USB_SPEED_HIGH; | ||
| 3969 | /* | ||
| 3970 | * USB 2.0 roothub under xHCI has an integrated TT, | ||
| 3971 | * (rate matching hub) as opposed to having an OHCI/UHCI | ||
| 3972 | * companion controller. | ||
| 3973 | */ | ||
| 3974 | hcd->has_tt = 1; | ||
| 3975 | } else { | ||
| 3976 | /* xHCI private pointer was set in xhci_pci_probe for the second | ||
| 3977 | * registered roothub. | ||
| 3978 | */ | ||
| 3979 | xhci = hcd_to_xhci(hcd); | ||
| 3980 | temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params); | ||
| 3981 | if (HCC_64BIT_ADDR(temp)) { | ||
| 3982 | xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); | ||
| 3983 | dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)); | ||
| 3984 | } else { | ||
| 3985 | dma_set_mask(hcd->self.controller, DMA_BIT_MASK(32)); | ||
| 3986 | } | ||
| 3987 | return 0; | ||
| 3988 | } | ||
| 3989 | |||
| 3990 | xhci->cap_regs = hcd->regs; | ||
| 3991 | xhci->op_regs = hcd->regs + | ||
| 3992 | HC_LENGTH(xhci_readl(xhci, &xhci->cap_regs->hc_capbase)); | ||
| 3993 | xhci->run_regs = hcd->regs + | ||
| 3994 | (xhci_readl(xhci, &xhci->cap_regs->run_regs_off) & RTSOFF_MASK); | ||
| 3995 | /* Cache read-only capability registers */ | ||
| 3996 | xhci->hcs_params1 = xhci_readl(xhci, &xhci->cap_regs->hcs_params1); | ||
| 3997 | xhci->hcs_params2 = xhci_readl(xhci, &xhci->cap_regs->hcs_params2); | ||
| 3998 | xhci->hcs_params3 = xhci_readl(xhci, &xhci->cap_regs->hcs_params3); | ||
| 3999 | xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hc_capbase); | ||
| 4000 | xhci->hci_version = HC_VERSION(xhci->hcc_params); | ||
| 4001 | xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hcc_params); | ||
| 4002 | xhci_print_registers(xhci); | ||
| 4003 | |||
| 4004 | get_quirks(dev, xhci); | ||
| 4005 | |||
| 4006 | /* Make sure the HC is halted. */ | ||
| 4007 | retval = xhci_halt(xhci); | ||
| 4008 | if (retval) | ||
| 4009 | goto error; | ||
| 4010 | |||
| 4011 | xhci_dbg(xhci, "Resetting HCD\n"); | ||
| 4012 | /* Reset the internal HC memory state and registers. */ | ||
| 4013 | retval = xhci_reset(xhci); | ||
| 4014 | if (retval) | ||
| 4015 | goto error; | ||
| 4016 | xhci_dbg(xhci, "Reset complete\n"); | ||
| 4017 | |||
| 4018 | temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params); | ||
| 4019 | if (HCC_64BIT_ADDR(temp)) { | ||
| 4020 | xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n"); | ||
| 4021 | dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64)); | ||
| 4022 | } else { | ||
| 4023 | dma_set_mask(hcd->self.controller, DMA_BIT_MASK(32)); | ||
| 4024 | } | ||
| 4025 | |||
| 4026 | xhci_dbg(xhci, "Calling HCD init\n"); | ||
| 4027 | /* Initialize HCD and host controller data structures. */ | ||
| 4028 | retval = xhci_init(hcd); | ||
| 4029 | if (retval) | ||
| 4030 | goto error; | ||
| 4031 | xhci_dbg(xhci, "Called HCD init\n"); | ||
| 4032 | return 0; | ||
| 4033 | error: | ||
| 4034 | kfree(xhci); | ||
| 4035 | return retval; | ||
| 4036 | } | ||
| 4037 | |||
| 3054 | MODULE_DESCRIPTION(DRIVER_DESC); | 4038 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 3055 | MODULE_AUTHOR(DRIVER_AUTHOR); | 4039 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 3056 | MODULE_LICENSE("GPL"); | 4040 | MODULE_LICENSE("GPL"); |
| 3057 | 4041 | ||
| 3058 | static int __init xhci_hcd_init(void) | 4042 | static int __init xhci_hcd_init(void) |
| 3059 | { | 4043 | { |
| 3060 | #ifdef CONFIG_PCI | 4044 | int retval; |
| 3061 | int retval = 0; | ||
| 3062 | 4045 | ||
| 3063 | retval = xhci_register_pci(); | 4046 | retval = xhci_register_pci(); |
| 3064 | |||
| 3065 | if (retval < 0) { | 4047 | if (retval < 0) { |
| 3066 | printk(KERN_DEBUG "Problem registering PCI driver."); | 4048 | printk(KERN_DEBUG "Problem registering PCI driver."); |
| 3067 | return retval; | 4049 | return retval; |
| 3068 | } | 4050 | } |
| 3069 | #endif | ||
| 3070 | /* | 4051 | /* |
| 3071 | * Check the compiler generated sizes of structures that must be laid | 4052 | * Check the compiler generated sizes of structures that must be laid |
| 3072 | * out in specific ways for hardware access. | 4053 | * out in specific ways for hardware access. |
| @@ -3091,8 +4072,6 @@ module_init(xhci_hcd_init); | |||
| 3091 | 4072 | ||
| 3092 | static void __exit xhci_hcd_cleanup(void) | 4073 | static void __exit xhci_hcd_cleanup(void) |
| 3093 | { | 4074 | { |
| 3094 | #ifdef CONFIG_PCI | ||
| 3095 | xhci_unregister_pci(); | 4075 | xhci_unregister_pci(); |
| 3096 | #endif | ||
| 3097 | } | 4076 | } |
| 3098 | module_exit(xhci_hcd_cleanup); | 4077 | module_exit(xhci_hcd_cleanup); |
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index cae8e23308bf..3c8fbd2772ea 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h | |||
| @@ -272,6 +272,7 @@ struct xhci_op_regs { | |||
| 272 | */ | 272 | */ |
| 273 | #define PORT_PLS_MASK (0xf << 5) | 273 | #define PORT_PLS_MASK (0xf << 5) |
| 274 | #define XDEV_U0 (0x0 << 5) | 274 | #define XDEV_U0 (0x0 << 5) |
| 275 | #define XDEV_U2 (0x2 << 5) | ||
| 275 | #define XDEV_U3 (0x3 << 5) | 276 | #define XDEV_U3 (0x3 << 5) |
| 276 | #define XDEV_RESUME (0xf << 5) | 277 | #define XDEV_RESUME (0xf << 5) |
| 277 | /* true: port has power (see HCC_PPC) */ | 278 | /* true: port has power (see HCC_PPC) */ |
| @@ -362,7 +363,13 @@ struct xhci_op_regs { | |||
| 362 | /* Bits 24:31 for port testing */ | 363 | /* Bits 24:31 for port testing */ |
| 363 | 364 | ||
| 364 | /* USB2 Protocol PORTSPMSC */ | 365 | /* USB2 Protocol PORTSPMSC */ |
| 365 | #define PORT_RWE (1 << 0x3) | 366 | #define PORT_L1S_MASK 7 |
| 367 | #define PORT_L1S_SUCCESS 1 | ||
| 368 | #define PORT_RWE (1 << 3) | ||
| 369 | #define PORT_HIRD(p) (((p) & 0xf) << 4) | ||
| 370 | #define PORT_HIRD_MASK (0xf << 4) | ||
| 371 | #define PORT_L1DS(p) (((p) & 0xff) << 8) | ||
| 372 | #define PORT_HLE (1 << 16) | ||
| 366 | 373 | ||
| 367 | /** | 374 | /** |
| 368 | * struct xhci_intr_reg - Interrupt Register Set | 375 | * struct xhci_intr_reg - Interrupt Register Set |
| @@ -611,11 +618,13 @@ struct xhci_ep_ctx { | |||
| 611 | #define EP_STATE_ERROR 4 | 618 | #define EP_STATE_ERROR 4 |
| 612 | /* Mult - Max number of burtst within an interval, in EP companion desc. */ | 619 | /* Mult - Max number of burtst within an interval, in EP companion desc. */ |
| 613 | #define EP_MULT(p) (((p) & 0x3) << 8) | 620 | #define EP_MULT(p) (((p) & 0x3) << 8) |
| 621 | #define CTX_TO_EP_MULT(p) (((p) >> 8) & 0x3) | ||
| 614 | /* bits 10:14 are Max Primary Streams */ | 622 | /* bits 10:14 are Max Primary Streams */ |
| 615 | /* bit 15 is Linear Stream Array */ | 623 | /* bit 15 is Linear Stream Array */ |
| 616 | /* Interval - period between requests to an endpoint - 125u increments. */ | 624 | /* Interval - period between requests to an endpoint - 125u increments. */ |
| 617 | #define EP_INTERVAL(p) (((p) & 0xff) << 16) | 625 | #define EP_INTERVAL(p) (((p) & 0xff) << 16) |
| 618 | #define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff)) | 626 | #define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff)) |
| 627 | #define CTX_TO_EP_INTERVAL(p) (((p) >> 16) & 0xff) | ||
| 619 | #define EP_MAXPSTREAMS_MASK (0x1f << 10) | 628 | #define EP_MAXPSTREAMS_MASK (0x1f << 10) |
| 620 | #define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK) | 629 | #define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK) |
| 621 | /* Endpoint is set up with a Linear Stream Array (vs. Secondary Stream Array) */ | 630 | /* Endpoint is set up with a Linear Stream Array (vs. Secondary Stream Array) */ |
| @@ -640,6 +649,7 @@ struct xhci_ep_ctx { | |||
| 640 | /* bit 6 reserved */ | 649 | /* bit 6 reserved */ |
| 641 | /* bit 7 is Host Initiate Disable - for disabling stream selection */ | 650 | /* bit 7 is Host Initiate Disable - for disabling stream selection */ |
| 642 | #define MAX_BURST(p) (((p)&0xff) << 8) | 651 | #define MAX_BURST(p) (((p)&0xff) << 8) |
| 652 | #define CTX_TO_MAX_BURST(p) (((p) >> 8) & 0xff) | ||
| 643 | #define MAX_PACKET(p) (((p)&0xffff) << 16) | 653 | #define MAX_PACKET(p) (((p)&0xffff) << 16) |
| 644 | #define MAX_PACKET_MASK (0xffff << 16) | 654 | #define MAX_PACKET_MASK (0xffff << 16) |
| 645 | #define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff) | 655 | #define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff) |
| @@ -652,6 +662,7 @@ struct xhci_ep_ctx { | |||
| 652 | /* tx_info bitmasks */ | 662 | /* tx_info bitmasks */ |
| 653 | #define AVG_TRB_LENGTH_FOR_EP(p) ((p) & 0xffff) | 663 | #define AVG_TRB_LENGTH_FOR_EP(p) ((p) & 0xffff) |
| 654 | #define MAX_ESIT_PAYLOAD_FOR_EP(p) (((p) & 0xffff) << 16) | 664 | #define MAX_ESIT_PAYLOAD_FOR_EP(p) (((p) & 0xffff) << 16) |
| 665 | #define CTX_TO_MAX_ESIT_PAYLOAD(p) (((p) >> 16) & 0xffff) | ||
| 655 | 666 | ||
| 656 | /* deq bitmasks */ | 667 | /* deq bitmasks */ |
| 657 | #define EP_CTX_CYCLE_MASK (1 << 0) | 668 | #define EP_CTX_CYCLE_MASK (1 << 0) |
| @@ -670,6 +681,11 @@ struct xhci_input_control_ctx { | |||
| 670 | __le32 rsvd2[6]; | 681 | __le32 rsvd2[6]; |
| 671 | }; | 682 | }; |
| 672 | 683 | ||
| 684 | #define EP_IS_ADDED(ctrl_ctx, i) \ | ||
| 685 | (le32_to_cpu(ctrl_ctx->add_flags) & (1 << (i + 1))) | ||
| 686 | #define EP_IS_DROPPED(ctrl_ctx, i) \ | ||
| 687 | (le32_to_cpu(ctrl_ctx->drop_flags) & (1 << (i + 1))) | ||
| 688 | |||
| 673 | /* Represents everything that is needed to issue a command on the command ring. | 689 | /* Represents everything that is needed to issue a command on the command ring. |
| 674 | * It's useful to pre-allocate these for commands that cannot fail due to | 690 | * It's useful to pre-allocate these for commands that cannot fail due to |
| 675 | * out-of-memory errors, like freeing streams. | 691 | * out-of-memory errors, like freeing streams. |
| @@ -731,6 +747,67 @@ struct xhci_stream_info { | |||
| 731 | #define SMALL_STREAM_ARRAY_SIZE 256 | 747 | #define SMALL_STREAM_ARRAY_SIZE 256 |
| 732 | #define MEDIUM_STREAM_ARRAY_SIZE 1024 | 748 | #define MEDIUM_STREAM_ARRAY_SIZE 1024 |
| 733 | 749 | ||
| 750 | /* Some Intel xHCI host controllers need software to keep track of the bus | ||
| 751 | * bandwidth. Keep track of endpoint info here. Each root port is allocated | ||
| 752 | * the full bus bandwidth. We must also treat TTs (including each port under a | ||
| 753 | * multi-TT hub) as a separate bandwidth domain. The direct memory interface | ||
| 754 | * (DMI) also limits the total bandwidth (across all domains) that can be used. | ||
| 755 | */ | ||
| 756 | struct xhci_bw_info { | ||
| 757 | /* ep_interval is zero-based */ | ||
| 758 | unsigned int ep_interval; | ||
| 759 | /* mult and num_packets are one-based */ | ||
| 760 | unsigned int mult; | ||
| 761 | unsigned int num_packets; | ||
| 762 | unsigned int max_packet_size; | ||
| 763 | unsigned int max_esit_payload; | ||
| 764 | unsigned int type; | ||
| 765 | }; | ||
| 766 | |||
| 767 | /* "Block" sizes in bytes the hardware uses for different device speeds. | ||
| 768 | * The logic in this part of the hardware limits the number of bits the hardware | ||
| 769 | * can use, so must represent bandwidth in a less precise manner to mimic what | ||
| 770 | * the scheduler hardware computes. | ||
| 771 | */ | ||
| 772 | #define FS_BLOCK 1 | ||
| 773 | #define HS_BLOCK 4 | ||
| 774 | #define SS_BLOCK 16 | ||
| 775 | #define DMI_BLOCK 32 | ||
| 776 | |||
| 777 | /* Each device speed has a protocol overhead (CRC, bit stuffing, etc) associated | ||
| 778 | * with each byte transferred. SuperSpeed devices have an initial overhead to | ||
| 779 | * set up bursts. These are in blocks, see above. LS overhead has already been | ||
| 780 | * translated into FS blocks. | ||
| 781 | */ | ||
| 782 | #define DMI_OVERHEAD 8 | ||
| 783 | #define DMI_OVERHEAD_BURST 4 | ||
| 784 | #define SS_OVERHEAD 8 | ||
| 785 | #define SS_OVERHEAD_BURST 32 | ||
| 786 | #define HS_OVERHEAD 26 | ||
| 787 | #define FS_OVERHEAD 20 | ||
| 788 | #define LS_OVERHEAD 128 | ||
| 789 | /* The TTs need to claim roughly twice as much bandwidth (94 bytes per | ||
| 790 | * microframe ~= 24Mbps) of the HS bus as the devices can actually use because | ||
| 791 | * of overhead associated with split transfers crossing microframe boundaries. | ||
| 792 | * 31 blocks is pure protocol overhead. | ||
| 793 | */ | ||
| 794 | #define TT_HS_OVERHEAD (31 + 94) | ||
| 795 | #define TT_DMI_OVERHEAD (25 + 12) | ||
| 796 | |||
| 797 | /* Bandwidth limits in blocks */ | ||
| 798 | #define FS_BW_LIMIT 1285 | ||
| 799 | #define TT_BW_LIMIT 1320 | ||
| 800 | #define HS_BW_LIMIT 1607 | ||
| 801 | #define SS_BW_LIMIT_IN 3906 | ||
| 802 | #define DMI_BW_LIMIT_IN 3906 | ||
| 803 | #define SS_BW_LIMIT_OUT 3906 | ||
| 804 | #define DMI_BW_LIMIT_OUT 3906 | ||
| 805 | |||
| 806 | /* Percentage of bus bandwidth reserved for non-periodic transfers */ | ||
| 807 | #define FS_BW_RESERVED 10 | ||
| 808 | #define HS_BW_RESERVED 20 | ||
| 809 | #define SS_BW_RESERVED 10 | ||
| 810 | |||
| 734 | struct xhci_virt_ep { | 811 | struct xhci_virt_ep { |
| 735 | struct xhci_ring *ring; | 812 | struct xhci_ring *ring; |
| 736 | /* Related to endpoints that are configured to use stream IDs only */ | 813 | /* Related to endpoints that are configured to use stream IDs only */ |
| @@ -772,8 +849,39 @@ struct xhci_virt_ep { | |||
| 772 | * process the missed tds on the endpoint ring. | 849 | * process the missed tds on the endpoint ring. |
| 773 | */ | 850 | */ |
| 774 | bool skip; | 851 | bool skip; |
| 852 | /* Bandwidth checking storage */ | ||
| 853 | struct xhci_bw_info bw_info; | ||
| 854 | struct list_head bw_endpoint_list; | ||
| 855 | }; | ||
| 856 | |||
| 857 | enum xhci_overhead_type { | ||
| 858 | LS_OVERHEAD_TYPE = 0, | ||
| 859 | FS_OVERHEAD_TYPE, | ||
| 860 | HS_OVERHEAD_TYPE, | ||
| 861 | }; | ||
| 862 | |||
| 863 | struct xhci_interval_bw { | ||
| 864 | unsigned int num_packets; | ||
| 865 | /* Sorted by max packet size. | ||
| 866 | * Head of the list is the greatest max packet size. | ||
| 867 | */ | ||
| 868 | struct list_head endpoints; | ||
| 869 | /* How many endpoints of each speed are present. */ | ||
| 870 | unsigned int overhead[3]; | ||
| 871 | }; | ||
| 872 | |||
| 873 | #define XHCI_MAX_INTERVAL 16 | ||
| 874 | |||
| 875 | struct xhci_interval_bw_table { | ||
| 876 | unsigned int interval0_esit_payload; | ||
| 877 | struct xhci_interval_bw interval_bw[XHCI_MAX_INTERVAL]; | ||
| 878 | /* Includes reserved bandwidth for async endpoints */ | ||
| 879 | unsigned int bw_used; | ||
| 880 | unsigned int ss_bw_in; | ||
| 881 | unsigned int ss_bw_out; | ||
| 775 | }; | 882 | }; |
| 776 | 883 | ||
| 884 | |||
| 777 | struct xhci_virt_device { | 885 | struct xhci_virt_device { |
| 778 | struct usb_device *udev; | 886 | struct usb_device *udev; |
| 779 | /* | 887 | /* |
| @@ -798,7 +906,32 @@ struct xhci_virt_device { | |||
| 798 | /* Status of the last command issued for this device */ | 906 | /* Status of the last command issued for this device */ |
| 799 | u32 cmd_status; | 907 | u32 cmd_status; |
| 800 | struct list_head cmd_list; | 908 | struct list_head cmd_list; |
| 801 | u8 port; | 909 | u8 fake_port; |
| 910 | u8 real_port; | ||
| 911 | struct xhci_interval_bw_table *bw_table; | ||
| 912 | struct xhci_tt_bw_info *tt_info; | ||
| 913 | }; | ||
| 914 | |||
| 915 | /* | ||
| 916 | * For each roothub, keep track of the bandwidth information for each periodic | ||
| 917 | * interval. | ||
| 918 | * | ||
| 919 | * If a high speed hub is attached to the roothub, each TT associated with that | ||
| 920 | * hub is a separate bandwidth domain. The interval information for the | ||
| 921 | * endpoints on the devices under that TT will appear in the TT structure. | ||
| 922 | */ | ||
| 923 | struct xhci_root_port_bw_info { | ||
| 924 | struct list_head tts; | ||
| 925 | unsigned int num_active_tts; | ||
| 926 | struct xhci_interval_bw_table bw_table; | ||
| 927 | }; | ||
| 928 | |||
| 929 | struct xhci_tt_bw_info { | ||
| 930 | struct list_head tt_list; | ||
| 931 | int slot_id; | ||
| 932 | int ttport; | ||
| 933 | struct xhci_interval_bw_table bw_table; | ||
| 934 | int active_eps; | ||
| 802 | }; | 935 | }; |
| 803 | 936 | ||
| 804 | 937 | ||
| @@ -1198,6 +1331,12 @@ struct s3_save { | |||
| 1198 | u64 erst_dequeue; | 1331 | u64 erst_dequeue; |
| 1199 | }; | 1332 | }; |
| 1200 | 1333 | ||
| 1334 | /* Use for lpm */ | ||
| 1335 | struct dev_info { | ||
| 1336 | u32 dev_id; | ||
| 1337 | struct list_head list; | ||
| 1338 | }; | ||
| 1339 | |||
| 1201 | struct xhci_bus_state { | 1340 | struct xhci_bus_state { |
| 1202 | unsigned long bus_suspended; | 1341 | unsigned long bus_suspended; |
| 1203 | unsigned long next_statechange; | 1342 | unsigned long next_statechange; |
| @@ -1261,12 +1400,16 @@ struct xhci_hcd { | |||
| 1261 | struct xhci_erst erst; | 1400 | struct xhci_erst erst; |
| 1262 | /* Scratchpad */ | 1401 | /* Scratchpad */ |
| 1263 | struct xhci_scratchpad *scratchpad; | 1402 | struct xhci_scratchpad *scratchpad; |
| 1403 | /* Store LPM test failed devices' information */ | ||
| 1404 | struct list_head lpm_failed_devs; | ||
| 1264 | 1405 | ||
| 1265 | /* slot enabling and address device helpers */ | 1406 | /* slot enabling and address device helpers */ |
| 1266 | struct completion addr_dev; | 1407 | struct completion addr_dev; |
| 1267 | int slot_id; | 1408 | int slot_id; |
| 1268 | /* Internal mirror of the HW's dcbaa */ | 1409 | /* Internal mirror of the HW's dcbaa */ |
| 1269 | struct xhci_virt_device *devs[MAX_HC_SLOTS]; | 1410 | struct xhci_virt_device *devs[MAX_HC_SLOTS]; |
| 1411 | /* For keeping track of bandwidth domains per roothub. */ | ||
| 1412 | struct xhci_root_port_bw_info *rh_bw; | ||
| 1270 | 1413 | ||
| 1271 | /* DMA pools */ | 1414 | /* DMA pools */ |
| 1272 | struct dma_pool *device_pool; | 1415 | struct dma_pool *device_pool; |
| @@ -1318,6 +1461,8 @@ struct xhci_hcd { | |||
| 1318 | #define XHCI_EP_LIMIT_QUIRK (1 << 5) | 1461 | #define XHCI_EP_LIMIT_QUIRK (1 << 5) |
| 1319 | #define XHCI_BROKEN_MSI (1 << 6) | 1462 | #define XHCI_BROKEN_MSI (1 << 6) |
| 1320 | #define XHCI_RESET_ON_RESUME (1 << 7) | 1463 | #define XHCI_RESET_ON_RESUME (1 << 7) |
| 1464 | #define XHCI_SW_BW_CHECKING (1 << 8) | ||
| 1465 | #define XHCI_AMD_0x96_HOST (1 << 9) | ||
| 1321 | unsigned int num_active_eps; | 1466 | unsigned int num_active_eps; |
| 1322 | unsigned int limit_active_eps; | 1467 | unsigned int limit_active_eps; |
| 1323 | /* There are two roothubs to keep track of bus suspend info for */ | 1468 | /* There are two roothubs to keep track of bus suspend info for */ |
| @@ -1330,6 +1475,10 @@ struct xhci_hcd { | |||
| 1330 | /* Array of pointers to USB 2.0 PORTSC registers */ | 1475 | /* Array of pointers to USB 2.0 PORTSC registers */ |
| 1331 | __le32 __iomem **usb2_ports; | 1476 | __le32 __iomem **usb2_ports; |
| 1332 | unsigned int num_usb2_ports; | 1477 | unsigned int num_usb2_ports; |
| 1478 | /* support xHCI 0.96 spec USB2 software LPM */ | ||
| 1479 | unsigned sw_lpm_support:1; | ||
| 1480 | /* support xHCI 1.0 spec USB2 hardware LPM */ | ||
| 1481 | unsigned hw_lpm_support:1; | ||
| 1333 | }; | 1482 | }; |
| 1334 | 1483 | ||
| 1335 | /* convert between an HCD pointer and the corresponding EHCI_HCD */ | 1484 | /* convert between an HCD pointer and the corresponding EHCI_HCD */ |
| @@ -1401,9 +1550,7 @@ static inline void xhci_write_64(struct xhci_hcd *xhci, | |||
| 1401 | 1550 | ||
| 1402 | static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci) | 1551 | static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci) |
| 1403 | { | 1552 | { |
| 1404 | u32 temp = xhci_readl(xhci, &xhci->cap_regs->hc_capbase); | 1553 | return xhci->quirks & XHCI_LINK_TRB_QUIRK; |
| 1405 | return ((HC_VERSION(temp) == 0x95) && | ||
| 1406 | (xhci->quirks & XHCI_LINK_TRB_QUIRK)); | ||
| 1407 | } | 1554 | } |
| 1408 | 1555 | ||
| 1409 | /* xHCI debugging */ | 1556 | /* xHCI debugging */ |
| @@ -1438,6 +1585,20 @@ unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc); | |||
| 1438 | unsigned int xhci_get_endpoint_flag_from_index(unsigned int ep_index); | 1585 | unsigned int xhci_get_endpoint_flag_from_index(unsigned int ep_index); |
| 1439 | unsigned int xhci_last_valid_endpoint(u32 added_ctxs); | 1586 | unsigned int xhci_last_valid_endpoint(u32 added_ctxs); |
| 1440 | void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep); | 1587 | void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep); |
| 1588 | void xhci_drop_ep_from_interval_table(struct xhci_hcd *xhci, | ||
| 1589 | struct xhci_bw_info *ep_bw, | ||
| 1590 | struct xhci_interval_bw_table *bw_table, | ||
| 1591 | struct usb_device *udev, | ||
| 1592 | struct xhci_virt_ep *virt_ep, | ||
| 1593 | struct xhci_tt_bw_info *tt_info); | ||
| 1594 | void xhci_update_tt_active_eps(struct xhci_hcd *xhci, | ||
| 1595 | struct xhci_virt_device *virt_dev, | ||
| 1596 | int old_active_eps); | ||
| 1597 | void xhci_clear_endpoint_bw_info(struct xhci_bw_info *bw_info); | ||
| 1598 | void xhci_update_bw_info(struct xhci_hcd *xhci, | ||
| 1599 | struct xhci_container_ctx *in_ctx, | ||
| 1600 | struct xhci_input_control_ctx *ctrl_ctx, | ||
| 1601 | struct xhci_virt_device *virt_dev); | ||
| 1441 | void xhci_endpoint_copy(struct xhci_hcd *xhci, | 1602 | void xhci_endpoint_copy(struct xhci_hcd *xhci, |
| 1442 | struct xhci_container_ctx *in_ctx, | 1603 | struct xhci_container_ctx *in_ctx, |
| 1443 | struct xhci_container_ctx *out_ctx, | 1604 | struct xhci_container_ctx *out_ctx, |
| @@ -1483,9 +1644,13 @@ void xhci_free_command(struct xhci_hcd *xhci, | |||
| 1483 | /* xHCI PCI glue */ | 1644 | /* xHCI PCI glue */ |
| 1484 | int xhci_register_pci(void); | 1645 | int xhci_register_pci(void); |
| 1485 | void xhci_unregister_pci(void); | 1646 | void xhci_unregister_pci(void); |
| 1647 | #else | ||
| 1648 | static inline int xhci_register_pci(void) { return 0; } | ||
| 1649 | static inline void xhci_unregister_pci(void) {} | ||
| 1486 | #endif | 1650 | #endif |
| 1487 | 1651 | ||
| 1488 | /* xHCI host controller glue */ | 1652 | /* xHCI host controller glue */ |
| 1653 | typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *); | ||
| 1489 | void xhci_quiesce(struct xhci_hcd *xhci); | 1654 | void xhci_quiesce(struct xhci_hcd *xhci); |
| 1490 | int xhci_halt(struct xhci_hcd *xhci); | 1655 | int xhci_halt(struct xhci_hcd *xhci); |
| 1491 | int xhci_reset(struct xhci_hcd *xhci); | 1656 | int xhci_reset(struct xhci_hcd *xhci); |
| @@ -1493,6 +1658,7 @@ int xhci_init(struct usb_hcd *hcd); | |||
| 1493 | int xhci_run(struct usb_hcd *hcd); | 1658 | int xhci_run(struct usb_hcd *hcd); |
| 1494 | void xhci_stop(struct usb_hcd *hcd); | 1659 | void xhci_stop(struct usb_hcd *hcd); |
| 1495 | void xhci_shutdown(struct usb_hcd *hcd); | 1660 | void xhci_shutdown(struct usb_hcd *hcd); |
| 1661 | int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks); | ||
| 1496 | 1662 | ||
| 1497 | #ifdef CONFIG_PM | 1663 | #ifdef CONFIG_PM |
| 1498 | int xhci_suspend(struct xhci_hcd *xhci); | 1664 | int xhci_suspend(struct xhci_hcd *xhci); |
| @@ -1507,6 +1673,10 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd); | |||
| 1507 | irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd); | 1673 | irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd); |
| 1508 | int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev); | 1674 | int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev); |
| 1509 | void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev); | 1675 | void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev); |
| 1676 | int xhci_alloc_tt_info(struct xhci_hcd *xhci, | ||
| 1677 | struct xhci_virt_device *virt_dev, | ||
| 1678 | struct usb_device *hdev, | ||
| 1679 | struct usb_tt *tt, gfp_t mem_flags); | ||
| 1510 | int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev, | 1680 | int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev, |
| 1511 | struct usb_host_endpoint **eps, unsigned int num_eps, | 1681 | struct usb_host_endpoint **eps, unsigned int num_eps, |
| 1512 | unsigned int num_streams, gfp_t mem_flags); | 1682 | unsigned int num_streams, gfp_t mem_flags); |
| @@ -1514,6 +1684,9 @@ int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev, | |||
| 1514 | struct usb_host_endpoint **eps, unsigned int num_eps, | 1684 | struct usb_host_endpoint **eps, unsigned int num_eps, |
| 1515 | gfp_t mem_flags); | 1685 | gfp_t mem_flags); |
| 1516 | int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev); | 1686 | int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev); |
| 1687 | int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev); | ||
| 1688 | int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, | ||
| 1689 | struct usb_device *udev, int enable); | ||
| 1517 | int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev, | 1690 | int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev, |
| 1518 | struct usb_tt *tt, gfp_t mem_flags); | 1691 | struct usb_tt *tt, gfp_t mem_flags); |
| 1519 | int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags); | 1692 | int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags); |
| @@ -1572,6 +1745,10 @@ void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id, | |||
| 1572 | unsigned int ep_index, unsigned int stream_id); | 1745 | unsigned int ep_index, unsigned int stream_id); |
| 1573 | 1746 | ||
| 1574 | /* xHCI roothub code */ | 1747 | /* xHCI roothub code */ |
| 1748 | void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array, | ||
| 1749 | int port_id, u32 link_state); | ||
| 1750 | void xhci_test_and_clear_bit(struct xhci_hcd *xhci, __le32 __iomem **port_array, | ||
| 1751 | int port_id, u32 port_bit); | ||
| 1575 | int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, | 1752 | int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, |
| 1576 | char *buf, u16 wLength); | 1753 | char *buf, u16 wLength); |
| 1577 | int xhci_hub_status_data(struct usb_hcd *hcd, char *buf); | 1754 | int xhci_hub_status_data(struct usb_hcd *hcd, char *buf); |
