Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'dwc3-for-v3.5' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next

usb: dwc3: patches for v3.5 merge window

This pull request contains one workaround for a Silicon
Issue found on all RTL releases prior to 2.20a, which
would cause a metastability state on Run/Stop bit.

We also have some patches implementing a few extra Standard
requests introduced by USB3 spec (Set SEL and Set Isoch Delay),
as well as one patch, which has been pending for a long time,
implementing LPM support.

Last, but not least, we are splitting the host address space
out of the dwc3 core driver otherwise xHCI won't be able to
request_mem_region() its own address space. This patch is
only needed because we are (as we should) re-using the xHCI
driver, which is a completely separate module.

Together with these three big changes, come a few extra preparatory
patches which most move code around, define macros and so on, as
well as a fix for Isochronous transfers which hasn't been triggered
before.

[ resolved conflicts and build error in drivers/usb/dwc3/gadget.c - gregkh]

+324 -83
+17 -12
drivers/usb/dwc3/core.c
··· 410 410 struct device *dev = &pdev->dev; 411 411 412 412 int ret = -ENOMEM; 413 - int irq; 414 413 415 414 void __iomem *regs; 416 415 void *mem; ··· 424 425 dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1); 425 426 dwc->mem = mem; 426 427 427 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 428 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 428 429 if (!res) { 429 - dev_err(dev, "missing resource\n"); 430 + dev_err(dev, "missing IRQ\n"); 430 431 return -ENODEV; 431 432 } 433 + dwc->xhci_resources[1] = *res; 432 434 433 - dwc->res = res; 435 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 436 + if (!res) { 437 + dev_err(dev, "missing memory resource\n"); 438 + return -ENODEV; 439 + } 440 + dwc->xhci_resources[0] = *res; 441 + dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + 442 + DWC3_XHCI_REGS_END; 434 443 435 - res = devm_request_mem_region(dev, res->start, resource_size(res), 444 + /* 445 + * Request memory region but exclude xHCI regs, 446 + * since it will be requested by the xhci-plat driver. 447 + */ 448 + res = devm_request_mem_region(dev, res->start + DWC3_GLOBALS_REGS_START, 449 + resource_size(res) - DWC3_GLOBALS_REGS_START, 436 450 dev_name(dev)); 437 451 if (!res) { 438 452 dev_err(dev, "can't request mem region\n"); ··· 458 446 return -ENOMEM; 459 447 } 460 448 461 - irq = platform_get_irq(pdev, 0); 462 - if (irq < 0) { 463 - dev_err(dev, "missing IRQ\n"); 464 - return -ENODEV; 465 - } 466 - 467 449 spin_lock_init(&dwc->lock); 468 450 platform_set_drvdata(pdev, dwc); 469 451 470 452 dwc->regs = regs; 471 453 dwc->regs_size = resource_size(res); 472 454 dwc->dev = dev; 473 - dwc->irq = irq; 474 455 475 456 if (!strncmp("super", maximum_speed, 5)) 476 457 dwc->maximum_speed = DWC3_DCFG_SUPERSPEED;
+34 -5
drivers/usb/dwc3/core.h
··· 51 51 #include <linux/usb/gadget.h> 52 52 53 53 /* Global constants */ 54 + #define DWC3_EP0_BOUNCE_SIZE 512 54 55 #define DWC3_ENDPOINTS_NUM 32 56 + #define DWC3_XHCI_RESOURCES_NUM 2 55 57 56 58 #define DWC3_EVENT_BUFFERS_SIZE PAGE_SIZE 57 59 #define DWC3_EVENT_TYPE_MASK 0xfe ··· 76 74 #define DWC3_GEVNTCOUNT_MASK 0xfffc 77 75 #define DWC3_GSNPSID_MASK 0xffff0000 78 76 #define DWC3_GSNPSREV_MASK 0xffff 77 + 78 + /* DWC3 registers memory space boundries */ 79 + #define DWC3_XHCI_REGS_START 0x0 80 + #define DWC3_XHCI_REGS_END 0x7fff 81 + #define DWC3_GLOBALS_REGS_START 0xc100 82 + #define DWC3_GLOBALS_REGS_END 0xc6ff 83 + #define DWC3_DEVICE_REGS_START 0xc700 84 + #define DWC3_DEVICE_REGS_END 0xcbff 85 + #define DWC3_OTG_REGS_START 0xcc00 86 + #define DWC3_OTG_REGS_END 0xccff 79 87 80 88 /* Global Registers */ 81 89 #define DWC3_GSBUSCFG0 0xc100 ··· 195 183 #define DWC3_GHWPARAMS1_EN_PWROPT_CLK 1 196 184 197 185 /* Device Configuration Register */ 186 + #define DWC3_DCFG_LPM_CAP (1 << 22) 198 187 #define DWC3_DCFG_DEVADDR(addr) ((addr) << 3) 199 188 #define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f) 200 189 ··· 285 272 #define DWC3_DGCMD_SET_ENDPOINT_NRDY 0x0c 286 273 #define DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK 0x10 287 274 275 + #define DWC3_DGCMD_STATUS(n) (((n) >> 15) & 1) 276 + #define DWC3_DGCMD_CMDACT (1 << 10) 277 + 288 278 /* Device Endpoint Command Register */ 289 279 #define DWC3_DEPCMD_PARAM_SHIFT 16 290 280 #define DWC3_DEPCMD_PARAM(x) ((x) << DWC3_DEPCMD_PARAM_SHIFT) 291 281 #define DWC3_DEPCMD_GET_RSC_IDX(x) (((x) >> DWC3_DEPCMD_PARAM_SHIFT) & 0x7f) 292 - #define DWC3_DEPCMD_STATUS_MASK (0x0f << 12) 293 - #define DWC3_DEPCMD_STATUS(x) (((x) & DWC3_DEPCMD_STATUS_MASK) >> 12) 282 + #define DWC3_DEPCMD_STATUS(x) (((x) >> 15) & 1) 294 283 #define DWC3_DEPCMD_HIPRI_FORCERM (1 << 11) 295 284 #define DWC3_DEPCMD_CMDACT (1 << 10) 296 285 #define DWC3_DEPCMD_CMDIOC (1 << 8) ··· 575 560 * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround 576 561 * @needs_fifo_resize: not all users might want fifo resizing, flag it 577 562 * @resize_fifos: tells us it's ok to reconfigure our TxFIFO sizes. 563 + * @isoch_delay: wValue from Set Isochronous Delay request; 564 + * @u2sel: parameter from Set SEL request. 565 + * @u2pel: parameter from Set SEL request. 566 + * @u1sel: parameter from Set SEL request. 567 + * @u1pel: parameter from Set SEL request. 578 568 * @ep0_next_event: hold the next expected event 579 569 * @ep0state: state of endpoint zero 580 570 * @link_state: link state ··· 602 582 struct device *dev; 603 583 604 584 struct platform_device *xhci; 605 - struct resource *res; 585 + struct resource xhci_resources[DWC3_XHCI_RESOURCES_NUM]; 606 586 607 587 struct dwc3_event_buffer **ev_buffs; 608 588 struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM]; ··· 612 592 613 593 void __iomem *regs; 614 594 size_t regs_size; 615 - 616 - int irq; 617 595 618 596 u32 num_event_buffers; 619 597 u32 u1u2; ··· 626 608 #define DWC3_REVISION_185A 0x5533185a 627 609 #define DWC3_REVISION_188A 0x5533188a 628 610 #define DWC3_REVISION_190A 0x5533190a 611 + #define DWC3_REVISION_200A 0x5533200a 612 + #define DWC3_REVISION_202A 0x5533202a 613 + #define DWC3_REVISION_210A 0x5533210a 614 + #define DWC3_REVISION_220A 0x5533220a 629 615 630 616 unsigned is_selfpowered:1; 631 617 unsigned three_stage_setup:1; ··· 646 624 enum dwc3_link_state link_state; 647 625 enum dwc3_device_state dev_state; 648 626 627 + u16 isoch_delay; 628 + u16 u2sel; 629 + u16 u2pel; 630 + u8 u1sel; 631 + u8 u1pel; 632 + 649 633 u8 speed; 634 + 650 635 void *mem; 651 636 652 637 struct dwc3_hwparams hwparams;
+21 -11
drivers/usb/dwc3/dwc3-omap.c
··· 49 49 #include <linux/of.h> 50 50 51 51 #include "core.h" 52 - #include "io.h" 53 52 54 53 /* 55 54 * All these registers belong to OMAP's Wrapper around the ··· 142 143 u32 dma_status:1; 143 144 }; 144 145 146 + static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset) 147 + { 148 + return readl(base + offset); 149 + } 150 + 151 + static inline void dwc3_omap_writel(void __iomem *base, u32 offset, u32 value) 152 + { 153 + writel(value, base + offset); 154 + } 155 + 156 + 145 157 static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap) 146 158 { 147 159 struct dwc3_omap *omap = _omap; ··· 160 150 161 151 spin_lock(&omap->lock); 162 152 163 - reg = dwc3_readl(omap->base, USBOTGSS_IRQSTATUS_1); 153 + reg = dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_1); 164 154 165 155 if (reg & USBOTGSS_IRQ1_DMADISABLECLR) { 166 156 dev_dbg(omap->dev, "DMA Disable was Cleared\n"); ··· 194 184 if (reg & USBOTGSS_IRQ1_IDPULLUP_FALL) 195 185 dev_dbg(omap->dev, "IDPULLUP Fall\n"); 196 186 197 - dwc3_writel(omap->base, USBOTGSS_IRQSTATUS_1, reg); 187 + dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_1, reg); 198 188 199 - reg = dwc3_readl(omap->base, USBOTGSS_IRQSTATUS_0); 200 - dwc3_writel(omap->base, USBOTGSS_IRQSTATUS_0, reg); 189 + reg = dwc3_omap_readl(omap->base, USBOTGSS_IRQSTATUS_0); 190 + dwc3_omap_writel(omap->base, USBOTGSS_IRQSTATUS_0, reg); 201 191 202 192 spin_unlock(&omap->lock); 203 193 ··· 280 270 omap->base = base; 281 271 omap->dwc3 = dwc3; 282 272 283 - reg = dwc3_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); 273 + reg = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); 284 274 285 275 utmi_mode = of_get_property(node, "utmi-mode", &size); 286 276 if (utmi_mode && size == sizeof(*utmi_mode)) { ··· 303 293 } 304 294 } 305 295 306 - dwc3_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, reg); 296 + dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, reg); 307 297 308 298 /* check the DMA Status */ 309 - reg = dwc3_readl(omap->base, USBOTGSS_SYSCONFIG); 299 + reg = dwc3_omap_readl(omap->base, USBOTGSS_SYSCONFIG); 310 300 omap->dma_status = !!(reg & USBOTGSS_SYSCONFIG_DMADISABLE); 311 301 312 302 /* Set No-Idle and No-Standby */ ··· 316 306 reg |= (USBOTGSS_SYSCONFIG_STANDBYMODE(USBOTGSS_STANDBYMODE_NO_STANDBY) 317 307 | USBOTGSS_SYSCONFIG_IDLEMODE(USBOTGSS_IDLEMODE_NO_IDLE)); 318 308 319 - dwc3_writel(omap->base, USBOTGSS_SYSCONFIG, reg); 309 + dwc3_omap_writel(omap->base, USBOTGSS_SYSCONFIG, reg); 320 310 321 311 ret = devm_request_irq(dev, omap->irq, dwc3_omap_interrupt, 0, 322 312 "dwc3-omap", omap); ··· 328 318 329 319 /* enable all IRQs */ 330 320 reg = USBOTGSS_IRQO_COREIRQ_ST; 331 - dwc3_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, reg); 321 + dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, reg); 332 322 333 323 reg = (USBOTGSS_IRQ1_OEVT | 334 324 USBOTGSS_IRQ1_DRVVBUS_RISE | ··· 340 330 USBOTGSS_IRQ1_DISCHRGVBUS_FALL | 341 331 USBOTGSS_IRQ1_IDPULLUP_FALL); 342 332 343 - dwc3_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg); 333 + dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg); 344 334 345 335 ret = platform_device_add_resources(dwc3, pdev->resource, 346 336 pdev->num_resources);
+144 -11
drivers/usb/dwc3/ep0.c
··· 261 261 { 262 262 struct dwc3_ep *dep; 263 263 u32 recip; 264 + u32 reg; 264 265 u16 usb_status = 0; 265 266 __le16 *response_pkt; 266 267 ··· 269 268 switch (recip) { 270 269 case USB_RECIP_DEVICE: 271 270 /* 272 - * We are self-powered. U1/U2/LTM will be set later 273 - * once we handle this states. RemoteWakeup is 0 on SS 271 + * LTM will be set once we know how to set this in HW. 274 272 */ 275 273 usb_status |= dwc->is_selfpowered << USB_DEVICE_SELF_POWERED; 274 + 275 + if (dwc->speed == DWC3_DSTS_SUPERSPEED) { 276 + reg = dwc3_readl(dwc->regs, DWC3_DCTL); 277 + if (reg & DWC3_DCTL_INITU1ENA) 278 + usb_status |= 1 << USB_DEV_STAT_U1_ENABLED; 279 + if (reg & DWC3_DCTL_INITU2ENA) 280 + usb_status |= 1 << USB_DEV_STAT_U2_ENABLED; 281 + } 282 + 276 283 break; 277 284 278 285 case USB_RECIP_INTERFACE: ··· 321 312 u32 recip; 322 313 u32 wValue; 323 314 u32 wIndex; 315 + u32 reg; 324 316 int ret; 325 317 326 318 wValue = le16_to_cpu(ctrl->wValue); ··· 330 320 switch (recip) { 331 321 case USB_RECIP_DEVICE: 332 322 323 + switch (wValue) { 324 + case USB_DEVICE_REMOTE_WAKEUP: 325 + break; 333 326 /* 334 327 * 9.4.1 says only only for SS, in AddressState only for 335 328 * default control pipe 336 329 */ 337 - switch (wValue) { 338 330 case USB_DEVICE_U1_ENABLE: 339 - case USB_DEVICE_U2_ENABLE: 340 - case USB_DEVICE_LTM_ENABLE: 341 331 if (dwc->dev_state != DWC3_CONFIGURED_STATE) 342 332 return -EINVAL; 343 333 if (dwc->speed != DWC3_DSTS_SUPERSPEED) 344 334 return -EINVAL; 345 - } 346 335 347 - /* XXX add U[12] & LTM */ 348 - switch (wValue) { 349 - case USB_DEVICE_REMOTE_WAKEUP: 336 + reg = dwc3_readl(dwc->regs, DWC3_DCTL); 337 + if (set) 338 + reg |= DWC3_DCTL_INITU1ENA; 339 + else 340 + reg &= ~DWC3_DCTL_INITU1ENA; 341 + dwc3_writel(dwc->regs, DWC3_DCTL, reg); 350 342 break; 351 - case USB_DEVICE_U1_ENABLE: 352 - break; 343 + 353 344 case USB_DEVICE_U2_ENABLE: 345 + if (dwc->dev_state != DWC3_CONFIGURED_STATE) 346 + return -EINVAL; 347 + if (dwc->speed != DWC3_DSTS_SUPERSPEED) 348 + return -EINVAL; 349 + 350 + reg = dwc3_readl(dwc->regs, DWC3_DCTL); 351 + if (set) 352 + reg |= DWC3_DCTL_INITU2ENA; 353 + else 354 + reg &= ~DWC3_DCTL_INITU2ENA; 355 + dwc3_writel(dwc->regs, DWC3_DCTL, reg); 354 356 break; 357 + 355 358 case USB_DEVICE_LTM_ENABLE: 359 + return -EINVAL; 356 360 break; 357 361 358 362 case USB_DEVICE_TEST_MODE: ··· 493 469 return ret; 494 470 } 495 471 472 + static void dwc3_ep0_set_sel_cmpl(struct usb_ep *ep, struct usb_request *req) 473 + { 474 + struct dwc3_ep *dep = to_dwc3_ep(ep); 475 + struct dwc3 *dwc = dep->dwc; 476 + 477 + u32 param = 0; 478 + u32 reg; 479 + 480 + struct timing { 481 + u8 u1sel; 482 + u8 u1pel; 483 + u16 u2sel; 484 + u16 u2pel; 485 + } __packed timing; 486 + 487 + int ret; 488 + 489 + memcpy(&timing, req->buf, sizeof(timing)); 490 + 491 + dwc->u1sel = timing.u1sel; 492 + dwc->u1pel = timing.u1pel; 493 + dwc->u2sel = timing.u2sel; 494 + dwc->u2pel = timing.u2pel; 495 + 496 + reg = dwc3_readl(dwc->regs, DWC3_DCTL); 497 + if (reg & DWC3_DCTL_INITU2ENA) 498 + param = dwc->u2pel; 499 + if (reg & DWC3_DCTL_INITU1ENA) 500 + param = dwc->u1pel; 501 + 502 + /* 503 + * According to Synopsys Databook, if parameter is 504 + * greater than 125, a value of zero should be 505 + * programmed in the register. 506 + */ 507 + if (param > 125) 508 + param = 0; 509 + 510 + /* now that we have the time, issue DGCMD Set Sel */ 511 + ret = dwc3_send_gadget_generic_command(dwc, 512 + DWC3_DGCMD_SET_PERIODIC_PAR, param); 513 + WARN_ON(ret < 0); 514 + } 515 + 516 + static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 517 + { 518 + struct dwc3_ep *dep; 519 + u16 wLength; 520 + u16 wValue; 521 + 522 + if (dwc->dev_state == DWC3_DEFAULT_STATE) 523 + return -EINVAL; 524 + 525 + wValue = le16_to_cpu(ctrl->wValue); 526 + wLength = le16_to_cpu(ctrl->wLength); 527 + 528 + if (wLength != 6) { 529 + dev_err(dwc->dev, "Set SEL should be 6 bytes, got %d\n", 530 + wLength); 531 + return -EINVAL; 532 + } 533 + 534 + /* 535 + * To handle Set SEL we need to receive 6 bytes from Host. So let's 536 + * queue a usb_request for 6 bytes. 537 + * 538 + * Remember, though, this controller can't handle non-wMaxPacketSize 539 + * aligned transfers on the OUT direction, so we queue a request for 540 + * wMaxPacketSize instead. 541 + */ 542 + dep = dwc->eps[0]; 543 + dwc->ep0_usb_req.dep = dep; 544 + dwc->ep0_usb_req.request.length = dep->endpoint.maxpacket; 545 + dwc->ep0_usb_req.request.buf = dwc->setup_buf; 546 + dwc->ep0_usb_req.request.complete = dwc3_ep0_set_sel_cmpl; 547 + 548 + return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req); 549 + } 550 + 551 + static int dwc3_ep0_set_isoch_delay(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 552 + { 553 + u16 wLength; 554 + u16 wValue; 555 + u16 wIndex; 556 + 557 + wValue = le16_to_cpu(ctrl->wValue); 558 + wLength = le16_to_cpu(ctrl->wLength); 559 + wIndex = le16_to_cpu(ctrl->wIndex); 560 + 561 + if (wIndex || wLength) 562 + return -EINVAL; 563 + 564 + /* 565 + * REVISIT It's unclear from Databook what to do with this 566 + * value. For now, just cache it. 567 + */ 568 + dwc->isoch_delay = wValue; 569 + 570 + return 0; 571 + } 572 + 496 573 static int dwc3_ep0_std_request(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 497 574 { 498 575 int ret; ··· 618 493 case USB_REQ_SET_CONFIGURATION: 619 494 dev_vdbg(dwc->dev, "USB_REQ_SET_CONFIGURATION\n"); 620 495 ret = dwc3_ep0_set_config(dwc, ctrl); 496 + break; 497 + case USB_REQ_SET_SEL: 498 + dev_vdbg(dwc->dev, "USB_REQ_SET_SEL\n"); 499 + ret = dwc3_ep0_set_sel(dwc, ctrl); 500 + break; 501 + case USB_REQ_SET_ISOCH_DELAY: 502 + dev_vdbg(dwc->dev, "USB_REQ_SET_ISOCH_DELAY\n"); 503 + ret = dwc3_ep0_set_isoch_delay(dwc, ctrl); 621 504 break; 622 505 default: 623 506 dev_vdbg(dwc->dev, "Forwarding to gadget driver\n");
+89 -25
drivers/usb/dwc3/gadget.c
··· 276 276 } 277 277 } 278 278 279 + int dwc3_send_gadget_generic_command(struct dwc3 *dwc, int cmd, u32 param) 280 + { 281 + u32 timeout = 500; 282 + u32 reg; 283 + 284 + dwc3_writel(dwc->regs, DWC3_DGCMDPAR, param); 285 + dwc3_writel(dwc->regs, DWC3_DGCMD, cmd | DWC3_DGCMD_CMDACT); 286 + 287 + do { 288 + reg = dwc3_readl(dwc->regs, DWC3_DGCMD); 289 + if (!(reg & DWC3_DGCMD_CMDACT)) { 290 + dev_vdbg(dwc->dev, "Command Complete --> %d\n", 291 + DWC3_DGCMD_STATUS(reg)); 292 + return 0; 293 + } 294 + 295 + /* 296 + * We can't sleep here, because it's also called from 297 + * interrupt context. 298 + */ 299 + timeout--; 300 + if (!timeout) 301 + return -ETIMEDOUT; 302 + udelay(1); 303 + } while (1); 304 + } 305 + 279 306 int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep, 280 307 unsigned cmd, struct dwc3_gadget_ep_cmd_params *params) 281 308 { ··· 956 929 } 957 930 958 931 dep->flags |= DWC3_EP_BUSY; 959 - dep->res_trans_idx = dwc3_gadget_ep_get_transfer_index(dwc, 960 - dep->number); 961 932 962 - WARN_ON_ONCE(!dep->res_trans_idx); 933 + if (start_new) { 934 + dep->res_trans_idx = dwc3_gadget_ep_get_transfer_index(dwc, 935 + dep->number); 936 + WARN_ON_ONCE(!dep->res_trans_idx); 937 + } 963 938 964 939 return 0; 965 940 } ··· 995 966 996 967 list_add_tail(&req->list, &dep->request_list); 997 968 969 + if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && (dep->flags & DWC3_EP_BUSY)) 970 + dep->flags |= DWC3_EP_PENDING_REQUEST; 971 + 998 972 /* 999 - * There is one special case: XferNotReady with 1000 - * empty list of requests. We need to kick the 1001 - * transfer here in that situation, otherwise 1002 - * we will be NAKing forever. 973 + * There are two special cases: 1003 974 * 1004 - * If we get XferNotReady before gadget driver 1005 - * has a chance to queue a request, we will ACK 1006 - * the IRQ but won't be able to receive the data 1007 - * until the next request is queued. The following 1008 - * code is handling exactly that. 975 + * 1. XferNotReady with empty list of requests. We need to kick the 976 + * transfer here in that situation, otherwise we will be NAKing 977 + * forever. If we get XferNotReady before gadget driver has a 978 + * chance to queue a request, we will ACK the IRQ but won't be 979 + * able to receive the data until the next request is queued. 980 + * The following code is handling exactly that. 981 + * 982 + * 2. XferInProgress on Isoc EP with an active transfer. We need to 983 + * kick the transfer here after queuing a request, otherwise the 984 + * core may not see the modified TRB(s). 1009 985 */ 1010 986 if (dep->flags & DWC3_EP_PENDING_REQUEST) { 1011 - int ret; 1012 - int start_trans; 987 + int ret; 988 + int start_trans = 1; 989 + u8 trans_idx = dep->res_trans_idx; 1013 990 1014 - start_trans = 1; 1015 991 if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && 1016 - (dep->flags & DWC3_EP_BUSY)) 992 + (dep->flags & DWC3_EP_BUSY)) { 1017 993 start_trans = 0; 994 + WARN_ON_ONCE(!trans_idx); 995 + } else { 996 + trans_idx = 0; 997 + } 1018 998 1019 - ret = __dwc3_gadget_kick_transfer(dep, 0, start_trans); 999 + ret = __dwc3_gadget_kick_transfer(dep, trans_idx, start_trans); 1020 1000 if (ret && ret != -EBUSY) { 1021 1001 struct dwc3 *dwc = dep->dwc; 1022 1002 ··· 1393 1355 1394 1356 reg = dwc3_readl(dwc->regs, DWC3_DCFG); 1395 1357 reg &= ~(DWC3_DCFG_SPEED_MASK); 1396 - reg |= dwc->maximum_speed; 1358 + 1359 + /** 1360 + * WORKAROUND: DWC3 revision < 2.20a have an issue 1361 + * which would cause metastability state on Run/Stop 1362 + * bit if we try to force the IP to USB2-only mode. 1363 + * 1364 + * Because of that, we cannot configure the IP to any 1365 + * speed other than the SuperSpeed 1366 + * 1367 + * Refers to: 1368 + * 1369 + * STAR#9000525659: Clock Domain Crossing on DCTL in 1370 + * USB 2.0 Mode 1371 + */ 1372 + if (dwc->revision < DWC3_REVISION_220A) 1373 + reg |= DWC3_DCFG_SUPERSPEED; 1374 + else 1375 + reg |= dwc->maximum_speed; 1397 1376 dwc3_writel(dwc->regs, DWC3_DCFG, reg); 1398 1377 1399 1378 dwc->start_config_issued = false; ··· 1970 1915 1971 1916 reg = dwc3_readl(dwc->regs, DWC3_DCTL); 1972 1917 reg &= ~DWC3_DCTL_TSTCTRL_MASK; 1918 + reg &= ~(DWC3_DCTL_INITU1ENA | DWC3_DCTL_INITU2ENA); 1973 1919 dwc3_writel(dwc->regs, DWC3_DCTL, reg); 1974 1920 dwc->test_mode = false; 1975 1921 ··· 2318 2262 goto err1; 2319 2263 } 2320 2264 2321 - dwc->setup_buf = kzalloc(sizeof(*dwc->setup_buf) * 2, 2322 - GFP_KERNEL); 2265 + dwc->setup_buf = kzalloc(DWC3_EP0_BOUNCE_SIZE, GFP_KERNEL); 2323 2266 if (!dwc->setup_buf) { 2324 2267 dev_err(dwc->dev, "failed to allocate setup buffer\n"); 2325 2268 ret = -ENOMEM; ··· 2326 2271 } 2327 2272 2328 2273 dwc->ep0_bounce = dma_alloc_coherent(dwc->dev, 2329 - 512, &dwc->ep0_bounce_addr, GFP_KERNEL); 2274 + DWC3_EP0_BOUNCE_SIZE, &dwc->ep0_bounce_addr, 2275 + GFP_KERNEL); 2330 2276 if (!dwc->ep0_bounce) { 2331 2277 dev_err(dwc->dev, "failed to allocate ep0 bounce buffer\n"); 2332 2278 ret = -ENOMEM; ··· 2368 2312 goto err5; 2369 2313 } 2370 2314 2315 + reg = dwc3_readl(dwc->regs, DWC3_DCFG); 2316 + reg |= DWC3_DCFG_LPM_CAP; 2317 + dwc3_writel(dwc->regs, DWC3_DCFG, reg); 2318 + 2319 + reg = dwc3_readl(dwc->regs, DWC3_DCTL); 2320 + reg |= DWC3_DCTL_ACCEPTU1ENA | DWC3_DCTL_ACCEPTU2ENA; 2321 + dwc3_writel(dwc->regs, DWC3_DCTL, reg); 2322 + 2371 2323 /* Enable all but Start and End of Frame IRQs */ 2372 2324 reg = (DWC3_DEVTEN_VNDRDEVTSTRCVEDEN | 2373 2325 DWC3_DEVTEN_EVNTOVERFLOWEN | ··· 2414 2350 dwc3_gadget_free_endpoints(dwc); 2415 2351 2416 2352 err4: 2417 - dma_free_coherent(dwc->dev, 512, dwc->ep0_bounce, 2418 - dwc->ep0_bounce_addr); 2353 + dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE, 2354 + dwc->ep0_bounce, dwc->ep0_bounce_addr); 2419 2355 2420 2356 err3: 2421 2357 kfree(dwc->setup_buf); ··· 2444 2380 2445 2381 dwc3_gadget_free_endpoints(dwc); 2446 2382 2447 - dma_free_coherent(dwc->dev, 512, dwc->ep0_bounce, 2448 - dwc->ep0_bounce_addr); 2383 + dma_free_coherent(dwc->dev, DWC3_EP0_BOUNCE_SIZE, 2384 + dwc->ep0_bounce, dwc->ep0_bounce_addr); 2449 2385 2450 2386 kfree(dwc->setup_buf); 2451 2387
+1
drivers/usb/dwc3/gadget.h
··· 111 111 int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value); 112 112 int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep, 113 113 unsigned cmd, struct dwc3_gadget_ep_cmd_params *params); 114 + int dwc3_send_gadget_generic_command(struct dwc3 *dwc, int cmd, u32 param); 114 115 115 116 /** 116 117 * dwc3_gadget_ep_get_transfer_index - Gets transfer index from HW
+2 -17
drivers/usb/dwc3/host.c
··· 39 39 40 40 #include "core.h" 41 41 42 - static struct resource generic_resources[] = { 43 - { 44 - .flags = IORESOURCE_IRQ, 45 - }, 46 - { 47 - .flags = IORESOURCE_MEM, 48 - }, 49 - }; 50 - 51 42 int dwc3_host_init(struct dwc3 *dwc) 52 43 { 53 44 struct platform_device *xhci; ··· 59 68 60 69 dwc->xhci = xhci; 61 70 62 - /* setup resources */ 63 - generic_resources[0].start = dwc->irq; 64 - 65 - generic_resources[1].start = dwc->res->start; 66 - generic_resources[1].end = dwc->res->start + 0x7fff; 67 - 68 - ret = platform_device_add_resources(xhci, generic_resources, 69 - ARRAY_SIZE(generic_resources)); 71 + ret = platform_device_add_resources(xhci, dwc->xhci_resources, 72 + DWC3_XHCI_RESOURCES_NUM); 70 73 if (ret) { 71 74 dev_err(dwc->dev, "couldn't add resources to xHCI device\n"); 72 75 goto err1;
+14 -2
drivers/usb/dwc3/io.h
··· 41 41 42 42 #include <linux/io.h> 43 43 44 + #include "core.h" 45 + 44 46 static inline u32 dwc3_readl(void __iomem *base, u32 offset) 45 47 { 46 - return readl(base + offset); 48 + /* 49 + * We requested the mem region starting from the Globals address 50 + * space, see dwc3_probe in core.c. 51 + * However, the offsets are given starting from xHCI address space. 52 + */ 53 + return readl(base + (offset - DWC3_GLOBALS_REGS_START)); 47 54 } 48 55 49 56 static inline void dwc3_writel(void __iomem *base, u32 offset, u32 value) 50 57 { 51 - writel(value, base + offset); 58 + /* 59 + * We requested the mem region starting from the Globals address 60 + * space, see dwc3_probe in core.c. 61 + * However, the offsets are given starting from xHCI address space. 62 + */ 63 + writel(value, base + (offset - DWC3_GLOBALS_REGS_START)); 52 64 } 53 65 54 66 #endif /* __DRIVERS_USB_DWC3_IO_H */
+2
include/linux/usb/ch9.h
··· 88 88 #define USB_REQ_GET_INTERFACE 0x0A 89 89 #define USB_REQ_SET_INTERFACE 0x0B 90 90 #define USB_REQ_SYNCH_FRAME 0x0C 91 + #define USB_REQ_SET_SEL 0x30 92 + #define USB_REQ_SET_ISOCH_DELAY 0x31 91 93 92 94 #define USB_REQ_SET_ENCRYPTION 0x0D /* Wireless USB */ 93 95 #define USB_REQ_GET_ENCRYPTION 0x0E