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

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

Felipe writes:

usb: patches for v4.5

A ton of improvements to dwc2 have been made. The
driver should be a lot more stable on v4.5 then ever
before.

Our good old dwc3 got a few cleanups and misc fixes
and also added support to Xilinx's integration of
this IP.

Yoshihiro Shimoda gives us support for a new USB3
peripheral controller from Renesas.

Other than these, the usual misc fixes all over the
place.

+4266 -1264
+2
Documentation/ABI/testing/configfs-usb-gadget-sourcesink
··· 10 10 isoc_mult - 0..2 (hs/ss only) 11 11 isoc_maxburst - 0..15 (ss only) 12 12 buflen - buffer length 13 + bulk_qlen - depth of queue for bulk 14 + iso_qlen - depth of queue for iso
+1
Documentation/devicetree/bindings/usb/dwc2.txt
··· 4 4 Required properties: 5 5 - compatible : One of: 6 6 - brcm,bcm2835-usb: The DWC2 USB controller instance in the BCM2835 SoC. 7 + - hisilicon,hi6220-usb: The DWC2 USB controller instance in the hi6220 SoC. 7 8 - rockchip,rk3066-usb: The DWC2 USB controller instance in the rk3066 Soc; 8 9 - "rockchip,rk3188-usb", "rockchip,rk3066-usb", "snps,dwc2": for rk3188 Soc; 9 10 - "rockchip,rk3288-usb", "rockchip,rk3066-usb", "snps,dwc2": for rk3288 Soc;
+33
Documentation/devicetree/bindings/usb/dwc3-xilinx.txt
··· 1 + Xilinx SuperSpeed DWC3 USB SoC controller 2 + 3 + Required properties: 4 + - compatible: Should contain "xlnx,zynqmp-dwc3" 5 + - clocks: A list of phandles for the clocks listed in clock-names 6 + - clock-names: Should contain the following: 7 + "bus_clk" Master/Core clock, have to be >= 125 MHz for SS 8 + operation and >= 60MHz for HS operation 9 + 10 + "ref_clk" Clock source to core during PHY power down 11 + 12 + Required child node: 13 + A child node must exist to represent the core DWC3 IP block. The name of 14 + the node is not important. The content of the node is defined in dwc3.txt. 15 + 16 + Example device node: 17 + 18 + usb@0 { 19 + #address-cells = <0x2>; 20 + #size-cells = <0x1>; 21 + status = "okay"; 22 + compatible = "xlnx,zynqmp-dwc3"; 23 + clock-names = "bus_clk" "ref_clk"; 24 + clocks = <&clk125>, <&clk125>; 25 + ranges; 26 + 27 + dwc3@fe200000 { 28 + compatible = "snps,dwc3"; 29 + reg = <0x0 0xfe200000 0x40000>; 30 + interrupts = <0x0 0x41 0x4>; 31 + dr_mode = "host"; 32 + }; 33 + };
+23
Documentation/devicetree/bindings/usb/renesas_usb3.txt
··· 1 + Renesas Electronics USB3.0 Peripheral driver 2 + 3 + Required properties: 4 + - compatible: Must contain one of the following: 5 + - "renesas,r8a7795-usb3-peri" 6 + - reg: Base address and length of the register for the USB3.0 Peripheral 7 + - interrupts: Interrupt specifier for the USB3.0 Peripheral 8 + - clocks: clock phandle and specifier pair 9 + 10 + Example: 11 + usb3_peri0: usb@ee020000 { 12 + compatible = "renesas,r8a7795-usb3-peri"; 13 + reg = <0 0xee020000 0 0x400>; 14 + interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>; 15 + clocks = <&cpg CPG_MOD 328>; 16 + }; 17 + 18 + usb3_peri1: usb@ee060000 { 19 + compatible = "renesas,r8a7795-usb3-peri"; 20 + reg = <0 0xee060000 0 0x400>; 21 + interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>; 22 + clocks = <&cpg CPG_MOD 327>; 23 + };
+16 -6
Documentation/devicetree/bindings/usb/renesas_usbhs.txt
··· 1 1 Renesas Electronics USBHS driver 2 2 3 3 Required properties: 4 - - compatible: Must contain one of the following: 5 - - "renesas,usbhs-r8a7790" 6 - - "renesas,usbhs-r8a7791" 7 - - "renesas,usbhs-r8a7794" 8 - - "renesas,usbhs-r8a7795" 4 + - compatible: Must contain one or more of the following: 5 + 6 + - "renesas,usbhs-r8a7790" for r8a7790 (R-Car H2) compatible device 7 + - "renesas,usbhs-r8a7791" for r8a7791 (R-Car M2-W) compatible device 8 + - "renesas,usbhs-r8a7792" for r8a7792 (R-Car V2H) compatible device 9 + - "renesas,usbhs-r8a7793" for r8a7793 (R-Car M2-N) compatible device 10 + - "renesas,usbhs-r8a7794" for r8a7794 (R-Car E2) compatible device 11 + - "renesas,usbhs-r8a7795" for r8a7795 (R-Car H3) compatible device 12 + - "renesas,rcar-gen2-usbhs" for R-Car Gen2 compatible device 13 + - "renesas,rcar-gen3-usbhs" for R-Car Gen3 compatible device 14 + 15 + When compatible with the generic version, nodes must list the 16 + SoC-specific version corresponding to the platform first followed 17 + by the generic version. 18 + 9 19 - reg: Base address and length of the register for the USBHS 10 20 - interrupts: Interrupt specifier for the USBHS 11 21 - clocks: A list of phandle + clock specifier pairs ··· 32 22 33 23 Example: 34 24 usbhs: usb@e6590000 { 35 - compatible = "renesas,usbhs-r8a7790"; 25 + compatible = "renesas,usbhs-r8a7790", "renesas,rcar-gen2-usbhs"; 36 26 reg = <0 0xe6590000 0 0x100>; 37 27 interrupts = <0 107 IRQ_TYPE_LEVEL_HIGH>; 38 28 clocks = <&mstp7_clks R8A7790_CLK_HSUSB>;
+3 -1
Documentation/usb/gadget-testing.txt
··· 434 434 435 435 where seriald and serialc are Felipe's utilities found here: 436 436 437 - https://git.gitorious.org/usb/usb-tools.git master 437 + https://github.com/felipebalbi/usb-tools.git master 438 438 439 439 12. PHONET function 440 440 =================== ··· 579 579 isoc_mult - 0..2 (hs/ss only) 580 580 isoc_maxburst - 0..15 (ss only) 581 581 bulk_buflen - buffer length 582 + bulk_qlen - depth of queue for bulk 583 + iso_qlen - depth of queue for iso 582 584 583 585 Testing the SOURCESINK function 584 586 -------------------------------
+16 -16
drivers/phy/phy-twl4030-usb.c
··· 34 34 #include <linux/usb/otg.h> 35 35 #include <linux/phy/phy.h> 36 36 #include <linux/pm_runtime.h> 37 - #include <linux/usb/musb-omap.h> 37 + #include <linux/usb/musb.h> 38 38 #include <linux/usb/ulpi.h> 39 39 #include <linux/i2c/twl.h> 40 40 #include <linux/regulator/consumer.h> ··· 148 148 * If VBUS is valid or ID is ground, then we know a 149 149 * cable is present and we need to be runtime-enabled 150 150 */ 151 - static inline bool cable_present(enum omap_musb_vbus_id_status stat) 151 + static inline bool cable_present(enum musb_vbus_id_status stat) 152 152 { 153 - return stat == OMAP_MUSB_VBUS_VALID || 154 - stat == OMAP_MUSB_ID_GROUND; 153 + return stat == MUSB_VBUS_VALID || 154 + stat == MUSB_ID_GROUND; 155 155 } 156 156 157 157 struct twl4030_usb { ··· 170 170 enum twl4030_usb_mode usb_mode; 171 171 172 172 int irq; 173 - enum omap_musb_vbus_id_status linkstat; 173 + enum musb_vbus_id_status linkstat; 174 174 bool vbus_supplied; 175 175 176 176 struct delayed_work id_workaround_work; ··· 276 276 return (ret & (ULPI_OTG_DRVVBUS | ULPI_OTG_CHRGVBUS)) ? true : false; 277 277 } 278 278 279 - static enum omap_musb_vbus_id_status 279 + static enum musb_vbus_id_status 280 280 twl4030_usb_linkstat(struct twl4030_usb *twl) 281 281 { 282 282 int status; 283 - enum omap_musb_vbus_id_status linkstat = OMAP_MUSB_UNKNOWN; 283 + enum musb_vbus_id_status linkstat = MUSB_UNKNOWN; 284 284 285 285 twl->vbus_supplied = false; 286 286 ··· 306 306 } 307 307 308 308 if (status & BIT(2)) 309 - linkstat = OMAP_MUSB_ID_GROUND; 309 + linkstat = MUSB_ID_GROUND; 310 310 else if (status & BIT(7)) 311 - linkstat = OMAP_MUSB_VBUS_VALID; 311 + linkstat = MUSB_VBUS_VALID; 312 312 else 313 - linkstat = OMAP_MUSB_VBUS_OFF; 313 + linkstat = MUSB_VBUS_OFF; 314 314 } else { 315 - if (twl->linkstat != OMAP_MUSB_UNKNOWN) 316 - linkstat = OMAP_MUSB_VBUS_OFF; 315 + if (twl->linkstat != MUSB_UNKNOWN) 316 + linkstat = MUSB_VBUS_OFF; 317 317 } 318 318 319 319 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n", ··· 535 535 static irqreturn_t twl4030_usb_irq(int irq, void *_twl) 536 536 { 537 537 struct twl4030_usb *twl = _twl; 538 - enum omap_musb_vbus_id_status status; 538 + enum musb_vbus_id_status status; 539 539 bool status_changed = false; 540 540 541 541 status = twl4030_usb_linkstat(twl); ··· 567 567 pm_runtime_mark_last_busy(twl->dev); 568 568 pm_runtime_put_autosuspend(twl->dev); 569 569 } 570 - omap_musb_mailbox(status); 570 + musb_mailbox(status); 571 571 } 572 572 573 573 /* don't schedule during sleep - irq works right then */ 574 - if (status == OMAP_MUSB_ID_GROUND && pm_runtime_active(twl->dev)) { 574 + if (status == MUSB_ID_GROUND && pm_runtime_active(twl->dev)) { 575 575 cancel_delayed_work(&twl->id_workaround_work); 576 576 schedule_delayed_work(&twl->id_workaround_work, HZ); 577 577 } ··· 670 670 twl->dev = &pdev->dev; 671 671 twl->irq = platform_get_irq(pdev, 0); 672 672 twl->vbus_supplied = false; 673 - twl->linkstat = OMAP_MUSB_UNKNOWN; 673 + twl->linkstat = MUSB_UNKNOWN; 674 674 675 675 twl->phy.dev = twl->dev; 676 676 twl->phy.label = "twl4030";
+54 -6
drivers/usb/common/common.c
··· 17 17 #include <linux/usb/ch9.h> 18 18 #include <linux/usb/of.h> 19 19 #include <linux/usb/otg.h> 20 + #include <linux/of_platform.h> 20 21 21 22 const char *usb_otg_state_string(enum usb_otg_state state) 22 23 { ··· 107 106 [USB_DR_MODE_OTG] = "otg", 108 107 }; 109 108 109 + static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str) 110 + { 111 + int i; 112 + 113 + for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++) 114 + if (!strcmp(usb_dr_modes[i], str)) 115 + return i; 116 + 117 + return USB_DR_MODE_UNKNOWN; 118 + } 119 + 110 120 enum usb_dr_mode usb_get_dr_mode(struct device *dev) 111 121 { 112 122 const char *dr_mode; 113 - int err, i; 123 + int err; 114 124 115 125 err = device_property_read_string(dev, "dr_mode", &dr_mode); 116 126 if (err < 0) 117 127 return USB_DR_MODE_UNKNOWN; 118 128 119 - for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++) 120 - if (!strcmp(dr_mode, usb_dr_modes[i])) 121 - return i; 122 - 123 - return USB_DR_MODE_UNKNOWN; 129 + return usb_get_dr_mode_from_string(dr_mode); 124 130 } 125 131 EXPORT_SYMBOL_GPL(usb_get_dr_mode); 126 132 127 133 #ifdef CONFIG_OF 134 + /** 135 + * of_usb_get_dr_mode_by_phy - Get dual role mode for the controller device 136 + * which is associated with the given phy device_node 137 + * @np: Pointer to the given phy device_node 138 + * 139 + * In dts a usb controller associates with phy devices. The function gets 140 + * the string from property 'dr_mode' of the controller associated with the 141 + * given phy device node, and returns the correspondig enum usb_dr_mode. 142 + */ 143 + enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np) 144 + { 145 + struct device_node *controller = NULL; 146 + struct device_node *phy; 147 + const char *dr_mode; 148 + int index; 149 + int err; 150 + 151 + do { 152 + controller = of_find_node_with_property(controller, "phys"); 153 + index = 0; 154 + do { 155 + phy = of_parse_phandle(controller, "phys", index); 156 + of_node_put(phy); 157 + if (phy == phy_np) 158 + goto finish; 159 + index++; 160 + } while (phy); 161 + } while (controller); 162 + 163 + finish: 164 + err = of_property_read_string(controller, "dr_mode", &dr_mode); 165 + of_node_put(controller); 166 + 167 + if (err < 0) 168 + return USB_DR_MODE_UNKNOWN; 169 + 170 + return usb_get_dr_mode_from_string(dr_mode); 171 + } 172 + EXPORT_SYMBOL_GPL(of_usb_get_dr_mode_by_phy); 173 + 128 174 /** 129 175 * of_usb_host_tpl_support - to get if Targeted Peripheral List is supported 130 176 * for given targeted hosts (non-PC hosts)
+349 -90
drivers/usb/dwc2/core.c
··· 481 481 * Do core a soft reset of the core. Be careful with this because it 482 482 * resets all the internal state machines of the core. 483 483 */ 484 - static int dwc2_core_reset(struct dwc2_hsotg *hsotg) 484 + int dwc2_core_reset(struct dwc2_hsotg *hsotg) 485 485 { 486 486 u32 greset; 487 487 int count = 0; 488 - u32 gusbcfg; 489 488 490 489 dev_vdbg(hsotg->dev, "%s()\n", __func__); 491 490 492 - /* Wait for AHB master IDLE state */ 493 - do { 494 - usleep_range(20000, 40000); 495 - greset = dwc2_readl(hsotg->regs + GRSTCTL); 496 - if (++count > 50) { 497 - dev_warn(hsotg->dev, 498 - "%s() HANG! AHB Idle GRSTCTL=%0x\n", 499 - __func__, greset); 500 - return -EBUSY; 501 - } 502 - } while (!(greset & GRSTCTL_AHBIDLE)); 503 - 504 491 /* Core Soft Reset */ 505 - count = 0; 492 + greset = dwc2_readl(hsotg->regs + GRSTCTL); 506 493 greset |= GRSTCTL_CSFTRST; 507 494 dwc2_writel(greset, hsotg->regs + GRSTCTL); 508 495 do { 509 - usleep_range(20000, 40000); 496 + udelay(1); 510 497 greset = dwc2_readl(hsotg->regs + GRSTCTL); 511 498 if (++count > 50) { 512 499 dev_warn(hsotg->dev, ··· 503 516 } 504 517 } while (greset & GRSTCTL_CSFTRST); 505 518 506 - if (hsotg->dr_mode == USB_DR_MODE_HOST) { 507 - gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 508 - gusbcfg &= ~GUSBCFG_FORCEDEVMODE; 509 - gusbcfg |= GUSBCFG_FORCEHOSTMODE; 510 - dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 511 - } else if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) { 512 - gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 513 - gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; 514 - gusbcfg |= GUSBCFG_FORCEDEVMODE; 515 - dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 516 - } else if (hsotg->dr_mode == USB_DR_MODE_OTG) { 517 - gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 518 - gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; 519 - gusbcfg &= ~GUSBCFG_FORCEDEVMODE; 520 - dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 521 - } 519 + /* Wait for AHB master IDLE state */ 520 + count = 0; 521 + do { 522 + udelay(1); 523 + greset = dwc2_readl(hsotg->regs + GRSTCTL); 524 + if (++count > 50) { 525 + dev_warn(hsotg->dev, 526 + "%s() HANG! AHB Idle GRSTCTL=%0x\n", 527 + __func__, greset); 528 + return -EBUSY; 529 + } 530 + } while (!(greset & GRSTCTL_AHBIDLE)); 531 + 532 + return 0; 533 + } 534 + 535 + /* 536 + * Force the mode of the controller. 537 + * 538 + * Forcing the mode is needed for two cases: 539 + * 540 + * 1) If the dr_mode is set to either HOST or PERIPHERAL we force the 541 + * controller to stay in a particular mode regardless of ID pin 542 + * changes. We do this usually after a core reset. 543 + * 544 + * 2) During probe we want to read reset values of the hw 545 + * configuration registers that are only available in either host or 546 + * device mode. We may need to force the mode if the current mode does 547 + * not allow us to access the register in the mode that we want. 548 + * 549 + * In either case it only makes sense to force the mode if the 550 + * controller hardware is OTG capable. 551 + * 552 + * Checks are done in this function to determine whether doing a force 553 + * would be valid or not. 554 + * 555 + * If a force is done, it requires a 25ms delay to take effect. 556 + * 557 + * Returns true if the mode was forced. 558 + */ 559 + static bool dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host) 560 + { 561 + u32 gusbcfg; 562 + u32 set; 563 + u32 clear; 564 + 565 + dev_dbg(hsotg->dev, "Forcing mode to %s\n", host ? "host" : "device"); 566 + 567 + /* 568 + * Force mode has no effect if the hardware is not OTG. 569 + */ 570 + if (!dwc2_hw_is_otg(hsotg)) 571 + return false; 572 + 573 + /* 574 + * If dr_mode is either peripheral or host only, there is no 575 + * need to ever force the mode to the opposite mode. 576 + */ 577 + if (WARN_ON(host && hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)) 578 + return false; 579 + 580 + if (WARN_ON(!host && hsotg->dr_mode == USB_DR_MODE_HOST)) 581 + return false; 582 + 583 + gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 584 + 585 + set = host ? GUSBCFG_FORCEHOSTMODE : GUSBCFG_FORCEDEVMODE; 586 + clear = host ? GUSBCFG_FORCEDEVMODE : GUSBCFG_FORCEHOSTMODE; 587 + 588 + /* 589 + * If the force mode bit is already set, don't set it. 590 + */ 591 + if ((gusbcfg & set) && !(gusbcfg & clear)) 592 + return false; 593 + 594 + gusbcfg &= ~clear; 595 + gusbcfg |= set; 596 + dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 597 + 598 + msleep(25); 599 + return true; 600 + } 601 + 602 + /* 603 + * Clears the force mode bits. 604 + */ 605 + static void dwc2_clear_force_mode(struct dwc2_hsotg *hsotg) 606 + { 607 + u32 gusbcfg; 608 + 609 + gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 610 + gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; 611 + gusbcfg &= ~GUSBCFG_FORCEDEVMODE; 612 + dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 522 613 523 614 /* 524 615 * NOTE: This long sleep is _very_ important, otherwise the core will 525 616 * not stay in host mode after a connector ID change! 526 617 */ 527 - usleep_range(150000, 200000); 618 + msleep(25); 619 + } 528 620 621 + /* 622 + * Sets or clears force mode based on the dr_mode parameter. 623 + */ 624 + void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg) 625 + { 626 + switch (hsotg->dr_mode) { 627 + case USB_DR_MODE_HOST: 628 + dwc2_force_mode(hsotg, true); 629 + break; 630 + case USB_DR_MODE_PERIPHERAL: 631 + dwc2_force_mode(hsotg, false); 632 + break; 633 + case USB_DR_MODE_OTG: 634 + dwc2_clear_force_mode(hsotg); 635 + break; 636 + default: 637 + dev_warn(hsotg->dev, "%s() Invalid dr_mode=%d\n", 638 + __func__, hsotg->dr_mode); 639 + break; 640 + } 641 + } 642 + 643 + /* 644 + * Do core a soft reset of the core. Be careful with this because it 645 + * resets all the internal state machines of the core. 646 + * 647 + * Additionally this will apply force mode as per the hsotg->dr_mode 648 + * parameter. 649 + */ 650 + int dwc2_core_reset_and_force_dr_mode(struct dwc2_hsotg *hsotg) 651 + { 652 + int retval; 653 + 654 + retval = dwc2_core_reset(hsotg); 655 + if (retval) 656 + return retval; 657 + 658 + dwc2_force_dr_mode(hsotg); 529 659 return 0; 530 660 } 531 661 ··· 657 553 */ 658 554 if (select_phy) { 659 555 dev_dbg(hsotg->dev, "FS PHY selected\n"); 660 - usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 661 - usbcfg |= GUSBCFG_PHYSEL; 662 - dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 663 556 664 - /* Reset after a PHY select */ 665 - retval = dwc2_core_reset(hsotg); 666 - if (retval) { 667 - dev_err(hsotg->dev, "%s() Reset failed, aborting", 668 - __func__); 669 - return retval; 557 + usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 558 + if (!(usbcfg & GUSBCFG_PHYSEL)) { 559 + usbcfg |= GUSBCFG_PHYSEL; 560 + dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 561 + 562 + /* Reset after a PHY select */ 563 + retval = dwc2_core_reset_and_force_dr_mode(hsotg); 564 + 565 + if (retval) { 566 + dev_err(hsotg->dev, 567 + "%s: Reset failed, aborting", __func__); 568 + return retval; 569 + } 670 570 } 671 571 } 672 572 ··· 705 597 706 598 static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) 707 599 { 708 - u32 usbcfg; 600 + u32 usbcfg, usbcfg_old; 709 601 int retval = 0; 710 602 711 603 if (!select_phy) 712 604 return 0; 713 605 714 - usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 606 + usbcfg = usbcfg_old = dwc2_readl(hsotg->regs + GUSBCFG); 715 607 716 608 /* 717 609 * HS PHY parameters. These parameters are preserved during soft reset ··· 739 631 break; 740 632 } 741 633 742 - dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 634 + if (usbcfg != usbcfg_old) { 635 + dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 743 636 744 - /* Reset after setting the PHY parameters */ 745 - retval = dwc2_core_reset(hsotg); 746 - if (retval) { 747 - dev_err(hsotg->dev, "%s() Reset failed, aborting", 748 - __func__); 749 - return retval; 637 + /* Reset after setting the PHY parameters */ 638 + retval = dwc2_core_reset_and_force_dr_mode(hsotg); 639 + if (retval) { 640 + dev_err(hsotg->dev, 641 + "%s: Reset failed, aborting", __func__); 642 + return retval; 643 + } 750 644 } 751 645 752 646 return retval; ··· 875 765 * dwc2_core_init() - Initializes the DWC_otg controller registers and 876 766 * prepares the core for device mode or host mode operation 877 767 * 878 - * @hsotg: Programming view of the DWC_otg controller 879 - * @select_phy: If true then also set the Phy type 880 - * @irq: If >= 0, the irq to register 768 + * @hsotg: Programming view of the DWC_otg controller 769 + * @initial_setup: If true then this is the first init for this instance. 881 770 */ 882 - int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq) 771 + int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup) 883 772 { 884 773 u32 usbcfg, otgctl; 885 774 int retval; ··· 900 791 901 792 dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 902 793 903 - /* Reset the Controller */ 904 - retval = dwc2_core_reset(hsotg); 905 - if (retval) { 906 - dev_err(hsotg->dev, "%s(): Reset failed, aborting\n", 907 - __func__); 908 - return retval; 794 + /* 795 + * Reset the Controller 796 + * 797 + * We only need to reset the controller if this is a re-init. 798 + * For the first init we know for sure that earlier code reset us (it 799 + * needed to in order to properly detect various parameters). 800 + */ 801 + if (!initial_setup) { 802 + retval = dwc2_core_reset_and_force_dr_mode(hsotg); 803 + if (retval) { 804 + dev_err(hsotg->dev, "%s(): Reset failed, aborting\n", 805 + __func__); 806 + return retval; 807 + } 909 808 } 910 809 911 810 /* 912 811 * This needs to happen in FS mode before any other programming occurs 913 812 */ 914 - retval = dwc2_phy_init(hsotg, select_phy); 813 + retval = dwc2_phy_init(hsotg, initial_setup); 915 814 if (retval) 916 815 return retval; 917 816 ··· 1824 1707 u32 hcchar; 1825 1708 u32 hctsiz = 0; 1826 1709 u16 num_packets; 1710 + u32 ec_mc; 1827 1711 1828 1712 if (dbg_hc(chan)) 1829 1713 dev_vdbg(hsotg->dev, "%s()\n", __func__); ··· 1861 1743 1862 1744 hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT & 1863 1745 TSIZ_XFERSIZE_MASK; 1746 + 1747 + /* For split set ec_mc for immediate retries */ 1748 + if (chan->ep_type == USB_ENDPOINT_XFER_INT || 1749 + chan->ep_type == USB_ENDPOINT_XFER_ISOC) 1750 + ec_mc = 3; 1751 + else 1752 + ec_mc = 1; 1864 1753 } else { 1865 1754 if (dbg_hc(chan)) 1866 1755 dev_vdbg(hsotg->dev, "no split\n"); ··· 1930 1805 1931 1806 hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT & 1932 1807 TSIZ_XFERSIZE_MASK; 1808 + 1809 + /* The ec_mc gets the multi_count for non-split */ 1810 + ec_mc = chan->multi_count; 1933 1811 } 1934 1812 1935 1813 chan->start_pkt_count = num_packets; ··· 1983 1855 1984 1856 hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); 1985 1857 hcchar &= ~HCCHAR_MULTICNT_MASK; 1986 - hcchar |= chan->multi_count << HCCHAR_MULTICNT_SHIFT & 1987 - HCCHAR_MULTICNT_MASK; 1858 + hcchar |= (ec_mc << HCCHAR_MULTICNT_SHIFT) & HCCHAR_MULTICNT_MASK; 1988 1859 dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar); 1989 1860 1990 1861 if (hcchar & HCCHAR_CHDIS) ··· 2032 1905 struct dwc2_host_chan *chan) 2033 1906 { 2034 1907 u32 hcchar; 2035 - u32 hc_dma; 2036 1908 u32 hctsiz = 0; 2037 1909 2038 1910 if (chan->do_ping) ··· 2060 1934 2061 1935 dwc2_writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num)); 2062 1936 2063 - hc_dma = (u32)chan->desc_list_addr & HCDMA_DMA_ADDR_MASK; 1937 + dma_sync_single_for_device(hsotg->dev, chan->desc_list_addr, 1938 + chan->desc_list_sz, DMA_TO_DEVICE); 2064 1939 2065 - /* Always start from first descriptor */ 2066 - hc_dma &= ~HCDMA_CTD_MASK; 2067 - dwc2_writel(hc_dma, hsotg->regs + HCDMA(chan->hc_num)); 1940 + dwc2_writel(chan->desc_list_addr, hsotg->regs + HCDMA(chan->hc_num)); 1941 + 2068 1942 if (dbg_hc(chan)) 2069 - dev_vdbg(hsotg->dev, "Wrote %08x to HCDMA(%d)\n", 2070 - hc_dma, chan->hc_num); 1943 + dev_vdbg(hsotg->dev, "Wrote %pad to HCDMA(%d)\n", 1944 + &chan->desc_list_addr, chan->hc_num); 2071 1945 2072 1946 hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); 2073 1947 hcchar &= ~HCCHAR_MULTICNT_MASK; ··· 2611 2485 hsotg->core_params->dma_desc_enable = val; 2612 2486 } 2613 2487 2488 + void dwc2_set_param_dma_desc_fs_enable(struct dwc2_hsotg *hsotg, int val) 2489 + { 2490 + int valid = 1; 2491 + 2492 + if (val > 0 && (hsotg->core_params->dma_enable <= 0 || 2493 + !hsotg->hw_params.dma_desc_enable)) 2494 + valid = 0; 2495 + if (val < 0) 2496 + valid = 0; 2497 + 2498 + if (!valid) { 2499 + if (val >= 0) 2500 + dev_err(hsotg->dev, 2501 + "%d invalid for dma_desc_fs_enable parameter. Check HW configuration.\n", 2502 + val); 2503 + val = (hsotg->core_params->dma_enable > 0 && 2504 + hsotg->hw_params.dma_desc_enable); 2505 + } 2506 + 2507 + hsotg->core_params->dma_desc_fs_enable = val; 2508 + dev_dbg(hsotg->dev, "Setting dma_desc_fs_enable to %d\n", val); 2509 + } 2510 + 2614 2511 void dwc2_set_param_host_support_fs_ls_low_power(struct dwc2_hsotg *hsotg, 2615 2512 int val) 2616 2513 { ··· 3165 3016 dwc2_set_param_otg_cap(hsotg, params->otg_cap); 3166 3017 dwc2_set_param_dma_enable(hsotg, params->dma_enable); 3167 3018 dwc2_set_param_dma_desc_enable(hsotg, params->dma_desc_enable); 3019 + dwc2_set_param_dma_desc_fs_enable(hsotg, params->dma_desc_fs_enable); 3168 3020 dwc2_set_param_host_support_fs_ls_low_power(hsotg, 3169 3021 params->host_support_fs_ls_low_power); 3170 3022 dwc2_set_param_enable_dynamic_fifo(hsotg, ··· 3202 3052 dwc2_set_param_hibernation(hsotg, params->hibernation); 3203 3053 } 3204 3054 3055 + /* 3056 + * Forces either host or device mode if the controller is not 3057 + * currently in that mode. 3058 + * 3059 + * Returns true if the mode was forced. 3060 + */ 3061 + static bool dwc2_force_mode_if_needed(struct dwc2_hsotg *hsotg, bool host) 3062 + { 3063 + if (host && dwc2_is_host_mode(hsotg)) 3064 + return false; 3065 + else if (!host && dwc2_is_device_mode(hsotg)) 3066 + return false; 3067 + 3068 + return dwc2_force_mode(hsotg, host); 3069 + } 3070 + 3071 + /* 3072 + * Gets host hardware parameters. Forces host mode if not currently in 3073 + * host mode. Should be called immediately after a core soft reset in 3074 + * order to get the reset values. 3075 + */ 3076 + static void dwc2_get_host_hwparams(struct dwc2_hsotg *hsotg) 3077 + { 3078 + struct dwc2_hw_params *hw = &hsotg->hw_params; 3079 + u32 gnptxfsiz; 3080 + u32 hptxfsiz; 3081 + bool forced; 3082 + 3083 + if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) 3084 + return; 3085 + 3086 + forced = dwc2_force_mode_if_needed(hsotg, true); 3087 + 3088 + gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); 3089 + hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ); 3090 + dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); 3091 + dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hptxfsiz); 3092 + 3093 + if (forced) 3094 + dwc2_clear_force_mode(hsotg); 3095 + 3096 + hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> 3097 + FIFOSIZE_DEPTH_SHIFT; 3098 + hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >> 3099 + FIFOSIZE_DEPTH_SHIFT; 3100 + } 3101 + 3102 + /* 3103 + * Gets device hardware parameters. Forces device mode if not 3104 + * currently in device mode. Should be called immediately after a core 3105 + * soft reset in order to get the reset values. 3106 + */ 3107 + static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg) 3108 + { 3109 + struct dwc2_hw_params *hw = &hsotg->hw_params; 3110 + bool forced; 3111 + u32 gnptxfsiz; 3112 + 3113 + if (hsotg->dr_mode == USB_DR_MODE_HOST) 3114 + return; 3115 + 3116 + forced = dwc2_force_mode_if_needed(hsotg, false); 3117 + 3118 + gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); 3119 + dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); 3120 + 3121 + if (forced) 3122 + dwc2_clear_force_mode(hsotg); 3123 + 3124 + hw->dev_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> 3125 + FIFOSIZE_DEPTH_SHIFT; 3126 + } 3127 + 3205 3128 /** 3206 3129 * During device initialization, read various hardware configuration 3207 3130 * registers and interpret the contents. 3131 + * 3132 + * This should be called during driver probe. It will perform a core 3133 + * soft reset in order to get the reset values of the parameters. 3208 3134 */ 3209 3135 int dwc2_get_hwparams(struct dwc2_hsotg *hsotg) 3210 3136 { 3211 3137 struct dwc2_hw_params *hw = &hsotg->hw_params; 3212 3138 unsigned width; 3213 3139 u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4; 3214 - u32 hptxfsiz, grxfsiz, gnptxfsiz; 3215 - u32 gusbcfg; 3140 + u32 grxfsiz; 3141 + int retval; 3216 3142 3217 3143 /* 3218 3144 * Attempt to ensure this device is really a DWC_otg Controller. ··· 3308 3082 hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf, 3309 3083 hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid); 3310 3084 3085 + retval = dwc2_core_reset(hsotg); 3086 + if (retval) 3087 + return retval; 3088 + 3311 3089 hwcfg1 = dwc2_readl(hsotg->regs + GHWCFG1); 3312 3090 hwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2); 3313 3091 hwcfg3 = dwc2_readl(hsotg->regs + GHWCFG3); ··· 3324 3094 dev_dbg(hsotg->dev, "hwcfg4=%08x\n", hwcfg4); 3325 3095 dev_dbg(hsotg->dev, "grxfsiz=%08x\n", grxfsiz); 3326 3096 3327 - /* Force host mode to get HPTXFSIZ / GNPTXFSIZ exact power on value */ 3328 - gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 3329 - gusbcfg |= GUSBCFG_FORCEHOSTMODE; 3330 - dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 3331 - usleep_range(100000, 150000); 3097 + /* 3098 + * Host specific hardware parameters. Reading these parameters 3099 + * requires the controller to be in host mode. The mode will 3100 + * be forced, if necessary, to read these values. 3101 + */ 3102 + dwc2_get_host_hwparams(hsotg); 3103 + dwc2_get_dev_hwparams(hsotg); 3332 3104 3333 - gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); 3334 - hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ); 3335 - dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); 3336 - dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hptxfsiz); 3337 - gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 3338 - gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; 3339 - dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 3340 - usleep_range(100000, 150000); 3105 + /* hwcfg1 */ 3106 + hw->dev_ep_dirs = hwcfg1; 3341 3107 3342 3108 /* hwcfg2 */ 3343 3109 hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >> ··· 3389 3163 /* fifo sizes */ 3390 3164 hw->host_rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >> 3391 3165 GRXFSIZ_DEPTH_SHIFT; 3392 - hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> 3393 - FIFOSIZE_DEPTH_SHIFT; 3394 - hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >> 3395 - FIFOSIZE_DEPTH_SHIFT; 3396 3166 3397 3167 dev_dbg(hsotg->dev, "Detected values from hardware:\n"); 3398 3168 dev_dbg(hsotg->dev, " op_mode=%d\n", ··· 3495 3273 3496 3274 ahbcfg &= ~GAHBCFG_GLBL_INTR_EN; 3497 3275 dwc2_writel(ahbcfg, hsotg->regs + GAHBCFG); 3276 + } 3277 + 3278 + /* Returns the controller's GHWCFG2.OTG_MODE. */ 3279 + unsigned dwc2_op_mode(struct dwc2_hsotg *hsotg) 3280 + { 3281 + u32 ghwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2); 3282 + 3283 + return (ghwcfg2 & GHWCFG2_OP_MODE_MASK) >> 3284 + GHWCFG2_OP_MODE_SHIFT; 3285 + } 3286 + 3287 + /* Returns true if the controller is capable of DRD. */ 3288 + bool dwc2_hw_is_otg(struct dwc2_hsotg *hsotg) 3289 + { 3290 + unsigned op_mode = dwc2_op_mode(hsotg); 3291 + 3292 + return (op_mode == GHWCFG2_OP_MODE_HNP_SRP_CAPABLE) || 3293 + (op_mode == GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE) || 3294 + (op_mode == GHWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE); 3295 + } 3296 + 3297 + /* Returns true if the controller is host-only. */ 3298 + bool dwc2_hw_is_host(struct dwc2_hsotg *hsotg) 3299 + { 3300 + unsigned op_mode = dwc2_op_mode(hsotg); 3301 + 3302 + return (op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_HOST) || 3303 + (op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST); 3304 + } 3305 + 3306 + /* Returns true if the controller is device-only. */ 3307 + bool dwc2_hw_is_device(struct dwc2_hsotg *hsotg) 3308 + { 3309 + unsigned op_mode = dwc2_op_mode(hsotg); 3310 + 3311 + return (op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) || 3312 + (op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE); 3498 3313 } 3499 3314 3500 3315 MODULE_DESCRIPTION("DESIGNWARE HS OTG Core");
+63 -3
drivers/usb/dwc2/core.h
··· 246 246 * value for this if none is specified. 247 247 * 0 - Address DMA 248 248 * 1 - Descriptor DMA (default, if available) 249 + * @dma_desc_fs_enable: When DMA mode is enabled, specifies whether to use 250 + * address DMA mode or descriptor DMA mode for accessing 251 + * the data FIFOs in Full Speed mode only. The driver 252 + * will automatically detect the value for this if none is 253 + * specified. 254 + * 0 - Address DMA 255 + * 1 - Descriptor DMA in FS (default, if available) 249 256 * @speed: Specifies the maximum speed of operation in host and 250 257 * device mode. The actual speed depends on the speed of 251 258 * the attached device and the value of phy_type. ··· 382 375 int otg_ver; 383 376 int dma_enable; 384 377 int dma_desc_enable; 378 + int dma_desc_fs_enable; 385 379 int speed; 386 380 int enable_dynamic_fifo; 387 381 int en_multiple_tx_fifo; ··· 459 451 * 1 - 16 bits 460 452 * 2 - 8 or 16 bits 461 453 * @snpsid: Value from SNPSID register 454 + * @dev_ep_dirs: Direction of device endpoints (GHWCFG1) 462 455 */ 463 456 struct dwc2_hw_params { 464 457 unsigned op_mode:3; 465 458 unsigned arch:2; 466 459 unsigned dma_desc_enable:1; 460 + unsigned dma_desc_fs_enable:1; 467 461 unsigned enable_dynamic_fifo:1; 468 462 unsigned en_multiple_tx_fifo:1; 469 463 unsigned host_rx_fifo_size:16; 470 464 unsigned host_nperio_tx_fifo_size:16; 465 + unsigned dev_nperio_tx_fifo_size:16; 471 466 unsigned host_perio_tx_fifo_size:16; 472 467 unsigned nperio_tx_q_depth:3; 473 468 unsigned host_perio_tx_q_depth:3; ··· 487 476 unsigned power_optimized:1; 488 477 unsigned utmi_phy_data_width:2; 489 478 u32 snpsid; 479 + u32 dev_ep_dirs; 490 480 }; 491 481 492 482 /* Size of control and EP0 buffers */ ··· 688 676 * @otg_port: OTG port number 689 677 * @frame_list: Frame list 690 678 * @frame_list_dma: Frame list DMA address 679 + * @frame_list_sz: Frame list size 680 + * @desc_gen_cache: Kmem cache for generic descriptors 681 + * @desc_hsisoc_cache: Kmem cache for hs isochronous descriptors 691 682 * 692 683 * These are for peripheral mode: 693 684 * ··· 785 770 u16 frame_number; 786 771 u16 periodic_qh_count; 787 772 bool bus_suspended; 773 + bool new_connection; 788 774 789 775 #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS 790 776 #define FRAME_NUM_ARRAY_SIZE 1000 ··· 810 794 u8 otg_port; 811 795 u32 *frame_list; 812 796 dma_addr_t frame_list_dma; 797 + u32 frame_list_sz; 798 + struct kmem_cache *desc_gen_cache; 799 + struct kmem_cache *desc_hsisoc_cache; 813 800 814 801 #ifdef DEBUG 815 802 u32 frrem_samples; ··· 883 864 * The following functions support initialization of the core driver component 884 865 * and the DWC_otg controller 885 866 */ 867 + extern int dwc2_core_reset(struct dwc2_hsotg *hsotg); 868 + extern int dwc2_core_reset_and_force_dr_mode(struct dwc2_hsotg *hsotg); 886 869 extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg); 887 870 extern int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg); 888 871 extern int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore); 872 + 873 + void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg); 889 874 890 875 /* 891 876 * Host core Functions. ··· 924 901 extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num); 925 902 extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg); 926 903 927 - extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq); 904 + extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup); 928 905 extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd); 929 906 extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd); 930 907 ··· 963 940 * 1 - DMA Descriptor(default, if available) 964 941 */ 965 942 extern void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val); 943 + 944 + /* 945 + * When DMA mode is enabled specifies whether to use 946 + * address DMA or DMA Descritor mode with full speed devices 947 + * for accessing the data FIFOs in host mode. 948 + * 0 - address DMA 949 + * 1 - FS DMA Descriptor(default, if available) 950 + */ 951 + extern void dwc2_set_param_dma_desc_fs_enable(struct dwc2_hsotg *hsotg, 952 + int val); 966 953 967 954 /* 968 955 * Specifies the maximum speed of operation in host and device mode. ··· 1143 1110 extern int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg); 1144 1111 1145 1112 /* 1113 + * The following functions check the controller's OTG operation mode 1114 + * capability (GHWCFG2.OTG_MODE). 1115 + * 1116 + * These functions can be used before the internal hsotg->hw_params 1117 + * are read in and cached so they always read directly from the 1118 + * GHWCFG2 register. 1119 + */ 1120 + unsigned dwc2_op_mode(struct dwc2_hsotg *hsotg); 1121 + bool dwc2_hw_is_otg(struct dwc2_hsotg *hsotg); 1122 + bool dwc2_hw_is_host(struct dwc2_hsotg *hsotg); 1123 + bool dwc2_hw_is_device(struct dwc2_hsotg *hsotg); 1124 + 1125 + /* 1126 + * Returns the mode of operation, host or device 1127 + */ 1128 + static inline int dwc2_is_host_mode(struct dwc2_hsotg *hsotg) 1129 + { 1130 + return (dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) != 0; 1131 + } 1132 + static inline int dwc2_is_device_mode(struct dwc2_hsotg *hsotg) 1133 + { 1134 + return (dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) == 0; 1135 + } 1136 + 1137 + /* 1146 1138 * Dump core registers and SPRAM 1147 1139 */ 1148 1140 extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg); ··· 1212 1154 1213 1155 #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) 1214 1156 extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg); 1215 - extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg); 1157 + extern void dwc2_hcd_connect(struct dwc2_hsotg *hsotg); 1158 + extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force); 1216 1159 extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg); 1217 1160 #else 1218 1161 static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg) 1219 1162 { return 0; } 1220 - static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg) {} 1163 + static inline void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) {} 1164 + static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) {} 1221 1165 static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {} 1222 1166 static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {} 1223 1167 static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq)
+25 -28
drivers/usb/dwc2/core_intr.c
··· 86 86 hprt0 &= ~HPRT0_ENA; 87 87 dwc2_writel(hprt0, hsotg->regs + HPRT0); 88 88 } 89 - 90 - /* Clear interrupt */ 91 - dwc2_writel(GINTSTS_PRTINT, hsotg->regs + GINTSTS); 92 89 } 93 90 94 91 /** ··· 95 98 */ 96 99 static void dwc2_handle_mode_mismatch_intr(struct dwc2_hsotg *hsotg) 97 100 { 98 - dev_warn(hsotg->dev, "Mode Mismatch Interrupt: currently in %s mode\n", 99 - dwc2_is_host_mode(hsotg) ? "Host" : "Device"); 100 - 101 101 /* Clear interrupt */ 102 102 dwc2_writel(GINTSTS_MODEMIS, hsotg->regs + GINTSTS); 103 + 104 + dev_warn(hsotg->dev, "Mode Mismatch Interrupt: currently in %s mode\n", 105 + dwc2_is_host_mode(hsotg) ? "Host" : "Device"); 103 106 } 104 107 105 108 /** ··· 236 239 dev_dbg(hsotg->dev, "a_suspend->a_peripheral (%d)\n", 237 240 hsotg->op_state); 238 241 spin_unlock(&hsotg->lock); 239 - dwc2_hcd_disconnect(hsotg); 242 + dwc2_hcd_disconnect(hsotg, false); 240 243 spin_lock(&hsotg->lock); 241 244 hsotg->op_state = OTG_STATE_A_PERIPHERAL; 242 245 } else { ··· 273 276 */ 274 277 static void dwc2_handle_conn_id_status_change_intr(struct dwc2_hsotg *hsotg) 275 278 { 276 - u32 gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 279 + u32 gintmsk; 280 + 281 + /* Clear interrupt */ 282 + dwc2_writel(GINTSTS_CONIDSTSCHNG, hsotg->regs + GINTSTS); 277 283 278 284 /* Need to disable SOF interrupt immediately */ 285 + gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 279 286 gintmsk &= ~GINTSTS_SOF; 280 287 dwc2_writel(gintmsk, hsotg->regs + GINTMSK); 281 288 ··· 296 295 queue_work(hsotg->wq_otg, &hsotg->wf_otg); 297 296 spin_lock(&hsotg->lock); 298 297 } 299 - 300 - /* Clear interrupt */ 301 - dwc2_writel(GINTSTS_CONIDSTSCHNG, hsotg->regs + GINTSTS); 302 298 } 303 299 304 300 /** ··· 313 315 { 314 316 int ret; 315 317 316 - dev_dbg(hsotg->dev, "Session request interrupt - lx_state=%d\n", 317 - hsotg->lx_state); 318 - 319 318 /* Clear interrupt */ 320 319 dwc2_writel(GINTSTS_SESSREQINT, hsotg->regs + GINTSTS); 320 + 321 + dev_dbg(hsotg->dev, "Session request interrupt - lx_state=%d\n", 322 + hsotg->lx_state); 321 323 322 324 if (dwc2_is_device_mode(hsotg)) { 323 325 if (hsotg->lx_state == DWC2_L2) { ··· 345 347 static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg) 346 348 { 347 349 int ret; 350 + 351 + /* Clear interrupt */ 352 + dwc2_writel(GINTSTS_WKUPINT, hsotg->regs + GINTSTS); 353 + 348 354 dev_dbg(hsotg->dev, "++Resume or Remote Wakeup Detected Interrupt++\n"); 349 355 dev_dbg(hsotg->dev, "%s lxstate = %d\n", __func__, hsotg->lx_state); 350 356 ··· 370 368 /* Change to L0 state */ 371 369 hsotg->lx_state = DWC2_L0; 372 370 } else { 373 - if (hsotg->core_params->hibernation) { 374 - dwc2_writel(GINTSTS_WKUPINT, hsotg->regs + GINTSTS); 371 + if (hsotg->core_params->hibernation) 375 372 return; 376 - } 373 + 377 374 if (hsotg->lx_state != DWC2_L1) { 378 375 u32 pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); 379 376 ··· 386 385 hsotg->lx_state = DWC2_L0; 387 386 } 388 387 } 389 - 390 - /* Clear interrupt */ 391 - dwc2_writel(GINTSTS_WKUPINT, hsotg->regs + GINTSTS); 392 388 } 393 389 394 390 /* ··· 394 396 */ 395 397 static void dwc2_handle_disconnect_intr(struct dwc2_hsotg *hsotg) 396 398 { 399 + dwc2_writel(GINTSTS_DISCONNINT, hsotg->regs + GINTSTS); 400 + 397 401 dev_dbg(hsotg->dev, "++Disconnect Detected Interrupt++ (%s) %s\n", 398 402 dwc2_is_host_mode(hsotg) ? "Host" : "Device", 399 403 dwc2_op_state_str(hsotg)); 400 404 401 405 if (hsotg->op_state == OTG_STATE_A_HOST) 402 - dwc2_hcd_disconnect(hsotg); 403 - 404 - dwc2_writel(GINTSTS_DISCONNINT, hsotg->regs + GINTSTS); 406 + dwc2_hcd_disconnect(hsotg, false); 405 407 } 406 408 407 409 /* ··· 416 418 { 417 419 u32 dsts; 418 420 int ret; 421 + 422 + /* Clear interrupt */ 423 + dwc2_writel(GINTSTS_USBSUSP, hsotg->regs + GINTSTS); 419 424 420 425 dev_dbg(hsotg->dev, "USB SUSPEND\n"); 421 426 ··· 438 437 if (!dwc2_is_device_connected(hsotg)) { 439 438 dev_dbg(hsotg->dev, 440 439 "ignore suspend request before enumeration\n"); 441 - goto clear_int; 440 + return; 442 441 } 443 442 444 443 ret = dwc2_enter_hibernation(hsotg); ··· 477 476 hsotg->op_state = OTG_STATE_A_HOST; 478 477 } 479 478 } 480 - 481 - clear_int: 482 - /* Clear interrupt */ 483 - dwc2_writel(GINTSTS_USBSUSP, hsotg->regs + GINTSTS); 484 479 } 485 480 486 481 #define GINTMSK_COMMON (GINTSTS_WKUPINT | GINTSTS_SESSREQINT | \
+25 -84
drivers/usb/dwc2/gadget.c
··· 2095 2095 */ 2096 2096 2097 2097 /* catch both EnumSpd_FS and EnumSpd_FS48 */ 2098 - switch (dsts & DSTS_ENUMSPD_MASK) { 2098 + switch ((dsts & DSTS_ENUMSPD_MASK) >> DSTS_ENUMSPD_SHIFT) { 2099 2099 case DSTS_ENUMSPD_FS: 2100 2100 case DSTS_ENUMSPD_FS48: 2101 2101 hsotg->gadget.speed = USB_SPEED_FULL; ··· 2244 2244 GINTSTS_RXFLVL) 2245 2245 2246 2246 /** 2247 - * dwc2_hsotg_corereset - issue softreset to the core 2248 - * @hsotg: The device state 2249 - * 2250 - * Issue a soft reset to the core, and await the core finishing it. 2251 - */ 2252 - static int dwc2_hsotg_corereset(struct dwc2_hsotg *hsotg) 2253 - { 2254 - int timeout; 2255 - u32 grstctl; 2256 - 2257 - dev_dbg(hsotg->dev, "resetting core\n"); 2258 - 2259 - /* issue soft reset */ 2260 - dwc2_writel(GRSTCTL_CSFTRST, hsotg->regs + GRSTCTL); 2261 - 2262 - timeout = 10000; 2263 - do { 2264 - grstctl = dwc2_readl(hsotg->regs + GRSTCTL); 2265 - } while ((grstctl & GRSTCTL_CSFTRST) && timeout-- > 0); 2266 - 2267 - if (grstctl & GRSTCTL_CSFTRST) { 2268 - dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); 2269 - return -EINVAL; 2270 - } 2271 - 2272 - timeout = 10000; 2273 - 2274 - while (1) { 2275 - u32 grstctl = dwc2_readl(hsotg->regs + GRSTCTL); 2276 - 2277 - if (timeout-- < 0) { 2278 - dev_info(hsotg->dev, 2279 - "%s: reset failed, GRSTCTL=%08x\n", 2280 - __func__, grstctl); 2281 - return -ETIMEDOUT; 2282 - } 2283 - 2284 - if (!(grstctl & GRSTCTL_AHBIDLE)) 2285 - continue; 2286 - 2287 - break; /* reset done */ 2288 - } 2289 - 2290 - dev_dbg(hsotg->dev, "reset successful\n"); 2291 - return 0; 2292 - } 2293 - 2294 - /** 2295 2247 * dwc2_hsotg_core_init - issue softreset to the core 2296 2248 * @hsotg: The device state 2297 2249 * ··· 2259 2307 kill_all_requests(hsotg, hsotg->eps_out[0], -ECONNRESET); 2260 2308 2261 2309 if (!is_usb_reset) 2262 - if (dwc2_hsotg_corereset(hsotg)) 2310 + if (dwc2_core_reset(hsotg)) 2263 2311 return; 2264 2312 2265 2313 /* ··· 2537 2585 if (gintsts & GINTSTS_GOUTNAKEFF) { 2538 2586 dev_info(hsotg->dev, "GOUTNakEff triggered\n"); 2539 2587 2540 - dwc2_writel(DCTL_CGOUTNAK, hsotg->regs + DCTL); 2588 + __orr32(hsotg->regs + DCTL, DCTL_CGOUTNAK); 2541 2589 2542 2590 dwc2_hsotg_dump(hsotg); 2543 2591 } ··· 2545 2593 if (gintsts & GINTSTS_GINNAKEFF) { 2546 2594 dev_info(hsotg->dev, "GINNakEff triggered\n"); 2547 2595 2548 - dwc2_writel(DCTL_CGNPINNAK, hsotg->regs + DCTL); 2596 + __orr32(hsotg->regs + DCTL, DCTL_CGNPINNAK); 2549 2597 2550 2598 dwc2_hsotg_dump(hsotg); 2551 2599 } ··· 2863 2911 "%s: timeout DIEPINT.NAKEFF\n", __func__); 2864 2912 } else { 2865 2913 /* Clear any pending nak effect interrupt */ 2866 - dwc2_writel(GINTSTS_GINNAKEFF, hsotg->regs + GINTSTS); 2914 + dwc2_writel(GINTSTS_GOUTNAKEFF, hsotg->regs + GINTSTS); 2867 2915 2868 - __orr32(hsotg->regs + DCTL, DCTL_SGNPINNAK); 2916 + __orr32(hsotg->regs + DCTL, DCTL_SGOUTNAK); 2869 2917 2870 2918 /* Wait for global nak to take effect */ 2871 2919 if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS, 2872 - GINTSTS_GINNAKEFF, 100)) 2920 + GINTSTS_GOUTNAKEFF, 100)) 2873 2921 dev_warn(hsotg->dev, 2874 - "%s: timeout GINTSTS.GINNAKEFF\n", __func__); 2922 + "%s: timeout GINTSTS.GOUTNAKEFF\n", __func__); 2875 2923 } 2876 2924 2877 2925 /* Disable ep */ ··· 2896 2944 /* TODO: Flush shared tx fifo */ 2897 2945 } else { 2898 2946 /* Remove global NAKs */ 2899 - __bic32(hsotg->regs + DCTL, DCTL_SGNPINNAK); 2947 + __bic32(hsotg->regs + DCTL, DCTL_SGOUTNAK); 2900 2948 } 2901 2949 } 2902 2950 ··· 3355 3403 3356 3404 /* check hardware configuration */ 3357 3405 3358 - cfg = dwc2_readl(hsotg->regs + GHWCFG2); 3359 - hsotg->num_of_eps = (cfg >> GHWCFG2_NUM_DEV_EP_SHIFT) & 0xF; 3406 + hsotg->num_of_eps = hsotg->hw_params.num_dev_ep; 3407 + 3360 3408 /* Add ep0 */ 3361 3409 hsotg->num_of_eps++; 3362 3410 ··· 3367 3415 /* Same dwc2_hsotg_ep is used in both directions for ep0 */ 3368 3416 hsotg->eps_out[0] = hsotg->eps_in[0]; 3369 3417 3370 - cfg = dwc2_readl(hsotg->regs + GHWCFG1); 3418 + cfg = hsotg->hw_params.dev_ep_dirs; 3371 3419 for (i = 1, cfg >>= 2; i < hsotg->num_of_eps; i++, cfg >>= 2) { 3372 3420 ep_type = cfg & 3; 3373 3421 /* Direction in or both */ ··· 3386 3434 } 3387 3435 } 3388 3436 3389 - cfg = dwc2_readl(hsotg->regs + GHWCFG3); 3390 - hsotg->fifo_mem = (cfg >> GHWCFG3_DFIFO_DEPTH_SHIFT); 3391 - 3392 - cfg = dwc2_readl(hsotg->regs + GHWCFG4); 3393 - hsotg->dedicated_fifos = (cfg >> GHWCFG4_DED_FIFO_SHIFT) & 1; 3437 + hsotg->fifo_mem = hsotg->hw_params.total_fifo_size; 3438 + hsotg->dedicated_fifos = hsotg->hw_params.en_multiple_tx_fifo; 3394 3439 3395 3440 dev_info(hsotg->dev, "EPs: %d, %s fifos, %d entries in SPRAM\n", 3396 3441 hsotg->num_of_eps, ··· 3512 3563 memcpy(&hsotg->g_tx_fifo_sz[1], p_tx_fifo, sizeof(p_tx_fifo)); 3513 3564 /* Device tree specific probe */ 3514 3565 dwc2_hsotg_of_probe(hsotg); 3566 + 3567 + /* Check against largest possible value. */ 3568 + if (hsotg->g_np_g_tx_fifo_sz > 3569 + hsotg->hw_params.dev_nperio_tx_fifo_size) { 3570 + dev_warn(dev, "Specified GNPTXFDEP=%d > %d\n", 3571 + hsotg->g_np_g_tx_fifo_sz, 3572 + hsotg->hw_params.dev_nperio_tx_fifo_size); 3573 + hsotg->g_np_g_tx_fifo_sz = 3574 + hsotg->hw_params.dev_nperio_tx_fifo_size; 3575 + } 3576 + 3515 3577 /* Dump fifo information */ 3516 3578 dev_dbg(dev, "NonPeriodic TXFIFO size: %d\n", 3517 3579 hsotg->g_np_g_tx_fifo_sz); ··· 3539 3579 else if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) 3540 3580 hsotg->op_state = OTG_STATE_B_PERIPHERAL; 3541 3581 3542 - /* 3543 - * Force Device mode before initialization. 3544 - * This allows correctly configuring fifo for device mode. 3545 - */ 3546 - __bic32(hsotg->regs + GUSBCFG, GUSBCFG_FORCEHOSTMODE); 3547 - __orr32(hsotg->regs + GUSBCFG, GUSBCFG_FORCEDEVMODE); 3548 - 3549 - /* 3550 - * According to Synopsys databook, this sleep is needed for the force 3551 - * device mode to take effect. 3552 - */ 3553 - msleep(25); 3554 - 3555 - dwc2_hsotg_corereset(hsotg); 3556 3582 ret = dwc2_hsotg_hw_cfg(hsotg); 3557 3583 if (ret) { 3558 3584 dev_err(hsotg->dev, "Hardware configuration failed: %d\n", ret); 3559 3585 return ret; 3560 3586 } 3561 - 3562 - dwc2_hsotg_init(hsotg); 3563 - 3564 - /* Switch back to default configuration */ 3565 - __bic32(hsotg->regs + GUSBCFG, GUSBCFG_FORCEDEVMODE); 3566 3587 3567 3588 hsotg->ctrl_buff = devm_kzalloc(hsotg->dev, 3568 3589 DWC2_CTRL_BUFF_SIZE, GFP_KERNEL);
+122 -8
drivers/usb/dwc2/hcd.c
··· 268 268 } 269 269 270 270 /** 271 - * dwc2_hcd_disconnect() - Handles disconnect of the HCD 271 + * dwc2_hcd_connect() - Handles connect of the HCD 272 272 * 273 273 * @hsotg: Pointer to struct dwc2_hsotg 274 274 * 275 275 * Must be called with interrupt disabled and spinlock held 276 276 */ 277 - void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg) 277 + void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) 278 + { 279 + if (hsotg->lx_state != DWC2_L0) 280 + usb_hcd_resume_root_hub(hsotg->priv); 281 + 282 + hsotg->flags.b.port_connect_status_change = 1; 283 + hsotg->flags.b.port_connect_status = 1; 284 + } 285 + 286 + /** 287 + * dwc2_hcd_disconnect() - Handles disconnect of the HCD 288 + * 289 + * @hsotg: Pointer to struct dwc2_hsotg 290 + * @force: If true, we won't try to reconnect even if we see device connected. 291 + * 292 + * Must be called with interrupt disabled and spinlock held 293 + */ 294 + void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) 278 295 { 279 296 u32 intr; 297 + u32 hprt0; 280 298 281 299 /* Set status flags for the hub driver */ 282 300 hsotg->flags.b.port_connect_status_change = 1; ··· 333 315 dwc2_hcd_cleanup_channels(hsotg); 334 316 335 317 dwc2_host_disconnect(hsotg); 318 + 319 + /* 320 + * Add an extra check here to see if we're actually connected but 321 + * we don't have a detection interrupt pending. This can happen if: 322 + * 1. hardware sees connect 323 + * 2. hardware sees disconnect 324 + * 3. hardware sees connect 325 + * 4. dwc2_port_intr() - clears connect interrupt 326 + * 5. dwc2_handle_common_intr() - calls here 327 + * 328 + * Without the extra check here we will end calling disconnect 329 + * and won't get any future interrupts to handle the connect. 330 + */ 331 + if (!force) { 332 + hprt0 = dwc2_readl(hsotg->regs + HPRT0); 333 + if (!(hprt0 & HPRT0_CONNDET) && (hprt0 & HPRT0_CONNSTS)) 334 + dwc2_hcd_connect(hsotg); 335 + } 336 336 } 337 337 338 338 /** ··· 917 881 */ 918 882 chan->multi_count = dwc2_hb_mult(qh->maxp); 919 883 920 - if (hsotg->core_params->dma_desc_enable > 0) 884 + if (hsotg->core_params->dma_desc_enable > 0) { 921 885 chan->desc_list_addr = qh->desc_list_dma; 886 + chan->desc_list_sz = qh->desc_list_sz; 887 + } 922 888 923 889 dwc2_hc_init(hsotg, chan); 924 890 chan->qh = qh; ··· 1420 1382 dev_err(hsotg->dev, 1421 1383 "Connection id status change timed out\n"); 1422 1384 hsotg->op_state = OTG_STATE_B_PERIPHERAL; 1423 - dwc2_core_init(hsotg, false, -1); 1385 + dwc2_core_init(hsotg, false); 1424 1386 dwc2_enable_global_interrupts(hsotg); 1425 1387 spin_lock_irqsave(&hsotg->lock, flags); 1426 1388 dwc2_hsotg_core_init_disconnected(hsotg, false); ··· 1443 1405 hsotg->op_state = OTG_STATE_A_HOST; 1444 1406 1445 1407 /* Initialize the Core for Host mode */ 1446 - dwc2_core_init(hsotg, false, -1); 1408 + dwc2_core_init(hsotg, false); 1447 1409 dwc2_enable_global_interrupts(hsotg); 1448 1410 dwc2_hcd_start(hsotg); 1449 1411 } ··· 1771 1733 if (hprt0 & HPRT0_TSTCTL_MASK) 1772 1734 port_status |= USB_PORT_STAT_TEST; 1773 1735 /* USB_PORT_FEAT_INDICATOR unsupported always 0 */ 1736 + 1737 + if (hsotg->core_params->dma_desc_fs_enable) { 1738 + /* 1739 + * Enable descriptor DMA only if a full speed 1740 + * device is connected. 1741 + */ 1742 + if (hsotg->new_connection && 1743 + ((port_status & 1744 + (USB_PORT_STAT_CONNECTION | 1745 + USB_PORT_STAT_HIGH_SPEED | 1746 + USB_PORT_STAT_LOW_SPEED)) == 1747 + USB_PORT_STAT_CONNECTION)) { 1748 + u32 hcfg; 1749 + 1750 + dev_info(hsotg->dev, "Enabling descriptor DMA mode\n"); 1751 + hsotg->core_params->dma_desc_enable = 1; 1752 + hcfg = dwc2_readl(hsotg->regs + HCFG); 1753 + hcfg |= HCFG_DESCDMA; 1754 + dwc2_writel(hcfg, hsotg->regs + HCFG); 1755 + hsotg->new_connection = false; 1756 + } 1757 + } 1774 1758 1775 1759 dev_vdbg(hsotg->dev, "port_status=%08x\n", port_status); 1776 1760 *(__le32 *)buf = cpu_to_le32(port_status); ··· 2358 2298 { 2359 2299 struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, 2360 2300 reset_work.work); 2301 + unsigned long flags; 2361 2302 u32 hprt0; 2362 2303 2363 2304 dev_dbg(hsotg->dev, "USB RESET function called\n"); 2305 + 2306 + spin_lock_irqsave(&hsotg->lock, flags); 2307 + 2364 2308 hprt0 = dwc2_read_hprt0(hsotg); 2365 2309 hprt0 &= ~HPRT0_RST; 2366 2310 dwc2_writel(hprt0, hsotg->regs + HPRT0); 2367 2311 hsotg->flags.b.port_reset_change = 1; 2312 + 2313 + spin_unlock_irqrestore(&hsotg->lock, flags); 2368 2314 } 2369 2315 2370 2316 /* ··· 2432 2366 2433 2367 spin_lock_irqsave(&hsotg->lock, flags); 2434 2368 /* Ensure hcd is disconnected */ 2435 - dwc2_hcd_disconnect(hsotg); 2369 + dwc2_hcd_disconnect(hsotg, true); 2436 2370 dwc2_hcd_stop(hsotg); 2437 2371 hsotg->lx_state = DWC2_L3; 2438 2372 hcd->state = HC_STATE_HALT; ··· 3120 3054 dwc2_disable_global_interrupts(hsotg); 3121 3055 3122 3056 /* Initialize the DWC_otg core, and select the Phy type */ 3123 - retval = dwc2_core_init(hsotg, true, irq); 3057 + retval = dwc2_core_init(hsotg, true); 3124 3058 if (retval) 3125 3059 goto error2; 3126 3060 ··· 3188 3122 if (!hsotg->status_buf) 3189 3123 goto error3; 3190 3124 3125 + /* 3126 + * Create kmem caches to handle descriptor buffers in descriptor 3127 + * DMA mode. 3128 + * Alignment must be set to 512 bytes. 3129 + */ 3130 + if (hsotg->core_params->dma_desc_enable || 3131 + hsotg->core_params->dma_desc_fs_enable) { 3132 + hsotg->desc_gen_cache = kmem_cache_create("dwc2-gen-desc", 3133 + sizeof(struct dwc2_hcd_dma_desc) * 3134 + MAX_DMA_DESC_NUM_GENERIC, 512, SLAB_CACHE_DMA, 3135 + NULL); 3136 + if (!hsotg->desc_gen_cache) { 3137 + dev_err(hsotg->dev, 3138 + "unable to create dwc2 generic desc cache\n"); 3139 + 3140 + /* 3141 + * Disable descriptor dma mode since it will not be 3142 + * usable. 3143 + */ 3144 + hsotg->core_params->dma_desc_enable = 0; 3145 + hsotg->core_params->dma_desc_fs_enable = 0; 3146 + } 3147 + 3148 + hsotg->desc_hsisoc_cache = kmem_cache_create("dwc2-hsisoc-desc", 3149 + sizeof(struct dwc2_hcd_dma_desc) * 3150 + MAX_DMA_DESC_NUM_HS_ISOC, 512, 0, NULL); 3151 + if (!hsotg->desc_hsisoc_cache) { 3152 + dev_err(hsotg->dev, 3153 + "unable to create dwc2 hs isoc desc cache\n"); 3154 + 3155 + kmem_cache_destroy(hsotg->desc_gen_cache); 3156 + 3157 + /* 3158 + * Disable descriptor dma mode since it will not be 3159 + * usable. 3160 + */ 3161 + hsotg->core_params->dma_desc_enable = 0; 3162 + hsotg->core_params->dma_desc_fs_enable = 0; 3163 + } 3164 + } 3165 + 3191 3166 hsotg->otg_port = 1; 3192 3167 hsotg->frame_list = NULL; 3193 3168 hsotg->frame_list_dma = 0; ··· 3252 3145 */ 3253 3146 retval = usb_add_hcd(hcd, irq, IRQF_SHARED); 3254 3147 if (retval < 0) 3255 - goto error3; 3148 + goto error4; 3256 3149 3257 3150 device_wakeup_enable(hcd->self.controller); 3258 3151 ··· 3262 3155 3263 3156 return 0; 3264 3157 3158 + error4: 3159 + kmem_cache_destroy(hsotg->desc_gen_cache); 3160 + kmem_cache_destroy(hsotg->desc_hsisoc_cache); 3265 3161 error3: 3266 3162 dwc2_hcd_release(hsotg); 3267 3163 error2: ··· 3305 3195 3306 3196 usb_remove_hcd(hcd); 3307 3197 hsotg->priv = NULL; 3198 + 3199 + kmem_cache_destroy(hsotg->desc_gen_cache); 3200 + kmem_cache_destroy(hsotg->desc_hsisoc_cache); 3201 + 3308 3202 dwc2_hcd_release(hsotg); 3309 3203 usb_put_hcd(hcd); 3310 3204
+19 -12
drivers/usb/dwc2/hcd.h
··· 107 107 * @qh: QH for the transfer being processed by this channel 108 108 * @hc_list_entry: For linking to list of host channels 109 109 * @desc_list_addr: Current QH's descriptor list DMA address 110 + * @desc_list_sz: Current QH's descriptor list size 110 111 * 111 112 * This structure represents the state of a single host channel when acting in 112 113 * host mode. It contains the data items needed to transfer packets to an ··· 160 159 struct dwc2_qh *qh; 161 160 struct list_head hc_list_entry; 162 161 dma_addr_t desc_list_addr; 162 + u32 desc_list_sz; 163 163 }; 164 164 165 165 struct dwc2_hcd_pipe_info { ··· 253 251 * schedule 254 252 * @desc_list: List of transfer descriptors 255 253 * @desc_list_dma: Physical address of desc_list 254 + * @desc_list_sz: Size of descriptors list 256 255 * @n_bytes: Xfer Bytes array. Each element corresponds to a transfer 257 256 * descriptor and indicates original XferSize value for the 258 257 * descriptor ··· 287 284 struct list_head qh_list_entry; 288 285 struct dwc2_hcd_dma_desc *desc_list; 289 286 dma_addr_t desc_list_dma; 287 + u32 desc_list_sz; 290 288 u32 *n_bytes; 291 289 unsigned tt_buffer_dirty:1; 292 290 }; ··· 344 340 u8 isoc_split_pos; 345 341 u16 isoc_frame_index; 346 342 u16 isoc_split_offset; 343 + u16 isoc_td_last; 344 + u16 isoc_td_first; 347 345 u32 ssplit_out_xfer_count; 348 346 u8 error_count; 349 347 u8 n_desc; ··· 381 375 382 376 mask &= ~intr; 383 377 dwc2_writel(mask, hsotg->regs + HCINTMSK(chnum)); 384 - } 385 - 386 - /* 387 - * Returns the mode of operation, host or device 388 - */ 389 - static inline int dwc2_is_host_mode(struct dwc2_hsotg *hsotg) 390 - { 391 - return (dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) != 0; 392 - } 393 - static inline int dwc2_is_device_mode(struct dwc2_hsotg *hsotg) 394 - { 395 - return (dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) == 0; 396 378 } 397 379 398 380 /* ··· 527 533 528 534 /* Packet size for any kind of endpoint descriptor */ 529 535 #define dwc2_max_packet(wmaxpacketsize) ((wmaxpacketsize) & 0x07ff) 536 + 537 + /* 538 + * Returns true if frame1 index is greater than frame2 index. The comparison 539 + * is done modulo FRLISTEN_64_SIZE. This accounts for the rollover of the 540 + * frame number when the max index frame number is reached. 541 + */ 542 + static inline bool dwc2_frame_idx_num_gt(u16 fr_idx1, u16 fr_idx2) 543 + { 544 + u16 diff = fr_idx1 - fr_idx2; 545 + u16 sign = diff & (FRLISTEN_64_SIZE >> 1); 546 + 547 + return diff && !sign; 548 + } 530 549 531 550 /* 532 551 * Returns true if frame1 is less than or equal to frame2. The comparison is
+200 -40
drivers/usb/dwc2/hcd_ddma.c
··· 87 87 static int dwc2_desc_list_alloc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, 88 88 gfp_t flags) 89 89 { 90 - qh->desc_list = dma_alloc_coherent(hsotg->dev, 91 - sizeof(struct dwc2_hcd_dma_desc) * 92 - dwc2_max_desc_num(qh), &qh->desc_list_dma, 93 - flags); 90 + struct kmem_cache *desc_cache; 94 91 92 + if (qh->ep_type == USB_ENDPOINT_XFER_ISOC 93 + && qh->dev_speed == USB_SPEED_HIGH) 94 + desc_cache = hsotg->desc_hsisoc_cache; 95 + else 96 + desc_cache = hsotg->desc_gen_cache; 97 + 98 + qh->desc_list_sz = sizeof(struct dwc2_hcd_dma_desc) * 99 + dwc2_max_desc_num(qh); 100 + 101 + qh->desc_list = kmem_cache_zalloc(desc_cache, flags | GFP_DMA); 95 102 if (!qh->desc_list) 96 103 return -ENOMEM; 97 104 98 - memset(qh->desc_list, 0, 99 - sizeof(struct dwc2_hcd_dma_desc) * dwc2_max_desc_num(qh)); 105 + qh->desc_list_dma = dma_map_single(hsotg->dev, qh->desc_list, 106 + qh->desc_list_sz, 107 + DMA_TO_DEVICE); 100 108 101 109 qh->n_bytes = kzalloc(sizeof(u32) * dwc2_max_desc_num(qh), flags); 102 110 if (!qh->n_bytes) { 103 - dma_free_coherent(hsotg->dev, sizeof(struct dwc2_hcd_dma_desc) 104 - * dwc2_max_desc_num(qh), qh->desc_list, 105 - qh->desc_list_dma); 111 + dma_unmap_single(hsotg->dev, qh->desc_list_dma, 112 + qh->desc_list_sz, 113 + DMA_FROM_DEVICE); 114 + kfree(qh->desc_list); 106 115 qh->desc_list = NULL; 107 116 return -ENOMEM; 108 117 } ··· 121 112 122 113 static void dwc2_desc_list_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) 123 114 { 115 + struct kmem_cache *desc_cache; 116 + 117 + if (qh->ep_type == USB_ENDPOINT_XFER_ISOC 118 + && qh->dev_speed == USB_SPEED_HIGH) 119 + desc_cache = hsotg->desc_hsisoc_cache; 120 + else 121 + desc_cache = hsotg->desc_gen_cache; 122 + 124 123 if (qh->desc_list) { 125 - dma_free_coherent(hsotg->dev, sizeof(struct dwc2_hcd_dma_desc) 126 - * dwc2_max_desc_num(qh), qh->desc_list, 127 - qh->desc_list_dma); 124 + dma_unmap_single(hsotg->dev, qh->desc_list_dma, 125 + qh->desc_list_sz, DMA_FROM_DEVICE); 126 + kmem_cache_free(desc_cache, qh->desc_list); 128 127 qh->desc_list = NULL; 129 128 } 130 129 ··· 145 128 if (hsotg->frame_list) 146 129 return 0; 147 130 148 - hsotg->frame_list = dma_alloc_coherent(hsotg->dev, 149 - 4 * FRLISTEN_64_SIZE, 150 - &hsotg->frame_list_dma, 151 - mem_flags); 131 + hsotg->frame_list_sz = 4 * FRLISTEN_64_SIZE; 132 + hsotg->frame_list = kzalloc(hsotg->frame_list_sz, GFP_ATOMIC | GFP_DMA); 152 133 if (!hsotg->frame_list) 153 134 return -ENOMEM; 154 135 155 - memset(hsotg->frame_list, 0, 4 * FRLISTEN_64_SIZE); 136 + hsotg->frame_list_dma = dma_map_single(hsotg->dev, hsotg->frame_list, 137 + hsotg->frame_list_sz, 138 + DMA_TO_DEVICE); 139 + 156 140 return 0; 157 141 } 158 142 159 143 static void dwc2_frame_list_free(struct dwc2_hsotg *hsotg) 160 144 { 161 - u32 *frame_list; 162 - dma_addr_t frame_list_dma; 163 145 unsigned long flags; 164 146 165 147 spin_lock_irqsave(&hsotg->lock, flags); ··· 168 152 return; 169 153 } 170 154 171 - frame_list = hsotg->frame_list; 172 - frame_list_dma = hsotg->frame_list_dma; 155 + dma_unmap_single(hsotg->dev, hsotg->frame_list_dma, 156 + hsotg->frame_list_sz, DMA_FROM_DEVICE); 157 + 158 + kfree(hsotg->frame_list); 173 159 hsotg->frame_list = NULL; 174 160 175 161 spin_unlock_irqrestore(&hsotg->lock, flags); 176 162 177 - dma_free_coherent(hsotg->dev, 4 * FRLISTEN_64_SIZE, frame_list, 178 - frame_list_dma); 179 163 } 180 164 181 165 static void dwc2_per_sched_enable(struct dwc2_hsotg *hsotg, u32 fr_list_en) ··· 265 249 j = (j + inc) & (FRLISTEN_64_SIZE - 1); 266 250 } while (j != i); 267 251 252 + /* 253 + * Sync frame list since controller will access it if periodic 254 + * channel is currently enabled. 255 + */ 256 + dma_sync_single_for_device(hsotg->dev, 257 + hsotg->frame_list_dma, 258 + hsotg->frame_list_sz, 259 + DMA_TO_DEVICE); 260 + 268 261 if (!enable) 269 262 return; 270 263 ··· 303 278 hsotg->non_periodic_channels--; 304 279 } else { 305 280 dwc2_update_frame_list(hsotg, qh, 0); 281 + hsotg->available_host_channels++; 306 282 } 307 283 308 284 /* ··· 386 360 */ 387 361 void dwc2_hcd_qh_free_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) 388 362 { 363 + unsigned long flags; 364 + 389 365 dwc2_desc_list_free(hsotg, qh); 390 366 391 367 /* ··· 397 369 * when it comes here from endpoint disable routine 398 370 * channel remains assigned. 399 371 */ 372 + spin_lock_irqsave(&hsotg->lock, flags); 400 373 if (qh->channel) 401 374 dwc2_release_channel_ddma(hsotg, qh); 375 + spin_unlock_irqrestore(&hsotg->lock, flags); 402 376 403 377 if ((qh->ep_type == USB_ENDPOINT_XFER_ISOC || 404 378 qh->ep_type == USB_ENDPOINT_XFER_INT) && ··· 554 524 dma_desc->status = qh->n_bytes[idx] << HOST_DMA_ISOC_NBYTES_SHIFT & 555 525 HOST_DMA_ISOC_NBYTES_MASK; 556 526 527 + /* Set active bit */ 528 + dma_desc->status |= HOST_DMA_A; 529 + 530 + qh->ntd++; 531 + qtd->isoc_frame_index_last++; 532 + 557 533 #ifdef ISOC_URB_GIVEBACK_ASAP 558 534 /* Set IOC for each descriptor corresponding to last frame of URB */ 559 535 if (qtd->isoc_frame_index_last == qtd->urb->packet_count) 560 536 dma_desc->status |= HOST_DMA_IOC; 561 537 #endif 562 538 563 - qh->ntd++; 564 - qtd->isoc_frame_index_last++; 539 + dma_sync_single_for_device(hsotg->dev, 540 + qh->desc_list_dma + 541 + (idx * sizeof(struct dwc2_hcd_dma_desc)), 542 + sizeof(struct dwc2_hcd_dma_desc), 543 + DMA_TO_DEVICE); 565 544 } 566 545 567 546 static void dwc2_init_isoc_dma_desc(struct dwc2_hsotg *hsotg, ··· 578 539 { 579 540 struct dwc2_qtd *qtd; 580 541 u32 max_xfer_size; 581 - u16 idx, inc, n_desc, ntd_max = 0; 542 + u16 idx, inc, n_desc = 0, ntd_max = 0; 543 + u16 cur_idx; 544 + u16 next_idx; 582 545 583 546 idx = qh->td_last; 584 547 inc = qh->interval; 585 - n_desc = 0; 548 + hsotg->frame_number = dwc2_hcd_get_frame_number(hsotg); 549 + cur_idx = dwc2_frame_list_idx(hsotg->frame_number); 550 + next_idx = dwc2_desclist_idx_inc(qh->td_last, inc, qh->dev_speed); 551 + 552 + /* 553 + * Ensure current frame number didn't overstep last scheduled 554 + * descriptor. If it happens, the only way to recover is to move 555 + * qh->td_last to current frame number + 1. 556 + * So that next isoc descriptor will be scheduled on frame number + 1 557 + * and not on a past frame. 558 + */ 559 + if (dwc2_frame_idx_num_gt(cur_idx, next_idx) || (cur_idx == next_idx)) { 560 + if (inc < 32) { 561 + dev_vdbg(hsotg->dev, 562 + "current frame number overstep last descriptor\n"); 563 + qh->td_last = dwc2_desclist_idx_inc(cur_idx, inc, 564 + qh->dev_speed); 565 + idx = qh->td_last; 566 + } 567 + } 586 568 587 569 if (qh->interval) { 588 570 ntd_max = (dwc2_max_desc_num(qh) + qh->interval - 1) / ··· 616 556 MAX_ISOC_XFER_SIZE_HS : MAX_ISOC_XFER_SIZE_FS; 617 557 618 558 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) { 559 + if (qtd->in_process && 560 + qtd->isoc_frame_index_last == 561 + qtd->urb->packet_count) 562 + continue; 563 + 564 + qtd->isoc_td_first = idx; 619 565 while (qh->ntd < ntd_max && qtd->isoc_frame_index_last < 620 566 qtd->urb->packet_count) { 621 - if (n_desc > 1) 622 - qh->desc_list[n_desc - 1].status |= HOST_DMA_A; 623 567 dwc2_fill_host_isoc_dma_desc(hsotg, qtd, qh, 624 568 max_xfer_size, idx); 625 569 idx = dwc2_desclist_idx_inc(idx, inc, qh->dev_speed); 626 570 n_desc++; 627 571 } 572 + qtd->isoc_td_last = idx; 628 573 qtd->in_process = 1; 629 574 } 630 575 ··· 640 575 if (qh->ntd == ntd_max) { 641 576 idx = dwc2_desclist_idx_dec(qh->td_last, inc, qh->dev_speed); 642 577 qh->desc_list[idx].status |= HOST_DMA_IOC; 578 + dma_sync_single_for_device(hsotg->dev, 579 + qh->desc_list_dma + (idx * 580 + sizeof(struct dwc2_hcd_dma_desc)), 581 + sizeof(struct dwc2_hcd_dma_desc), 582 + DMA_TO_DEVICE); 643 583 } 644 584 #else 645 585 /* ··· 674 604 idx = dwc2_desclist_idx_dec(qh->td_last, inc, qh->dev_speed); 675 605 676 606 qh->desc_list[idx].status |= HOST_DMA_IOC; 607 + dma_sync_single_for_device(hsotg->dev, 608 + qh->desc_list_dma + 609 + (idx * sizeof(struct dwc2_hcd_dma_desc)), 610 + sizeof(struct dwc2_hcd_dma_desc), 611 + DMA_TO_DEVICE); 677 612 #endif 678 - 679 - if (n_desc) { 680 - qh->desc_list[n_desc - 1].status |= HOST_DMA_A; 681 - if (n_desc > 1) 682 - qh->desc_list[0].status |= HOST_DMA_A; 683 - } 684 613 } 685 614 686 615 static void dwc2_fill_host_dma_desc(struct dwc2_hsotg *hsotg, ··· 715 646 dma_desc->status |= HOST_DMA_SUP; 716 647 717 648 dma_desc->buf = (u32)chan->xfer_dma; 649 + 650 + dma_sync_single_for_device(hsotg->dev, 651 + qh->desc_list_dma + 652 + (n_desc * sizeof(struct dwc2_hcd_dma_desc)), 653 + sizeof(struct dwc2_hcd_dma_desc), 654 + DMA_TO_DEVICE); 718 655 719 656 /* 720 657 * Last (or only) descriptor of IN transfer with actual size less ··· 772 697 "set A bit in desc %d (%p)\n", 773 698 n_desc - 1, 774 699 &qh->desc_list[n_desc - 1]); 700 + dma_sync_single_for_device(hsotg->dev, 701 + qh->desc_list_dma + 702 + ((n_desc - 1) * 703 + sizeof(struct dwc2_hcd_dma_desc)), 704 + sizeof(struct dwc2_hcd_dma_desc), 705 + DMA_TO_DEVICE); 775 706 } 776 707 dwc2_fill_host_dma_desc(hsotg, chan, qtd, qh, n_desc); 777 708 dev_vdbg(hsotg->dev, ··· 803 722 HOST_DMA_IOC | HOST_DMA_EOL | HOST_DMA_A; 804 723 dev_vdbg(hsotg->dev, "set IOC/EOL/A bits in desc %d (%p)\n", 805 724 n_desc - 1, &qh->desc_list[n_desc - 1]); 725 + dma_sync_single_for_device(hsotg->dev, 726 + qh->desc_list_dma + (n_desc - 1) * 727 + sizeof(struct dwc2_hcd_dma_desc), 728 + sizeof(struct dwc2_hcd_dma_desc), 729 + DMA_TO_DEVICE); 806 730 if (n_desc > 1) { 807 731 qh->desc_list[0].status |= HOST_DMA_A; 808 732 dev_vdbg(hsotg->dev, "set A bit in desc 0 (%p)\n", 809 733 &qh->desc_list[0]); 734 + dma_sync_single_for_device(hsotg->dev, 735 + qh->desc_list_dma, 736 + sizeof(struct dwc2_hcd_dma_desc), 737 + DMA_TO_DEVICE); 810 738 } 811 739 chan->ntd = n_desc; 812 740 } ··· 890 800 struct dwc2_qtd *qtd, 891 801 struct dwc2_qh *qh, u16 idx) 892 802 { 893 - struct dwc2_hcd_dma_desc *dma_desc = &qh->desc_list[idx]; 803 + struct dwc2_hcd_dma_desc *dma_desc; 894 804 struct dwc2_hcd_iso_packet_desc *frame_desc; 895 805 u16 remain = 0; 896 806 int rc = 0; 897 807 898 808 if (!qtd->urb) 899 809 return -EINVAL; 810 + 811 + dma_sync_single_for_cpu(hsotg->dev, qh->desc_list_dma + (idx * 812 + sizeof(struct dwc2_hcd_dma_desc)), 813 + sizeof(struct dwc2_hcd_dma_desc), 814 + DMA_FROM_DEVICE); 815 + 816 + dma_desc = &qh->desc_list[idx]; 900 817 901 818 frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last]; 902 819 dma_desc->buf = (u32)(qtd->urb->dma + frame_desc->offset); ··· 1008 911 list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) { 1009 912 if (!qtd->in_process) 1010 913 break; 914 + 915 + /* 916 + * Ensure idx corresponds to descriptor where first urb of this 917 + * qtd was added. In fact, during isoc desc init, dwc2 may skip 918 + * an index if current frame number is already over this index. 919 + */ 920 + if (idx != qtd->isoc_td_first) { 921 + dev_vdbg(hsotg->dev, 922 + "try to complete %d instead of %d\n", 923 + idx, qtd->isoc_td_first); 924 + idx = qtd->isoc_td_first; 925 + } 926 + 1011 927 do { 928 + struct dwc2_qtd *qtd_next; 929 + u16 cur_idx; 930 + 1012 931 rc = dwc2_cmpl_host_isoc_dma_desc(hsotg, chan, qtd, qh, 1013 932 idx); 1014 933 if (rc < 0) 1015 934 return; 1016 935 idx = dwc2_desclist_idx_inc(idx, qh->interval, 1017 936 chan->speed); 1018 - if (rc == DWC2_CMPL_STOP) 1019 - goto stop_scan; 937 + if (!rc) 938 + continue; 939 + 1020 940 if (rc == DWC2_CMPL_DONE) 1021 941 break; 942 + 943 + /* rc == DWC2_CMPL_STOP */ 944 + 945 + if (qh->interval >= 32) 946 + goto stop_scan; 947 + 948 + qh->td_first = idx; 949 + cur_idx = dwc2_frame_list_idx(hsotg->frame_number); 950 + qtd_next = list_first_entry(&qh->qtd_list, 951 + struct dwc2_qtd, 952 + qtd_list_entry); 953 + if (dwc2_frame_idx_num_gt(cur_idx, 954 + qtd_next->isoc_td_last)) 955 + break; 956 + 957 + goto stop_scan; 958 + 1022 959 } while (idx != qh->td_first); 1023 960 } 1024 961 ··· 1160 1029 if (!urb) 1161 1030 return -EINVAL; 1162 1031 1032 + dma_sync_single_for_cpu(hsotg->dev, 1033 + qh->desc_list_dma + (desc_num * 1034 + sizeof(struct dwc2_hcd_dma_desc)), 1035 + sizeof(struct dwc2_hcd_dma_desc), 1036 + DMA_FROM_DEVICE); 1037 + 1163 1038 dma_desc = &qh->desc_list[desc_num]; 1164 1039 n_bytes = qh->n_bytes[desc_num]; 1165 1040 dev_vdbg(hsotg->dev, ··· 1174 1037 failed = dwc2_update_non_isoc_urb_state_ddma(hsotg, chan, qtd, dma_desc, 1175 1038 halt_status, n_bytes, 1176 1039 xfer_done); 1177 - if (failed || (*xfer_done && urb->status != -EINPROGRESS)) { 1040 + if (*xfer_done && urb->status != -EINPROGRESS) 1041 + failed = 1; 1042 + 1043 + if (failed) { 1178 1044 dwc2_host_complete(hsotg, qtd, urb->status); 1179 1045 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); 1180 1046 dev_vdbg(hsotg->dev, "failed=%1x xfer_done=%1x status=%08x\n", ··· 1305 1165 /* Release the channel if halted or session completed */ 1306 1166 if (halt_status != DWC2_HC_XFER_COMPLETE || 1307 1167 list_empty(&qh->qtd_list)) { 1168 + struct dwc2_qtd *qtd, *qtd_tmp; 1169 + 1170 + /* 1171 + * Kill all remainings QTDs since channel has been 1172 + * halted. 1173 + */ 1174 + list_for_each_entry_safe(qtd, qtd_tmp, 1175 + &qh->qtd_list, 1176 + qtd_list_entry) { 1177 + dwc2_host_complete(hsotg, qtd, 1178 + -ECONNRESET); 1179 + dwc2_hcd_qtd_unlink_and_free(hsotg, 1180 + qtd, qh); 1181 + } 1182 + 1308 1183 /* Halt the channel if session completed */ 1309 1184 if (halt_status == DWC2_HC_XFER_COMPLETE) 1310 1185 dwc2_hc_halt(hsotg, chan, halt_status); ··· 1329 1174 /* Keep in assigned schedule to continue transfer */ 1330 1175 list_move(&qh->qh_list_entry, 1331 1176 &hsotg->periodic_sched_assigned); 1332 - continue_isoc_xfer = 1; 1177 + /* 1178 + * If channel has been halted during giveback of urb 1179 + * then prevent any new scheduling. 1180 + */ 1181 + if (!chan->halt_status) 1182 + continue_isoc_xfer = 1; 1333 1183 } 1334 1184 /* 1335 1185 * Todo: Consider the case when period exceeds FrameList size.
+23 -16
drivers/usb/dwc2/hcd_intr.c
··· 122 122 struct dwc2_qh *qh; 123 123 enum dwc2_transaction_type tr_type; 124 124 125 + /* Clear interrupt */ 126 + dwc2_writel(GINTSTS_SOF, hsotg->regs + GINTSTS); 127 + 125 128 #ifdef DEBUG_SOF 126 129 dev_vdbg(hsotg->dev, "--Start of Frame Interrupt--\n"); 127 130 #endif ··· 149 146 tr_type = dwc2_hcd_select_transactions(hsotg); 150 147 if (tr_type != DWC2_TRANSACTION_NONE) 151 148 dwc2_hcd_queue_transactions(hsotg, tr_type); 152 - 153 - /* Clear interrupt */ 154 - dwc2_writel(GINTSTS_SOF, hsotg->regs + GINTSTS); 155 149 } 156 150 157 151 /* ··· 312 312 313 313 if (do_reset) { 314 314 *hprt0_modify |= HPRT0_RST; 315 + dwc2_writel(*hprt0_modify, hsotg->regs + HPRT0); 315 316 queue_delayed_work(hsotg->wq_otg, &hsotg->reset_work, 316 317 msecs_to_jiffies(60)); 317 318 } else { ··· 348 347 * Set flag and clear if detected 349 348 */ 350 349 if (hprt0 & HPRT0_CONNDET) { 350 + dwc2_writel(hprt0_modify | HPRT0_CONNDET, hsotg->regs + HPRT0); 351 + 351 352 dev_vdbg(hsotg->dev, 352 353 "--Port Interrupt HPRT0=0x%08x Port Connect Detected--\n", 353 354 hprt0); 354 - if (hsotg->lx_state != DWC2_L0) 355 - usb_hcd_resume_root_hub(hsotg->priv); 356 - 357 - hsotg->flags.b.port_connect_status_change = 1; 358 - hsotg->flags.b.port_connect_status = 1; 359 - hprt0_modify |= HPRT0_CONNDET; 355 + dwc2_hcd_connect(hsotg); 360 356 361 357 /* 362 358 * The Hub driver asserts a reset when it sees port connect ··· 366 368 * Clear if detected - Set internal flag if disabled 367 369 */ 368 370 if (hprt0 & HPRT0_ENACHG) { 371 + dwc2_writel(hprt0_modify | HPRT0_ENACHG, hsotg->regs + HPRT0); 369 372 dev_vdbg(hsotg->dev, 370 373 " --Port Interrupt HPRT0=0x%08x Port Enable Changed (now %d)--\n", 371 374 hprt0, !!(hprt0 & HPRT0_ENA)); 372 - hprt0_modify |= HPRT0_ENACHG; 373 - if (hprt0 & HPRT0_ENA) 375 + if (hprt0 & HPRT0_ENA) { 376 + hsotg->new_connection = true; 374 377 dwc2_hprt0_enable(hsotg, hprt0, &hprt0_modify); 375 - else 378 + } else { 376 379 hsotg->flags.b.port_enable_change = 1; 380 + if (hsotg->core_params->dma_desc_fs_enable) { 381 + u32 hcfg; 382 + 383 + hsotg->core_params->dma_desc_enable = 0; 384 + hsotg->new_connection = false; 385 + hcfg = dwc2_readl(hsotg->regs + HCFG); 386 + hcfg &= ~HCFG_DESCDMA; 387 + dwc2_writel(hcfg, hsotg->regs + HCFG); 388 + } 389 + } 377 390 } 378 391 379 392 /* Overcurrent Change Interrupt */ 380 393 if (hprt0 & HPRT0_OVRCURRCHG) { 394 + dwc2_writel(hprt0_modify | HPRT0_OVRCURRCHG, 395 + hsotg->regs + HPRT0); 381 396 dev_vdbg(hsotg->dev, 382 397 " --Port Interrupt HPRT0=0x%08x Port Overcurrent Changed--\n", 383 398 hprt0); 384 399 hsotg->flags.b.port_over_current_change = 1; 385 - hprt0_modify |= HPRT0_OVRCURRCHG; 386 400 } 387 - 388 - /* Clear Port Interrupts */ 389 - dwc2_writel(hprt0_modify, hsotg->regs + HPRT0); 390 401 } 391 402 392 403 /*
+1 -1
drivers/usb/dwc2/hcd_queue.c
··· 232 232 */ 233 233 void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) 234 234 { 235 - if (hsotg->core_params->dma_desc_enable > 0) { 235 + if (qh->desc_list) { 236 236 dwc2_hcd_qh_free_ddma(hsotg, qh); 237 237 } else { 238 238 /* kfree(NULL) is safe */
-4
drivers/usb/dwc2/hw.h
··· 769 769 #define TSIZ_XFERSIZE_SHIFT 0 770 770 771 771 #define HCDMA(_ch) HSOTG_REG(0x0514 + 0x20 * (_ch)) 772 - #define HCDMA_DMA_ADDR_MASK (0x1fffff << 11) 773 - #define HCDMA_DMA_ADDR_SHIFT 11 774 - #define HCDMA_CTD_MASK (0xff << 3) 775 - #define HCDMA_CTD_SHIFT 3 776 772 777 773 #define HCDMAB(_ch) HSOTG_REG(0x051c + 0x20 * (_ch)) 778 774
+136 -22
drivers/usb/dwc2/platform.c
··· 54 54 55 55 static const char dwc2_driver_name[] = "dwc2"; 56 56 57 + static const struct dwc2_core_params params_hi6220 = { 58 + .otg_cap = 2, /* No HNP/SRP capable */ 59 + .otg_ver = 0, /* 1.3 */ 60 + .dma_enable = 1, 61 + .dma_desc_enable = 0, 62 + .dma_desc_fs_enable = 0, 63 + .speed = 0, /* High Speed */ 64 + .enable_dynamic_fifo = 1, 65 + .en_multiple_tx_fifo = 1, 66 + .host_rx_fifo_size = 512, 67 + .host_nperio_tx_fifo_size = 512, 68 + .host_perio_tx_fifo_size = 512, 69 + .max_transfer_size = 65535, 70 + .max_packet_count = 511, 71 + .host_channels = 16, 72 + .phy_type = 1, /* UTMI */ 73 + .phy_utmi_width = 8, 74 + .phy_ulpi_ddr = 0, /* Single */ 75 + .phy_ulpi_ext_vbus = 0, 76 + .i2c_enable = 0, 77 + .ulpi_fs_ls = 0, 78 + .host_support_fs_ls_low_power = 0, 79 + .host_ls_low_power_phy_clk = 0, /* 48 MHz */ 80 + .ts_dline = 0, 81 + .reload_ctl = 0, 82 + .ahbcfg = GAHBCFG_HBSTLEN_INCR16 << 83 + GAHBCFG_HBSTLEN_SHIFT, 84 + .uframe_sched = 0, 85 + .external_id_pin_ctl = -1, 86 + .hibernation = -1, 87 + }; 88 + 57 89 static const struct dwc2_core_params params_bcm2835 = { 58 90 .otg_cap = 0, /* HNP/SRP capable */ 59 91 .otg_ver = 0, /* 1.3 */ 60 92 .dma_enable = 1, 61 93 .dma_desc_enable = 0, 94 + .dma_desc_fs_enable = 0, 62 95 .speed = 0, /* High Speed */ 63 96 .enable_dynamic_fifo = 1, 64 97 .en_multiple_tx_fifo = 1, ··· 122 89 .otg_ver = -1, 123 90 .dma_enable = -1, 124 91 .dma_desc_enable = 0, 92 + .dma_desc_fs_enable = 0, 125 93 .speed = -1, 126 94 .enable_dynamic_fifo = 1, 127 95 .en_multiple_tx_fifo = -1, ··· 148 114 .external_id_pin_ctl = -1, 149 115 .hibernation = -1, 150 116 }; 117 + 118 + /* 119 + * Check the dr_mode against the module configuration and hardware 120 + * capabilities. 121 + * 122 + * The hardware, module, and dr_mode, can each be set to host, device, 123 + * or otg. Check that all these values are compatible and adjust the 124 + * value of dr_mode if possible. 125 + * 126 + * actual 127 + * HW MOD dr_mode dr_mode 128 + * ------------------------------ 129 + * HST HST any : HST 130 + * HST DEV any : --- 131 + * HST OTG any : HST 132 + * 133 + * DEV HST any : --- 134 + * DEV DEV any : DEV 135 + * DEV OTG any : DEV 136 + * 137 + * OTG HST any : HST 138 + * OTG DEV any : DEV 139 + * OTG OTG any : dr_mode 140 + */ 141 + static int dwc2_get_dr_mode(struct dwc2_hsotg *hsotg) 142 + { 143 + enum usb_dr_mode mode; 144 + 145 + hsotg->dr_mode = usb_get_dr_mode(hsotg->dev); 146 + if (hsotg->dr_mode == USB_DR_MODE_UNKNOWN) 147 + hsotg->dr_mode = USB_DR_MODE_OTG; 148 + 149 + mode = hsotg->dr_mode; 150 + 151 + if (dwc2_hw_is_device(hsotg)) { 152 + if (IS_ENABLED(CONFIG_USB_DWC2_HOST)) { 153 + dev_err(hsotg->dev, 154 + "Controller does not support host mode.\n"); 155 + return -EINVAL; 156 + } 157 + mode = USB_DR_MODE_PERIPHERAL; 158 + } else if (dwc2_hw_is_host(hsotg)) { 159 + if (IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL)) { 160 + dev_err(hsotg->dev, 161 + "Controller does not support device mode.\n"); 162 + return -EINVAL; 163 + } 164 + mode = USB_DR_MODE_HOST; 165 + } else { 166 + if (IS_ENABLED(CONFIG_USB_DWC2_HOST)) 167 + mode = USB_DR_MODE_HOST; 168 + else if (IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL)) 169 + mode = USB_DR_MODE_PERIPHERAL; 170 + } 171 + 172 + if (mode != hsotg->dr_mode) { 173 + dev_warn(hsotg->dev, 174 + "Configuration mismatch. dr_mode forced to %s\n", 175 + mode == USB_DR_MODE_HOST ? "host" : "device"); 176 + 177 + hsotg->dr_mode = mode; 178 + } 179 + 180 + return 0; 181 + } 151 182 152 183 static int __dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg) 153 184 { ··· 405 306 return 0; 406 307 } 407 308 309 + /** 310 + * dwc2_driver_shutdown() - Called on device shutdown 311 + * 312 + * @dev: Platform device 313 + * 314 + * In specific conditions (involving usb hubs) dwc2 devices can create a 315 + * lot of interrupts, even to the point of overwhelming devices running 316 + * at low frequencies. Some devices need to do special clock handling 317 + * at shutdown-time which may bring the system clock below the threshold 318 + * of being able to handle the dwc2 interrupts. Disabling dwc2-irqs 319 + * prevents reboots/poweroffs from getting stuck in such cases. 320 + */ 321 + static void dwc2_driver_shutdown(struct platform_device *dev) 322 + { 323 + struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); 324 + 325 + disable_irq(hsotg->irq); 326 + } 327 + 408 328 static const struct of_device_id dwc2_of_match_table[] = { 409 329 { .compatible = "brcm,bcm2835-usb", .data = &params_bcm2835 }, 330 + { .compatible = "hisilicon,hi6220-usb", .data = &params_hi6220 }, 410 331 { .compatible = "rockchip,rk3066-usb", .data = &params_rk3066 }, 411 332 { .compatible = "snps,dwc2", .data = NULL }, 412 333 { .compatible = "samsung,s3c6400-hsotg", .data = NULL}, ··· 454 335 struct dwc2_hsotg *hsotg; 455 336 struct resource *res; 456 337 int retval; 457 - int irq; 458 338 459 339 match = of_match_device(dwc2_of_match_table, &dev->dev); 460 340 if (match && match->data) { ··· 466 348 /* 467 349 * Disable descriptor dma mode by default as the HW can support 468 350 * it, but does not support it for SPLIT transactions. 351 + * Disable it for FS devices as well. 469 352 */ 470 353 defparams.dma_desc_enable = 0; 354 + defparams.dma_desc_fs_enable = 0; 471 355 } 472 356 473 357 hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL); ··· 495 375 dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n", 496 376 (unsigned long)res->start, hsotg->regs); 497 377 498 - hsotg->dr_mode = usb_get_dr_mode(&dev->dev); 499 - if (IS_ENABLED(CONFIG_USB_DWC2_HOST) && 500 - hsotg->dr_mode != USB_DR_MODE_HOST) { 501 - hsotg->dr_mode = USB_DR_MODE_HOST; 502 - dev_warn(hsotg->dev, 503 - "Configuration mismatch. Forcing host mode\n"); 504 - } else if (IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) && 505 - hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) { 506 - hsotg->dr_mode = USB_DR_MODE_PERIPHERAL; 507 - dev_warn(hsotg->dev, 508 - "Configuration mismatch. Forcing peripheral mode\n"); 509 - } 510 - 511 378 retval = dwc2_lowlevel_hw_init(hsotg); 512 379 if (retval) 513 380 return retval; ··· 508 401 509 402 dwc2_set_all_params(hsotg->core_params, -1); 510 403 511 - irq = platform_get_irq(dev, 0); 512 - if (irq < 0) { 404 + hsotg->irq = platform_get_irq(dev, 0); 405 + if (hsotg->irq < 0) { 513 406 dev_err(&dev->dev, "missing IRQ resource\n"); 514 - return irq; 407 + return hsotg->irq; 515 408 } 516 409 517 410 dev_dbg(hsotg->dev, "registering common handler for irq%d\n", 518 - irq); 519 - retval = devm_request_irq(hsotg->dev, irq, 411 + hsotg->irq); 412 + retval = devm_request_irq(hsotg->dev, hsotg->irq, 520 413 dwc2_handle_common_intr, IRQF_SHARED, 521 414 dev_name(hsotg->dev), hsotg); 522 415 if (retval) ··· 526 419 if (retval) 527 420 return retval; 528 421 529 - /* Detect config values from hardware */ 422 + retval = dwc2_get_dr_mode(hsotg); 423 + if (retval) 424 + return retval; 425 + 426 + /* Reset the controller and detect hardware config values */ 530 427 retval = dwc2_get_hwparams(hsotg); 531 428 if (retval) 532 429 goto error; ··· 538 427 /* Validate parameter values */ 539 428 dwc2_set_parameters(hsotg, params); 540 429 430 + dwc2_force_dr_mode(hsotg); 431 + 541 432 if (hsotg->dr_mode != USB_DR_MODE_HOST) { 542 - retval = dwc2_gadget_init(hsotg, irq); 433 + retval = dwc2_gadget_init(hsotg, hsotg->irq); 543 434 if (retval) 544 435 goto error; 545 436 hsotg->gadget_enabled = 1; 546 437 } 547 438 548 439 if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) { 549 - retval = dwc2_hcd_init(hsotg, irq); 440 + retval = dwc2_hcd_init(hsotg, hsotg->irq); 550 441 if (retval) { 551 442 if (hsotg->gadget_enabled) 552 443 dwc2_hsotg_remove(hsotg); ··· 615 502 }, 616 503 .probe = dwc2_driver_probe, 617 504 .remove = dwc2_driver_remove, 505 + .shutdown = dwc2_driver_shutdown, 618 506 }; 619 507 620 508 module_platform_driver(dwc2_platform_driver);
+9 -8
drivers/usb/dwc3/Kconfig
··· 87 87 Support of USB2/3 functionality in TI Keystone2 platforms. 88 88 Say 'Y' or 'M' here if you have one such device 89 89 90 + config USB_DWC3_OF_SIMPLE 91 + tristate "Generic OF Simple Glue Layer" 92 + depends on OF && COMMON_CLK 93 + default USB_DWC3 94 + help 95 + Support USB2/3 functionality in simple SoC integrations. 96 + Currently supports Xilinx and Qualcomm DWC USB3 IP. 97 + Say 'Y' or 'M' if you have one such device. 98 + 90 99 config USB_DWC3_ST 91 100 tristate "STMicroelectronics Platforms" 92 101 depends on ARCH_STI && OF ··· 104 95 STMicroelectronics SoCs with one DesignWare Core USB3 IP 105 96 inside (i.e. STiH407). 106 97 Say 'Y' or 'M' if you have one such device. 107 - 108 - config USB_DWC3_QCOM 109 - tristate "Qualcomm Platforms" 110 - depends on ARCH_QCOM || COMPILE_TEST 111 - default USB_DWC3 112 - help 113 - Recent Qualcomm SoCs ship with one DesignWare Core USB3 IP inside, 114 - say 'Y' or 'M' if you have one such device. 115 98 116 99 endif
+1 -1
drivers/usb/dwc3/Makefile
··· 37 37 obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o 38 38 obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o 39 39 obj-$(CONFIG_USB_DWC3_KEYSTONE) += dwc3-keystone.o 40 - obj-$(CONFIG_USB_DWC3_QCOM) += dwc3-qcom.o 40 + obj-$(CONFIG_USB_DWC3_OF_SIMPLE) += dwc3-of-simple.o 41 41 obj-$(CONFIG_USB_DWC3_ST) += dwc3-st.o
+5 -3
drivers/usb/dwc3/core.c
··· 272 272 273 273 for (n = 0; n < dwc->num_event_buffers; n++) { 274 274 evt = dwc->ev_buffs[n]; 275 - dev_dbg(dwc->dev, "Event buf %p dma %08llx length %d\n", 275 + dwc3_trace(trace_dwc3_core, 276 + "Event buf %p dma %08llx length %d\n", 276 277 evt->buf, (unsigned long long) evt->dma, 277 278 evt->length); 278 279 ··· 609 608 reg |= DWC3_GCTL_GBLHIBERNATIONEN; 610 609 break; 611 610 default: 612 - dev_dbg(dwc->dev, "No power optimization available\n"); 611 + dwc3_trace(trace_dwc3_core, "No power optimization available\n"); 613 612 } 614 613 615 614 /* check if current dwc3 is on simulation board */ 616 615 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { 617 - dev_dbg(dwc->dev, "it is on FPGA board\n"); 616 + dwc3_trace(trace_dwc3_core, 617 + "running on FPGA platform\n"); 618 618 dwc->is_fpga = true; 619 619 } 620 620
+3
drivers/usb/dwc3/core.h
··· 37 37 #define DWC3_MSG_MAX 500 38 38 39 39 /* Global constants */ 40 + #define DWC3_ZLP_BUF_SIZE 1024 /* size of a superspeed bulk */ 40 41 #define DWC3_EP0_BOUNCE_SIZE 512 41 42 #define DWC3_ENDPOINTS_NUM 32 42 43 #define DWC3_XHCI_RESOURCES_NUM 2 ··· 648 647 * @ctrl_req: usb control request which is used for ep0 649 648 * @ep0_trb: trb which is used for the ctrl_req 650 649 * @ep0_bounce: bounce buffer for ep0 650 + * @zlp_buf: used when request->zero is set 651 651 * @setup_buf: used while precessing STD USB requests 652 652 * @ctrl_req_addr: dma address of ctrl_req 653 653 * @ep0_trb: dma address of ep0_trb ··· 736 734 struct usb_ctrlrequest *ctrl_req; 737 735 struct dwc3_trb *ep0_trb; 738 736 void *ep0_bounce; 737 + void *zlp_buf; 739 738 void *scratchbuf; 740 739 u8 *setup_buf; 741 740 dma_addr_t ctrl_req_addr;
+180
drivers/usb/dwc3/dwc3-of-simple.c
··· 1 + /** 2 + * dwc3-of-simple.c - OF glue layer for simple integrations 3 + * 4 + * Copyright (c) 2015 Texas Instruments Incorporated - http://www.ti.com 5 + * 6 + * Author: Felipe Balbi <balbi@ti.com> 7 + * 8 + * This program is free software: you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License version 2 of 10 + * the License as published by the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + * 17 + * This is a combination of the old dwc3-qcom.c by Ivan T. Ivanov 18 + * <iivanov@mm-sol.com> and the original patch adding support for Xilinx' SoC 19 + * by Subbaraya Sundeep Bhatta <subbaraya.sundeep.bhatta@xilinx.com> 20 + */ 21 + 22 + #include <linux/module.h> 23 + #include <linux/kernel.h> 24 + #include <linux/slab.h> 25 + #include <linux/platform_device.h> 26 + #include <linux/dma-mapping.h> 27 + #include <linux/clk.h> 28 + #include <linux/clk-provider.h> 29 + #include <linux/of.h> 30 + #include <linux/of_platform.h> 31 + #include <linux/pm_runtime.h> 32 + 33 + struct dwc3_of_simple { 34 + struct device *dev; 35 + struct clk **clks; 36 + int num_clocks; 37 + }; 38 + 39 + static int dwc3_of_simple_probe(struct platform_device *pdev) 40 + { 41 + struct dwc3_of_simple *simple; 42 + struct device *dev = &pdev->dev; 43 + struct device_node *np = dev->of_node; 44 + 45 + int ret; 46 + int i; 47 + 48 + simple = devm_kzalloc(dev, sizeof(*simple), GFP_KERNEL); 49 + if (!simple) 50 + return -ENOMEM; 51 + 52 + ret = of_clk_get_parent_count(np); 53 + if (ret < 0) 54 + return ret; 55 + 56 + simple->num_clocks = ret; 57 + 58 + simple->clks = devm_kcalloc(dev, simple->num_clocks, 59 + sizeof(struct clk *), GFP_KERNEL); 60 + if (!simple->clks) 61 + return -ENOMEM; 62 + 63 + simple->dev = dev; 64 + 65 + for (i = 0; i < simple->num_clocks; i++) { 66 + struct clk *clk; 67 + 68 + clk = of_clk_get(np, i); 69 + if (IS_ERR(clk)) { 70 + while (--i >= 0) 71 + clk_put(simple->clks[i]); 72 + return PTR_ERR(clk); 73 + } 74 + 75 + ret = clk_prepare_enable(clk); 76 + if (ret < 0) { 77 + while (--i >= 0) { 78 + clk_disable_unprepare(simple->clks[i]); 79 + clk_put(simple->clks[i]); 80 + } 81 + clk_put(clk); 82 + 83 + return ret; 84 + } 85 + 86 + simple->clks[i] = clk; 87 + } 88 + 89 + ret = of_platform_populate(np, NULL, NULL, dev); 90 + if (ret) { 91 + for (i = 0; i < simple->num_clocks; i++) { 92 + clk_disable_unprepare(simple->clks[i]); 93 + clk_put(simple->clks[i]); 94 + } 95 + 96 + return ret; 97 + } 98 + 99 + pm_runtime_set_active(dev); 100 + pm_runtime_enable(dev); 101 + pm_runtime_get_sync(dev); 102 + 103 + return 0; 104 + } 105 + 106 + static int dwc3_of_simple_remove(struct platform_device *pdev) 107 + { 108 + struct dwc3_of_simple *simple = platform_get_drvdata(pdev); 109 + struct device *dev = &pdev->dev; 110 + int i; 111 + 112 + for (i = 0; i < simple->num_clocks; i++) { 113 + clk_unprepare(simple->clks[i]); 114 + clk_put(simple->clks[i]); 115 + } 116 + 117 + of_platform_depopulate(dev); 118 + 119 + pm_runtime_put_sync(dev); 120 + pm_runtime_disable(dev); 121 + 122 + return 0; 123 + } 124 + 125 + #ifdef CONFIG_PM 126 + static int dwc3_of_simple_runtime_suspend(struct device *dev) 127 + { 128 + struct dwc3_of_simple *simple = dev_get_drvdata(dev); 129 + int i; 130 + 131 + for (i = 0; i < simple->num_clocks; i++) 132 + clk_disable(simple->clks[i]); 133 + 134 + return 0; 135 + } 136 + 137 + static int dwc3_of_simple_runtime_resume(struct device *dev) 138 + { 139 + struct dwc3_of_simple *simple = dev_get_drvdata(dev); 140 + int ret; 141 + int i; 142 + 143 + for (i = 0; i < simple->num_clocks; i++) { 144 + ret = clk_enable(simple->clks[i]); 145 + if (ret < 0) { 146 + while (--i >= 0) 147 + clk_disable(simple->clks[i]); 148 + return ret; 149 + } 150 + } 151 + 152 + return 0; 153 + } 154 + #endif 155 + 156 + static const struct dev_pm_ops dwc3_of_simple_dev_pm_ops = { 157 + SET_RUNTIME_PM_OPS(dwc3_of_simple_runtime_suspend, 158 + dwc3_of_simple_runtime_resume, NULL) 159 + }; 160 + 161 + static const struct of_device_id of_dwc3_simple_match[] = { 162 + { .compatible = "qcom,dwc3" }, 163 + { .compatible = "xlnx,zynqmp-dwc3" }, 164 + { /* Sentinel */ } 165 + }; 166 + MODULE_DEVICE_TABLE(of, of_dwc3_simple_match); 167 + 168 + static struct platform_driver dwc3_of_simple_driver = { 169 + .probe = dwc3_of_simple_probe, 170 + .remove = dwc3_of_simple_remove, 171 + .driver = { 172 + .name = "dwc3-of-simple", 173 + .of_match_table = of_dwc3_simple_match, 174 + }, 175 + }; 176 + 177 + module_platform_driver(dwc3_of_simple_driver); 178 + MODULE_LICENSE("GPL v2"); 179 + MODULE_DESCRIPTION("DesignWare USB3 OF Simple Glue Layer"); 180 + MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
-130
drivers/usb/dwc3/dwc3-qcom.c
··· 1 - /* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. 2 - * 3 - * This program is free software; you can redistribute it and/or modify 4 - * it under the terms of the GNU General Public License version 2 and 5 - * only version 2 as published by the Free Software Foundation. 6 - * 7 - * This program is distributed in the hope that it will be useful, 8 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 - * GNU General Public License for more details. 11 - */ 12 - 13 - #include <linux/clk.h> 14 - #include <linux/err.h> 15 - #include <linux/io.h> 16 - #include <linux/module.h> 17 - #include <linux/of.h> 18 - #include <linux/of_platform.h> 19 - #include <linux/platform_device.h> 20 - 21 - struct dwc3_qcom { 22 - struct device *dev; 23 - 24 - struct clk *core_clk; 25 - struct clk *iface_clk; 26 - struct clk *sleep_clk; 27 - }; 28 - 29 - static int dwc3_qcom_probe(struct platform_device *pdev) 30 - { 31 - struct device_node *node = pdev->dev.of_node; 32 - struct dwc3_qcom *qdwc; 33 - int ret; 34 - 35 - qdwc = devm_kzalloc(&pdev->dev, sizeof(*qdwc), GFP_KERNEL); 36 - if (!qdwc) 37 - return -ENOMEM; 38 - 39 - platform_set_drvdata(pdev, qdwc); 40 - 41 - qdwc->dev = &pdev->dev; 42 - 43 - qdwc->core_clk = devm_clk_get(qdwc->dev, "core"); 44 - if (IS_ERR(qdwc->core_clk)) { 45 - dev_err(qdwc->dev, "failed to get core clock\n"); 46 - return PTR_ERR(qdwc->core_clk); 47 - } 48 - 49 - qdwc->iface_clk = devm_clk_get(qdwc->dev, "iface"); 50 - if (IS_ERR(qdwc->iface_clk)) { 51 - dev_info(qdwc->dev, "failed to get optional iface clock\n"); 52 - qdwc->iface_clk = NULL; 53 - } 54 - 55 - qdwc->sleep_clk = devm_clk_get(qdwc->dev, "sleep"); 56 - if (IS_ERR(qdwc->sleep_clk)) { 57 - dev_info(qdwc->dev, "failed to get optional sleep clock\n"); 58 - qdwc->sleep_clk = NULL; 59 - } 60 - 61 - ret = clk_prepare_enable(qdwc->core_clk); 62 - if (ret) { 63 - dev_err(qdwc->dev, "failed to enable core clock\n"); 64 - goto err_core; 65 - } 66 - 67 - ret = clk_prepare_enable(qdwc->iface_clk); 68 - if (ret) { 69 - dev_err(qdwc->dev, "failed to enable optional iface clock\n"); 70 - goto err_iface; 71 - } 72 - 73 - ret = clk_prepare_enable(qdwc->sleep_clk); 74 - if (ret) { 75 - dev_err(qdwc->dev, "failed to enable optional sleep clock\n"); 76 - goto err_sleep; 77 - } 78 - 79 - ret = of_platform_populate(node, NULL, NULL, qdwc->dev); 80 - if (ret) { 81 - dev_err(qdwc->dev, "failed to register core - %d\n", ret); 82 - goto err_clks; 83 - } 84 - 85 - return 0; 86 - 87 - err_clks: 88 - clk_disable_unprepare(qdwc->sleep_clk); 89 - err_sleep: 90 - clk_disable_unprepare(qdwc->iface_clk); 91 - err_iface: 92 - clk_disable_unprepare(qdwc->core_clk); 93 - err_core: 94 - return ret; 95 - } 96 - 97 - static int dwc3_qcom_remove(struct platform_device *pdev) 98 - { 99 - struct dwc3_qcom *qdwc = platform_get_drvdata(pdev); 100 - 101 - of_platform_depopulate(&pdev->dev); 102 - 103 - clk_disable_unprepare(qdwc->sleep_clk); 104 - clk_disable_unprepare(qdwc->iface_clk); 105 - clk_disable_unprepare(qdwc->core_clk); 106 - 107 - return 0; 108 - } 109 - 110 - static const struct of_device_id of_dwc3_match[] = { 111 - { .compatible = "qcom,dwc3" }, 112 - { /* Sentinel */ } 113 - }; 114 - MODULE_DEVICE_TABLE(of, of_dwc3_match); 115 - 116 - static struct platform_driver dwc3_qcom_driver = { 117 - .probe = dwc3_qcom_probe, 118 - .remove = dwc3_qcom_remove, 119 - .driver = { 120 - .name = "qcom-dwc3", 121 - .of_match_table = of_dwc3_match, 122 - }, 123 - }; 124 - 125 - module_platform_driver(dwc3_qcom_driver); 126 - 127 - MODULE_ALIAS("platform:qcom-dwc3"); 128 - MODULE_LICENSE("GPL v2"); 129 - MODULE_DESCRIPTION("DesignWare USB3 QCOM Glue Layer"); 130 - MODULE_AUTHOR("Ivan T. Ivanov <iivanov@mm-sol.com>");
+7 -5
drivers/usb/dwc3/ep0.c
··· 817 817 818 818 status = DWC3_TRB_SIZE_TRBSTS(trb->size); 819 819 if (status == DWC3_TRBSTS_SETUP_PENDING) { 820 + dwc->setup_packet_pending = true; 821 + 820 822 dwc3_trace(trace_dwc3_ep0, "Setup Pending received"); 821 823 822 824 if (r) ··· 918 916 } 919 917 920 918 status = DWC3_TRB_SIZE_TRBSTS(trb->size); 921 - if (status == DWC3_TRBSTS_SETUP_PENDING) 919 + if (status == DWC3_TRBSTS_SETUP_PENDING) { 920 + dwc->setup_packet_pending = true; 922 921 dwc3_trace(trace_dwc3_ep0, "Setup Pending received"); 922 + } 923 923 924 924 dwc->ep0state = EP0_SETUP_PHASE; 925 925 dwc3_ep0_out_start(dwc); ··· 975 971 ret = usb_gadget_map_request(&dwc->gadget, &req->request, 976 972 dep->number); 977 973 if (ret) { 978 - dev_dbg(dwc->dev, "failed to map request\n"); 974 + dwc3_trace(trace_dwc3_ep0, "failed to map request\n"); 979 975 return; 980 976 } 981 977 ··· 1003 999 ret = usb_gadget_map_request(&dwc->gadget, &req->request, 1004 1000 dep->number); 1005 1001 if (ret) { 1006 - dev_dbg(dwc->dev, "failed to map request\n"); 1002 + dwc3_trace(trace_dwc3_ep0, "failed to map request\n"); 1007 1003 return; 1008 1004 } 1009 1005 ··· 1067 1063 static void dwc3_ep0_xfernotready(struct dwc3 *dwc, 1068 1064 const struct dwc3_event_depevt *event) 1069 1065 { 1070 - dwc->setup_packet_pending = true; 1071 - 1072 1066 switch (event->status) { 1073 1067 case DEPEVT_STATUS_CONTROL_DATA: 1074 1068 dwc3_trace(trace_dwc3_ep0, "Control Data");
+89 -44
drivers/usb/dwc3/gadget.c
··· 265 265 usb_gadget_unmap_request(&dwc->gadget, &req->request, 266 266 req->direction); 267 267 268 - dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n", 269 - req, dep->name, req->request.actual, 270 - req->request.length, status); 271 268 trace_dwc3_gadget_giveback(req); 272 269 273 270 spin_unlock(&dwc->lock); ··· 661 664 dep = to_dwc3_ep(ep); 662 665 dwc = dep->dwc; 663 666 664 - if (dep->flags & DWC3_EP_ENABLED) { 665 - dev_WARN_ONCE(dwc->dev, true, "%s is already enabled\n", 666 - dep->name); 667 + if (dev_WARN_ONCE(dwc->dev, dep->flags & DWC3_EP_ENABLED, 668 + "%s is already enabled\n", 669 + dep->name)) 667 670 return 0; 668 - } 669 671 670 672 spin_lock_irqsave(&dwc->lock, flags); 671 673 ret = __dwc3_gadget_ep_enable(dep, desc, ep->comp_desc, false, false); ··· 688 692 dep = to_dwc3_ep(ep); 689 693 dwc = dep->dwc; 690 694 691 - if (!(dep->flags & DWC3_EP_ENABLED)) { 692 - dev_WARN_ONCE(dwc->dev, true, "%s is already disabled\n", 693 - dep->name); 695 + if (dev_WARN_ONCE(dwc->dev, !(dep->flags & DWC3_EP_ENABLED), 696 + "%s is already disabled\n", 697 + dep->name)) 694 698 return 0; 695 - } 696 699 697 700 spin_lock_irqsave(&dwc->lock, flags); 698 701 ret = __dwc3_gadget_ep_disable(dep); ··· 980 985 cmd |= DWC3_DEPCMD_PARAM(cmd_param); 981 986 ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params); 982 987 if (ret < 0) { 983 - dev_dbg(dwc->dev, "failed to send STARTTRANSFER command\n"); 984 - 985 988 /* 986 989 * FIXME we need to iterate over the list of requests 987 990 * here and stop, unmap, free and del each of the linked ··· 1036 1043 { 1037 1044 struct dwc3 *dwc = dep->dwc; 1038 1045 int ret; 1046 + 1047 + if (!dep->endpoint.desc) { 1048 + dwc3_trace(trace_dwc3_gadget, 1049 + "trying to queue request %p to disabled %s\n", 1050 + &req->request, dep->endpoint.name); 1051 + return -ESHUTDOWN; 1052 + } 1053 + 1054 + if (WARN(req->dep != dep, "request %p belongs to '%s'\n", 1055 + &req->request, req->dep->name)) { 1056 + dwc3_trace(trace_dwc3_gadget, "request %p belongs to '%s'\n", 1057 + &req->request, req->dep->name); 1058 + return -EINVAL; 1059 + } 1039 1060 1040 1061 req->request.actual = 0; 1041 1062 req->request.status = -EINPROGRESS; ··· 1148 1141 1149 1142 out: 1150 1143 if (ret && ret != -EBUSY) 1151 - dev_dbg(dwc->dev, "%s: failed to kick transfers\n", 1144 + dwc3_trace(trace_dwc3_gadget, 1145 + "%s: failed to kick transfers\n", 1152 1146 dep->name); 1153 1147 if (ret == -EBUSY) 1154 1148 ret = 0; 1155 1149 1156 1150 return ret; 1151 + } 1152 + 1153 + static void __dwc3_gadget_ep_zlp_complete(struct usb_ep *ep, 1154 + struct usb_request *request) 1155 + { 1156 + dwc3_gadget_ep_free_request(ep, request); 1157 + } 1158 + 1159 + static int __dwc3_gadget_ep_queue_zlp(struct dwc3 *dwc, struct dwc3_ep *dep) 1160 + { 1161 + struct dwc3_request *req; 1162 + struct usb_request *request; 1163 + struct usb_ep *ep = &dep->endpoint; 1164 + 1165 + dwc3_trace(trace_dwc3_gadget, "queueing ZLP\n"); 1166 + request = dwc3_gadget_ep_alloc_request(ep, GFP_ATOMIC); 1167 + if (!request) 1168 + return -ENOMEM; 1169 + 1170 + request->length = 0; 1171 + request->buf = dwc->zlp_buf; 1172 + request->complete = __dwc3_gadget_ep_zlp_complete; 1173 + 1174 + req = to_dwc3_request(request); 1175 + 1176 + return __dwc3_gadget_ep_queue(dep, req); 1157 1177 } 1158 1178 1159 1179 static int dwc3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request, ··· 1195 1161 int ret; 1196 1162 1197 1163 spin_lock_irqsave(&dwc->lock, flags); 1198 - if (!dep->endpoint.desc) { 1199 - dev_dbg(dwc->dev, "trying to queue request %p to disabled %s\n", 1200 - request, ep->name); 1201 - ret = -ESHUTDOWN; 1202 - goto out; 1203 - } 1204 - 1205 - if (WARN(req->dep != dep, "request %p belongs to '%s'\n", 1206 - request, req->dep->name)) { 1207 - ret = -EINVAL; 1208 - goto out; 1209 - } 1210 - 1211 1164 ret = __dwc3_gadget_ep_queue(dep, req); 1212 1165 1213 - out: 1166 + /* 1167 + * Okay, here's the thing, if gadget driver has requested for a ZLP by 1168 + * setting request->zero, instead of doing magic, we will just queue an 1169 + * extra usb_request ourselves so that it gets handled the same way as 1170 + * any other request. 1171 + */ 1172 + if (ret == 0 && request->zero && request->length && 1173 + (request->length % ep->maxpacket == 0)) 1174 + ret = __dwc3_gadget_ep_queue_zlp(dwc, dep); 1175 + 1214 1176 spin_unlock_irqrestore(&dwc->lock, flags); 1215 1177 1216 1178 return ret; ··· 1276 1246 if (!protocol && ((dep->direction && dep->flags & DWC3_EP_BUSY) || 1277 1247 (!list_empty(&dep->req_queued) || 1278 1248 !list_empty(&dep->request_list)))) { 1279 - dev_dbg(dwc->dev, "%s: pending request, cannot halt\n", 1249 + dwc3_trace(trace_dwc3_gadget, 1250 + "%s: pending request, cannot halt\n", 1280 1251 dep->name); 1281 1252 return -EAGAIN; 1282 1253 } ··· 1404 1373 1405 1374 speed = reg & DWC3_DSTS_CONNECTSPD; 1406 1375 if (speed == DWC3_DSTS_SUPERSPEED) { 1407 - dev_dbg(dwc->dev, "no wakeup on SuperSpeed\n"); 1376 + dwc3_trace(trace_dwc3_gadget, "no wakeup on SuperSpeed\n"); 1408 1377 ret = -EINVAL; 1409 1378 goto out; 1410 1379 } ··· 1416 1385 case DWC3_LINK_STATE_U3: /* in HS, means SUSPEND */ 1417 1386 break; 1418 1387 default: 1419 - dev_dbg(dwc->dev, "can't wakeup from link state %d\n", 1420 - link_state); 1388 + dwc3_trace(trace_dwc3_gadget, 1389 + "can't wakeup from '%s'\n", 1390 + dwc3_gadget_link_string(link_state)); 1421 1391 ret = -EINVAL; 1422 1392 goto out; 1423 1393 } ··· 1857 1825 if (count) { 1858 1826 trb_status = DWC3_TRB_SIZE_TRBSTS(trb->size); 1859 1827 if (trb_status == DWC3_TRBSTS_MISSED_ISOC) { 1860 - dev_dbg(dwc->dev, "incomplete IN transfer %s\n", 1828 + dwc3_trace(trace_dwc3_gadget, 1829 + "%s: incomplete IN transfer\n", 1861 1830 dep->name); 1862 1831 /* 1863 1832 * If missed isoc occurred and there is ··· 1920 1887 1921 1888 do { 1922 1889 req = next_request(&dep->req_queued); 1923 - if (!req) { 1924 - WARN_ON_ONCE(1); 1890 + if (WARN_ON_ONCE(!req)) 1925 1891 return 1; 1926 - } 1892 + 1927 1893 i = 0; 1928 1894 do { 1929 1895 slot = req->start_slot + i; ··· 2036 2004 dep->resource_index = 0; 2037 2005 2038 2006 if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) { 2039 - dev_dbg(dwc->dev, "%s is an Isochronous endpoint\n", 2007 + dwc3_trace(trace_dwc3_gadget, 2008 + "%s is an Isochronous endpoint\n", 2040 2009 dep->name); 2041 2010 return; 2042 2011 } ··· 2064 2031 if (!ret || ret == -EBUSY) 2065 2032 return; 2066 2033 2067 - dev_dbg(dwc->dev, "%s: failed to kick transfers\n", 2034 + dwc3_trace(trace_dwc3_gadget, 2035 + "%s: failed to kick transfers\n", 2068 2036 dep->name); 2069 2037 } 2070 2038 ··· 2087 2053 case DEPEVT_STREAMEVT_NOTFOUND: 2088 2054 /* FALLTHROUGH */ 2089 2055 default: 2090 - dev_dbg(dwc->dev, "Couldn't find suitable stream\n"); 2056 + dwc3_trace(trace_dwc3_gadget, 2057 + "unable to find suitable stream\n"); 2091 2058 } 2092 2059 break; 2093 2060 case DWC3_DEPEVT_RXTXFIFOEVT: 2094 - dev_dbg(dwc->dev, "%s FIFO Overrun\n", dep->name); 2061 + dwc3_trace(trace_dwc3_gadget, "%s FIFO Overrun\n", dep->name); 2095 2062 break; 2096 2063 case DWC3_DEPEVT_EPCMDCMPLT: 2097 2064 dwc3_trace(trace_dwc3_gadget, "Endpoint Command Complete"); ··· 2265 2230 * 2266 2231 * Our suggested workaround is to follow the Disconnect 2267 2232 * Event steps here, instead, based on a setup_packet_pending 2268 - * flag. Such flag gets set whenever we have a XferNotReady 2269 - * event on EP0 and gets cleared on XferComplete for the 2233 + * flag. Such flag gets set whenever we have a SETUP_PENDING 2234 + * status for EP0 TRBs and gets cleared on XferComplete for the 2270 2235 * same endpoint. 2271 2236 * 2272 2237 * Refers to: ··· 2779 2744 goto err3; 2780 2745 } 2781 2746 2747 + dwc->zlp_buf = kzalloc(DWC3_ZLP_BUF_SIZE, GFP_KERNEL); 2748 + if (!dwc->zlp_buf) { 2749 + ret = -ENOMEM; 2750 + goto err4; 2751 + } 2752 + 2782 2753 dwc->gadget.ops = &dwc3_gadget_ops; 2783 2754 dwc->gadget.speed = USB_SPEED_UNKNOWN; 2784 2755 dwc->gadget.sg_supported = true; ··· 2826 2785 2827 2786 ret = dwc3_gadget_init_endpoints(dwc); 2828 2787 if (ret) 2829 - goto err4; 2788 + goto err5; 2830 2789 2831 2790 ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget); 2832 2791 if (ret) { 2833 2792 dev_err(dwc->dev, "failed to register udc\n"); 2834 - goto err4; 2793 + goto err5; 2835 2794 } 2836 2795 2837 2796 return 0; 2797 + 2798 + err5: 2799 + kfree(dwc->zlp_buf); 2838 2800 2839 2801 err4: 2840 2802 dwc3_gadget_free_endpoints(dwc); ··· 2871 2827 dwc->ep0_bounce, dwc->ep0_bounce_addr); 2872 2828 2873 2829 kfree(dwc->setup_buf); 2830 + kfree(dwc->zlp_buf); 2874 2831 2875 2832 dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb), 2876 2833 dwc->ep0_trb, dwc->ep0_trb_addr);
+10 -1
drivers/usb/dwc3/trace.h
··· 117 117 __field(unsigned, actual) 118 118 __field(unsigned, length) 119 119 __field(int, status) 120 + __field(int, zero) 121 + __field(int, short_not_ok) 122 + __field(int, no_interrupt) 120 123 ), 121 124 TP_fast_assign( 122 125 snprintf(__get_str(name), DWC3_MSG_MAX, "%s", req->dep->name); ··· 127 124 __entry->actual = req->request.actual; 128 125 __entry->length = req->request.length; 129 126 __entry->status = req->request.status; 127 + __entry->zero = req->request.zero; 128 + __entry->short_not_ok = req->request.short_not_ok; 129 + __entry->no_interrupt = req->request.no_interrupt; 130 130 ), 131 - TP_printk("%s: req %p length %u/%u ==> %d", 131 + TP_printk("%s: req %p length %u/%u %s%s%s ==> %d", 132 132 __get_str(name), __entry->req, __entry->actual, __entry->length, 133 + __entry->zero ? "Z" : "z", 134 + __entry->short_not_ok ? "S" : "s", 135 + __entry->no_interrupt ? "i" : "I", 133 136 __entry->status 134 137 ) 135 138 );
+6
drivers/usb/gadget/Kconfig
··· 127 127 a module parameter as well. 128 128 If unsure, say 2. 129 129 130 + config U_SERIAL_CONSOLE 131 + bool "Serial gadget console support" 132 + depends on USB_G_SERIAL 133 + help 134 + It supports the serial gadget can be used as a console. 135 + 130 136 source "drivers/usb/gadget/udc/Kconfig" 131 137 132 138 #
+16 -13
drivers/usb/gadget/configfs.c
··· 56 56 struct list_head string_list; 57 57 struct list_head available_func; 58 58 59 - const char *udc_name; 60 59 struct usb_composite_driver composite; 61 60 struct usb_composite_dev cdev; 62 61 bool use_os_desc; ··· 232 233 233 234 static ssize_t gadget_dev_desc_UDC_show(struct config_item *item, char *page) 234 235 { 235 - return sprintf(page, "%s\n", to_gadget_info(item)->udc_name ?: ""); 236 + char *udc_name = to_gadget_info(item)->composite.gadget_driver.udc_name; 237 + 238 + return sprintf(page, "%s\n", udc_name ?: ""); 236 239 } 237 240 238 241 static int unregister_gadget(struct gadget_info *gi) 239 242 { 240 243 int ret; 241 244 242 - if (!gi->udc_name) 245 + if (!gi->composite.gadget_driver.udc_name) 243 246 return -ENODEV; 244 247 245 248 ret = usb_gadget_unregister_driver(&gi->composite.gadget_driver); 246 249 if (ret) 247 250 return ret; 248 - kfree(gi->udc_name); 249 - gi->udc_name = NULL; 251 + kfree(gi->composite.gadget_driver.udc_name); 252 + gi->composite.gadget_driver.udc_name = NULL; 250 253 return 0; 251 254 } 252 255 ··· 272 271 if (ret) 273 272 goto err; 274 273 } else { 275 - if (gi->udc_name) { 274 + if (gi->composite.gadget_driver.udc_name) { 276 275 ret = -EBUSY; 277 276 goto err; 278 277 } 279 - ret = usb_udc_attach_driver(name, &gi->composite.gadget_driver); 280 - if (ret) 278 + gi->composite.gadget_driver.udc_name = name; 279 + ret = usb_gadget_probe_driver(&gi->composite.gadget_driver); 280 + if (ret) { 281 + gi->composite.gadget_driver.udc_name = NULL; 281 282 goto err; 282 - gi->udc_name = name; 283 + } 283 284 } 284 285 mutex_unlock(&gi->lock); 285 286 return len; ··· 430 427 * remove the function. 431 428 */ 432 429 mutex_lock(&gi->lock); 433 - if (gi->udc_name) 430 + if (gi->composite.gadget_driver.udc_name) 434 431 unregister_gadget(gi); 435 - WARN_ON(gi->udc_name); 432 + WARN_ON(gi->composite.gadget_driver.udc_name); 436 433 437 434 list_for_each_entry(f, &cfg->func_list, list) { 438 435 if (f->fi == fi) { ··· 876 873 struct usb_composite_dev *cdev = &gi->cdev; 877 874 878 875 mutex_lock(&gi->lock); 879 - if (gi->udc_name) 876 + if (gi->composite.gadget_driver.udc_name) 880 877 unregister_gadget(gi); 881 878 cdev->os_desc_config = NULL; 882 - WARN_ON(gi->udc_name); 879 + WARN_ON(gi->composite.gadget_driver.udc_name); 883 880 mutex_unlock(&gi->lock); 884 881 return 0; 885 882 }
+131 -63
drivers/usb/gadget/function/f_midi.c
··· 23 23 #include <linux/module.h> 24 24 #include <linux/slab.h> 25 25 #include <linux/device.h> 26 + #include <linux/kfifo.h> 26 27 27 28 #include <sound/core.h> 28 29 #include <sound/initval.h> ··· 76 75 struct usb_ep *in_ep, *out_ep; 77 76 struct snd_card *card; 78 77 struct snd_rawmidi *rmidi; 78 + u8 ms_id; 79 79 80 80 struct snd_rawmidi_substream *in_substream[MAX_PORTS]; 81 81 struct snd_rawmidi_substream *out_substream[MAX_PORTS]; ··· 89 87 int index; 90 88 char *id; 91 89 unsigned int buflen, qlen; 90 + /* This fifo is used as a buffer ring for pre-allocated IN usb_requests */ 91 + DECLARE_KFIFO_PTR(in_req_fifo, struct usb_request *); 92 + unsigned int in_last_port; 92 93 }; 93 94 94 95 static inline struct f_midi *func_to_midi(struct usb_function *f) ··· 99 94 return container_of(f, struct f_midi, func); 100 95 } 101 96 102 - static void f_midi_transmit(struct f_midi *midi, struct usb_request *req); 97 + static void f_midi_transmit(struct f_midi *midi); 103 98 104 99 DECLARE_UAC_AC_HEADER_DESCRIPTOR(1); 105 100 DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1); ··· 206 201 return alloc_ep_req(ep, length, length); 207 202 } 208 203 209 - static void free_ep_req(struct usb_ep *ep, struct usb_request *req) 210 - { 211 - kfree(req->buf); 212 - usb_ep_free_request(ep, req); 213 - } 214 - 215 204 static const uint8_t f_midi_cin_length[] = { 216 205 0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1 217 206 }; ··· 257 258 } else if (ep == midi->in_ep) { 258 259 /* Our transmit completed. See if there's more to go. 259 260 * f_midi_transmit eats req, don't queue it again. */ 260 - f_midi_transmit(midi, req); 261 + req->length = 0; 262 + f_midi_transmit(midi); 261 263 return; 262 264 } 263 265 break; ··· 269 269 case -ESHUTDOWN: /* disconnect from host */ 270 270 VDBG(cdev, "%s gone (%d), %d/%d\n", ep->name, status, 271 271 req->actual, req->length); 272 - if (ep == midi->out_ep) 272 + if (ep == midi->out_ep) { 273 273 f_midi_handle_out_data(ep, req); 274 - 275 - free_ep_req(ep, req); 274 + /* We don't need to free IN requests because it's handled 275 + * by the midi->in_req_fifo. */ 276 + free_ep_req(ep, req); 277 + } 276 278 return; 277 279 278 280 case -EOVERFLOW: /* buffer overrun on read means that ··· 326 324 static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt) 327 325 { 328 326 struct f_midi *midi = func_to_midi(f); 329 - struct usb_composite_dev *cdev = f->config->cdev; 330 327 unsigned i; 331 328 int err; 332 329 333 - /* For Control Device interface we do nothing */ 334 - if (intf == 0) 330 + /* we only set alt for MIDIStreaming interface */ 331 + if (intf != midi->ms_id) 335 332 return 0; 336 333 337 334 err = f_midi_start_ep(midi, f, midi->in_ep); ··· 341 340 if (err) 342 341 return err; 343 342 344 - usb_ep_disable(midi->out_ep); 343 + /* pre-allocate write usb requests to use on f_midi_transmit. */ 344 + while (kfifo_avail(&midi->in_req_fifo)) { 345 + struct usb_request *req = 346 + midi_alloc_ep_req(midi->in_ep, midi->buflen); 345 347 346 - err = config_ep_by_speed(midi->gadget, f, midi->out_ep); 347 - if (err) { 348 - ERROR(cdev, "can't configure %s: %d\n", 349 - midi->out_ep->name, err); 350 - return err; 348 + if (req == NULL) 349 + return -ENOMEM; 350 + 351 + req->length = 0; 352 + req->complete = f_midi_complete; 353 + 354 + kfifo_put(&midi->in_req_fifo, req); 351 355 } 352 - 353 - err = usb_ep_enable(midi->out_ep); 354 - if (err) { 355 - ERROR(cdev, "can't start %s: %d\n", 356 - midi->out_ep->name, err); 357 - return err; 358 - } 359 - 360 - midi->out_ep->driver_data = midi; 361 356 362 357 /* allocate a bunch of read buffers and queue them all at once. */ 363 358 for (i = 0; i < midi->qlen && err == 0; i++) { ··· 365 368 req->complete = f_midi_complete; 366 369 err = usb_ep_queue(midi->out_ep, req, GFP_ATOMIC); 367 370 if (err) { 368 - ERROR(midi, "%s queue req: %d\n", 371 + ERROR(midi, "%s: couldn't enqueue request: %d\n", 369 372 midi->out_ep->name, err); 370 373 free_ep_req(midi->out_ep, req); 374 + return err; 371 375 } 372 376 } 373 377 ··· 379 381 { 380 382 struct f_midi *midi = func_to_midi(f); 381 383 struct usb_composite_dev *cdev = f->config->cdev; 384 + struct usb_request *req = NULL; 382 385 383 386 DBG(cdev, "disable\n"); 384 387 ··· 389 390 */ 390 391 usb_ep_disable(midi->in_ep); 391 392 usb_ep_disable(midi->out_ep); 393 + 394 + /* release IN requests */ 395 + while (kfifo_get(&midi->in_req_fifo, &req)) 396 + free_ep_req(midi->in_ep, req); 392 397 } 393 398 394 399 static int f_midi_snd_free(struct snd_device *device) ··· 514 511 } 515 512 } 516 513 517 - static void f_midi_transmit(struct f_midi *midi, struct usb_request *req) 514 + static void f_midi_drop_out_substreams(struct f_midi *midi) 518 515 { 519 - struct usb_ep *ep = midi->in_ep; 520 - int i; 521 - 522 - if (!ep) 523 - return; 524 - 525 - if (!req) 526 - req = midi_alloc_ep_req(ep, midi->buflen); 527 - 528 - if (!req) { 529 - ERROR(midi, "%s: alloc_ep_request failed\n", __func__); 530 - return; 531 - } 532 - req->length = 0; 533 - req->complete = f_midi_complete; 516 + unsigned int i; 534 517 535 518 for (i = 0; i < MAX_PORTS; i++) { 536 519 struct gmidi_in_port *port = midi->in_port[i]; 537 520 struct snd_rawmidi_substream *substream = midi->in_substream[i]; 538 521 539 - if (!port || !port->active || !substream) 522 + if (!port) 523 + break; 524 + 525 + if (!port->active || !substream) 540 526 continue; 541 527 542 - while (req->length + 3 < midi->buflen) { 543 - uint8_t b; 544 - if (snd_rawmidi_transmit(substream, &b, 1) != 1) { 545 - port->active = 0; 528 + snd_rawmidi_drop_output(substream); 529 + } 530 + } 531 + 532 + static void f_midi_transmit(struct f_midi *midi) 533 + { 534 + struct usb_ep *ep = midi->in_ep; 535 + bool active; 536 + 537 + /* We only care about USB requests if IN endpoint is enabled */ 538 + if (!ep || !ep->enabled) 539 + goto drop_out; 540 + 541 + do { 542 + struct usb_request *req = NULL; 543 + unsigned int len, i; 544 + 545 + active = false; 546 + 547 + /* We peek the request in order to reuse it if it fails 548 + * to enqueue on its endpoint */ 549 + len = kfifo_peek(&midi->in_req_fifo, &req); 550 + if (len != 1) { 551 + ERROR(midi, "%s: Couldn't get usb request\n", __func__); 552 + goto drop_out; 553 + } 554 + 555 + /* If buffer overrun, then we ignore this transmission. 556 + * IMPORTANT: This will cause the user-space rawmidi device to block until a) usb 557 + * requests have been completed or b) snd_rawmidi_write() times out. */ 558 + if (req->length > 0) 559 + return; 560 + 561 + for (i = midi->in_last_port; i < MAX_PORTS; i++) { 562 + struct gmidi_in_port *port = midi->in_port[i]; 563 + struct snd_rawmidi_substream *substream = midi->in_substream[i]; 564 + 565 + if (!port) { 566 + /* Reset counter when we reach the last available port */ 567 + midi->in_last_port = 0; 546 568 break; 547 569 } 548 - f_midi_transmit_byte(req, port, b); 570 + 571 + if (!port->active || !substream) 572 + continue; 573 + 574 + while (req->length + 3 < midi->buflen) { 575 + uint8_t b; 576 + 577 + if (snd_rawmidi_transmit(substream, &b, 1) != 1) { 578 + port->active = 0; 579 + break; 580 + } 581 + f_midi_transmit_byte(req, port, b); 582 + } 583 + 584 + active = !!port->active; 585 + /* Check if last port is still active, which means that 586 + * there is still data on that substream but this current 587 + * request run out of space. */ 588 + if (active) { 589 + midi->in_last_port = i; 590 + /* There is no need to re-iterate though midi ports. */ 591 + break; 592 + } 549 593 } 550 - } 551 594 552 - if (req->length > 0 && ep->enabled) { 553 - int err; 595 + if (req->length > 0) { 596 + int err; 554 597 555 - err = usb_ep_queue(ep, req, GFP_ATOMIC); 556 - if (err < 0) 557 - ERROR(midi, "%s queue req: %d\n", 558 - midi->in_ep->name, err); 559 - } else { 560 - free_ep_req(ep, req); 561 - } 598 + err = usb_ep_queue(ep, req, GFP_ATOMIC); 599 + if (err < 0) { 600 + ERROR(midi, "%s failed to queue req: %d\n", 601 + midi->in_ep->name, err); 602 + req->length = 0; /* Re-use request next time. */ 603 + } else { 604 + /* Upon success, put request at the back of the queue. */ 605 + kfifo_skip(&midi->in_req_fifo); 606 + kfifo_put(&midi->in_req_fifo, req); 607 + } 608 + } 609 + } while (active); 610 + 611 + return; 612 + 613 + drop_out: 614 + f_midi_drop_out_substreams(midi); 562 615 } 563 616 564 617 static void f_midi_in_tasklet(unsigned long data) 565 618 { 566 619 struct f_midi *midi = (struct f_midi *) data; 567 - f_midi_transmit(midi, NULL); 620 + f_midi_transmit(midi); 568 621 } 569 622 570 623 static int f_midi_in_open(struct snd_rawmidi_substream *substream) ··· 746 687 goto fail; 747 688 } 748 689 midi->rmidi = rmidi; 690 + midi->in_last_port = 0; 749 691 strcpy(rmidi->name, card->shortname); 750 692 rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | 751 693 SNDRV_RAWMIDI_INFO_INPUT | ··· 815 755 goto fail; 816 756 ms_interface_desc.bInterfaceNumber = status; 817 757 ac_header_desc.baInterfaceNr[0] = status; 758 + midi->ms_id = status; 818 759 819 760 status = -ENODEV; 820 761 ··· 1136 1075 mutex_lock(&opts->lock); 1137 1076 for (i = opts->in_ports - 1; i >= 0; --i) 1138 1077 kfree(midi->in_port[i]); 1078 + kfifo_free(&midi->in_req_fifo); 1139 1079 kfree(midi); 1140 1080 --opts->refcnt; 1141 1081 mutex_unlock(&opts->lock); ··· 1210 1148 midi->index = opts->index; 1211 1149 midi->buflen = opts->buflen; 1212 1150 midi->qlen = opts->qlen; 1151 + midi->in_last_port = 0; 1152 + 1153 + status = kfifo_alloc(&midi->in_req_fifo, midi->qlen, GFP_KERNEL); 1154 + if (status) 1155 + goto setup_fail; 1156 + 1213 1157 ++opts->refcnt; 1214 1158 mutex_unlock(&opts->lock); 1215 1159
+109 -38
drivers/usb/gadget/function/f_sourcesink.c
··· 34 34 * plus two that support control-OUT tests. If the optional "autoresume" 35 35 * mode is enabled, it provides good functional coverage for the "USBCV" 36 36 * test harness from USB-IF. 37 - * 38 - * Note that because this doesn't queue more than one request at a time, 39 - * some other function must be used to test queueing logic. The network 40 - * link (g_ether) is the best overall option for that, since its TX and RX 41 - * queues are relatively independent, will receive a range of packet sizes, 42 - * and can often be made to run out completely. Those issues are important 43 - * when stress testing peripheral controller drivers. 44 37 */ 45 38 struct f_sourcesink { 46 39 struct usb_function function; ··· 50 57 unsigned isoc_mult; 51 58 unsigned isoc_maxburst; 52 59 unsigned buflen; 60 + unsigned bulk_qlen; 61 + unsigned iso_qlen; 53 62 }; 54 63 55 64 static inline struct f_sourcesink *func_to_ss(struct usb_function *f) ··· 296 301 struct f_sourcesink *ss = ep->driver_data; 297 302 298 303 return alloc_ep_req(ep, len, ss->buflen); 299 - } 300 - 301 - void free_ep_req(struct usb_ep *ep, struct usb_request *req) 302 - { 303 - kfree(req->buf); 304 - usb_ep_free_request(ep, req); 305 304 } 306 305 307 306 static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep) ··· 584 595 { 585 596 struct usb_ep *ep; 586 597 struct usb_request *req; 587 - int i, size, status; 598 + int i, size, qlen, status = 0; 588 599 589 - for (i = 0; i < 8; i++) { 590 - if (is_iso) { 591 - switch (speed) { 592 - case USB_SPEED_SUPER: 593 - size = ss->isoc_maxpacket * 594 - (ss->isoc_mult + 1) * 595 - (ss->isoc_maxburst + 1); 596 - break; 597 - case USB_SPEED_HIGH: 598 - size = ss->isoc_maxpacket * (ss->isoc_mult + 1); 599 - break; 600 - default: 601 - size = ss->isoc_maxpacket > 1023 ? 602 - 1023 : ss->isoc_maxpacket; 603 - break; 604 - } 605 - ep = is_in ? ss->iso_in_ep : ss->iso_out_ep; 606 - req = ss_alloc_ep_req(ep, size); 607 - } else { 608 - ep = is_in ? ss->in_ep : ss->out_ep; 609 - req = ss_alloc_ep_req(ep, 0); 600 + if (is_iso) { 601 + switch (speed) { 602 + case USB_SPEED_SUPER: 603 + size = ss->isoc_maxpacket * 604 + (ss->isoc_mult + 1) * 605 + (ss->isoc_maxburst + 1); 606 + break; 607 + case USB_SPEED_HIGH: 608 + size = ss->isoc_maxpacket * (ss->isoc_mult + 1); 609 + break; 610 + default: 611 + size = ss->isoc_maxpacket > 1023 ? 612 + 1023 : ss->isoc_maxpacket; 613 + break; 610 614 } 615 + ep = is_in ? ss->iso_in_ep : ss->iso_out_ep; 616 + qlen = ss->iso_qlen; 617 + } else { 618 + ep = is_in ? ss->in_ep : ss->out_ep; 619 + qlen = ss->bulk_qlen; 620 + size = 0; 621 + } 611 622 623 + for (i = 0; i < qlen; i++) { 624 + req = ss_alloc_ep_req(ep, size); 612 625 if (!req) 613 626 return -ENOMEM; 614 627 ··· 629 638 is_iso ? "ISO-" : "", is_in ? "IN" : "OUT", 630 639 ep->name, status); 631 640 free_ep_req(ep, req); 641 + return status; 632 642 } 633 - 634 - if (!is_iso) 635 - break; 636 643 } 637 644 638 645 return status; ··· 858 869 ss->isoc_mult = ss_opts->isoc_mult; 859 870 ss->isoc_maxburst = ss_opts->isoc_maxburst; 860 871 ss->buflen = ss_opts->bulk_buflen; 872 + ss->bulk_qlen = ss_opts->bulk_qlen; 873 + ss->iso_qlen = ss_opts->iso_qlen; 861 874 862 875 ss->function.name = "source/sink"; 863 876 ss->function.bind = sourcesink_bind; ··· 1144 1153 1145 1154 CONFIGFS_ATTR(f_ss_opts_, bulk_buflen); 1146 1155 1156 + static ssize_t f_ss_opts_bulk_qlen_show(struct config_item *item, char *page) 1157 + { 1158 + struct f_ss_opts *opts = to_f_ss_opts(item); 1159 + int result; 1160 + 1161 + mutex_lock(&opts->lock); 1162 + result = sprintf(page, "%u\n", opts->bulk_qlen); 1163 + mutex_unlock(&opts->lock); 1164 + 1165 + return result; 1166 + } 1167 + 1168 + static ssize_t f_ss_opts_bulk_qlen_store(struct config_item *item, 1169 + const char *page, size_t len) 1170 + { 1171 + struct f_ss_opts *opts = to_f_ss_opts(item); 1172 + int ret; 1173 + u32 num; 1174 + 1175 + mutex_lock(&opts->lock); 1176 + if (opts->refcnt) { 1177 + ret = -EBUSY; 1178 + goto end; 1179 + } 1180 + 1181 + ret = kstrtou32(page, 0, &num); 1182 + if (ret) 1183 + goto end; 1184 + 1185 + opts->bulk_qlen = num; 1186 + ret = len; 1187 + end: 1188 + mutex_unlock(&opts->lock); 1189 + return ret; 1190 + } 1191 + 1192 + CONFIGFS_ATTR(f_ss_opts_, bulk_qlen); 1193 + 1194 + static ssize_t f_ss_opts_iso_qlen_show(struct config_item *item, char *page) 1195 + { 1196 + struct f_ss_opts *opts = to_f_ss_opts(item); 1197 + int result; 1198 + 1199 + mutex_lock(&opts->lock); 1200 + result = sprintf(page, "%u\n", opts->iso_qlen); 1201 + mutex_unlock(&opts->lock); 1202 + 1203 + return result; 1204 + } 1205 + 1206 + static ssize_t f_ss_opts_iso_qlen_store(struct config_item *item, 1207 + const char *page, size_t len) 1208 + { 1209 + struct f_ss_opts *opts = to_f_ss_opts(item); 1210 + int ret; 1211 + u32 num; 1212 + 1213 + mutex_lock(&opts->lock); 1214 + if (opts->refcnt) { 1215 + ret = -EBUSY; 1216 + goto end; 1217 + } 1218 + 1219 + ret = kstrtou32(page, 0, &num); 1220 + if (ret) 1221 + goto end; 1222 + 1223 + opts->iso_qlen = num; 1224 + ret = len; 1225 + end: 1226 + mutex_unlock(&opts->lock); 1227 + return ret; 1228 + } 1229 + 1230 + CONFIGFS_ATTR(f_ss_opts_, iso_qlen); 1231 + 1147 1232 static struct configfs_attribute *ss_attrs[] = { 1148 1233 &f_ss_opts_attr_pattern, 1149 1234 &f_ss_opts_attr_isoc_interval, ··· 1227 1160 &f_ss_opts_attr_isoc_mult, 1228 1161 &f_ss_opts_attr_isoc_maxburst, 1229 1162 &f_ss_opts_attr_bulk_buflen, 1163 + &f_ss_opts_attr_bulk_qlen, 1164 + &f_ss_opts_attr_iso_qlen, 1230 1165 NULL, 1231 1166 }; 1232 1167 ··· 1258 1189 ss_opts->isoc_interval = GZERO_ISOC_INTERVAL; 1259 1190 ss_opts->isoc_maxpacket = GZERO_ISOC_MAXPACKET; 1260 1191 ss_opts->bulk_buflen = GZERO_BULK_BUFLEN; 1192 + ss_opts->bulk_qlen = GZERO_SS_BULK_QLEN; 1193 + ss_opts->iso_qlen = GZERO_SS_ISO_QLEN; 1261 1194 1262 1195 config_group_init_type_name(&ss_opts->func_inst.group, "", 1263 1196 &ss_func_type);
+6 -1
drivers/usb/gadget/function/g_zero.h
··· 10 10 #define GZERO_QLEN 32 11 11 #define GZERO_ISOC_INTERVAL 4 12 12 #define GZERO_ISOC_MAXPACKET 1024 13 + #define GZERO_SS_BULK_QLEN 1 14 + #define GZERO_SS_ISO_QLEN 8 13 15 14 16 struct usb_zero_options { 15 17 unsigned pattern; ··· 21 19 unsigned isoc_maxburst; 22 20 unsigned bulk_buflen; 23 21 unsigned qlen; 22 + unsigned ss_bulk_qlen; 23 + unsigned ss_iso_qlen; 24 24 }; 25 25 26 26 struct f_ss_opts { ··· 33 29 unsigned isoc_mult; 34 30 unsigned isoc_maxburst; 35 31 unsigned bulk_buflen; 32 + unsigned bulk_qlen; 33 + unsigned iso_qlen; 36 34 37 35 /* 38 36 * Read/write access to configfs attributes is handled by configfs. ··· 65 59 int lb_modinit(void); 66 60 67 61 /* common utilities */ 68 - void free_ep_req(struct usb_ep *ep, struct usb_request *req); 69 62 void disable_endpoints(struct usb_composite_dev *cdev, 70 63 struct usb_ep *in, struct usb_ep *out, 71 64 struct usb_ep *iso_in, struct usb_ep *iso_out);
+4 -14
drivers/usb/gadget/function/u_ether.c
··· 143 143 144 144 static int ueth_change_mtu(struct net_device *net, int new_mtu) 145 145 { 146 - struct eth_dev *dev = netdev_priv(net); 147 - unsigned long flags; 148 - int status = 0; 146 + if (new_mtu <= ETH_HLEN || new_mtu > GETHER_MAX_ETH_FRAME_LEN) 147 + return -ERANGE; 148 + net->mtu = new_mtu; 149 149 150 - /* don't change MTU on "live" link (peer won't know) */ 151 - spin_lock_irqsave(&dev->lock, flags); 152 - if (dev->port_usb) 153 - status = -EBUSY; 154 - else if (new_mtu <= ETH_HLEN || new_mtu > GETHER_MAX_ETH_FRAME_LEN) 155 - status = -ERANGE; 156 - else 157 - net->mtu = new_mtu; 158 - spin_unlock_irqrestore(&dev->lock, flags); 159 - 160 - return status; 150 + return 0; 161 151 } 162 152 163 153 static void eth_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *p)
+258
drivers/usb/gadget/function/u_serial.c
··· 27 27 #include <linux/slab.h> 28 28 #include <linux/export.h> 29 29 #include <linux/module.h> 30 + #include <linux/console.h> 31 + #include <linux/kthread.h> 30 32 31 33 #include "u_serial.h" 32 34 ··· 81 79 */ 82 80 #define QUEUE_SIZE 16 83 81 #define WRITE_BUF_SIZE 8192 /* TX only */ 82 + #define GS_CONSOLE_BUF_SIZE 8192 84 83 85 84 /* circular buffer */ 86 85 struct gs_buf { ··· 89 86 char *buf_buf; 90 87 char *buf_get; 91 88 char *buf_put; 89 + }; 90 + 91 + /* console info */ 92 + struct gscons_info { 93 + struct gs_port *port; 94 + struct task_struct *console_thread; 95 + struct gs_buf con_buf; 96 + /* protect the buf and busy flag */ 97 + spinlock_t con_lock; 98 + int req_busy; 99 + struct usb_request *console_req; 92 100 }; 93 101 94 102 /* ··· 1037 1023 1038 1024 static struct tty_driver *gs_tty_driver; 1039 1025 1026 + #ifdef CONFIG_U_SERIAL_CONSOLE 1027 + 1028 + static struct gscons_info gscons_info; 1029 + static struct console gserial_cons; 1030 + 1031 + static struct usb_request *gs_request_new(struct usb_ep *ep) 1032 + { 1033 + struct usb_request *req = usb_ep_alloc_request(ep, GFP_ATOMIC); 1034 + if (!req) 1035 + return NULL; 1036 + 1037 + req->buf = kmalloc(ep->maxpacket, GFP_ATOMIC); 1038 + if (!req->buf) { 1039 + usb_ep_free_request(ep, req); 1040 + return NULL; 1041 + } 1042 + 1043 + return req; 1044 + } 1045 + 1046 + static void gs_request_free(struct usb_request *req, struct usb_ep *ep) 1047 + { 1048 + if (!req) 1049 + return; 1050 + 1051 + kfree(req->buf); 1052 + usb_ep_free_request(ep, req); 1053 + } 1054 + 1055 + static void gs_complete_out(struct usb_ep *ep, struct usb_request *req) 1056 + { 1057 + struct gscons_info *info = &gscons_info; 1058 + 1059 + switch (req->status) { 1060 + default: 1061 + pr_warn("%s: unexpected %s status %d\n", 1062 + __func__, ep->name, req->status); 1063 + case 0: 1064 + /* normal completion */ 1065 + spin_lock(&info->con_lock); 1066 + info->req_busy = 0; 1067 + spin_unlock(&info->con_lock); 1068 + 1069 + wake_up_process(info->console_thread); 1070 + break; 1071 + case -ESHUTDOWN: 1072 + /* disconnect */ 1073 + pr_vdebug("%s: %s shutdown\n", __func__, ep->name); 1074 + break; 1075 + } 1076 + } 1077 + 1078 + static int gs_console_connect(int port_num) 1079 + { 1080 + struct gscons_info *info = &gscons_info; 1081 + struct gs_port *port; 1082 + struct usb_ep *ep; 1083 + 1084 + if (port_num != gserial_cons.index) { 1085 + pr_err("%s: port num [%d] is not support console\n", 1086 + __func__, port_num); 1087 + return -ENXIO; 1088 + } 1089 + 1090 + port = ports[port_num].port; 1091 + ep = port->port_usb->in; 1092 + if (!info->console_req) { 1093 + info->console_req = gs_request_new(ep); 1094 + if (!info->console_req) 1095 + return -ENOMEM; 1096 + info->console_req->complete = gs_complete_out; 1097 + } 1098 + 1099 + info->port = port; 1100 + spin_lock(&info->con_lock); 1101 + info->req_busy = 0; 1102 + spin_unlock(&info->con_lock); 1103 + pr_vdebug("port[%d] console connect!\n", port_num); 1104 + return 0; 1105 + } 1106 + 1107 + static void gs_console_disconnect(struct usb_ep *ep) 1108 + { 1109 + struct gscons_info *info = &gscons_info; 1110 + struct usb_request *req = info->console_req; 1111 + 1112 + gs_request_free(req, ep); 1113 + info->console_req = NULL; 1114 + } 1115 + 1116 + static int gs_console_thread(void *data) 1117 + { 1118 + struct gscons_info *info = &gscons_info; 1119 + struct gs_port *port; 1120 + struct usb_request *req; 1121 + struct usb_ep *ep; 1122 + int xfer, ret, count, size; 1123 + 1124 + do { 1125 + port = info->port; 1126 + set_current_state(TASK_INTERRUPTIBLE); 1127 + if (!port || !port->port_usb 1128 + || !port->port_usb->in || !info->console_req) 1129 + goto sched; 1130 + 1131 + req = info->console_req; 1132 + ep = port->port_usb->in; 1133 + 1134 + spin_lock_irq(&info->con_lock); 1135 + count = gs_buf_data_avail(&info->con_buf); 1136 + size = ep->maxpacket; 1137 + 1138 + if (count > 0 && !info->req_busy) { 1139 + set_current_state(TASK_RUNNING); 1140 + if (count < size) 1141 + size = count; 1142 + 1143 + xfer = gs_buf_get(&info->con_buf, req->buf, size); 1144 + req->length = xfer; 1145 + 1146 + spin_unlock(&info->con_lock); 1147 + ret = usb_ep_queue(ep, req, GFP_ATOMIC); 1148 + spin_lock(&info->con_lock); 1149 + if (ret < 0) 1150 + info->req_busy = 0; 1151 + else 1152 + info->req_busy = 1; 1153 + 1154 + spin_unlock_irq(&info->con_lock); 1155 + } else { 1156 + spin_unlock_irq(&info->con_lock); 1157 + sched: 1158 + if (kthread_should_stop()) { 1159 + set_current_state(TASK_RUNNING); 1160 + break; 1161 + } 1162 + schedule(); 1163 + } 1164 + } while (1); 1165 + 1166 + return 0; 1167 + } 1168 + 1169 + static int gs_console_setup(struct console *co, char *options) 1170 + { 1171 + struct gscons_info *info = &gscons_info; 1172 + int status; 1173 + 1174 + info->port = NULL; 1175 + info->console_req = NULL; 1176 + info->req_busy = 0; 1177 + spin_lock_init(&info->con_lock); 1178 + 1179 + status = gs_buf_alloc(&info->con_buf, GS_CONSOLE_BUF_SIZE); 1180 + if (status) { 1181 + pr_err("%s: allocate console buffer failed\n", __func__); 1182 + return status; 1183 + } 1184 + 1185 + info->console_thread = kthread_create(gs_console_thread, 1186 + co, "gs_console"); 1187 + if (IS_ERR(info->console_thread)) { 1188 + pr_err("%s: cannot create console thread\n", __func__); 1189 + gs_buf_free(&info->con_buf); 1190 + return PTR_ERR(info->console_thread); 1191 + } 1192 + wake_up_process(info->console_thread); 1193 + 1194 + return 0; 1195 + } 1196 + 1197 + static void gs_console_write(struct console *co, 1198 + const char *buf, unsigned count) 1199 + { 1200 + struct gscons_info *info = &gscons_info; 1201 + unsigned long flags; 1202 + 1203 + spin_lock_irqsave(&info->con_lock, flags); 1204 + gs_buf_put(&info->con_buf, buf, count); 1205 + spin_unlock_irqrestore(&info->con_lock, flags); 1206 + 1207 + wake_up_process(info->console_thread); 1208 + } 1209 + 1210 + static struct tty_driver *gs_console_device(struct console *co, int *index) 1211 + { 1212 + struct tty_driver **p = (struct tty_driver **)co->data; 1213 + 1214 + if (!*p) 1215 + return NULL; 1216 + 1217 + *index = co->index; 1218 + return *p; 1219 + } 1220 + 1221 + static struct console gserial_cons = { 1222 + .name = "ttyGS", 1223 + .write = gs_console_write, 1224 + .device = gs_console_device, 1225 + .setup = gs_console_setup, 1226 + .flags = CON_PRINTBUFFER, 1227 + .index = -1, 1228 + .data = &gs_tty_driver, 1229 + }; 1230 + 1231 + static void gserial_console_init(void) 1232 + { 1233 + register_console(&gserial_cons); 1234 + } 1235 + 1236 + static void gserial_console_exit(void) 1237 + { 1238 + struct gscons_info *info = &gscons_info; 1239 + 1240 + unregister_console(&gserial_cons); 1241 + kthread_stop(info->console_thread); 1242 + gs_buf_free(&info->con_buf); 1243 + } 1244 + 1245 + #else 1246 + 1247 + static int gs_console_connect(int port_num) 1248 + { 1249 + return 0; 1250 + } 1251 + 1252 + static void gs_console_disconnect(struct usb_ep *ep) 1253 + { 1254 + } 1255 + 1256 + static void gserial_console_init(void) 1257 + { 1258 + } 1259 + 1260 + static void gserial_console_exit(void) 1261 + { 1262 + } 1263 + 1264 + #endif 1265 + 1040 1266 static int 1041 1267 gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding) 1042 1268 { ··· 1350 1096 1351 1097 gserial_free_port(port); 1352 1098 tty_unregister_device(gs_tty_driver, port_num); 1099 + gserial_console_exit(); 1353 1100 } 1354 1101 EXPORT_SYMBOL_GPL(gserial_free_line); 1355 1102 ··· 1393 1138 goto err; 1394 1139 } 1395 1140 *line_num = port_num; 1141 + gserial_console_init(); 1396 1142 err: 1397 1143 return ret; 1398 1144 } ··· 1475 1219 gser->disconnect(gser); 1476 1220 } 1477 1221 1222 + status = gs_console_connect(port_num); 1478 1223 spin_unlock_irqrestore(&port->port_lock, flags); 1479 1224 1480 1225 return status; ··· 1534 1277 port->read_allocated = port->read_started = 1535 1278 port->write_allocated = port->write_started = 0; 1536 1279 1280 + gs_console_disconnect(gser->in); 1537 1281 spin_unlock_irqrestore(&port->port_lock, flags); 1538 1282 } 1539 1283 EXPORT_SYMBOL_GPL(gserial_disconnect);
+1 -1
drivers/usb/gadget/legacy/acm_ms.c
··· 40 40 .bLength = sizeof device_desc, 41 41 .bDescriptorType = USB_DT_DEVICE, 42 42 43 - .bcdUSB = cpu_to_le16(0x0200), 43 + /* .bcdUSB = DYNAMIC */ 44 44 45 45 .bDeviceClass = USB_CLASS_MISC /* 0xEF */, 46 46 .bDeviceSubClass = 2,
+1 -1
drivers/usb/gadget/legacy/audio.c
··· 123 123 .bLength = sizeof device_desc, 124 124 .bDescriptorType = USB_DT_DEVICE, 125 125 126 - .bcdUSB = cpu_to_le16(0x200), 126 + /* .bcdUSB = DYNAMIC */ 127 127 128 128 #ifdef CONFIG_GADGET_UAC1 129 129 .bDeviceClass = USB_CLASS_PER_INTERFACE,
+1 -1
drivers/usb/gadget/legacy/cdc2.c
··· 43 43 .bLength = sizeof device_desc, 44 44 .bDescriptorType = USB_DT_DEVICE, 45 45 46 - .bcdUSB = cpu_to_le16(0x0200), 46 + /* .bcdUSB = DYNAMIC */ 47 47 48 48 .bDeviceClass = USB_CLASS_COMM, 49 49 .bDeviceSubClass = 0,
+1 -1
drivers/usb/gadget/legacy/ether.c
··· 151 151 .bLength = sizeof device_desc, 152 152 .bDescriptorType = USB_DT_DEVICE, 153 153 154 - .bcdUSB = cpu_to_le16 (0x0200), 154 + /* .bcdUSB = DYNAMIC */ 155 155 156 156 .bDeviceClass = USB_CLASS_COMM, 157 157 .bDeviceSubClass = 0,
+1 -1
drivers/usb/gadget/legacy/g_ffs.c
··· 69 69 .bLength = sizeof gfs_dev_desc, 70 70 .bDescriptorType = USB_DT_DEVICE, 71 71 72 - .bcdUSB = cpu_to_le16(0x0200), 72 + /* .bcdUSB = DYNAMIC */ 73 73 .bDeviceClass = USB_CLASS_PER_INTERFACE, 74 74 75 75 .idVendor = cpu_to_le16(GFS_VENDOR_ID),
+2 -10
drivers/usb/gadget/legacy/gmidi.c
··· 21 21 /* #define VERBOSE_DEBUG */ 22 22 23 23 #include <linux/kernel.h> 24 - #include <linux/slab.h> 25 24 #include <linux/module.h> 26 - #include <linux/device.h> 27 25 28 - #include <sound/core.h> 29 26 #include <sound/initval.h> 30 - #include <sound/rawmidi.h> 31 27 32 - #include <linux/usb/ch9.h> 33 28 #include <linux/usb/composite.h> 34 29 #include <linux/usb/gadget.h> 35 - #include <linux/usb/audio.h> 36 - #include <linux/usb/midi.h> 37 30 38 31 #include "u_midi.h" 39 32 ··· 35 42 MODULE_AUTHOR("Ben Williamson"); 36 43 MODULE_LICENSE("GPL v2"); 37 44 38 - static const char shortname[] = "g_midi"; 39 45 static const char longname[] = "MIDI Gadget"; 40 46 41 47 USB_GADGET_COMPOSITE_OPTIONS(); ··· 53 61 54 62 static unsigned int qlen = 32; 55 63 module_param(qlen, uint, S_IRUGO); 56 - MODULE_PARM_DESC(qlen, "USB read request queue length"); 64 + MODULE_PARM_DESC(qlen, "USB read and write request queue length"); 57 65 58 66 static unsigned int in_ports = 1; 59 67 module_param(in_ports, uint, S_IRUGO); ··· 78 86 static struct usb_device_descriptor device_desc = { 79 87 .bLength = USB_DT_DEVICE_SIZE, 80 88 .bDescriptorType = USB_DT_DEVICE, 81 - .bcdUSB = cpu_to_le16(0x0200), 89 + /* .bcdUSB = DYNAMIC */ 82 90 .bDeviceClass = USB_CLASS_PER_INTERFACE, 83 91 .idVendor = cpu_to_le16(DRIVER_VENDOR_NUM), 84 92 .idProduct = cpu_to_le16(DRIVER_PRODUCT_NUM),
+1 -1
drivers/usb/gadget/legacy/hid.c
··· 47 47 .bLength = sizeof device_desc, 48 48 .bDescriptorType = USB_DT_DEVICE, 49 49 50 - .bcdUSB = cpu_to_le16(0x0200), 50 + /* .bcdUSB = DYNAMIC */ 51 51 52 52 /* .bDeviceClass = USB_CLASS_COMM, */ 53 53 /* .bDeviceSubClass = 0, */
+1 -2
drivers/usb/gadget/legacy/inode.c
··· 1137 1137 dev->gadget->ep0, dev->req, 1138 1138 GFP_KERNEL); 1139 1139 } 1140 + spin_lock_irq(&dev->lock); 1140 1141 if (retval < 0) { 1141 - spin_lock_irq (&dev->lock); 1142 1142 clean_req (dev->gadget->ep0, dev->req); 1143 - spin_unlock_irq (&dev->lock); 1144 1143 } else 1145 1144 retval = len; 1146 1145
+1 -1
drivers/usb/gadget/legacy/mass_storage.c
··· 55 55 .bLength = sizeof msg_device_desc, 56 56 .bDescriptorType = USB_DT_DEVICE, 57 57 58 - .bcdUSB = cpu_to_le16(0x0200), 58 + /* .bcdUSB = DYNAMIC */ 59 59 .bDeviceClass = USB_CLASS_PER_INTERFACE, 60 60 61 61 /* Vendor and product id can be overridden by module parameters. */
+1 -1
drivers/usb/gadget/legacy/multi.c
··· 67 67 .bLength = sizeof device_desc, 68 68 .bDescriptorType = USB_DT_DEVICE, 69 69 70 - .bcdUSB = cpu_to_le16(0x0200), 70 + /* .bcdUSB = DYNAMIC */ 71 71 72 72 .bDeviceClass = USB_CLASS_MISC /* 0xEF */, 73 73 .bDeviceSubClass = 2,
+1 -1
drivers/usb/gadget/legacy/ncm.c
··· 49 49 .bLength = sizeof device_desc, 50 50 .bDescriptorType = USB_DT_DEVICE, 51 51 52 - .bcdUSB = cpu_to_le16 (0x0200), 52 + /* .bcdUSB = DYNAMIC */ 53 53 54 54 .bDeviceClass = USB_CLASS_COMM, 55 55 .bDeviceSubClass = 0,
+1 -1
drivers/usb/gadget/legacy/nokia.c
··· 89 89 static struct usb_device_descriptor device_desc = { 90 90 .bLength = USB_DT_DEVICE_SIZE, 91 91 .bDescriptorType = USB_DT_DEVICE, 92 - .bcdUSB = cpu_to_le16(0x0200), 92 + /* .bcdUSB = DYNAMIC */ 93 93 .bDeviceClass = USB_CLASS_COMM, 94 94 .idVendor = cpu_to_le16(NOKIA_VENDOR_ID), 95 95 .idProduct = cpu_to_le16(NOKIA_PRODUCT_ID),
+1 -1
drivers/usb/gadget/legacy/printer.c
··· 71 71 static struct usb_device_descriptor device_desc = { 72 72 .bLength = sizeof device_desc, 73 73 .bDescriptorType = USB_DT_DEVICE, 74 - .bcdUSB = cpu_to_le16(0x0200), 74 + /* .bcdUSB = DYNAMIC */ 75 75 .bDeviceClass = USB_CLASS_PER_INTERFACE, 76 76 .bDeviceSubClass = 0, 77 77 .bDeviceProtocol = 0,
+1 -1
drivers/usb/gadget/legacy/serial.c
··· 65 65 static struct usb_device_descriptor device_desc = { 66 66 .bLength = USB_DT_DEVICE_SIZE, 67 67 .bDescriptorType = USB_DT_DEVICE, 68 - .bcdUSB = cpu_to_le16(0x0200), 68 + /* .bcdUSB = DYNAMIC */ 69 69 /* .bDeviceClass = f(use_acm) */ 70 70 .bDeviceSubClass = 0, 71 71 .bDeviceProtocol = 0,
+1 -1
drivers/usb/gadget/legacy/tcm_usb_gadget.c
··· 1974 1974 static struct usb_device_descriptor usbg_device_desc = { 1975 1975 .bLength = sizeof(usbg_device_desc), 1976 1976 .bDescriptorType = USB_DT_DEVICE, 1977 - .bcdUSB = cpu_to_le16(0x0200), 1977 + /* .bcdUSB = DYNAMIC */ 1978 1978 .bDeviceClass = USB_CLASS_PER_INTERFACE, 1979 1979 .idVendor = cpu_to_le16(UAS_VENDOR_ID), 1980 1980 .idProduct = cpu_to_le16(UAS_PRODUCT_ID),
+1 -1
drivers/usb/gadget/legacy/webcam.c
··· 77 77 static struct usb_device_descriptor webcam_device_descriptor = { 78 78 .bLength = USB_DT_DEVICE_SIZE, 79 79 .bDescriptorType = USB_DT_DEVICE, 80 - .bcdUSB = cpu_to_le16(0x0200), 80 + /* .bcdUSB = DYNAMIC */ 81 81 .bDeviceClass = USB_CLASS_MISC, 82 82 .bDeviceSubClass = 0x02, 83 83 .bDeviceProtocol = 0x01,
+13 -1
drivers/usb/gadget/legacy/zero.c
··· 68 68 .isoc_maxpacket = GZERO_ISOC_MAXPACKET, 69 69 .bulk_buflen = GZERO_BULK_BUFLEN, 70 70 .qlen = GZERO_QLEN, 71 + .ss_bulk_qlen = GZERO_SS_BULK_QLEN, 72 + .ss_iso_qlen = GZERO_SS_ISO_QLEN, 71 73 }; 72 74 73 75 /*-------------------------------------------------------------------------*/ ··· 115 113 .bLength = sizeof device_desc, 116 114 .bDescriptorType = USB_DT_DEVICE, 117 115 118 - .bcdUSB = cpu_to_le16(0x0200), 116 + /* .bcdUSB = DYNAMIC */ 119 117 .bDeviceClass = USB_CLASS_VENDOR_SPEC, 120 118 121 119 .idVendor = cpu_to_le16(DRIVER_VENDOR_NUM), ··· 257 255 module_param_named(qlen, gzero_options.qlen, uint, S_IRUGO|S_IWUSR); 258 256 MODULE_PARM_DESC(qlen, "depth of loopback queue"); 259 257 258 + module_param_named(ss_bulk_qlen, gzero_options.ss_bulk_qlen, uint, 259 + S_IRUGO|S_IWUSR); 260 + MODULE_PARM_DESC(bulk_qlen, "depth of sourcesink queue for bulk transfer"); 261 + 262 + module_param_named(ss_iso_qlen, gzero_options.ss_iso_qlen, uint, 263 + S_IRUGO|S_IWUSR); 264 + MODULE_PARM_DESC(iso_qlen, "depth of sourcesink queue for iso transfer"); 265 + 260 266 static int zero_bind(struct usb_composite_dev *cdev) 261 267 { 262 268 struct f_ss_opts *ss_opts; ··· 295 285 ss_opts->isoc_mult = gzero_options.isoc_mult; 296 286 ss_opts->isoc_maxburst = gzero_options.isoc_maxburst; 297 287 ss_opts->bulk_buflen = gzero_options.bulk_buflen; 288 + ss_opts->bulk_qlen = gzero_options.ss_bulk_qlen; 289 + ss_opts->iso_qlen = gzero_options.ss_iso_qlen; 298 290 299 291 func_ss = usb_get_function(func_inst_ss); 300 292 if (IS_ERR(func_ss)) {
-1
drivers/usb/gadget/u_f.c
··· 11 11 * published by the Free Software Foundation. 12 12 */ 13 13 14 - #include <linux/usb/gadget.h> 15 14 #include "u_f.h" 16 15 17 16 struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len)
+8 -2
drivers/usb/gadget/u_f.h
··· 16 16 #ifndef __U_F_H__ 17 17 #define __U_F_H__ 18 18 19 + #include <linux/usb/gadget.h> 20 + 19 21 /* Variable Length Array Macros **********************************************/ 20 22 #define vla_group(groupname) size_t groupname##__next = 0 21 23 #define vla_group_size(groupname) groupname##__next ··· 47 45 struct usb_ep; 48 46 struct usb_request; 49 47 48 + /* Requests allocated via alloc_ep_req() must be freed by free_ep_req(). */ 50 49 struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len); 50 + static inline void free_ep_req(struct usb_ep *ep, struct usb_request *req) 51 + { 52 + kfree(req->buf); 53 + usb_ep_free_request(ep, req); 54 + } 51 55 52 56 #endif /* __U_F_H__ */ 53 - 54 -
+11
drivers/usb/gadget/udc/Kconfig
··· 174 174 dynamically linked module called "renesas_usbhs" and force all 175 175 gadget drivers to also be dynamically linked. 176 176 177 + config USB_RENESAS_USB3 178 + tristate 'Renesas USB3.0 Peripheral controller' 179 + depends on ARCH_SHMOBILE || COMPILE_TEST 180 + help 181 + Renesas USB3.0 Peripheral controller is a USB peripheral controller 182 + that supports super, high, and full speed USB 3.0 data transfers. 183 + 184 + Say "y" to link the driver statically, or "m" to build a 185 + dynamically linked module called "renesas_usb3" and force all 186 + gadget drivers to also be dynamically linked. 187 + 177 188 config USB_PXA27X 178 189 tristate "PXA 27x" 179 190 help
+1
drivers/usb/gadget/udc/Makefile
··· 19 19 fsl_usb2_udc-$(CONFIG_ARCH_MXC) += fsl_mxc_udc.o 20 20 obj-$(CONFIG_USB_M66592) += m66592-udc.o 21 21 obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o 22 + obj-$(CONFIG_USB_RENESAS_USB3) += renesas_usb3.o 22 23 obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o 23 24 obj-$(CONFIG_USB_S3C_HSUDC) += s3c-hsudc.o 24 25 obj-$(CONFIG_USB_LPC32XX) += lpc32xx_udc.o
+2 -5
drivers/usb/gadget/udc/bcm63xx_udc.c
··· 1083 1083 struct bcm63xx_ep *bep = our_ep(ep); 1084 1084 struct bcm63xx_udc *udc = bep->udc; 1085 1085 struct iudma_ch *iudma = bep->iudma; 1086 - struct list_head *pos, *n; 1086 + struct bcm63xx_req *breq, *n; 1087 1087 unsigned long flags; 1088 1088 1089 1089 if (!ep || !ep->desc) ··· 1099 1099 iudma_reset_channel(udc, iudma); 1100 1100 1101 1101 if (!list_empty(&bep->queue)) { 1102 - list_for_each_safe(pos, n, &bep->queue) { 1103 - struct bcm63xx_req *breq = 1104 - list_entry(pos, struct bcm63xx_req, queue); 1105 - 1102 + list_for_each_entry_safe(breq, n, &bep->queue, queue) { 1106 1103 usb_gadget_unmap_request(&udc->gadget, &breq->req, 1107 1104 iudma->is_tx); 1108 1105 list_del(&breq->queue);
+12 -25
drivers/usb/gadget/udc/lpc32xx_udc.c
··· 28 28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 29 29 */ 30 30 31 - #include <linux/kernel.h> 32 - #include <linux/module.h> 33 - #include <linux/platform_device.h> 34 - #include <linux/delay.h> 35 - #include <linux/ioport.h> 36 - #include <linux/slab.h> 37 - #include <linux/errno.h> 38 - #include <linux/init.h> 39 - #include <linux/list.h> 40 - #include <linux/interrupt.h> 41 - #include <linux/proc_fs.h> 42 31 #include <linux/clk.h> 43 - #include <linux/usb/ch9.h> 44 - #include <linux/usb/gadget.h> 45 - #include <linux/i2c.h> 46 - #include <linux/kthread.h> 47 - #include <linux/freezer.h> 32 + #include <linux/delay.h> 48 33 #include <linux/dma-mapping.h> 49 34 #include <linux/dmapool.h> 50 - #include <linux/workqueue.h> 35 + #include <linux/i2c.h> 36 + #include <linux/interrupt.h> 37 + #include <linux/module.h> 51 38 #include <linux/of.h> 39 + #include <linux/platform_device.h> 40 + #include <linux/proc_fs.h> 41 + #include <linux/slab.h> 42 + #include <linux/usb/ch9.h> 43 + #include <linux/usb/gadget.h> 52 44 #include <linux/usb/isp1301.h> 53 45 54 - #include <asm/byteorder.h> 55 - #include <mach/hardware.h> 56 - #include <linux/io.h> 57 - #include <asm/irq.h> 58 - 59 - #include <mach/platform.h> 60 - #include <mach/irqs.h> 61 - #include <mach/board.h> 62 46 #ifdef CONFIG_USB_GADGET_DEBUG_FILES 63 47 #include <linux/debugfs.h> 64 48 #include <linux/seq_file.h> 65 49 #endif 50 + 51 + #include <mach/hardware.h> 52 + #include <mach/platform.h> 66 53 67 54 /* 68 55 * USB device configuration structure
+1975
drivers/usb/gadget/udc/renesas_usb3.c
··· 1 + /* 2 + * Renesas USB3.0 Peripheral driver (USB gadget) 3 + * 4 + * Copyright (C) 2015 Renesas Electronics Corporation 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; version 2 of the License. 9 + */ 10 + 11 + #include <linux/delay.h> 12 + #include <linux/err.h> 13 + #include <linux/interrupt.h> 14 + #include <linux/io.h> 15 + #include <linux/module.h> 16 + #include <linux/of_device.h> 17 + #include <linux/platform_device.h> 18 + #include <linux/pm_runtime.h> 19 + #include <linux/sizes.h> 20 + #include <linux/slab.h> 21 + #include <linux/usb/ch9.h> 22 + #include <linux/usb/gadget.h> 23 + 24 + /* register definitions */ 25 + #define USB3_AXI_INT_STA 0x008 26 + #define USB3_AXI_INT_ENA 0x00c 27 + #define USB3_DMA_INT_STA 0x010 28 + #define USB3_DMA_INT_ENA 0x014 29 + #define USB3_USB_COM_CON 0x200 30 + #define USB3_USB20_CON 0x204 31 + #define USB3_USB30_CON 0x208 32 + #define USB3_USB_STA 0x210 33 + #define USB3_DRD_CON 0x218 34 + #define USB3_USB_INT_STA_1 0x220 35 + #define USB3_USB_INT_STA_2 0x224 36 + #define USB3_USB_INT_ENA_1 0x228 37 + #define USB3_USB_INT_ENA_2 0x22c 38 + #define USB3_STUP_DAT_0 0x230 39 + #define USB3_STUP_DAT_1 0x234 40 + #define USB3_P0_MOD 0x280 41 + #define USB3_P0_CON 0x288 42 + #define USB3_P0_STA 0x28c 43 + #define USB3_P0_INT_STA 0x290 44 + #define USB3_P0_INT_ENA 0x294 45 + #define USB3_P0_LNG 0x2a0 46 + #define USB3_P0_READ 0x2a4 47 + #define USB3_P0_WRITE 0x2a8 48 + #define USB3_PIPE_COM 0x2b0 49 + #define USB3_PN_MOD 0x2c0 50 + #define USB3_PN_RAMMAP 0x2c4 51 + #define USB3_PN_CON 0x2c8 52 + #define USB3_PN_STA 0x2cc 53 + #define USB3_PN_INT_STA 0x2d0 54 + #define USB3_PN_INT_ENA 0x2d4 55 + #define USB3_PN_LNG 0x2e0 56 + #define USB3_PN_READ 0x2e4 57 + #define USB3_PN_WRITE 0x2e8 58 + #define USB3_SSIFCMD 0x340 59 + 60 + /* AXI_INT_ENA and AXI_INT_STA */ 61 + #define AXI_INT_DMAINT BIT(31) 62 + #define AXI_INT_EPCINT BIT(30) 63 + 64 + /* LCLKSEL */ 65 + #define LCLKSEL_LSEL BIT(18) 66 + 67 + /* USB_COM_CON */ 68 + #define USB_COM_CON_CONF BIT(24) 69 + #define USB_COM_CON_SPD_MODE BIT(17) 70 + #define USB_COM_CON_EP0_EN BIT(16) 71 + #define USB_COM_CON_DEV_ADDR_SHIFT 8 72 + #define USB_COM_CON_DEV_ADDR_MASK GENMASK(14, USB_COM_CON_DEV_ADDR_SHIFT) 73 + #define USB_COM_CON_DEV_ADDR(n) (((n) << USB_COM_CON_DEV_ADDR_SHIFT) & \ 74 + USB_COM_CON_DEV_ADDR_MASK) 75 + #define USB_COM_CON_RX_DETECTION BIT(1) 76 + #define USB_COM_CON_PIPE_CLR BIT(0) 77 + 78 + /* USB20_CON */ 79 + #define USB20_CON_B2_PUE BIT(31) 80 + #define USB20_CON_B2_SUSPEND BIT(24) 81 + #define USB20_CON_B2_CONNECT BIT(17) 82 + #define USB20_CON_B2_TSTMOD_SHIFT 8 83 + #define USB20_CON_B2_TSTMOD_MASK GENMASK(10, USB20_CON_B2_TSTMOD_SHIFT) 84 + #define USB20_CON_B2_TSTMOD(n) (((n) << USB20_CON_B2_TSTMOD_SHIFT) & \ 85 + USB20_CON_B2_TSTMOD_MASK) 86 + #define USB20_CON_B2_TSTMOD_EN BIT(0) 87 + 88 + /* USB30_CON */ 89 + #define USB30_CON_POW_SEL_SHIFT 24 90 + #define USB30_CON_POW_SEL_MASK GENMASK(26, USB30_CON_POW_SEL_SHIFT) 91 + #define USB30_CON_POW_SEL_IN_U3 BIT(26) 92 + #define USB30_CON_POW_SEL_IN_DISCON 0 93 + #define USB30_CON_POW_SEL_P2_TO_P0 BIT(25) 94 + #define USB30_CON_POW_SEL_P0_TO_P3 BIT(24) 95 + #define USB30_CON_POW_SEL_P0_TO_P2 0 96 + #define USB30_CON_B3_PLLWAKE BIT(23) 97 + #define USB30_CON_B3_CONNECT BIT(17) 98 + #define USB30_CON_B3_HOTRST_CMP BIT(1) 99 + 100 + /* USB_STA */ 101 + #define USB_STA_SPEED_MASK (BIT(2) | BIT(1)) 102 + #define USB_STA_SPEED_HS BIT(2) 103 + #define USB_STA_SPEED_FS BIT(1) 104 + #define USB_STA_SPEED_SS 0 105 + #define USB_STA_VBUS_STA BIT(0) 106 + 107 + /* DRD_CON */ 108 + #define DRD_CON_PERI_CON BIT(24) 109 + 110 + /* USB_INT_ENA_1 and USB_INT_STA_1 */ 111 + #define USB_INT_1_B3_PLLWKUP BIT(31) 112 + #define USB_INT_1_B3_LUPSUCS BIT(30) 113 + #define USB_INT_1_B3_DISABLE BIT(27) 114 + #define USB_INT_1_B3_WRMRST BIT(21) 115 + #define USB_INT_1_B3_HOTRST BIT(20) 116 + #define USB_INT_1_B2_USBRST BIT(12) 117 + #define USB_INT_1_B2_L1SPND BIT(11) 118 + #define USB_INT_1_B2_SPND BIT(9) 119 + #define USB_INT_1_B2_RSUM BIT(8) 120 + #define USB_INT_1_SPEED BIT(1) 121 + #define USB_INT_1_VBUS_CNG BIT(0) 122 + 123 + /* USB_INT_ENA_2 and USB_INT_STA_2 */ 124 + #define USB_INT_2_PIPE(n) BIT(n) 125 + 126 + /* P0_MOD */ 127 + #define P0_MOD_DIR BIT(6) 128 + 129 + /* P0_CON and PN_CON */ 130 + #define PX_CON_BYTE_EN_MASK (BIT(10) | BIT(9)) 131 + #define PX_CON_BYTE_EN_SHIFT 9 132 + #define PX_CON_BYTE_EN_BYTES(n) (((n) << PX_CON_BYTE_EN_SHIFT) & \ 133 + PX_CON_BYTE_EN_MASK) 134 + #define PX_CON_SEND BIT(8) 135 + 136 + /* P0_CON */ 137 + #define P0_CON_ST_RES_MASK (BIT(27) | BIT(26)) 138 + #define P0_CON_ST_RES_FORCE_STALL BIT(27) 139 + #define P0_CON_ST_RES_NORMAL BIT(26) 140 + #define P0_CON_ST_RES_FORCE_NRDY 0 141 + #define P0_CON_OT_RES_MASK (BIT(25) | BIT(24)) 142 + #define P0_CON_OT_RES_FORCE_STALL BIT(25) 143 + #define P0_CON_OT_RES_NORMAL BIT(24) 144 + #define P0_CON_OT_RES_FORCE_NRDY 0 145 + #define P0_CON_IN_RES_MASK (BIT(17) | BIT(16)) 146 + #define P0_CON_IN_RES_FORCE_STALL BIT(17) 147 + #define P0_CON_IN_RES_NORMAL BIT(16) 148 + #define P0_CON_IN_RES_FORCE_NRDY 0 149 + #define P0_CON_RES_WEN BIT(7) 150 + #define P0_CON_BCLR BIT(1) 151 + 152 + /* P0_STA and PN_STA */ 153 + #define PX_STA_BUFSTS BIT(0) 154 + 155 + /* P0_INT_ENA and P0_INT_STA */ 156 + #define P0_INT_STSED BIT(18) 157 + #define P0_INT_STSST BIT(17) 158 + #define P0_INT_SETUP BIT(16) 159 + #define P0_INT_RCVNL BIT(8) 160 + #define P0_INT_ERDY BIT(7) 161 + #define P0_INT_FLOW BIT(6) 162 + #define P0_INT_STALL BIT(2) 163 + #define P0_INT_NRDY BIT(1) 164 + #define P0_INT_BFRDY BIT(0) 165 + #define P0_INT_ALL_BITS (P0_INT_STSED | P0_INT_SETUP | P0_INT_BFRDY) 166 + 167 + /* PN_MOD */ 168 + #define PN_MOD_DIR BIT(6) 169 + #define PN_MOD_TYPE_SHIFT 4 170 + #define PN_MOD_TYPE_MASK GENMASK(5, PN_MOD_TYPE_SHIFT) 171 + #define PN_MOD_TYPE(n) (((n) << PN_MOD_TYPE_SHIFT) & \ 172 + PN_MOD_TYPE_MASK) 173 + #define PN_MOD_EPNUM_MASK GENMASK(3, 0) 174 + #define PN_MOD_EPNUM(n) ((n) & PN_MOD_EPNUM_MASK) 175 + 176 + /* PN_RAMMAP */ 177 + #define PN_RAMMAP_RAMAREA_SHIFT 29 178 + #define PN_RAMMAP_RAMAREA_MASK GENMASK(31, PN_RAMMAP_RAMAREA_SHIFT) 179 + #define PN_RAMMAP_RAMAREA_16KB BIT(31) 180 + #define PN_RAMMAP_RAMAREA_8KB (BIT(30) | BIT(29)) 181 + #define PN_RAMMAP_RAMAREA_4KB BIT(30) 182 + #define PN_RAMMAP_RAMAREA_2KB BIT(29) 183 + #define PN_RAMMAP_RAMAREA_1KB 0 184 + #define PN_RAMMAP_MPKT_SHIFT 16 185 + #define PN_RAMMAP_MPKT_MASK GENMASK(26, PN_RAMMAP_MPKT_SHIFT) 186 + #define PN_RAMMAP_MPKT(n) (((n) << PN_RAMMAP_MPKT_SHIFT) & \ 187 + PN_RAMMAP_MPKT_MASK) 188 + #define PN_RAMMAP_RAMIF_SHIFT 14 189 + #define PN_RAMMAP_RAMIF_MASK GENMASK(15, PN_RAMMAP_RAMIF_SHIFT) 190 + #define PN_RAMMAP_RAMIF(n) (((n) << PN_RAMMAP_RAMIF_SHIFT) & \ 191 + PN_RAMMAP_RAMIF_MASK) 192 + #define PN_RAMMAP_BASEAD_MASK GENMASK(13, 0) 193 + #define PN_RAMMAP_BASEAD(offs) (((offs) >> 3) & PN_RAMMAP_BASEAD_MASK) 194 + #define PN_RAMMAP_DATA(area, ramif, basead) ((PN_RAMMAP_##area) | \ 195 + (PN_RAMMAP_RAMIF(ramif)) | \ 196 + (PN_RAMMAP_BASEAD(basead))) 197 + 198 + /* PN_CON */ 199 + #define PN_CON_EN BIT(31) 200 + #define PN_CON_DATAIF_EN BIT(30) 201 + #define PN_CON_RES_MASK (BIT(17) | BIT(16)) 202 + #define PN_CON_RES_FORCE_STALL BIT(17) 203 + #define PN_CON_RES_NORMAL BIT(16) 204 + #define PN_CON_RES_FORCE_NRDY 0 205 + #define PN_CON_LAST BIT(11) 206 + #define PN_CON_RES_WEN BIT(7) 207 + #define PN_CON_CLR BIT(0) 208 + 209 + /* PN_INT_STA and PN_INT_ENA */ 210 + #define PN_INT_LSTTR BIT(4) 211 + #define PN_INT_BFRDY BIT(0) 212 + 213 + /* USB3_SSIFCMD */ 214 + #define SSIFCMD_URES_U2 BIT(9) 215 + #define SSIFCMD_URES_U1 BIT(8) 216 + #define SSIFCMD_UDIR_U2 BIT(7) 217 + #define SSIFCMD_UDIR_U1 BIT(6) 218 + #define SSIFCMD_UREQ_U2 BIT(5) 219 + #define SSIFCMD_UREQ_U1 BIT(4) 220 + 221 + #define USB3_EP0_SS_MAX_PACKET_SIZE 512 222 + #define USB3_EP0_HSFS_MAX_PACKET_SIZE 64 223 + #define USB3_EP0_BUF_SIZE 8 224 + #define USB3_MAX_NUM_PIPES 30 225 + #define USB3_WAIT_US 3 226 + 227 + struct renesas_usb3; 228 + struct renesas_usb3_request { 229 + struct usb_request req; 230 + struct list_head queue; 231 + }; 232 + 233 + #define USB3_EP_NAME_SIZE 8 234 + struct renesas_usb3_ep { 235 + struct usb_ep ep; 236 + struct renesas_usb3 *usb3; 237 + int num; 238 + char ep_name[USB3_EP_NAME_SIZE]; 239 + struct list_head queue; 240 + u32 rammap_val; 241 + bool dir_in; 242 + bool halt; 243 + bool wedge; 244 + bool started; 245 + }; 246 + 247 + struct renesas_usb3_priv { 248 + int ramsize_per_ramif; /* unit = bytes */ 249 + int num_ramif; 250 + int ramsize_per_pipe; /* unit = bytes */ 251 + bool workaround_for_vbus; /* if true, don't check vbus signal */ 252 + }; 253 + 254 + struct renesas_usb3 { 255 + void __iomem *reg; 256 + 257 + struct usb_gadget gadget; 258 + struct usb_gadget_driver *driver; 259 + 260 + struct renesas_usb3_ep *usb3_ep; 261 + int num_usb3_eps; 262 + 263 + spinlock_t lock; 264 + int disabled_count; 265 + 266 + struct usb_request *ep0_req; 267 + u16 test_mode; 268 + u8 ep0_buf[USB3_EP0_BUF_SIZE]; 269 + bool softconnect; 270 + bool workaround_for_vbus; 271 + }; 272 + 273 + #define gadget_to_renesas_usb3(_gadget) \ 274 + container_of(_gadget, struct renesas_usb3, gadget) 275 + #define renesas_usb3_to_gadget(renesas_usb3) (&renesas_usb3->gadget) 276 + #define usb3_to_dev(_usb3) (_usb3->gadget.dev.parent) 277 + 278 + #define usb_ep_to_usb3_ep(_ep) container_of(_ep, struct renesas_usb3_ep, ep) 279 + #define usb3_ep_to_usb3(_usb3_ep) (_usb3_ep->usb3) 280 + #define usb_req_to_usb3_req(_req) container_of(_req, \ 281 + struct renesas_usb3_request, req) 282 + 283 + #define usb3_get_ep(usb3, n) ((usb3)->usb3_ep + (n)) 284 + #define usb3_for_each_ep(usb3_ep, usb3, i) \ 285 + for ((i) = 0, usb3_ep = usb3_get_ep(usb3, (i)); \ 286 + (i) < (usb3)->num_usb3_eps; \ 287 + (i)++, usb3_ep = usb3_get_ep(usb3, (i))) 288 + 289 + static const char udc_name[] = "renesas_usb3"; 290 + 291 + static void usb3_write(struct renesas_usb3 *usb3, u32 data, u32 offs) 292 + { 293 + iowrite32(data, usb3->reg + offs); 294 + } 295 + 296 + static u32 usb3_read(struct renesas_usb3 *usb3, u32 offs) 297 + { 298 + return ioread32(usb3->reg + offs); 299 + } 300 + 301 + static void usb3_set_bit(struct renesas_usb3 *usb3, u32 bits, u32 offs) 302 + { 303 + u32 val = usb3_read(usb3, offs); 304 + 305 + val |= bits; 306 + usb3_write(usb3, val, offs); 307 + } 308 + 309 + static void usb3_clear_bit(struct renesas_usb3 *usb3, u32 bits, u32 offs) 310 + { 311 + u32 val = usb3_read(usb3, offs); 312 + 313 + val &= ~bits; 314 + usb3_write(usb3, val, offs); 315 + } 316 + 317 + static int usb3_wait(struct renesas_usb3 *usb3, u32 reg, u32 mask, 318 + u32 expected) 319 + { 320 + int i; 321 + 322 + for (i = 0; i < USB3_WAIT_US; i++) { 323 + if ((usb3_read(usb3, reg) & mask) == expected) 324 + return 0; 325 + udelay(1); 326 + } 327 + 328 + dev_dbg(usb3_to_dev(usb3), "%s: timed out (%8x, %08x, %08x)\n", 329 + __func__, reg, mask, expected); 330 + 331 + return -EBUSY; 332 + } 333 + 334 + static void usb3_enable_irq_1(struct renesas_usb3 *usb3, u32 bits) 335 + { 336 + usb3_set_bit(usb3, bits, USB3_USB_INT_ENA_1); 337 + } 338 + 339 + static void usb3_disable_irq_1(struct renesas_usb3 *usb3, u32 bits) 340 + { 341 + usb3_clear_bit(usb3, bits, USB3_USB_INT_ENA_1); 342 + } 343 + 344 + static void usb3_enable_pipe_irq(struct renesas_usb3 *usb3, int num) 345 + { 346 + usb3_set_bit(usb3, USB_INT_2_PIPE(num), USB3_USB_INT_ENA_2); 347 + } 348 + 349 + static void usb3_disable_pipe_irq(struct renesas_usb3 *usb3, int num) 350 + { 351 + usb3_clear_bit(usb3, USB_INT_2_PIPE(num), USB3_USB_INT_ENA_2); 352 + } 353 + 354 + static void usb3_init_axi_bridge(struct renesas_usb3 *usb3) 355 + { 356 + /* Set AXI_INT */ 357 + usb3_write(usb3, ~0, USB3_DMA_INT_STA); 358 + usb3_write(usb3, 0, USB3_DMA_INT_ENA); 359 + usb3_set_bit(usb3, AXI_INT_DMAINT | AXI_INT_EPCINT, USB3_AXI_INT_ENA); 360 + } 361 + 362 + static void usb3_init_epc_registers(struct renesas_usb3 *usb3) 363 + { 364 + /* FIXME: How to change host / peripheral mode as well? */ 365 + usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); 366 + 367 + usb3_write(usb3, ~0, USB3_USB_INT_STA_1); 368 + usb3_enable_irq_1(usb3, USB_INT_1_VBUS_CNG); 369 + } 370 + 371 + static bool usb3_wakeup_usb2_phy(struct renesas_usb3 *usb3) 372 + { 373 + if (!(usb3_read(usb3, USB3_USB20_CON) & USB20_CON_B2_SUSPEND)) 374 + return true; /* already waked it up */ 375 + 376 + usb3_clear_bit(usb3, USB20_CON_B2_SUSPEND, USB3_USB20_CON); 377 + usb3_enable_irq_1(usb3, USB_INT_1_B2_RSUM); 378 + 379 + return false; 380 + } 381 + 382 + static void usb3_usb2_pullup(struct renesas_usb3 *usb3, int pullup) 383 + { 384 + u32 bits = USB20_CON_B2_PUE | USB20_CON_B2_CONNECT; 385 + 386 + if (usb3->softconnect && pullup) 387 + usb3_set_bit(usb3, bits, USB3_USB20_CON); 388 + else 389 + usb3_clear_bit(usb3, bits, USB3_USB20_CON); 390 + } 391 + 392 + static void usb3_set_test_mode(struct renesas_usb3 *usb3) 393 + { 394 + u32 val = usb3_read(usb3, USB3_USB20_CON); 395 + 396 + val &= ~USB20_CON_B2_TSTMOD_MASK; 397 + val |= USB20_CON_B2_TSTMOD(usb3->test_mode); 398 + usb3_write(usb3, val | USB20_CON_B2_TSTMOD_EN, USB3_USB20_CON); 399 + if (!usb3->test_mode) 400 + usb3_clear_bit(usb3, USB20_CON_B2_TSTMOD_EN, USB3_USB20_CON); 401 + } 402 + 403 + static void usb3_start_usb2_connection(struct renesas_usb3 *usb3) 404 + { 405 + usb3->disabled_count++; 406 + usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); 407 + usb3_set_bit(usb3, USB_COM_CON_SPD_MODE, USB3_USB_COM_CON); 408 + usb3_usb2_pullup(usb3, 1); 409 + } 410 + 411 + static int usb3_is_usb3_phy_in_u3(struct renesas_usb3 *usb3) 412 + { 413 + return usb3_read(usb3, USB3_USB30_CON) & USB30_CON_POW_SEL_IN_U3; 414 + } 415 + 416 + static bool usb3_wakeup_usb3_phy(struct renesas_usb3 *usb3) 417 + { 418 + if (!usb3_is_usb3_phy_in_u3(usb3)) 419 + return true; /* already waked it up */ 420 + 421 + usb3_set_bit(usb3, USB30_CON_B3_PLLWAKE, USB3_USB30_CON); 422 + usb3_enable_irq_1(usb3, USB_INT_1_B3_PLLWKUP); 423 + 424 + return false; 425 + } 426 + 427 + static u16 usb3_feature_get_un_enabled(struct renesas_usb3 *usb3) 428 + { 429 + u32 mask_u2 = SSIFCMD_UDIR_U2 | SSIFCMD_UREQ_U2; 430 + u32 mask_u1 = SSIFCMD_UDIR_U1 | SSIFCMD_UREQ_U1; 431 + u32 val = usb3_read(usb3, USB3_SSIFCMD); 432 + u16 ret = 0; 433 + 434 + /* Enables {U2,U1} if the bits of UDIR and UREQ are set to 0 */ 435 + if (!(val & mask_u2)) 436 + ret |= 1 << USB_DEV_STAT_U2_ENABLED; 437 + if (!(val & mask_u1)) 438 + ret |= 1 << USB_DEV_STAT_U1_ENABLED; 439 + 440 + return ret; 441 + } 442 + 443 + static void usb3_feature_u2_enable(struct renesas_usb3 *usb3, bool enable) 444 + { 445 + u32 bits = SSIFCMD_UDIR_U2 | SSIFCMD_UREQ_U2; 446 + 447 + /* Enables U2 if the bits of UDIR and UREQ are set to 0 */ 448 + if (enable) 449 + usb3_clear_bit(usb3, bits, USB3_SSIFCMD); 450 + else 451 + usb3_set_bit(usb3, bits, USB3_SSIFCMD); 452 + } 453 + 454 + static void usb3_feature_u1_enable(struct renesas_usb3 *usb3, bool enable) 455 + { 456 + u32 bits = SSIFCMD_UDIR_U1 | SSIFCMD_UREQ_U1; 457 + 458 + /* Enables U1 if the bits of UDIR and UREQ are set to 0 */ 459 + if (enable) 460 + usb3_clear_bit(usb3, bits, USB3_SSIFCMD); 461 + else 462 + usb3_set_bit(usb3, bits, USB3_SSIFCMD); 463 + } 464 + 465 + static void usb3_start_operation_for_usb3(struct renesas_usb3 *usb3) 466 + { 467 + usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); 468 + usb3_clear_bit(usb3, USB_COM_CON_SPD_MODE, USB3_USB_COM_CON); 469 + usb3_set_bit(usb3, USB30_CON_B3_CONNECT, USB3_USB30_CON); 470 + } 471 + 472 + static void usb3_start_usb3_connection(struct renesas_usb3 *usb3) 473 + { 474 + usb3_start_operation_for_usb3(usb3); 475 + usb3_set_bit(usb3, USB_COM_CON_RX_DETECTION, USB3_USB_COM_CON); 476 + 477 + usb3_enable_irq_1(usb3, USB_INT_1_B3_LUPSUCS | USB_INT_1_B3_DISABLE | 478 + USB_INT_1_SPEED); 479 + } 480 + 481 + static void usb3_stop_usb3_connection(struct renesas_usb3 *usb3) 482 + { 483 + usb3_clear_bit(usb3, USB30_CON_B3_CONNECT, USB3_USB30_CON); 484 + } 485 + 486 + static void usb3_transition_to_default_state(struct renesas_usb3 *usb3, 487 + bool is_usb3) 488 + { 489 + usb3_set_bit(usb3, USB_INT_2_PIPE(0), USB3_USB_INT_ENA_2); 490 + usb3_write(usb3, P0_INT_ALL_BITS, USB3_P0_INT_STA); 491 + usb3_set_bit(usb3, P0_INT_ALL_BITS, USB3_P0_INT_ENA); 492 + 493 + if (is_usb3) 494 + usb3_enable_irq_1(usb3, USB_INT_1_B3_WRMRST | 495 + USB_INT_1_B3_HOTRST); 496 + else 497 + usb3_enable_irq_1(usb3, USB_INT_1_B2_SPND | 498 + USB_INT_1_B2_L1SPND | USB_INT_1_B2_USBRST); 499 + } 500 + 501 + static void usb3_connect(struct renesas_usb3 *usb3) 502 + { 503 + if (usb3_wakeup_usb3_phy(usb3)) 504 + usb3_start_usb3_connection(usb3); 505 + } 506 + 507 + static void usb3_reset_epc(struct renesas_usb3 *usb3) 508 + { 509 + usb3_clear_bit(usb3, USB_COM_CON_CONF, USB3_USB_COM_CON); 510 + usb3_clear_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); 511 + usb3_set_bit(usb3, USB_COM_CON_PIPE_CLR, USB3_USB_COM_CON); 512 + usb3->test_mode = 0; 513 + usb3_set_test_mode(usb3); 514 + } 515 + 516 + static void usb3_disconnect(struct renesas_usb3 *usb3) 517 + { 518 + usb3->disabled_count = 0; 519 + usb3_usb2_pullup(usb3, 0); 520 + usb3_clear_bit(usb3, USB30_CON_B3_CONNECT, USB3_USB30_CON); 521 + usb3_reset_epc(usb3); 522 + 523 + if (usb3->driver) 524 + usb3->driver->disconnect(&usb3->gadget); 525 + } 526 + 527 + static void usb3_check_vbus(struct renesas_usb3 *usb3) 528 + { 529 + if (usb3->workaround_for_vbus) { 530 + usb3_connect(usb3); 531 + } else { 532 + if (usb3_read(usb3, USB3_USB_STA) & USB_STA_VBUS_STA) 533 + usb3_connect(usb3); 534 + else 535 + usb3_disconnect(usb3); 536 + } 537 + } 538 + 539 + static void renesas_usb3_init_controller(struct renesas_usb3 *usb3) 540 + { 541 + usb3_init_axi_bridge(usb3); 542 + usb3_init_epc_registers(usb3); 543 + 544 + usb3_check_vbus(usb3); 545 + } 546 + 547 + static void renesas_usb3_stop_controller(struct renesas_usb3 *usb3) 548 + { 549 + usb3_disconnect(usb3); 550 + usb3_write(usb3, 0, USB3_P0_INT_ENA); 551 + usb3_write(usb3, 0, USB3_PN_INT_ENA); 552 + usb3_write(usb3, 0, USB3_USB_INT_ENA_1); 553 + usb3_write(usb3, 0, USB3_USB_INT_ENA_2); 554 + usb3_write(usb3, 0, USB3_AXI_INT_ENA); 555 + } 556 + 557 + static void usb3_irq_epc_int_1_pll_wakeup(struct renesas_usb3 *usb3) 558 + { 559 + usb3_disable_irq_1(usb3, USB_INT_1_B3_PLLWKUP); 560 + usb3_clear_bit(usb3, USB30_CON_B3_PLLWAKE, USB3_USB30_CON); 561 + usb3_start_usb3_connection(usb3); 562 + } 563 + 564 + static void usb3_irq_epc_int_1_linkup_success(struct renesas_usb3 *usb3) 565 + { 566 + usb3_transition_to_default_state(usb3, true); 567 + } 568 + 569 + static void usb3_irq_epc_int_1_resume(struct renesas_usb3 *usb3) 570 + { 571 + usb3_disable_irq_1(usb3, USB_INT_1_B2_RSUM); 572 + usb3_start_usb2_connection(usb3); 573 + usb3_transition_to_default_state(usb3, false); 574 + } 575 + 576 + static void usb3_irq_epc_int_1_disable(struct renesas_usb3 *usb3) 577 + { 578 + usb3_stop_usb3_connection(usb3); 579 + if (usb3_wakeup_usb2_phy(usb3)) 580 + usb3_irq_epc_int_1_resume(usb3); 581 + } 582 + 583 + static void usb3_irq_epc_int_1_bus_reset(struct renesas_usb3 *usb3) 584 + { 585 + usb3_reset_epc(usb3); 586 + if (usb3->disabled_count < 3) 587 + usb3_start_usb3_connection(usb3); 588 + else 589 + usb3_start_usb2_connection(usb3); 590 + } 591 + 592 + static void usb3_irq_epc_int_1_vbus_change(struct renesas_usb3 *usb3) 593 + { 594 + usb3_check_vbus(usb3); 595 + } 596 + 597 + static void usb3_irq_epc_int_1_hot_reset(struct renesas_usb3 *usb3) 598 + { 599 + usb3_reset_epc(usb3); 600 + usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); 601 + 602 + /* This bit shall be set within 12ms from the start of HotReset */ 603 + usb3_set_bit(usb3, USB30_CON_B3_HOTRST_CMP, USB3_USB30_CON); 604 + } 605 + 606 + static void usb3_irq_epc_int_1_warm_reset(struct renesas_usb3 *usb3) 607 + { 608 + usb3_reset_epc(usb3); 609 + usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); 610 + 611 + usb3_start_operation_for_usb3(usb3); 612 + usb3_enable_irq_1(usb3, USB_INT_1_SPEED); 613 + } 614 + 615 + static void usb3_irq_epc_int_1_speed(struct renesas_usb3 *usb3) 616 + { 617 + u32 speed = usb3_read(usb3, USB3_USB_STA) & USB_STA_SPEED_MASK; 618 + 619 + switch (speed) { 620 + case USB_STA_SPEED_SS: 621 + usb3->gadget.speed = USB_SPEED_SUPER; 622 + break; 623 + case USB_STA_SPEED_HS: 624 + usb3->gadget.speed = USB_SPEED_HIGH; 625 + break; 626 + case USB_STA_SPEED_FS: 627 + usb3->gadget.speed = USB_SPEED_FULL; 628 + break; 629 + default: 630 + usb3->gadget.speed = USB_SPEED_UNKNOWN; 631 + break; 632 + } 633 + } 634 + 635 + static void usb3_irq_epc_int_1(struct renesas_usb3 *usb3, u32 int_sta_1) 636 + { 637 + if (int_sta_1 & USB_INT_1_B3_PLLWKUP) 638 + usb3_irq_epc_int_1_pll_wakeup(usb3); 639 + 640 + if (int_sta_1 & USB_INT_1_B3_LUPSUCS) 641 + usb3_irq_epc_int_1_linkup_success(usb3); 642 + 643 + if (int_sta_1 & USB_INT_1_B3_HOTRST) 644 + usb3_irq_epc_int_1_hot_reset(usb3); 645 + 646 + if (int_sta_1 & USB_INT_1_B3_WRMRST) 647 + usb3_irq_epc_int_1_warm_reset(usb3); 648 + 649 + if (int_sta_1 & USB_INT_1_B3_DISABLE) 650 + usb3_irq_epc_int_1_disable(usb3); 651 + 652 + if (int_sta_1 & USB_INT_1_B2_USBRST) 653 + usb3_irq_epc_int_1_bus_reset(usb3); 654 + 655 + if (int_sta_1 & USB_INT_1_B2_RSUM) 656 + usb3_irq_epc_int_1_resume(usb3); 657 + 658 + if (int_sta_1 & USB_INT_1_SPEED) 659 + usb3_irq_epc_int_1_speed(usb3); 660 + 661 + if (int_sta_1 & USB_INT_1_VBUS_CNG) 662 + usb3_irq_epc_int_1_vbus_change(usb3); 663 + } 664 + 665 + static struct renesas_usb3_request *__usb3_get_request(struct renesas_usb3_ep 666 + *usb3_ep) 667 + { 668 + return list_first_entry_or_null(&usb3_ep->queue, 669 + struct renesas_usb3_request, queue); 670 + } 671 + 672 + static struct renesas_usb3_request *usb3_get_request(struct renesas_usb3_ep 673 + *usb3_ep) 674 + { 675 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 676 + struct renesas_usb3_request *usb3_req; 677 + unsigned long flags; 678 + 679 + spin_lock_irqsave(&usb3->lock, flags); 680 + usb3_req = __usb3_get_request(usb3_ep); 681 + spin_unlock_irqrestore(&usb3->lock, flags); 682 + 683 + return usb3_req; 684 + } 685 + 686 + static void usb3_request_done(struct renesas_usb3_ep *usb3_ep, 687 + struct renesas_usb3_request *usb3_req, int status) 688 + { 689 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 690 + unsigned long flags; 691 + 692 + dev_dbg(usb3_to_dev(usb3), "giveback: ep%2d, %u, %u, %d\n", 693 + usb3_ep->num, usb3_req->req.length, usb3_req->req.actual, 694 + status); 695 + usb3_req->req.status = status; 696 + spin_lock_irqsave(&usb3->lock, flags); 697 + usb3_ep->started = false; 698 + list_del_init(&usb3_req->queue); 699 + spin_unlock_irqrestore(&usb3->lock, flags); 700 + usb_gadget_giveback_request(&usb3_ep->ep, &usb3_req->req); 701 + } 702 + 703 + static void usb3_irq_epc_pipe0_status_end(struct renesas_usb3 *usb3) 704 + { 705 + struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); 706 + struct renesas_usb3_request *usb3_req = usb3_get_request(usb3_ep); 707 + 708 + if (usb3_req) 709 + usb3_request_done(usb3_ep, usb3_req, 0); 710 + if (usb3->test_mode) 711 + usb3_set_test_mode(usb3); 712 + } 713 + 714 + static void usb3_get_setup_data(struct renesas_usb3 *usb3, 715 + struct usb_ctrlrequest *ctrl) 716 + { 717 + struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); 718 + u32 *data = (u32 *)ctrl; 719 + 720 + *data++ = usb3_read(usb3, USB3_STUP_DAT_0); 721 + *data = usb3_read(usb3, USB3_STUP_DAT_1); 722 + 723 + /* update this driver's flag */ 724 + usb3_ep->dir_in = !!(ctrl->bRequestType & USB_DIR_IN); 725 + } 726 + 727 + static void usb3_set_p0_con_update_res(struct renesas_usb3 *usb3, u32 res) 728 + { 729 + u32 val = usb3_read(usb3, USB3_P0_CON); 730 + 731 + val &= ~(P0_CON_ST_RES_MASK | P0_CON_OT_RES_MASK | P0_CON_IN_RES_MASK); 732 + val |= res | P0_CON_RES_WEN; 733 + usb3_write(usb3, val, USB3_P0_CON); 734 + } 735 + 736 + static void usb3_set_p0_con_for_ctrl_read_data(struct renesas_usb3 *usb3) 737 + { 738 + usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_NRDY | 739 + P0_CON_OT_RES_FORCE_STALL | 740 + P0_CON_IN_RES_NORMAL); 741 + } 742 + 743 + static void usb3_set_p0_con_for_ctrl_read_status(struct renesas_usb3 *usb3) 744 + { 745 + usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_NORMAL | 746 + P0_CON_OT_RES_FORCE_STALL | 747 + P0_CON_IN_RES_NORMAL); 748 + } 749 + 750 + static void usb3_set_p0_con_for_ctrl_write_data(struct renesas_usb3 *usb3) 751 + { 752 + usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_NRDY | 753 + P0_CON_OT_RES_NORMAL | 754 + P0_CON_IN_RES_FORCE_STALL); 755 + } 756 + 757 + static void usb3_set_p0_con_for_ctrl_write_status(struct renesas_usb3 *usb3) 758 + { 759 + usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_NORMAL | 760 + P0_CON_OT_RES_NORMAL | 761 + P0_CON_IN_RES_FORCE_STALL); 762 + } 763 + 764 + static void usb3_set_p0_con_for_no_data(struct renesas_usb3 *usb3) 765 + { 766 + usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_NORMAL | 767 + P0_CON_OT_RES_FORCE_STALL | 768 + P0_CON_IN_RES_FORCE_STALL); 769 + } 770 + 771 + static void usb3_set_p0_con_stall(struct renesas_usb3 *usb3) 772 + { 773 + usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_STALL | 774 + P0_CON_OT_RES_FORCE_STALL | 775 + P0_CON_IN_RES_FORCE_STALL); 776 + } 777 + 778 + static void usb3_set_p0_con_stop(struct renesas_usb3 *usb3) 779 + { 780 + usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_NRDY | 781 + P0_CON_OT_RES_FORCE_NRDY | 782 + P0_CON_IN_RES_FORCE_NRDY); 783 + } 784 + 785 + static int usb3_pn_change(struct renesas_usb3 *usb3, int num) 786 + { 787 + if (num == 0 || num > usb3->num_usb3_eps) 788 + return -ENXIO; 789 + 790 + usb3_write(usb3, num, USB3_PIPE_COM); 791 + 792 + return 0; 793 + } 794 + 795 + static void usb3_set_pn_con_update_res(struct renesas_usb3 *usb3, u32 res) 796 + { 797 + u32 val = usb3_read(usb3, USB3_PN_CON); 798 + 799 + val &= ~PN_CON_RES_MASK; 800 + val |= res & PN_CON_RES_MASK; 801 + val |= PN_CON_RES_WEN; 802 + usb3_write(usb3, val, USB3_PN_CON); 803 + } 804 + 805 + static void usb3_pn_start(struct renesas_usb3 *usb3) 806 + { 807 + usb3_set_pn_con_update_res(usb3, PN_CON_RES_NORMAL); 808 + } 809 + 810 + static void usb3_pn_stop(struct renesas_usb3 *usb3) 811 + { 812 + usb3_set_pn_con_update_res(usb3, PN_CON_RES_FORCE_NRDY); 813 + } 814 + 815 + static void usb3_pn_stall(struct renesas_usb3 *usb3) 816 + { 817 + usb3_set_pn_con_update_res(usb3, PN_CON_RES_FORCE_STALL); 818 + } 819 + 820 + static int usb3_pn_con_clear(struct renesas_usb3 *usb3) 821 + { 822 + usb3_set_bit(usb3, PN_CON_CLR, USB3_PN_CON); 823 + 824 + return usb3_wait(usb3, USB3_PN_CON, PN_CON_CLR, 0); 825 + } 826 + 827 + static bool usb3_is_transfer_complete(struct renesas_usb3_ep *usb3_ep, 828 + struct renesas_usb3_request *usb3_req) 829 + { 830 + struct usb_request *req = &usb3_req->req; 831 + 832 + if ((!req->zero && req->actual == req->length) || 833 + (req->actual % usb3_ep->ep.maxpacket) || (req->length == 0)) 834 + return true; 835 + else 836 + return false; 837 + } 838 + 839 + static int usb3_wait_pipe_status(struct renesas_usb3_ep *usb3_ep, u32 mask) 840 + { 841 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 842 + u32 sta_reg = usb3_ep->num ? USB3_PN_STA : USB3_P0_STA; 843 + 844 + return usb3_wait(usb3, sta_reg, mask, mask); 845 + } 846 + 847 + static void usb3_set_px_con_send(struct renesas_usb3_ep *usb3_ep, int bytes, 848 + bool last) 849 + { 850 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 851 + u32 con_reg = usb3_ep->num ? USB3_PN_CON : USB3_P0_CON; 852 + u32 val = usb3_read(usb3, con_reg); 853 + 854 + val |= PX_CON_SEND | PX_CON_BYTE_EN_BYTES(bytes); 855 + val |= (usb3_ep->num && last) ? PN_CON_LAST : 0; 856 + usb3_write(usb3, val, con_reg); 857 + } 858 + 859 + static int usb3_write_pipe(struct renesas_usb3_ep *usb3_ep, 860 + struct renesas_usb3_request *usb3_req, 861 + u32 fifo_reg) 862 + { 863 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 864 + int i; 865 + int len = min_t(unsigned, usb3_req->req.length - usb3_req->req.actual, 866 + usb3_ep->ep.maxpacket); 867 + u8 *buf = usb3_req->req.buf + usb3_req->req.actual; 868 + u32 tmp = 0; 869 + bool is_last; 870 + 871 + if (usb3_wait_pipe_status(usb3_ep, PX_STA_BUFSTS) < 0) 872 + return -EBUSY; 873 + 874 + /* Update gadget driver parameter */ 875 + usb3_req->req.actual += len; 876 + 877 + /* Write data to the register */ 878 + if (len >= 4) { 879 + iowrite32_rep(usb3->reg + fifo_reg, buf, len / 4); 880 + buf += (len / 4) * 4; 881 + len %= 4; /* update len to use usb3_set_pX_con_send() */ 882 + } 883 + 884 + if (len) { 885 + for (i = 0; i < len; i++) 886 + tmp |= buf[i] << (8 * i); 887 + usb3_write(usb3, tmp, fifo_reg); 888 + } 889 + 890 + is_last = usb3_is_transfer_complete(usb3_ep, usb3_req); 891 + /* Send the data */ 892 + usb3_set_px_con_send(usb3_ep, len, is_last); 893 + 894 + return is_last ? 0 : -EAGAIN; 895 + } 896 + 897 + static u32 usb3_get_received_length(struct renesas_usb3_ep *usb3_ep) 898 + { 899 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 900 + u32 lng_reg = usb3_ep->num ? USB3_PN_LNG : USB3_P0_LNG; 901 + 902 + return usb3_read(usb3, lng_reg); 903 + } 904 + 905 + static int usb3_read_pipe(struct renesas_usb3_ep *usb3_ep, 906 + struct renesas_usb3_request *usb3_req, u32 fifo_reg) 907 + { 908 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 909 + int i; 910 + int len = min_t(unsigned, usb3_req->req.length - usb3_req->req.actual, 911 + usb3_get_received_length(usb3_ep)); 912 + u8 *buf = usb3_req->req.buf + usb3_req->req.actual; 913 + u32 tmp = 0; 914 + 915 + if (!len) 916 + return 0; 917 + 918 + /* Update gadget driver parameter */ 919 + usb3_req->req.actual += len; 920 + 921 + /* Read data from the register */ 922 + if (len >= 4) { 923 + ioread32_rep(usb3->reg + fifo_reg, buf, len / 4); 924 + buf += (len / 4) * 4; 925 + len %= 4; 926 + } 927 + 928 + if (len) { 929 + tmp = usb3_read(usb3, fifo_reg); 930 + for (i = 0; i < len; i++) 931 + buf[i] = (tmp >> (8 * i)) & 0xff; 932 + } 933 + 934 + return usb3_is_transfer_complete(usb3_ep, usb3_req) ? 0 : -EAGAIN; 935 + } 936 + 937 + static void usb3_set_status_stage(struct renesas_usb3_ep *usb3_ep, 938 + struct renesas_usb3_request *usb3_req) 939 + { 940 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 941 + 942 + if (usb3_ep->dir_in) { 943 + usb3_set_p0_con_for_ctrl_read_status(usb3); 944 + } else { 945 + if (!usb3_req->req.length) 946 + usb3_set_p0_con_for_no_data(usb3); 947 + else 948 + usb3_set_p0_con_for_ctrl_write_status(usb3); 949 + } 950 + } 951 + 952 + static void usb3_p0_xfer(struct renesas_usb3_ep *usb3_ep, 953 + struct renesas_usb3_request *usb3_req) 954 + { 955 + int ret = -EAGAIN; 956 + 957 + if (usb3_ep->dir_in) 958 + ret = usb3_write_pipe(usb3_ep, usb3_req, USB3_P0_WRITE); 959 + else 960 + ret = usb3_read_pipe(usb3_ep, usb3_req, USB3_P0_READ); 961 + 962 + if (!ret) 963 + usb3_set_status_stage(usb3_ep, usb3_req); 964 + } 965 + 966 + static void usb3_start_pipe0(struct renesas_usb3_ep *usb3_ep, 967 + struct renesas_usb3_request *usb3_req) 968 + { 969 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 970 + 971 + if (usb3_ep->started) 972 + return; 973 + 974 + usb3_ep->started = true; 975 + 976 + if (usb3_ep->dir_in) { 977 + usb3_set_bit(usb3, P0_MOD_DIR, USB3_P0_MOD); 978 + usb3_set_p0_con_for_ctrl_read_data(usb3); 979 + } else { 980 + usb3_clear_bit(usb3, P0_MOD_DIR, USB3_P0_MOD); 981 + usb3_set_p0_con_for_ctrl_write_data(usb3); 982 + } 983 + 984 + usb3_p0_xfer(usb3_ep, usb3_req); 985 + } 986 + 987 + static void usb3_start_pipen(struct renesas_usb3_ep *usb3_ep, 988 + struct renesas_usb3_request *usb3_req) 989 + { 990 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 991 + struct renesas_usb3_request *usb3_req_first = usb3_get_request(usb3_ep); 992 + unsigned long flags; 993 + int ret = -EAGAIN; 994 + u32 enable_bits = 0; 995 + 996 + if (usb3_ep->halt || usb3_ep->started) 997 + return; 998 + if (usb3_req != usb3_req_first) 999 + return; 1000 + 1001 + spin_lock_irqsave(&usb3->lock, flags); 1002 + if (usb3_pn_change(usb3, usb3_ep->num) < 0) 1003 + goto out; 1004 + 1005 + usb3_ep->started = true; 1006 + usb3_pn_start(usb3); 1007 + 1008 + if (usb3_ep->dir_in) { 1009 + ret = usb3_write_pipe(usb3_ep, usb3_req, USB3_PN_WRITE); 1010 + enable_bits |= PN_INT_LSTTR; 1011 + } 1012 + 1013 + if (ret < 0) 1014 + enable_bits |= PN_INT_BFRDY; 1015 + 1016 + if (enable_bits) { 1017 + usb3_set_bit(usb3, enable_bits, USB3_PN_INT_ENA); 1018 + usb3_enable_pipe_irq(usb3, usb3_ep->num); 1019 + } 1020 + out: 1021 + spin_unlock_irqrestore(&usb3->lock, flags); 1022 + } 1023 + 1024 + static int renesas_usb3_ep_queue(struct usb_ep *_ep, struct usb_request *_req, 1025 + gfp_t gfp_flags) 1026 + { 1027 + struct renesas_usb3_ep *usb3_ep = usb_ep_to_usb3_ep(_ep); 1028 + struct renesas_usb3_request *usb3_req = usb_req_to_usb3_req(_req); 1029 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 1030 + unsigned long flags; 1031 + 1032 + dev_dbg(usb3_to_dev(usb3), "ep_queue: ep%2d, %u\n", usb3_ep->num, 1033 + _req->length); 1034 + 1035 + _req->status = -EINPROGRESS; 1036 + _req->actual = 0; 1037 + spin_lock_irqsave(&usb3->lock, flags); 1038 + list_add_tail(&usb3_req->queue, &usb3_ep->queue); 1039 + spin_unlock_irqrestore(&usb3->lock, flags); 1040 + 1041 + if (!usb3_ep->num) 1042 + usb3_start_pipe0(usb3_ep, usb3_req); 1043 + else 1044 + usb3_start_pipen(usb3_ep, usb3_req); 1045 + 1046 + return 0; 1047 + } 1048 + 1049 + static void usb3_set_device_address(struct renesas_usb3 *usb3, u16 addr) 1050 + { 1051 + /* DEV_ADDR bit field is cleared by WarmReset, HotReset and BusReset */ 1052 + usb3_set_bit(usb3, USB_COM_CON_DEV_ADDR(addr), USB3_USB_COM_CON); 1053 + } 1054 + 1055 + static bool usb3_std_req_set_address(struct renesas_usb3 *usb3, 1056 + struct usb_ctrlrequest *ctrl) 1057 + { 1058 + if (ctrl->wValue >= 128) 1059 + return true; /* stall */ 1060 + 1061 + usb3_set_device_address(usb3, ctrl->wValue); 1062 + usb3_set_p0_con_for_no_data(usb3); 1063 + 1064 + return false; 1065 + } 1066 + 1067 + static void usb3_pipe0_internal_xfer(struct renesas_usb3 *usb3, 1068 + void *tx_data, size_t len, 1069 + void (*complete)(struct usb_ep *ep, 1070 + struct usb_request *req)) 1071 + { 1072 + struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); 1073 + 1074 + if (tx_data) 1075 + memcpy(usb3->ep0_buf, tx_data, 1076 + min_t(size_t, len, USB3_EP0_BUF_SIZE)); 1077 + 1078 + usb3->ep0_req->buf = &usb3->ep0_buf; 1079 + usb3->ep0_req->length = len; 1080 + usb3->ep0_req->complete = complete; 1081 + renesas_usb3_ep_queue(&usb3_ep->ep, usb3->ep0_req, GFP_ATOMIC); 1082 + } 1083 + 1084 + static void usb3_pipe0_get_status_completion(struct usb_ep *ep, 1085 + struct usb_request *req) 1086 + { 1087 + } 1088 + 1089 + static bool usb3_std_req_get_status(struct renesas_usb3 *usb3, 1090 + struct usb_ctrlrequest *ctrl) 1091 + { 1092 + bool stall = false; 1093 + struct renesas_usb3_ep *usb3_ep; 1094 + int num; 1095 + u16 status = 0; 1096 + 1097 + switch (ctrl->bRequestType & USB_RECIP_MASK) { 1098 + case USB_RECIP_DEVICE: 1099 + if (usb3->gadget.is_selfpowered) 1100 + status |= 1 << USB_DEVICE_SELF_POWERED; 1101 + if (usb3->gadget.speed == USB_SPEED_SUPER) 1102 + status |= usb3_feature_get_un_enabled(usb3); 1103 + break; 1104 + case USB_RECIP_INTERFACE: 1105 + break; 1106 + case USB_RECIP_ENDPOINT: 1107 + num = le16_to_cpu(ctrl->wIndex) & USB_ENDPOINT_NUMBER_MASK; 1108 + usb3_ep = usb3_get_ep(usb3, num); 1109 + if (usb3_ep->halt) 1110 + status |= 1 << USB_ENDPOINT_HALT; 1111 + break; 1112 + default: 1113 + stall = true; 1114 + break; 1115 + } 1116 + 1117 + if (!stall) { 1118 + status = cpu_to_le16(status); 1119 + dev_dbg(usb3_to_dev(usb3), "get_status: req = %p\n", 1120 + usb_req_to_usb3_req(usb3->ep0_req)); 1121 + usb3_pipe0_internal_xfer(usb3, &status, sizeof(status), 1122 + usb3_pipe0_get_status_completion); 1123 + } 1124 + 1125 + return stall; 1126 + } 1127 + 1128 + static bool usb3_std_req_feature_device(struct renesas_usb3 *usb3, 1129 + struct usb_ctrlrequest *ctrl, bool set) 1130 + { 1131 + bool stall = true; 1132 + u16 w_value = le16_to_cpu(ctrl->wValue); 1133 + 1134 + switch (w_value) { 1135 + case USB_DEVICE_TEST_MODE: 1136 + if (!set) 1137 + break; 1138 + usb3->test_mode = le16_to_cpu(ctrl->wIndex) >> 8; 1139 + stall = false; 1140 + break; 1141 + case USB_DEVICE_U1_ENABLE: 1142 + case USB_DEVICE_U2_ENABLE: 1143 + if (usb3->gadget.speed != USB_SPEED_SUPER) 1144 + break; 1145 + if (w_value == USB_DEVICE_U1_ENABLE) 1146 + usb3_feature_u1_enable(usb3, set); 1147 + if (w_value == USB_DEVICE_U2_ENABLE) 1148 + usb3_feature_u2_enable(usb3, set); 1149 + stall = false; 1150 + break; 1151 + default: 1152 + break; 1153 + } 1154 + 1155 + return stall; 1156 + } 1157 + 1158 + static int usb3_set_halt_p0(struct renesas_usb3_ep *usb3_ep, bool halt) 1159 + { 1160 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 1161 + 1162 + if (unlikely(usb3_ep->num)) 1163 + return -EINVAL; 1164 + 1165 + usb3_ep->halt = halt; 1166 + if (halt) 1167 + usb3_set_p0_con_stall(usb3); 1168 + else 1169 + usb3_set_p0_con_stop(usb3); 1170 + 1171 + return 0; 1172 + } 1173 + 1174 + static int usb3_set_halt_pn(struct renesas_usb3_ep *usb3_ep, bool halt, 1175 + bool is_clear_feature) 1176 + { 1177 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 1178 + unsigned long flags; 1179 + 1180 + spin_lock_irqsave(&usb3->lock, flags); 1181 + if (!usb3_pn_change(usb3, usb3_ep->num)) { 1182 + usb3_ep->halt = halt; 1183 + if (halt) { 1184 + usb3_pn_stall(usb3); 1185 + } else if (!is_clear_feature || !usb3_ep->wedge) { 1186 + usb3_pn_con_clear(usb3); 1187 + usb3_set_bit(usb3, PN_CON_EN, USB3_PN_CON); 1188 + usb3_pn_stop(usb3); 1189 + } 1190 + } 1191 + spin_unlock_irqrestore(&usb3->lock, flags); 1192 + 1193 + return 0; 1194 + } 1195 + 1196 + static int usb3_set_halt(struct renesas_usb3_ep *usb3_ep, bool halt, 1197 + bool is_clear_feature) 1198 + { 1199 + int ret = 0; 1200 + 1201 + if (halt && usb3_ep->started) 1202 + return -EAGAIN; 1203 + 1204 + if (usb3_ep->num) 1205 + ret = usb3_set_halt_pn(usb3_ep, halt, is_clear_feature); 1206 + else 1207 + ret = usb3_set_halt_p0(usb3_ep, halt); 1208 + 1209 + return ret; 1210 + } 1211 + 1212 + static bool usb3_std_req_feature_endpoint(struct renesas_usb3 *usb3, 1213 + struct usb_ctrlrequest *ctrl, 1214 + bool set) 1215 + { 1216 + int num = le16_to_cpu(ctrl->wIndex) & USB_ENDPOINT_NUMBER_MASK; 1217 + struct renesas_usb3_ep *usb3_ep; 1218 + struct renesas_usb3_request *usb3_req; 1219 + 1220 + if (le16_to_cpu(ctrl->wValue) != USB_ENDPOINT_HALT) 1221 + return true; /* stall */ 1222 + 1223 + usb3_ep = usb3_get_ep(usb3, num); 1224 + usb3_set_halt(usb3_ep, set, true); 1225 + 1226 + /* Restarts a queue if clear feature */ 1227 + if (!set) { 1228 + usb3_ep->started = false; 1229 + usb3_req = usb3_get_request(usb3_ep); 1230 + if (usb3_req) 1231 + usb3_start_pipen(usb3_ep, usb3_req); 1232 + } 1233 + 1234 + return false; 1235 + } 1236 + 1237 + static bool usb3_std_req_feature(struct renesas_usb3 *usb3, 1238 + struct usb_ctrlrequest *ctrl, bool set) 1239 + { 1240 + bool stall = false; 1241 + 1242 + switch (ctrl->bRequestType & USB_RECIP_MASK) { 1243 + case USB_RECIP_DEVICE: 1244 + stall = usb3_std_req_feature_device(usb3, ctrl, set); 1245 + break; 1246 + case USB_RECIP_INTERFACE: 1247 + break; 1248 + case USB_RECIP_ENDPOINT: 1249 + stall = usb3_std_req_feature_endpoint(usb3, ctrl, set); 1250 + break; 1251 + default: 1252 + stall = true; 1253 + break; 1254 + } 1255 + 1256 + if (!stall) 1257 + usb3_set_p0_con_for_no_data(usb3); 1258 + 1259 + return stall; 1260 + } 1261 + 1262 + static void usb3_pipe0_set_sel_completion(struct usb_ep *ep, 1263 + struct usb_request *req) 1264 + { 1265 + /* TODO */ 1266 + } 1267 + 1268 + static bool usb3_std_req_set_sel(struct renesas_usb3 *usb3, 1269 + struct usb_ctrlrequest *ctrl) 1270 + { 1271 + u16 w_length = le16_to_cpu(ctrl->wLength); 1272 + 1273 + if (w_length != 6) 1274 + return true; /* stall */ 1275 + 1276 + dev_dbg(usb3_to_dev(usb3), "set_sel: req = %p\n", 1277 + usb_req_to_usb3_req(usb3->ep0_req)); 1278 + usb3_pipe0_internal_xfer(usb3, NULL, 6, usb3_pipe0_set_sel_completion); 1279 + 1280 + return false; 1281 + } 1282 + 1283 + static bool usb3_std_req_set_configuration(struct renesas_usb3 *usb3, 1284 + struct usb_ctrlrequest *ctrl) 1285 + { 1286 + if (ctrl->wValue > 0) 1287 + usb3_set_bit(usb3, USB_COM_CON_CONF, USB3_USB_COM_CON); 1288 + else 1289 + usb3_clear_bit(usb3, USB_COM_CON_CONF, USB3_USB_COM_CON); 1290 + 1291 + return false; 1292 + } 1293 + 1294 + /** 1295 + * usb3_handle_standard_request - handle some standard requests 1296 + * @usb3: the renesas_usb3 pointer 1297 + * @ctrl: a pointer of setup data 1298 + * 1299 + * Returns true if this function handled a standard request 1300 + */ 1301 + static bool usb3_handle_standard_request(struct renesas_usb3 *usb3, 1302 + struct usb_ctrlrequest *ctrl) 1303 + { 1304 + bool ret = false; 1305 + bool stall = false; 1306 + 1307 + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { 1308 + switch (ctrl->bRequest) { 1309 + case USB_REQ_SET_ADDRESS: 1310 + stall = usb3_std_req_set_address(usb3, ctrl); 1311 + ret = true; 1312 + break; 1313 + case USB_REQ_GET_STATUS: 1314 + stall = usb3_std_req_get_status(usb3, ctrl); 1315 + ret = true; 1316 + break; 1317 + case USB_REQ_CLEAR_FEATURE: 1318 + stall = usb3_std_req_feature(usb3, ctrl, false); 1319 + ret = true; 1320 + break; 1321 + case USB_REQ_SET_FEATURE: 1322 + stall = usb3_std_req_feature(usb3, ctrl, true); 1323 + ret = true; 1324 + break; 1325 + case USB_REQ_SET_SEL: 1326 + stall = usb3_std_req_set_sel(usb3, ctrl); 1327 + ret = true; 1328 + break; 1329 + case USB_REQ_SET_ISOCH_DELAY: 1330 + /* This hardware doesn't support Isochronous xfer */ 1331 + stall = true; 1332 + ret = true; 1333 + break; 1334 + case USB_REQ_SET_CONFIGURATION: 1335 + usb3_std_req_set_configuration(usb3, ctrl); 1336 + break; 1337 + default: 1338 + break; 1339 + } 1340 + } 1341 + 1342 + if (stall) 1343 + usb3_set_p0_con_stall(usb3); 1344 + 1345 + return ret; 1346 + } 1347 + 1348 + static int usb3_p0_con_clear_buffer(struct renesas_usb3 *usb3) 1349 + { 1350 + usb3_set_bit(usb3, P0_CON_BCLR, USB3_P0_CON); 1351 + 1352 + return usb3_wait(usb3, USB3_P0_CON, P0_CON_BCLR, 0); 1353 + } 1354 + 1355 + static void usb3_irq_epc_pipe0_setup(struct renesas_usb3 *usb3) 1356 + { 1357 + struct usb_ctrlrequest ctrl; 1358 + struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); 1359 + 1360 + /* Call giveback function if previous transfer is not completed */ 1361 + if (usb3_ep->started) 1362 + usb3_request_done(usb3_ep, usb3_get_request(usb3_ep), 1363 + -ECONNRESET); 1364 + 1365 + usb3_p0_con_clear_buffer(usb3); 1366 + usb3_get_setup_data(usb3, &ctrl); 1367 + if (!usb3_handle_standard_request(usb3, &ctrl)) 1368 + if (usb3->driver->setup(&usb3->gadget, &ctrl) < 0) 1369 + usb3_set_p0_con_stall(usb3); 1370 + } 1371 + 1372 + static void usb3_irq_epc_pipe0_bfrdy(struct renesas_usb3 *usb3) 1373 + { 1374 + struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); 1375 + struct renesas_usb3_request *usb3_req = usb3_get_request(usb3_ep); 1376 + 1377 + if (!usb3_req) 1378 + return; 1379 + 1380 + usb3_p0_xfer(usb3_ep, usb3_req); 1381 + } 1382 + 1383 + static void usb3_irq_epc_pipe0(struct renesas_usb3 *usb3) 1384 + { 1385 + u32 p0_int_sta = usb3_read(usb3, USB3_P0_INT_STA); 1386 + 1387 + p0_int_sta &= usb3_read(usb3, USB3_P0_INT_ENA); 1388 + usb3_write(usb3, p0_int_sta, USB3_P0_INT_STA); 1389 + if (p0_int_sta & P0_INT_STSED) 1390 + usb3_irq_epc_pipe0_status_end(usb3); 1391 + if (p0_int_sta & P0_INT_SETUP) 1392 + usb3_irq_epc_pipe0_setup(usb3); 1393 + if (p0_int_sta & P0_INT_BFRDY) 1394 + usb3_irq_epc_pipe0_bfrdy(usb3); 1395 + } 1396 + 1397 + static void usb3_request_done_pipen(struct renesas_usb3 *usb3, 1398 + struct renesas_usb3_ep *usb3_ep, 1399 + struct renesas_usb3_request *usb3_req, 1400 + int status) 1401 + { 1402 + usb3_pn_stop(usb3); 1403 + usb3_disable_pipe_irq(usb3, usb3_ep->num); 1404 + usb3_request_done(usb3_ep, usb3_req, status); 1405 + 1406 + /* get next usb3_req */ 1407 + usb3_req = usb3_get_request(usb3_ep); 1408 + if (usb3_req) 1409 + usb3_start_pipen(usb3_ep, usb3_req); 1410 + } 1411 + 1412 + static void usb3_irq_epc_pipen_lsttr(struct renesas_usb3 *usb3, int num) 1413 + { 1414 + struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, num); 1415 + struct renesas_usb3_request *usb3_req = usb3_get_request(usb3_ep); 1416 + 1417 + if (!usb3_req) 1418 + return; 1419 + 1420 + if (usb3_ep->dir_in) { 1421 + dev_dbg(usb3_to_dev(usb3), "%s: len = %u, actual = %u\n", 1422 + __func__, usb3_req->req.length, usb3_req->req.actual); 1423 + usb3_request_done_pipen(usb3, usb3_ep, usb3_req, 0); 1424 + } 1425 + } 1426 + 1427 + static void usb3_irq_epc_pipen_bfrdy(struct renesas_usb3 *usb3, int num) 1428 + { 1429 + struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, num); 1430 + struct renesas_usb3_request *usb3_req = usb3_get_request(usb3_ep); 1431 + 1432 + if (!usb3_req) 1433 + return; 1434 + 1435 + if (usb3_ep->dir_in) { 1436 + /* Do not stop the IN pipe here to detect LSTTR interrupt */ 1437 + if (!usb3_write_pipe(usb3_ep, usb3_req, USB3_PN_WRITE)) 1438 + usb3_clear_bit(usb3, PN_INT_BFRDY, USB3_PN_INT_ENA); 1439 + } else { 1440 + if (!usb3_read_pipe(usb3_ep, usb3_req, USB3_PN_READ)) 1441 + usb3_request_done_pipen(usb3, usb3_ep, usb3_req, 0); 1442 + } 1443 + } 1444 + 1445 + static void usb3_irq_epc_pipen(struct renesas_usb3 *usb3, int num) 1446 + { 1447 + u32 pn_int_sta; 1448 + 1449 + if (usb3_pn_change(usb3, num) < 0) 1450 + return; 1451 + 1452 + pn_int_sta = usb3_read(usb3, USB3_PN_INT_STA); 1453 + pn_int_sta &= usb3_read(usb3, USB3_PN_INT_ENA); 1454 + usb3_write(usb3, pn_int_sta, USB3_PN_INT_STA); 1455 + if (pn_int_sta & PN_INT_LSTTR) 1456 + usb3_irq_epc_pipen_lsttr(usb3, num); 1457 + if (pn_int_sta & PN_INT_BFRDY) 1458 + usb3_irq_epc_pipen_bfrdy(usb3, num); 1459 + } 1460 + 1461 + static void usb3_irq_epc_int_2(struct renesas_usb3 *usb3, u32 int_sta_2) 1462 + { 1463 + int i; 1464 + 1465 + for (i = 0; i < usb3->num_usb3_eps; i++) { 1466 + if (int_sta_2 & USB_INT_2_PIPE(i)) { 1467 + if (!i) 1468 + usb3_irq_epc_pipe0(usb3); 1469 + else 1470 + usb3_irq_epc_pipen(usb3, i); 1471 + } 1472 + } 1473 + } 1474 + 1475 + static void usb3_irq_epc(struct renesas_usb3 *usb3) 1476 + { 1477 + u32 int_sta_1 = usb3_read(usb3, USB3_USB_INT_STA_1); 1478 + u32 int_sta_2 = usb3_read(usb3, USB3_USB_INT_STA_2); 1479 + 1480 + int_sta_1 &= usb3_read(usb3, USB3_USB_INT_ENA_1); 1481 + if (int_sta_1) { 1482 + usb3_write(usb3, int_sta_1, USB3_USB_INT_STA_1); 1483 + usb3_irq_epc_int_1(usb3, int_sta_1); 1484 + } 1485 + 1486 + int_sta_2 &= usb3_read(usb3, USB3_USB_INT_ENA_2); 1487 + if (int_sta_2) 1488 + usb3_irq_epc_int_2(usb3, int_sta_2); 1489 + } 1490 + 1491 + static irqreturn_t renesas_usb3_irq(int irq, void *_usb3) 1492 + { 1493 + struct renesas_usb3 *usb3 = _usb3; 1494 + irqreturn_t ret = IRQ_NONE; 1495 + u32 axi_int_sta = usb3_read(usb3, USB3_AXI_INT_STA); 1496 + 1497 + if (axi_int_sta & AXI_INT_EPCINT) { 1498 + usb3_irq_epc(usb3); 1499 + ret = IRQ_HANDLED; 1500 + } 1501 + 1502 + return ret; 1503 + } 1504 + 1505 + static void usb3_write_pn_mod(struct renesas_usb3_ep *usb3_ep, 1506 + const struct usb_endpoint_descriptor *desc) 1507 + { 1508 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 1509 + u32 val = 0; 1510 + 1511 + val |= usb3_ep->dir_in ? PN_MOD_DIR : 0; 1512 + val |= PN_MOD_TYPE(usb_endpoint_type(desc)); 1513 + val |= PN_MOD_EPNUM(usb_endpoint_num(desc)); 1514 + usb3_write(usb3, val, USB3_PN_MOD); 1515 + } 1516 + 1517 + static u32 usb3_calc_ramarea(int ram_size) 1518 + { 1519 + WARN_ON(ram_size > SZ_16K); 1520 + 1521 + if (ram_size <= SZ_1K) 1522 + return PN_RAMMAP_RAMAREA_1KB; 1523 + else if (ram_size <= SZ_2K) 1524 + return PN_RAMMAP_RAMAREA_2KB; 1525 + else if (ram_size <= SZ_4K) 1526 + return PN_RAMMAP_RAMAREA_4KB; 1527 + else if (ram_size <= SZ_8K) 1528 + return PN_RAMMAP_RAMAREA_8KB; 1529 + else 1530 + return PN_RAMMAP_RAMAREA_16KB; 1531 + } 1532 + 1533 + static u32 usb3_calc_rammap_val(struct renesas_usb3_ep *usb3_ep, 1534 + const struct usb_endpoint_descriptor *desc) 1535 + { 1536 + return usb3_ep->rammap_val | PN_RAMMAP_MPKT(usb_endpoint_maxp(desc)); 1537 + } 1538 + 1539 + static int usb3_enable_pipe_n(struct renesas_usb3_ep *usb3_ep, 1540 + const struct usb_endpoint_descriptor *desc) 1541 + { 1542 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 1543 + unsigned long flags; 1544 + 1545 + usb3_ep->dir_in = usb_endpoint_dir_in(desc); 1546 + 1547 + spin_lock_irqsave(&usb3->lock, flags); 1548 + if (!usb3_pn_change(usb3, usb3_ep->num)) { 1549 + usb3_write_pn_mod(usb3_ep, desc); 1550 + usb3_write(usb3, usb3_calc_rammap_val(usb3_ep, desc), 1551 + USB3_PN_RAMMAP); 1552 + usb3_pn_con_clear(usb3); 1553 + usb3_set_bit(usb3, PN_CON_EN, USB3_PN_CON); 1554 + } 1555 + spin_unlock_irqrestore(&usb3->lock, flags); 1556 + 1557 + return 0; 1558 + } 1559 + 1560 + static int usb3_disable_pipe_n(struct renesas_usb3_ep *usb3_ep) 1561 + { 1562 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 1563 + unsigned long flags; 1564 + 1565 + usb3_ep->halt = false; 1566 + 1567 + spin_lock_irqsave(&usb3->lock, flags); 1568 + if (!usb3_pn_change(usb3, usb3_ep->num)) { 1569 + usb3_write(usb3, 0, USB3_PN_RAMMAP); 1570 + usb3_clear_bit(usb3, PN_CON_EN, USB3_PN_CON); 1571 + } 1572 + spin_unlock_irqrestore(&usb3->lock, flags); 1573 + 1574 + return 0; 1575 + } 1576 + 1577 + /*------- usb_ep_ops -----------------------------------------------------*/ 1578 + static int renesas_usb3_ep_enable(struct usb_ep *_ep, 1579 + const struct usb_endpoint_descriptor *desc) 1580 + { 1581 + struct renesas_usb3_ep *usb3_ep = usb_ep_to_usb3_ep(_ep); 1582 + 1583 + return usb3_enable_pipe_n(usb3_ep, desc); 1584 + } 1585 + 1586 + static int renesas_usb3_ep_disable(struct usb_ep *_ep) 1587 + { 1588 + struct renesas_usb3_ep *usb3_ep = usb_ep_to_usb3_ep(_ep); 1589 + struct renesas_usb3_request *usb3_req; 1590 + 1591 + do { 1592 + usb3_req = usb3_get_request(usb3_ep); 1593 + if (!usb3_req) 1594 + break; 1595 + usb3_request_done(usb3_ep, usb3_req, -ESHUTDOWN); 1596 + } while (1); 1597 + 1598 + return usb3_disable_pipe_n(usb3_ep); 1599 + } 1600 + 1601 + static struct usb_request *__renesas_usb3_ep_alloc_request(gfp_t gfp_flags) 1602 + { 1603 + struct renesas_usb3_request *usb3_req; 1604 + 1605 + usb3_req = kzalloc(sizeof(struct renesas_usb3_request), gfp_flags); 1606 + if (!usb3_req) 1607 + return NULL; 1608 + 1609 + INIT_LIST_HEAD(&usb3_req->queue); 1610 + 1611 + return &usb3_req->req; 1612 + } 1613 + 1614 + static void __renesas_usb3_ep_free_request(struct usb_request *_req) 1615 + { 1616 + struct renesas_usb3_request *usb3_req = usb_req_to_usb3_req(_req); 1617 + 1618 + kfree(usb3_req); 1619 + } 1620 + 1621 + static struct usb_request *renesas_usb3_ep_alloc_request(struct usb_ep *_ep, 1622 + gfp_t gfp_flags) 1623 + { 1624 + return __renesas_usb3_ep_alloc_request(gfp_flags); 1625 + } 1626 + 1627 + static void renesas_usb3_ep_free_request(struct usb_ep *_ep, 1628 + struct usb_request *_req) 1629 + { 1630 + __renesas_usb3_ep_free_request(_req); 1631 + } 1632 + 1633 + static int renesas_usb3_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 1634 + { 1635 + struct renesas_usb3_ep *usb3_ep = usb_ep_to_usb3_ep(_ep); 1636 + struct renesas_usb3_request *usb3_req = usb_req_to_usb3_req(_req); 1637 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 1638 + 1639 + dev_dbg(usb3_to_dev(usb3), "ep_dequeue: ep%2d, %u\n", usb3_ep->num, 1640 + _req->length); 1641 + 1642 + usb3_request_done_pipen(usb3, usb3_ep, usb3_req, -ECONNRESET); 1643 + 1644 + return 0; 1645 + } 1646 + 1647 + static int renesas_usb3_ep_set_halt(struct usb_ep *_ep, int value) 1648 + { 1649 + return usb3_set_halt(usb_ep_to_usb3_ep(_ep), !!value, false); 1650 + } 1651 + 1652 + static int renesas_usb3_ep_set_wedge(struct usb_ep *_ep) 1653 + { 1654 + struct renesas_usb3_ep *usb3_ep = usb_ep_to_usb3_ep(_ep); 1655 + 1656 + usb3_ep->wedge = true; 1657 + return usb3_set_halt(usb3_ep, true, false); 1658 + } 1659 + 1660 + static void renesas_usb3_ep_fifo_flush(struct usb_ep *_ep) 1661 + { 1662 + struct renesas_usb3_ep *usb3_ep = usb_ep_to_usb3_ep(_ep); 1663 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 1664 + unsigned long flags; 1665 + 1666 + if (usb3_ep->num) { 1667 + spin_lock_irqsave(&usb3->lock, flags); 1668 + if (!usb3_pn_change(usb3, usb3_ep->num)) { 1669 + usb3_pn_con_clear(usb3); 1670 + usb3_set_bit(usb3, PN_CON_EN, USB3_PN_CON); 1671 + } 1672 + spin_unlock_irqrestore(&usb3->lock, flags); 1673 + } else { 1674 + usb3_p0_con_clear_buffer(usb3); 1675 + } 1676 + } 1677 + 1678 + static struct usb_ep_ops renesas_usb3_ep_ops = { 1679 + .enable = renesas_usb3_ep_enable, 1680 + .disable = renesas_usb3_ep_disable, 1681 + 1682 + .alloc_request = renesas_usb3_ep_alloc_request, 1683 + .free_request = renesas_usb3_ep_free_request, 1684 + 1685 + .queue = renesas_usb3_ep_queue, 1686 + .dequeue = renesas_usb3_ep_dequeue, 1687 + 1688 + .set_halt = renesas_usb3_ep_set_halt, 1689 + .set_wedge = renesas_usb3_ep_set_wedge, 1690 + .fifo_flush = renesas_usb3_ep_fifo_flush, 1691 + }; 1692 + 1693 + /*------- usb_gadget_ops -------------------------------------------------*/ 1694 + static int renesas_usb3_start(struct usb_gadget *gadget, 1695 + struct usb_gadget_driver *driver) 1696 + { 1697 + struct renesas_usb3 *usb3; 1698 + 1699 + if (!driver || driver->max_speed < USB_SPEED_FULL || 1700 + !driver->setup) 1701 + return -EINVAL; 1702 + 1703 + usb3 = gadget_to_renesas_usb3(gadget); 1704 + 1705 + /* hook up the driver */ 1706 + usb3->driver = driver; 1707 + 1708 + renesas_usb3_init_controller(usb3); 1709 + 1710 + return 0; 1711 + } 1712 + 1713 + static int renesas_usb3_stop(struct usb_gadget *gadget) 1714 + { 1715 + struct renesas_usb3 *usb3 = gadget_to_renesas_usb3(gadget); 1716 + unsigned long flags; 1717 + 1718 + spin_lock_irqsave(&usb3->lock, flags); 1719 + usb3->softconnect = false; 1720 + usb3->gadget.speed = USB_SPEED_UNKNOWN; 1721 + usb3->driver = NULL; 1722 + renesas_usb3_stop_controller(usb3); 1723 + spin_unlock_irqrestore(&usb3->lock, flags); 1724 + 1725 + return 0; 1726 + } 1727 + 1728 + static int renesas_usb3_get_frame(struct usb_gadget *_gadget) 1729 + { 1730 + return -EOPNOTSUPP; 1731 + } 1732 + 1733 + static int renesas_usb3_pullup(struct usb_gadget *gadget, int is_on) 1734 + { 1735 + struct renesas_usb3 *usb3 = gadget_to_renesas_usb3(gadget); 1736 + 1737 + usb3->softconnect = !!is_on; 1738 + 1739 + return 0; 1740 + } 1741 + 1742 + static int renesas_usb3_set_selfpowered(struct usb_gadget *gadget, int is_self) 1743 + { 1744 + gadget->is_selfpowered = !!is_self; 1745 + 1746 + return 0; 1747 + } 1748 + 1749 + static const struct usb_gadget_ops renesas_usb3_gadget_ops = { 1750 + .get_frame = renesas_usb3_get_frame, 1751 + .udc_start = renesas_usb3_start, 1752 + .udc_stop = renesas_usb3_stop, 1753 + .pullup = renesas_usb3_pullup, 1754 + .set_selfpowered = renesas_usb3_set_selfpowered, 1755 + }; 1756 + 1757 + /*------- platform_driver ------------------------------------------------*/ 1758 + static int renesas_usb3_remove(struct platform_device *pdev) 1759 + { 1760 + struct renesas_usb3 *usb3 = platform_get_drvdata(pdev); 1761 + 1762 + pm_runtime_put(&pdev->dev); 1763 + pm_runtime_disable(&pdev->dev); 1764 + 1765 + usb_del_gadget_udc(&usb3->gadget); 1766 + 1767 + __renesas_usb3_ep_free_request(usb3->ep0_req); 1768 + 1769 + return 0; 1770 + } 1771 + 1772 + static int renesas_usb3_init_ep(struct renesas_usb3 *usb3, struct device *dev, 1773 + const struct renesas_usb3_priv *priv) 1774 + { 1775 + struct renesas_usb3_ep *usb3_ep; 1776 + int i; 1777 + 1778 + /* calculate num_usb3_eps from renesas_usb3_priv */ 1779 + usb3->num_usb3_eps = priv->ramsize_per_ramif * priv->num_ramif * 2 / 1780 + priv->ramsize_per_pipe + 1; 1781 + 1782 + if (usb3->num_usb3_eps > USB3_MAX_NUM_PIPES) 1783 + usb3->num_usb3_eps = USB3_MAX_NUM_PIPES; 1784 + 1785 + usb3->usb3_ep = devm_kzalloc(dev, sizeof(*usb3_ep) * usb3->num_usb3_eps, 1786 + GFP_KERNEL); 1787 + if (!usb3->usb3_ep) 1788 + return -ENOMEM; 1789 + 1790 + dev_dbg(dev, "%s: num_usb3_eps = %d\n", __func__, usb3->num_usb3_eps); 1791 + /* 1792 + * This driver prepares pipes as the followings: 1793 + * - odd pipes = IN pipe 1794 + * - even pipes = OUT pipe (except pipe 0) 1795 + */ 1796 + usb3_for_each_ep(usb3_ep, usb3, i) { 1797 + snprintf(usb3_ep->ep_name, sizeof(usb3_ep->ep_name), "ep%d", i); 1798 + usb3_ep->usb3 = usb3; 1799 + usb3_ep->num = i; 1800 + usb3_ep->ep.name = usb3_ep->ep_name; 1801 + usb3_ep->ep.ops = &renesas_usb3_ep_ops; 1802 + INIT_LIST_HEAD(&usb3_ep->queue); 1803 + INIT_LIST_HEAD(&usb3_ep->ep.ep_list); 1804 + if (!i) { 1805 + /* for control pipe */ 1806 + usb3->gadget.ep0 = &usb3_ep->ep; 1807 + usb_ep_set_maxpacket_limit(&usb3_ep->ep, 1808 + USB3_EP0_HSFS_MAX_PACKET_SIZE); 1809 + usb3_ep->ep.caps.type_control = true; 1810 + usb3_ep->ep.caps.dir_in = true; 1811 + usb3_ep->ep.caps.dir_out = true; 1812 + continue; 1813 + } 1814 + 1815 + /* for bulk or interrupt pipe */ 1816 + usb_ep_set_maxpacket_limit(&usb3_ep->ep, ~0); 1817 + list_add_tail(&usb3_ep->ep.ep_list, &usb3->gadget.ep_list); 1818 + usb3_ep->ep.caps.type_bulk = true; 1819 + usb3_ep->ep.caps.type_int = true; 1820 + if (i & 1) 1821 + usb3_ep->ep.caps.dir_in = true; 1822 + else 1823 + usb3_ep->ep.caps.dir_out = true; 1824 + } 1825 + 1826 + return 0; 1827 + } 1828 + 1829 + static void renesas_usb3_init_ram(struct renesas_usb3 *usb3, struct device *dev, 1830 + const struct renesas_usb3_priv *priv) 1831 + { 1832 + struct renesas_usb3_ep *usb3_ep; 1833 + int i; 1834 + u32 ramif[2], basead[2]; /* index 0 = for IN pipes */ 1835 + u32 *cur_ramif, *cur_basead; 1836 + u32 val; 1837 + 1838 + memset(ramif, 0, sizeof(ramif)); 1839 + memset(basead, 0, sizeof(basead)); 1840 + 1841 + /* 1842 + * This driver prepares pipes as the followings: 1843 + * - all pipes = the same size as "ramsize_per_pipe" 1844 + * Please refer to the "Method of Specifying RAM Mapping" 1845 + */ 1846 + usb3_for_each_ep(usb3_ep, usb3, i) { 1847 + if (!i) 1848 + continue; /* out of scope if ep num = 0 */ 1849 + if (usb3_ep->ep.caps.dir_in) { 1850 + cur_ramif = &ramif[0]; 1851 + cur_basead = &basead[0]; 1852 + } else { 1853 + cur_ramif = &ramif[1]; 1854 + cur_basead = &basead[1]; 1855 + } 1856 + 1857 + if (*cur_basead > priv->ramsize_per_ramif) 1858 + continue; /* out of memory for IN or OUT pipe */ 1859 + 1860 + /* calculate rammap_val */ 1861 + val = PN_RAMMAP_RAMIF(*cur_ramif); 1862 + val |= usb3_calc_ramarea(priv->ramsize_per_pipe); 1863 + val |= PN_RAMMAP_BASEAD(*cur_basead); 1864 + usb3_ep->rammap_val = val; 1865 + 1866 + dev_dbg(dev, "ep%2d: val = %08x, ramif = %d, base = %x\n", 1867 + i, val, *cur_ramif, *cur_basead); 1868 + 1869 + /* update current ramif */ 1870 + if (*cur_ramif + 1 == priv->num_ramif) { 1871 + *cur_ramif = 0; 1872 + *cur_basead += priv->ramsize_per_pipe; 1873 + } else { 1874 + (*cur_ramif)++; 1875 + } 1876 + } 1877 + } 1878 + 1879 + static const struct renesas_usb3_priv renesas_usb3_priv_r8a7795 = { 1880 + .ramsize_per_ramif = SZ_16K, 1881 + .num_ramif = 2, 1882 + .ramsize_per_pipe = SZ_4K, 1883 + .workaround_for_vbus = true, 1884 + }; 1885 + 1886 + static const struct of_device_id usb3_of_match[] = { 1887 + { 1888 + .compatible = "renesas,r8a7795-usb3-peri", 1889 + .data = &renesas_usb3_priv_r8a7795, 1890 + }, 1891 + { }, 1892 + }; 1893 + MODULE_DEVICE_TABLE(of, usb3_of_match); 1894 + 1895 + static int renesas_usb3_probe(struct platform_device *pdev) 1896 + { 1897 + struct renesas_usb3 *usb3; 1898 + struct resource *res; 1899 + const struct of_device_id *match; 1900 + int irq, ret; 1901 + const struct renesas_usb3_priv *priv; 1902 + 1903 + match = of_match_node(usb3_of_match, pdev->dev.of_node); 1904 + if (!match) 1905 + return -ENODEV; 1906 + priv = match->data; 1907 + 1908 + irq = platform_get_irq(pdev, 0); 1909 + if (irq < 0) 1910 + return -ENODEV; 1911 + 1912 + usb3 = devm_kzalloc(&pdev->dev, sizeof(*usb3), GFP_KERNEL); 1913 + if (!usb3) 1914 + return -ENOMEM; 1915 + 1916 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1917 + usb3->reg = devm_ioremap_resource(&pdev->dev, res); 1918 + if (IS_ERR(usb3->reg)) 1919 + return PTR_ERR(usb3->reg); 1920 + 1921 + platform_set_drvdata(pdev, usb3); 1922 + spin_lock_init(&usb3->lock); 1923 + 1924 + usb3->gadget.ops = &renesas_usb3_gadget_ops; 1925 + usb3->gadget.name = udc_name; 1926 + usb3->gadget.max_speed = USB_SPEED_SUPER; 1927 + INIT_LIST_HEAD(&usb3->gadget.ep_list); 1928 + ret = renesas_usb3_init_ep(usb3, &pdev->dev, priv); 1929 + if (ret < 0) 1930 + return ret; 1931 + renesas_usb3_init_ram(usb3, &pdev->dev, priv); 1932 + 1933 + ret = devm_request_irq(&pdev->dev, irq, renesas_usb3_irq, 0, 1934 + dev_name(&pdev->dev), usb3); 1935 + if (ret < 0) 1936 + return ret; 1937 + 1938 + /* for ep0 handling */ 1939 + usb3->ep0_req = __renesas_usb3_ep_alloc_request(GFP_KERNEL); 1940 + if (!usb3->ep0_req) 1941 + return -ENOMEM; 1942 + 1943 + ret = usb_add_gadget_udc(&pdev->dev, &usb3->gadget); 1944 + if (ret < 0) 1945 + goto err_add_udc; 1946 + 1947 + usb3->workaround_for_vbus = priv->workaround_for_vbus; 1948 + 1949 + pm_runtime_enable(&pdev->dev); 1950 + pm_runtime_get_sync(&pdev->dev); 1951 + 1952 + dev_info(&pdev->dev, "probed\n"); 1953 + 1954 + return 0; 1955 + 1956 + err_add_udc: 1957 + __renesas_usb3_ep_free_request(usb3->ep0_req); 1958 + 1959 + return ret; 1960 + } 1961 + 1962 + static struct platform_driver renesas_usb3_driver = { 1963 + .probe = renesas_usb3_probe, 1964 + .remove = renesas_usb3_remove, 1965 + .driver = { 1966 + .name = (char *)udc_name, 1967 + .of_match_table = of_match_ptr(usb3_of_match), 1968 + }, 1969 + }; 1970 + module_platform_driver(renesas_usb3_driver); 1971 + 1972 + MODULE_DESCRIPTION("Renesas USB3.0 Peripheral driver"); 1973 + MODULE_LICENSE("GPL v2"); 1974 + MODULE_AUTHOR("Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>"); 1975 + MODULE_ALIAS("platform:renesas_usb3");
+1 -1
drivers/usb/gadget/udc/s3c-hsudc.c
··· 569 569 hsep = &hsudc->ep[ep_num]; 570 570 switch (le16_to_cpu(ctrl->wValue)) { 571 571 case USB_ENDPOINT_HALT: 572 - if (set || (!set && !hsep->wedge)) 572 + if (set || !hsep->wedge) 573 573 s3c_hsudc_set_halt(&hsep->ep, set); 574 574 return 0; 575 575 }
+45 -34
drivers/usb/gadget/udc/udc-core.c
··· 51 51 52 52 static struct class *udc_class; 53 53 static LIST_HEAD(udc_list); 54 + static LIST_HEAD(gadget_driver_pending_list); 54 55 static DEFINE_MUTEX(udc_lock); 56 + 57 + static int udc_bind_to_driver(struct usb_udc *udc, 58 + struct usb_gadget_driver *driver); 55 59 56 60 /* ------------------------------------------------------------------------- */ 57 61 ··· 360 356 void (*release)(struct device *dev)) 361 357 { 362 358 struct usb_udc *udc; 359 + struct usb_gadget_driver *driver; 363 360 int ret = -ENOMEM; 364 361 365 362 udc = kzalloc(sizeof(*udc), GFP_KERNEL); ··· 407 402 408 403 usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED); 409 404 udc->vbus = true; 405 + 406 + /* pick up one of pending gadget drivers */ 407 + list_for_each_entry(driver, &gadget_driver_pending_list, pending) { 408 + if (!driver->udc_name || strcmp(driver->udc_name, 409 + dev_name(&udc->dev)) == 0) { 410 + ret = udc_bind_to_driver(udc, driver); 411 + if (ret) 412 + goto err4; 413 + list_del(&driver->pending); 414 + break; 415 + } 416 + } 410 417 411 418 mutex_unlock(&udc_lock); 412 419 ··· 490 473 491 474 mutex_lock(&udc_lock); 492 475 list_del(&udc->list); 493 - mutex_unlock(&udc_lock); 494 476 495 - if (udc->driver) 477 + if (udc->driver) { 478 + struct usb_gadget_driver *driver = udc->driver; 479 + 496 480 usb_gadget_remove_driver(udc); 481 + list_add(&driver->pending, &gadget_driver_pending_list); 482 + } 483 + mutex_unlock(&udc_lock); 497 484 498 485 kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); 499 486 flush_work(&gadget->work); ··· 541 520 return ret; 542 521 } 543 522 544 - int usb_udc_attach_driver(const char *name, struct usb_gadget_driver *driver) 545 - { 546 - struct usb_udc *udc = NULL; 547 - int ret = -ENODEV; 548 - 549 - mutex_lock(&udc_lock); 550 - list_for_each_entry(udc, &udc_list, list) { 551 - ret = strcmp(name, dev_name(&udc->dev)); 552 - if (!ret) 553 - break; 554 - } 555 - if (ret) { 556 - ret = -ENODEV; 557 - goto out; 558 - } 559 - if (udc->driver) { 560 - ret = -EBUSY; 561 - goto out; 562 - } 563 - ret = udc_bind_to_driver(udc, driver); 564 - out: 565 - mutex_unlock(&udc_lock); 566 - return ret; 567 - } 568 - EXPORT_SYMBOL_GPL(usb_udc_attach_driver); 569 - 570 523 int usb_gadget_probe_driver(struct usb_gadget_driver *driver) 571 524 { 572 525 struct usb_udc *udc = NULL; 573 - int ret; 526 + int ret = -ENODEV; 574 527 575 528 if (!driver || !driver->bind || !driver->setup) 576 529 return -EINVAL; 577 530 578 531 mutex_lock(&udc_lock); 579 - list_for_each_entry(udc, &udc_list, list) { 580 - /* For now we take the first one */ 581 - if (!udc->driver) 532 + if (driver->udc_name) { 533 + list_for_each_entry(udc, &udc_list, list) { 534 + ret = strcmp(driver->udc_name, dev_name(&udc->dev)); 535 + if (!ret) 536 + break; 537 + } 538 + if (!ret && !udc->driver) 582 539 goto found; 540 + } else { 541 + list_for_each_entry(udc, &udc_list, list) { 542 + /* For now we take the first one */ 543 + if (!udc->driver) 544 + goto found; 545 + } 583 546 } 584 547 585 - pr_debug("couldn't find an available UDC\n"); 548 + list_add_tail(&driver->pending, &gadget_driver_pending_list); 549 + pr_info("udc-core: couldn't find an available UDC - added [%s] to list of pending drivers\n", 550 + driver->function); 586 551 mutex_unlock(&udc_lock); 587 - return -ENODEV; 552 + return 0; 588 553 found: 589 554 ret = udc_bind_to_driver(udc, driver); 590 555 mutex_unlock(&udc_lock); ··· 596 589 break; 597 590 } 598 591 592 + if (ret) { 593 + list_del(&driver->pending); 594 + ret = 0; 595 + } 599 596 mutex_unlock(&udc_lock); 600 597 return ret; 601 598 }
+38 -10
drivers/usb/musb/musb_core.c
··· 1360 1360 break; 1361 1361 } 1362 1362 1363 - printk(KERN_DEBUG "%s: setup fifo_mode %d\n", 1364 - musb_driver_name, fifo_mode); 1363 + pr_debug("%s: setup fifo_mode %d\n", musb_driver_name, fifo_mode); 1365 1364 1366 1365 1367 1366 done: ··· 1389 1390 musb->nr_endpoints = max(epn, musb->nr_endpoints); 1390 1391 } 1391 1392 1392 - printk(KERN_DEBUG "%s: %d/%d max ep, %d/%d memory\n", 1393 + pr_debug("%s: %d/%d max ep, %d/%d memory\n", 1393 1394 musb_driver_name, 1394 1395 n + 1, musb->config->num_eps * 2 - 1, 1395 1396 offset, (1 << (musb->config->ram_bits + 2))); ··· 1490 1491 if (reg & MUSB_CONFIGDATA_SOFTCONE) 1491 1492 strcat(aInfo, ", SoftConn"); 1492 1493 1493 - printk(KERN_DEBUG "%s: ConfigData=0x%02x (%s)\n", 1494 - musb_driver_name, reg, aInfo); 1494 + pr_debug("%s: ConfigData=0x%02x (%s)\n", musb_driver_name, reg, aInfo); 1495 1495 1496 1496 aDate[0] = 0; 1497 1497 if (MUSB_CONTROLLER_MHDRC == musb_type) { ··· 1500 1502 musb->is_multipoint = 0; 1501 1503 type = ""; 1502 1504 #ifndef CONFIG_USB_OTG_BLACKLIST_HUB 1503 - printk(KERN_ERR 1504 - "%s: kernel must blacklist external hubs\n", 1505 - musb_driver_name); 1505 + pr_err("%s: kernel must blacklist external hubs\n", 1506 + musb_driver_name); 1506 1507 #endif 1507 1508 } 1508 1509 ··· 1510 1513 snprintf(aRevision, 32, "%d.%d%s", MUSB_HWVERS_MAJOR(musb->hwvers), 1511 1514 MUSB_HWVERS_MINOR(musb->hwvers), 1512 1515 (musb->hwvers & MUSB_HWVERS_RC) ? "RC" : ""); 1513 - printk(KERN_DEBUG "%s: %sHDRC RTL version %s %s\n", 1514 - musb_driver_name, type, aRevision, aDate); 1516 + pr_debug("%s: %sHDRC RTL version %s %s\n", 1517 + musb_driver_name, type, aRevision, aDate); 1515 1518 1516 1519 /* configure ep0 */ 1517 1520 musb_configure_ep0(musb); ··· 1701 1704 #else 1702 1705 #define use_dma 0 1703 1706 #endif 1707 + 1708 + static void (*musb_phy_callback)(enum musb_vbus_id_status status); 1709 + 1710 + /* 1711 + * musb_mailbox - optional phy notifier function 1712 + * @status phy state change 1713 + * 1714 + * Optionally gets called from the USB PHY. Note that the USB PHY must be 1715 + * disabled at the point the phy_callback is registered or unregistered. 1716 + */ 1717 + void musb_mailbox(enum musb_vbus_id_status status) 1718 + { 1719 + if (musb_phy_callback) 1720 + musb_phy_callback(status); 1721 + 1722 + }; 1723 + EXPORT_SYMBOL_GPL(musb_mailbox); 1704 1724 1705 1725 /*-------------------------------------------------------------------------*/ 1706 1726 ··· 2131 2117 musb->xceiv->io_ops = &musb_ulpi_access; 2132 2118 } 2133 2119 2120 + if (musb->ops->phy_callback) 2121 + musb_phy_callback = musb->ops->phy_callback; 2122 + 2134 2123 pm_runtime_get_sync(musb->controller); 2124 + 2125 + status = usb_phy_init(musb->xceiv); 2126 + if (status < 0) 2127 + goto err_usb_phy_init; 2135 2128 2136 2129 if (use_dma && dev->dma_mask) { 2137 2130 musb->dma_controller = ··· 2260 2239 cancel_delayed_work_sync(&musb->deassert_reset_work); 2261 2240 if (musb->dma_controller) 2262 2241 musb_dma_controller_destroy(musb->dma_controller); 2242 + 2263 2243 fail2_5: 2244 + usb_phy_shutdown(musb->xceiv); 2245 + 2246 + err_usb_phy_init: 2264 2247 pm_runtime_put_sync(musb->controller); 2265 2248 2266 2249 fail2: ··· 2320 2295 */ 2321 2296 musb_exit_debugfs(musb); 2322 2297 musb_shutdown(pdev); 2298 + musb_phy_callback = NULL; 2323 2299 2324 2300 if (musb->dma_controller) 2325 2301 musb_dma_controller_destroy(musb->dma_controller); 2302 + 2303 + usb_phy_shutdown(musb->xceiv); 2326 2304 2327 2305 cancel_work_sync(&musb->irq_work); 2328 2306 cancel_delayed_work_sync(&musb->finish_resume_work);
+2
drivers/usb/musb/musb_core.h
··· 168 168 * @adjust_channel_params: pre check for standard dma channel_program func 169 169 * @pre_root_reset_end: called before the root usb port reset flag gets cleared 170 170 * @post_root_reset_end: called after the root usb port reset flag gets cleared 171 + * @phy_callback: optional callback function for the phy to call 171 172 */ 172 173 struct musb_platform_ops { 173 174 ··· 215 214 dma_addr_t *dma_addr, u32 *len); 216 215 void (*pre_root_reset_end)(struct musb *musb); 217 216 void (*post_root_reset_end)(struct musb *musb); 217 + void (*phy_callback)(enum musb_vbus_id_status status); 218 218 }; 219 219 220 220 /*
+2 -3
drivers/usb/musb/musb_gadget.c
··· 353 353 * 1 >0 Yes(FS bulk) 354 354 */ 355 355 if (!musb_ep->hb_mult || 356 - (musb_ep->hb_mult && 357 - can_bulk_split(musb, 358 - musb_ep->type))) 356 + can_bulk_split(musb, 357 + musb_ep->type)) 359 358 csr |= MUSB_TXCSR_AUTOSET; 360 359 } 361 360 csr &= ~MUSB_TXCSR_P_UNDERRUN;
+17 -13
drivers/usb/musb/omap2430.c
··· 36 36 #include <linux/pm_runtime.h> 37 37 #include <linux/err.h> 38 38 #include <linux/delay.h> 39 - #include <linux/usb/musb-omap.h> 39 + #include <linux/usb/musb.h> 40 40 #include <linux/phy/omap_control_phy.h> 41 41 #include <linux/of_platform.h> 42 42 ··· 46 46 struct omap2430_glue { 47 47 struct device *dev; 48 48 struct platform_device *musb; 49 - enum omap_musb_vbus_id_status status; 49 + enum musb_vbus_id_status status; 50 50 struct work_struct omap_musb_mailbox_work; 51 51 struct device *control_otghs; 52 52 }; ··· 234 234 musb_writel(musb->mregs, OTG_FORCESTDBY, l); 235 235 } 236 236 237 - void omap_musb_mailbox(enum omap_musb_vbus_id_status status) 237 + static void omap2430_musb_mailbox(enum musb_vbus_id_status status) 238 238 { 239 239 struct omap2430_glue *glue = _glue; 240 240 ··· 251 251 252 252 schedule_work(&glue->omap_musb_mailbox_work); 253 253 } 254 - EXPORT_SYMBOL_GPL(omap_musb_mailbox); 255 254 256 255 static void omap_musb_set_mailbox(struct omap2430_glue *glue) 257 256 { ··· 261 262 struct usb_otg *otg = musb->xceiv->otg; 262 263 263 264 switch (glue->status) { 264 - case OMAP_MUSB_ID_GROUND: 265 + case MUSB_ID_GROUND: 265 266 dev_dbg(dev, "ID GND\n"); 266 267 267 268 otg->default_a = true; ··· 275 276 } 276 277 break; 277 278 278 - case OMAP_MUSB_VBUS_VALID: 279 + case MUSB_VBUS_VALID: 279 280 dev_dbg(dev, "VBUS Connect\n"); 280 281 281 282 otg->default_a = false; ··· 286 287 omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE); 287 288 break; 288 289 289 - case OMAP_MUSB_ID_FLOAT: 290 - case OMAP_MUSB_VBUS_OFF: 290 + case MUSB_ID_FLOAT: 291 + case MUSB_VBUS_OFF: 291 292 dev_dbg(dev, "VBUS Disconnect\n"); 292 293 293 294 musb->xceiv->last_event = USB_EVENT_NONE; ··· 429 430 430 431 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); 431 432 432 - if (glue->status != OMAP_MUSB_UNKNOWN) 433 + if (glue->status != MUSB_UNKNOWN) 433 434 omap_musb_set_mailbox(glue); 434 435 435 436 phy_init(musb->phy); ··· 454 455 455 456 switch (glue->status) { 456 457 457 - case OMAP_MUSB_ID_GROUND: 458 + case MUSB_ID_GROUND: 458 459 omap_control_usb_set_mode(glue->control_otghs, USB_MODE_HOST); 459 460 if (data->interface_type != MUSB_INTERFACE_UTMI) 460 461 break; ··· 473 474 } 474 475 break; 475 476 476 - case OMAP_MUSB_VBUS_VALID: 477 + case MUSB_VBUS_VALID: 477 478 omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE); 478 479 break; 479 480 ··· 487 488 struct device *dev = musb->controller; 488 489 struct omap2430_glue *glue = dev_get_drvdata(dev->parent); 489 490 490 - if (glue->status != OMAP_MUSB_UNKNOWN) 491 + if (glue->status != MUSB_UNKNOWN) 491 492 omap_control_usb_set_mode(glue->control_otghs, 492 493 USB_MODE_DISCONNECT); 493 494 } ··· 519 520 520 521 .enable = omap2430_musb_enable, 521 522 .disable = omap2430_musb_disable, 523 + 524 + .phy_callback = omap2430_musb_mailbox, 522 525 }; 523 526 524 527 static u64 omap2430_dmamask = DMA_BIT_MASK(32); ··· 552 551 553 552 glue->dev = &pdev->dev; 554 553 glue->musb = musb; 555 - glue->status = OMAP_MUSB_UNKNOWN; 554 + glue->status = MUSB_UNKNOWN; 556 555 glue->control_otghs = ERR_PTR(-ENODEV); 557 556 558 557 if (np) { ··· 664 663 { 665 664 struct omap2430_glue *glue = platform_get_drvdata(pdev); 666 665 666 + pm_runtime_get_sync(glue->dev); 667 667 cancel_work_sync(&glue->omap_musb_mailbox_work); 668 668 platform_device_unregister(glue->musb); 669 + pm_runtime_put_sync(glue->dev); 670 + pm_runtime_disable(glue->dev); 669 671 670 672 return 0; 671 673 }
+1 -13
drivers/usb/phy/Kconfig
··· 66 66 select USB_PHY 67 67 select AM335X_CONTROL_USB 68 68 select NOP_USB_XCEIV 69 + select USB_COMMON 69 70 help 70 71 This driver provides PHY support for that phy which part for the 71 72 AM335x SoC. ··· 186 185 Enable this to support the Freescale MXS USB PHY. 187 186 188 187 MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x. 189 - 190 - config USB_RCAR_PHY 191 - tristate "Renesas R-Car USB PHY support" 192 - depends on USB || USB_GADGET 193 - depends on ARCH_R8A7778 || ARCH_R8A7779 || COMPILE_TEST 194 - select USB_PHY 195 - help 196 - Say Y here to add support for the Renesas R-Car USB common PHY driver. 197 - This chip is typically used as USB PHY for USB host, gadget. 198 - This driver supports R8A7778 and R8A7779. 199 - 200 - To compile this driver as a module, choose M here: the 201 - module will be called phy-rcar-usb. 202 188 203 189 config USB_ULPI 204 190 bool "Generic ULPI Transceiver Driver"
-1
drivers/usb/phy/Makefile
··· 23 23 obj-$(CONFIG_USB_QCOM_8X16_PHY) += phy-qcom-8x16-usb.o 24 24 obj-$(CONFIG_USB_MV_OTG) += phy-mv-usb.o 25 25 obj-$(CONFIG_USB_MXS_PHY) += phy-mxs-usb.o 26 - obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o 27 26 obj-$(CONFIG_USB_ULPI) += phy-ulpi.o 28 27 obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o 29 28 obj-$(CONFIG_KEYSTONE_USB_PHY) += phy-keystone.o
+5 -3
drivers/usb/phy/am35x-phy-control.h drivers/usb/phy/phy-am335x-control.h
··· 2 2 #define _AM335x_PHY_CONTROL_H_ 3 3 4 4 struct phy_control { 5 - void (*phy_power)(struct phy_control *phy_ctrl, u32 id, bool on); 5 + void (*phy_power)(struct phy_control *phy_ctrl, u32 id, 6 + enum usb_dr_mode dr_mode, bool on); 6 7 void (*phy_wkup)(struct phy_control *phy_ctrl, u32 id, bool on); 7 8 }; 8 9 9 - static inline void phy_ctrl_power(struct phy_control *phy_ctrl, u32 id, bool on) 10 + static inline void phy_ctrl_power(struct phy_control *phy_ctrl, u32 id, 11 + enum usb_dr_mode dr_mode, bool on) 10 12 { 11 - phy_ctrl->phy_power(phy_ctrl, id, on); 13 + phy_ctrl->phy_power(phy_ctrl, id, dr_mode, on); 12 14 } 13 15 14 16 static inline void phy_ctrl_wkup(struct phy_control *phy_ctrl, u32 id, bool on)
+12 -4
drivers/usb/phy/phy-am335x-control.c
··· 4 4 #include <linux/of.h> 5 5 #include <linux/io.h> 6 6 #include <linux/delay.h> 7 - #include "am35x-phy-control.h" 7 + #include <linux/usb/otg.h> 8 + #include "phy-am335x-control.h" 8 9 9 10 struct am335x_control_usb { 10 11 struct device *dev; ··· 59 58 spin_unlock(&usb_ctrl->lock); 60 59 } 61 60 62 - static void am335x_phy_power(struct phy_control *phy_ctrl, u32 id, bool on) 61 + static void am335x_phy_power(struct phy_control *phy_ctrl, u32 id, 62 + enum usb_dr_mode dr_mode, bool on) 63 63 { 64 64 struct am335x_control_usb *usb_ctrl; 65 65 u32 val; ··· 82 80 83 81 val = readl(usb_ctrl->phy_reg + reg); 84 82 if (on) { 85 - val &= ~(USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN); 86 - val |= USBPHY_OTGVDET_EN | USBPHY_OTGSESSEND_EN; 83 + if (dr_mode == USB_DR_MODE_HOST) { 84 + val &= ~(USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN | 85 + USBPHY_OTGVDET_EN); 86 + val |= USBPHY_OTGSESSEND_EN; 87 + } else { 88 + val &= ~(USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN); 89 + val |= USBPHY_OTGVDET_EN | USBPHY_OTGSESSEND_EN; 90 + } 87 91 } else { 88 92 val |= USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN; 89 93 }
+11 -6
drivers/usb/phy/phy-am335x.c
··· 8 8 #include <linux/regulator/consumer.h> 9 9 #include <linux/of.h> 10 10 #include <linux/of_address.h> 11 + #include <linux/usb/of.h> 11 12 12 - #include "am35x-phy-control.h" 13 + #include "phy-am335x-control.h" 13 14 #include "phy-generic.h" 14 15 15 16 struct am335x_phy { 16 17 struct usb_phy_generic usb_phy_gen; 17 18 struct phy_control *phy_ctrl; 18 19 int id; 20 + enum usb_dr_mode dr_mode; 19 21 }; 20 22 21 23 static int am335x_init(struct usb_phy *phy) 22 24 { 23 25 struct am335x_phy *am_phy = dev_get_drvdata(phy->dev); 24 26 25 - phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true); 27 + phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, true); 26 28 return 0; 27 29 } 28 30 ··· 32 30 { 33 31 struct am335x_phy *am_phy = dev_get_drvdata(phy->dev); 34 32 35 - phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); 33 + phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, false); 36 34 } 37 35 38 36 static int am335x_phy_probe(struct platform_device *pdev) ··· 48 46 am_phy->phy_ctrl = am335x_get_phy_control(dev); 49 47 if (!am_phy->phy_ctrl) 50 48 return -EPROBE_DEFER; 49 + 51 50 am_phy->id = of_alias_get_id(pdev->dev.of_node, "phy"); 52 51 if (am_phy->id < 0) { 53 52 dev_err(&pdev->dev, "Missing PHY id: %d\n", am_phy->id); 54 53 return am_phy->id; 55 54 } 55 + 56 + am_phy->dr_mode = of_usb_get_dr_mode_by_phy(pdev->dev.of_node); 56 57 57 58 ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, NULL); 58 59 if (ret) ··· 80 75 */ 81 76 82 77 device_set_wakeup_enable(dev, false); 83 - phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); 78 + phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, false); 84 79 85 80 return 0; 86 81 } ··· 110 105 if (device_may_wakeup(dev)) 111 106 phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true); 112 107 113 - phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); 108 + phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, false); 114 109 115 110 return 0; 116 111 } ··· 120 115 struct platform_device *pdev = to_platform_device(dev); 121 116 struct am335x_phy *am_phy = platform_get_drvdata(pdev); 122 117 123 - phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true); 118 + phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, true); 124 119 125 120 if (device_may_wakeup(dev)) 126 121 phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false);
-247
drivers/usb/phy/phy-rcar-usb.c
··· 1 - /* 2 - * Renesas R-Car USB phy driver 3 - * 4 - * Copyright (C) 2012-2013 Renesas Solutions Corp. 5 - * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 6 - * Copyright (C) 2013 Cogent Embedded, Inc. 7 - * 8 - * This program is free software; you can redistribute it and/or modify 9 - * it under the terms of the GNU General Public License version 2 as 10 - * published by the Free Software Foundation. 11 - */ 12 - 13 - #include <linux/delay.h> 14 - #include <linux/io.h> 15 - #include <linux/usb/otg.h> 16 - #include <linux/platform_device.h> 17 - #include <linux/spinlock.h> 18 - #include <linux/module.h> 19 - #include <linux/platform_data/usb-rcar-phy.h> 20 - 21 - /* REGS block */ 22 - #define USBPCTRL0 0x00 23 - #define USBPCTRL1 0x04 24 - #define USBST 0x08 25 - #define USBEH0 0x0C 26 - #define USBOH0 0x1C 27 - #define USBCTL0 0x58 28 - 29 - /* High-speed signal quality characteristic control registers (R8A7778 only) */ 30 - #define HSQCTL1 0x24 31 - #define HSQCTL2 0x28 32 - 33 - /* USBPCTRL0 */ 34 - #define OVC2 (1 << 10) /* (R8A7779 only) */ 35 - /* Switches the OVC input pin for port 2: */ 36 - /* 1: USB_OVC2, 0: OVC2 */ 37 - #define OVC1_VBUS1 (1 << 9) /* Switches the OVC input pin for port 1: */ 38 - /* 1: USB_OVC1, 0: OVC1/VBUS1 */ 39 - /* Function mode: set to 0 */ 40 - #define OVC0 (1 << 8) /* Switches the OVC input pin for port 0: */ 41 - /* 1: USB_OVC0 pin, 0: OVC0 */ 42 - #define OVC2_ACT (1 << 6) /* (R8A7779 only) */ 43 - /* Host mode: OVC2 polarity: */ 44 - /* 1: active-high, 0: active-low */ 45 - #define PENC (1 << 4) /* Function mode: output level of PENC1 pin: */ 46 - /* 1: high, 0: low */ 47 - #define OVC0_ACT (1 << 3) /* Host mode: OVC0 polarity: */ 48 - /* 1: active-high, 0: active-low */ 49 - #define OVC1_ACT (1 << 1) /* Host mode: OVC1 polarity: */ 50 - /* 1: active-high, 0: active-low */ 51 - /* Function mode: be sure to set to 1 */ 52 - #define PORT1 (1 << 0) /* Selects port 1 mode: */ 53 - /* 1: function, 0: host */ 54 - /* USBPCTRL1 */ 55 - #define PHY_RST (1 << 2) 56 - #define PLL_ENB (1 << 1) 57 - #define PHY_ENB (1 << 0) 58 - 59 - /* USBST */ 60 - #define ST_ACT (1 << 31) 61 - #define ST_PLL (1 << 30) 62 - 63 - struct rcar_usb_phy_priv { 64 - struct usb_phy phy; 65 - spinlock_t lock; 66 - 67 - void __iomem *reg0; 68 - void __iomem *reg1; 69 - int counter; 70 - }; 71 - 72 - #define usb_phy_to_priv(p) container_of(p, struct rcar_usb_phy_priv, phy) 73 - 74 - 75 - /* 76 - * USB initial/install operation. 77 - * 78 - * This function setup USB phy. 79 - * The used value and setting order came from 80 - * [USB :: Initial setting] on datasheet. 81 - */ 82 - static int rcar_usb_phy_init(struct usb_phy *phy) 83 - { 84 - struct rcar_usb_phy_priv *priv = usb_phy_to_priv(phy); 85 - struct device *dev = phy->dev; 86 - struct rcar_phy_platform_data *pdata = dev_get_platdata(dev); 87 - void __iomem *reg0 = priv->reg0; 88 - void __iomem *reg1 = priv->reg1; 89 - static const u8 ovcn_act[] = { OVC0_ACT, OVC1_ACT, OVC2_ACT }; 90 - int i; 91 - u32 val; 92 - unsigned long flags; 93 - 94 - spin_lock_irqsave(&priv->lock, flags); 95 - if (priv->counter++ == 0) { 96 - 97 - /* 98 - * USB phy start-up 99 - */ 100 - 101 - /* (1) USB-PHY standby release */ 102 - iowrite32(PHY_ENB, (reg0 + USBPCTRL1)); 103 - 104 - /* (2) start USB-PHY internal PLL */ 105 - iowrite32(PHY_ENB | PLL_ENB, (reg0 + USBPCTRL1)); 106 - 107 - /* (3) set USB-PHY in accord with the conditions of usage */ 108 - if (reg1) { 109 - u32 hsqctl1 = pdata->ferrite_bead ? 0x41 : 0; 110 - u32 hsqctl2 = pdata->ferrite_bead ? 0x0d : 7; 111 - 112 - iowrite32(hsqctl1, reg1 + HSQCTL1); 113 - iowrite32(hsqctl2, reg1 + HSQCTL2); 114 - } 115 - 116 - /* (4) USB module status check */ 117 - for (i = 0; i < 1024; i++) { 118 - udelay(10); 119 - val = ioread32(reg0 + USBST); 120 - if (val == (ST_ACT | ST_PLL)) 121 - break; 122 - } 123 - 124 - if (val != (ST_ACT | ST_PLL)) { 125 - dev_err(dev, "USB phy not ready\n"); 126 - goto phy_init_end; 127 - } 128 - 129 - /* (5) USB-PHY reset clear */ 130 - iowrite32(PHY_ENB | PLL_ENB | PHY_RST, (reg0 + USBPCTRL1)); 131 - 132 - /* Board specific port settings */ 133 - val = 0; 134 - if (pdata->port1_func) 135 - val |= PORT1; 136 - if (pdata->penc1) 137 - val |= PENC; 138 - for (i = 0; i < 3; i++) { 139 - /* OVCn bits follow each other in the right order */ 140 - if (pdata->ovc_pin[i].select_3_3v) 141 - val |= OVC0 << i; 142 - /* OVCn_ACT bits are spaced by irregular intervals */ 143 - if (pdata->ovc_pin[i].active_high) 144 - val |= ovcn_act[i]; 145 - } 146 - iowrite32(val, (reg0 + USBPCTRL0)); 147 - 148 - /* 149 - * Bus alignment settings 150 - */ 151 - 152 - /* (1) EHCI bus alignment (little endian) */ 153 - iowrite32(0x00000000, (reg0 + USBEH0)); 154 - 155 - /* (1) OHCI bus alignment (little endian) */ 156 - iowrite32(0x00000000, (reg0 + USBOH0)); 157 - } 158 - 159 - phy_init_end: 160 - spin_unlock_irqrestore(&priv->lock, flags); 161 - 162 - return 0; 163 - } 164 - 165 - static void rcar_usb_phy_shutdown(struct usb_phy *phy) 166 - { 167 - struct rcar_usb_phy_priv *priv = usb_phy_to_priv(phy); 168 - void __iomem *reg0 = priv->reg0; 169 - unsigned long flags; 170 - 171 - spin_lock_irqsave(&priv->lock, flags); 172 - 173 - if (priv->counter-- == 1) /* last user */ 174 - iowrite32(0x00000000, (reg0 + USBPCTRL1)); 175 - 176 - spin_unlock_irqrestore(&priv->lock, flags); 177 - } 178 - 179 - static int rcar_usb_phy_probe(struct platform_device *pdev) 180 - { 181 - struct rcar_usb_phy_priv *priv; 182 - struct resource *res0, *res1; 183 - struct device *dev = &pdev->dev; 184 - void __iomem *reg0, *reg1 = NULL; 185 - int ret; 186 - 187 - if (!dev_get_platdata(&pdev->dev)) { 188 - dev_err(dev, "No platform data\n"); 189 - return -EINVAL; 190 - } 191 - 192 - res0 = platform_get_resource(pdev, IORESOURCE_MEM, 0); 193 - reg0 = devm_ioremap_resource(dev, res0); 194 - if (IS_ERR(reg0)) 195 - return PTR_ERR(reg0); 196 - 197 - res1 = platform_get_resource(pdev, IORESOURCE_MEM, 1); 198 - reg1 = devm_ioremap_resource(dev, res1); 199 - if (IS_ERR(reg1)) 200 - return PTR_ERR(reg1); 201 - 202 - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 203 - if (!priv) 204 - return -ENOMEM; 205 - 206 - priv->reg0 = reg0; 207 - priv->reg1 = reg1; 208 - priv->counter = 0; 209 - priv->phy.dev = dev; 210 - priv->phy.label = dev_name(dev); 211 - priv->phy.init = rcar_usb_phy_init; 212 - priv->phy.shutdown = rcar_usb_phy_shutdown; 213 - spin_lock_init(&priv->lock); 214 - 215 - ret = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2); 216 - if (ret < 0) { 217 - dev_err(dev, "usb phy addition error\n"); 218 - return ret; 219 - } 220 - 221 - platform_set_drvdata(pdev, priv); 222 - 223 - return ret; 224 - } 225 - 226 - static int rcar_usb_phy_remove(struct platform_device *pdev) 227 - { 228 - struct rcar_usb_phy_priv *priv = platform_get_drvdata(pdev); 229 - 230 - usb_remove_phy(&priv->phy); 231 - 232 - return 0; 233 - } 234 - 235 - static struct platform_driver rcar_usb_phy_driver = { 236 - .driver = { 237 - .name = "rcar_usb_phy", 238 - }, 239 - .probe = rcar_usb_phy_probe, 240 - .remove = rcar_usb_phy_remove, 241 - }; 242 - 243 - module_platform_driver(rcar_usb_phy_driver); 244 - 245 - MODULE_LICENSE("GPL v2"); 246 - MODULE_DESCRIPTION("Renesas R-Car USB phy"); 247 - MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
+15 -15
drivers/usb/phy/phy-twl6030-usb.c
··· 25 25 #include <linux/interrupt.h> 26 26 #include <linux/platform_device.h> 27 27 #include <linux/io.h> 28 - #include <linux/usb/musb-omap.h> 28 + #include <linux/usb/musb.h> 29 29 #include <linux/usb/phy_companion.h> 30 30 #include <linux/phy/omap_usb.h> 31 31 #include <linux/i2c/twl.h> ··· 102 102 103 103 int irq1; 104 104 int irq2; 105 - enum omap_musb_vbus_id_status linkstat; 105 + enum musb_vbus_id_status linkstat; 106 106 u8 asleep; 107 107 bool vbus_enable; 108 108 const char *regulator; ··· 189 189 spin_lock_irqsave(&twl->lock, flags); 190 190 191 191 switch (twl->linkstat) { 192 - case OMAP_MUSB_VBUS_VALID: 192 + case MUSB_VBUS_VALID: 193 193 ret = snprintf(buf, PAGE_SIZE, "vbus\n"); 194 194 break; 195 - case OMAP_MUSB_ID_GROUND: 195 + case MUSB_ID_GROUND: 196 196 ret = snprintf(buf, PAGE_SIZE, "id\n"); 197 197 break; 198 - case OMAP_MUSB_VBUS_OFF: 198 + case MUSB_VBUS_OFF: 199 199 ret = snprintf(buf, PAGE_SIZE, "none\n"); 200 200 break; 201 201 default: ··· 210 210 static irqreturn_t twl6030_usb_irq(int irq, void *_twl) 211 211 { 212 212 struct twl6030_usb *twl = _twl; 213 - enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN; 213 + enum musb_vbus_id_status status = MUSB_UNKNOWN; 214 214 u8 vbus_state, hw_state; 215 215 int ret; 216 216 ··· 225 225 dev_err(twl->dev, "Failed to enable usb3v3\n"); 226 226 227 227 twl->asleep = 1; 228 - status = OMAP_MUSB_VBUS_VALID; 228 + status = MUSB_VBUS_VALID; 229 229 twl->linkstat = status; 230 - omap_musb_mailbox(status); 230 + musb_mailbox(status); 231 231 } else { 232 - if (twl->linkstat != OMAP_MUSB_UNKNOWN) { 233 - status = OMAP_MUSB_VBUS_OFF; 232 + if (twl->linkstat != MUSB_UNKNOWN) { 233 + status = MUSB_VBUS_OFF; 234 234 twl->linkstat = status; 235 - omap_musb_mailbox(status); 235 + musb_mailbox(status); 236 236 if (twl->asleep) { 237 237 regulator_disable(twl->usb3v3); 238 238 twl->asleep = 0; ··· 248 248 static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl) 249 249 { 250 250 struct twl6030_usb *twl = _twl; 251 - enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN; 251 + enum musb_vbus_id_status status = MUSB_UNKNOWN; 252 252 u8 hw_state; 253 253 int ret; 254 254 ··· 262 262 twl->asleep = 1; 263 263 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_CLR); 264 264 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_SET); 265 - status = OMAP_MUSB_ID_GROUND; 265 + status = MUSB_ID_GROUND; 266 266 twl->linkstat = status; 267 - omap_musb_mailbox(status); 267 + musb_mailbox(status); 268 268 } else { 269 269 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_CLR); 270 270 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_SET); ··· 334 334 twl->dev = &pdev->dev; 335 335 twl->irq1 = platform_get_irq(pdev, 0); 336 336 twl->irq2 = platform_get_irq(pdev, 1); 337 - twl->linkstat = OMAP_MUSB_UNKNOWN; 337 + twl->linkstat = MUSB_UNKNOWN; 338 338 339 339 twl->comparator.set_vbus = twl6030_set_vbus; 340 340 twl->comparator.start_srp = twl6030_start_srp;
+43 -35
drivers/usb/renesas_usbhs/common.c
··· 302 302 */ 303 303 304 304 /* commonly used on old SH-Mobile SoCs */ 305 - static u32 usbhsc_default_pipe_type[] = { 306 - USB_ENDPOINT_XFER_CONTROL, 307 - USB_ENDPOINT_XFER_ISOC, 308 - USB_ENDPOINT_XFER_ISOC, 309 - USB_ENDPOINT_XFER_BULK, 310 - USB_ENDPOINT_XFER_BULK, 311 - USB_ENDPOINT_XFER_BULK, 312 - USB_ENDPOINT_XFER_INT, 313 - USB_ENDPOINT_XFER_INT, 314 - USB_ENDPOINT_XFER_INT, 315 - USB_ENDPOINT_XFER_INT, 305 + static struct renesas_usbhs_driver_pipe_config usbhsc_default_pipe[] = { 306 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_CONTROL, 64, 0x00, false), 307 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x08, false), 308 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x18, false), 309 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x28, true), 310 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x38, true), 311 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x48, true), 312 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x04, false), 313 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x05, false), 314 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x06, false), 315 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x07, false), 316 316 }; 317 317 318 318 /* commonly used on newer SH-Mobile and R-Car SoCs */ 319 - static u32 usbhsc_new_pipe_type[] = { 320 - USB_ENDPOINT_XFER_CONTROL, 321 - USB_ENDPOINT_XFER_ISOC, 322 - USB_ENDPOINT_XFER_ISOC, 323 - USB_ENDPOINT_XFER_BULK, 324 - USB_ENDPOINT_XFER_BULK, 325 - USB_ENDPOINT_XFER_BULK, 326 - USB_ENDPOINT_XFER_INT, 327 - USB_ENDPOINT_XFER_INT, 328 - USB_ENDPOINT_XFER_INT, 329 - USB_ENDPOINT_XFER_BULK, 330 - USB_ENDPOINT_XFER_BULK, 331 - USB_ENDPOINT_XFER_BULK, 332 - USB_ENDPOINT_XFER_BULK, 333 - USB_ENDPOINT_XFER_BULK, 334 - USB_ENDPOINT_XFER_BULK, 335 - USB_ENDPOINT_XFER_BULK, 319 + static struct renesas_usbhs_driver_pipe_config usbhsc_new_pipe[] = { 320 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_CONTROL, 64, 0x00, false), 321 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x08, true), 322 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x28, true), 323 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x48, true), 324 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x58, true), 325 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x68, true), 326 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x04, false), 327 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x05, false), 328 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x06, false), 329 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x78, true), 330 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x88, true), 331 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x98, true), 332 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xa8, true), 333 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xb8, true), 334 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xc8, true), 335 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xd8, true), 336 336 }; 337 337 338 338 /* ··· 481 481 .compatible = "renesas,usbhs-r8a7795", 482 482 .data = (void *)USBHS_TYPE_RCAR_GEN2, 483 483 }, 484 + { 485 + .compatible = "renesas,rcar-gen2-usbhs", 486 + .data = (void *)USBHS_TYPE_RCAR_GEN2, 487 + }, 488 + { 489 + /* Gen3 is compatible with Gen2 */ 490 + .compatible = "renesas,rcar-gen3-usbhs", 491 + .data = (void *)USBHS_TYPE_RCAR_GEN2, 492 + }, 484 493 { }, 485 494 }; 486 495 MODULE_DEVICE_TABLE(of, usbhs_of_match); ··· 573 564 switch (priv->dparam.type) { 574 565 case USBHS_TYPE_RCAR_GEN2: 575 566 priv->pfunc = usbhs_rcar2_ops; 576 - if (!priv->dparam.pipe_type) { 577 - priv->dparam.pipe_type = usbhsc_new_pipe_type; 578 - priv->dparam.pipe_size = 579 - ARRAY_SIZE(usbhsc_new_pipe_type); 567 + if (!priv->dparam.pipe_configs) { 568 + priv->dparam.pipe_configs = usbhsc_new_pipe; 569 + priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_new_pipe); 580 570 } 581 571 break; 582 572 default: ··· 594 586 dfunc->notify_hotplug = usbhsc_drvcllbck_notify_hotplug; 595 587 596 588 /* set default param if platform doesn't have */ 597 - if (!priv->dparam.pipe_type) { 598 - priv->dparam.pipe_type = usbhsc_default_pipe_type; 599 - priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_default_pipe_type); 589 + if (!priv->dparam.pipe_configs) { 590 + priv->dparam.pipe_configs = usbhsc_default_pipe; 591 + priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_default_pipe); 600 592 } 601 593 if (!priv->dparam.pio_dma_border) 602 594 priv->dparam.pio_dma_border = 64; /* 64byte */
+12 -7
drivers/usb/renesas_usbhs/mod_gadget.c
··· 1042 1042 struct usbhsg_gpriv *gpriv; 1043 1043 struct usbhsg_uep *uep; 1044 1044 struct device *dev = usbhs_priv_to_dev(priv); 1045 + struct renesas_usbhs_driver_pipe_config *pipe_configs = 1046 + usbhs_get_dparam(priv, pipe_configs); 1045 1047 int pipe_size = usbhs_get_dparam(priv, pipe_size); 1046 1048 int i; 1047 1049 int ret; ··· 1113 1111 gpriv->gadget.ep0 = &uep->ep; 1114 1112 usb_ep_set_maxpacket_limit(&uep->ep, 64); 1115 1113 uep->ep.caps.type_control = true; 1116 - } 1117 - /* init normal pipe */ 1118 - else { 1119 - usb_ep_set_maxpacket_limit(&uep->ep, 512); 1120 - uep->ep.caps.type_iso = true; 1121 - uep->ep.caps.type_bulk = true; 1122 - uep->ep.caps.type_int = true; 1114 + } else { 1115 + /* init normal pipe */ 1116 + if (pipe_configs[i].type == USB_ENDPOINT_XFER_ISOC) 1117 + uep->ep.caps.type_iso = true; 1118 + if (pipe_configs[i].type == USB_ENDPOINT_XFER_BULK) 1119 + uep->ep.caps.type_bulk = true; 1120 + if (pipe_configs[i].type == USB_ENDPOINT_XFER_INT) 1121 + uep->ep.caps.type_int = true; 1122 + usb_ep_set_maxpacket_limit(&uep->ep, 1123 + pipe_configs[i].bufsize); 1123 1124 list_add_tail(&uep->ep.ep_list, &gpriv->gadget.ep_list); 1124 1125 } 1125 1126 uep->ep.caps.dir_in = true;
+6 -5
drivers/usb/renesas_usbhs/mod_host.c
··· 1414 1414 { 1415 1415 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv); 1416 1416 struct usbhs_pipe *pipe; 1417 - u32 *pipe_type = usbhs_get_dparam(priv, pipe_type); 1417 + struct renesas_usbhs_driver_pipe_config *pipe_configs = 1418 + usbhs_get_dparam(priv, pipe_configs); 1418 1419 int pipe_size = usbhs_get_dparam(priv, pipe_size); 1419 1420 int old_type, dir_in, i; 1420 1421 ··· 1443 1442 * USB_ENDPOINT_XFER_BULK -> dir in 1444 1443 * ... 1445 1444 */ 1446 - dir_in = (pipe_type[i] == old_type); 1447 - old_type = pipe_type[i]; 1445 + dir_in = (pipe_configs[i].type == old_type); 1446 + old_type = pipe_configs[i].type; 1448 1447 1449 - if (USB_ENDPOINT_XFER_CONTROL == pipe_type[i]) { 1448 + if (USB_ENDPOINT_XFER_CONTROL == pipe_configs[i].type) { 1450 1449 pipe = usbhs_dcp_malloc(priv); 1451 1450 usbhsh_hpriv_to_dcp(hpriv) = pipe; 1452 1451 } else { 1453 1452 pipe = usbhs_pipe_malloc(priv, 1454 - pipe_type[i], 1453 + pipe_configs[i].type, 1455 1454 dir_in); 1456 1455 } 1457 1456
+26 -86
drivers/usb/renesas_usbhs/pipe.c
··· 44 44 return usbhsp_pipe_name[usbhs_pipe_type(pipe)]; 45 45 } 46 46 47 + static struct renesas_usbhs_driver_pipe_config 48 + *usbhsp_get_pipe_config(struct usbhs_priv *priv, int pipe_num) 49 + { 50 + struct renesas_usbhs_driver_pipe_config *pipe_configs = 51 + usbhs_get_dparam(priv, pipe_configs); 52 + 53 + return &pipe_configs[pipe_num]; 54 + } 55 + 47 56 /* 48 57 * DCPCTR/PIPEnCTR functions 49 58 */ ··· 393 384 /* 394 385 * pipe setup 395 386 */ 396 - static int usbhsp_possible_double_buffer(struct usbhs_pipe *pipe) 397 - { 398 - /* 399 - * only ISO / BULK pipe can use double buffer 400 - */ 401 - if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK) || 402 - usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_ISOC)) 403 - return 1; 404 - 405 - return 0; 406 - } 407 - 408 387 static u16 usbhsp_setup_pipecfg(struct usbhs_pipe *pipe, 409 388 int is_host, 410 389 int dir_in) ··· 409 412 [USB_ENDPOINT_XFER_INT] = TYPE_INT, 410 413 [USB_ENDPOINT_XFER_ISOC] = TYPE_ISO, 411 414 }; 412 - int is_double = usbhsp_possible_double_buffer(pipe); 413 415 414 416 if (usbhs_pipe_is_dcp(pipe)) 415 417 return -EINVAL; ··· 430 434 usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK)) 431 435 bfre = 0; /* FIXME */ 432 436 433 - /* DBLB */ 434 - if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_ISOC) || 435 - usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK)) 436 - dblb = (is_double) ? DBLB : 0; 437 + /* DBLB: see usbhs_pipe_config_update() */ 437 438 438 439 /* CNTMD */ 439 440 if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK)) ··· 466 473 static u16 usbhsp_setup_pipebuff(struct usbhs_pipe *pipe) 467 474 { 468 475 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); 469 - struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv); 470 476 struct device *dev = usbhs_priv_to_dev(priv); 471 477 int pipe_num = usbhs_pipe_number(pipe); 472 - int is_double = usbhsp_possible_double_buffer(pipe); 473 478 u16 buff_size; 474 479 u16 bufnmb; 475 480 u16 bufnmb_cnt; 481 + struct renesas_usbhs_driver_pipe_config *pipe_config = 482 + usbhsp_get_pipe_config(priv, pipe_num); 476 483 477 484 /* 478 485 * PIPEBUF ··· 482 489 * - "Features" - "Pipe configuration" 483 490 * - "Operation" - "FIFO Buffer Memory" 484 491 * - "Operation" - "Pipe Control" 485 - * 486 - * ex) if pipe6 - pipe9 are USB_ENDPOINT_XFER_INT (SH7724) 487 - * 488 - * BUFNMB: PIPE 489 - * 0: pipe0 (DCP 256byte) 490 - * 1: - 491 - * 2: - 492 - * 3: - 493 - * 4: pipe6 (INT 64byte) 494 - * 5: pipe7 (INT 64byte) 495 - * 6: pipe8 (INT 64byte) 496 - * 7: pipe9 (INT 64byte) 497 - * 8 - xx: free (for BULK, ISOC) 498 492 */ 499 - 500 - /* 501 - * FIXME 502 - * 503 - * it doesn't have good buffer allocator 504 - * 505 - * DCP : 256 byte 506 - * BULK: 512 byte 507 - * INT : 64 byte 508 - * ISOC: 512 byte 509 - */ 510 - if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_CONTROL)) 511 - buff_size = 256; 512 - else if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_INT)) 513 - buff_size = 64; 514 - else 515 - buff_size = 512; 493 + buff_size = pipe_config->bufsize; 494 + bufnmb = pipe_config->bufnum; 516 495 517 496 /* change buff_size to register value */ 518 497 bufnmb_cnt = (buff_size / 64) - 1; 519 - 520 - /* BUFNMB has been reserved for INT pipe 521 - * see above */ 522 - if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_INT)) { 523 - bufnmb = pipe_num - 2; 524 - } else { 525 - bufnmb = info->bufnmb_last; 526 - info->bufnmb_last += bufnmb_cnt + 1; 527 - 528 - /* 529 - * double buffer 530 - */ 531 - if (is_double) 532 - info->bufnmb_last += bufnmb_cnt + 1; 533 - } 534 498 535 499 dev_dbg(dev, "pipe : %d : buff_size 0x%x: bufnmb 0x%x\n", 536 500 pipe_num, buff_size, bufnmb); ··· 499 549 void usbhs_pipe_config_update(struct usbhs_pipe *pipe, u16 devsel, 500 550 u16 epnum, u16 maxp) 501 551 { 552 + struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); 553 + int pipe_num = usbhs_pipe_number(pipe); 554 + struct renesas_usbhs_driver_pipe_config *pipe_config = 555 + usbhsp_get_pipe_config(priv, pipe_num); 556 + u16 dblb = pipe_config->double_buf ? DBLB : 0; 557 + 502 558 if (devsel > 0xA) { 503 - struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); 504 559 struct device *dev = usbhs_priv_to_dev(priv); 505 560 506 561 dev_err(dev, "devsel error %d\n", devsel); ··· 523 568 maxp); 524 569 525 570 if (!usbhs_pipe_is_dcp(pipe)) 526 - usbhsp_pipe_cfg_set(pipe, 0x000F, epnum); 571 + usbhsp_pipe_cfg_set(pipe, 0x000F | DBLB, epnum | dblb); 527 572 } 528 573 529 574 /* ··· 663 708 struct usbhs_pipe *pipe; 664 709 int i; 665 710 666 - /* 667 - * FIXME 668 - * 669 - * driver needs good allocator. 670 - * 671 - * find first free buffer area (BULK, ISOC) 672 - * (DCP, INT area is fixed) 673 - * 674 - * buffer number 0 - 3 have been reserved for DCP 675 - * see 676 - * usbhsp_to_bufnmb 677 - */ 678 - info->bufnmb_last = 4; 679 711 usbhs_for_each_pipe_with_dcp(pipe, priv, i) { 680 - if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_INT)) 681 - info->bufnmb_last++; 682 - 683 712 usbhsp_flags_init(pipe); 684 713 pipe->fifo = NULL; 685 714 pipe->mod_private = NULL; ··· 790 851 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv); 791 852 struct usbhs_pipe *pipe; 792 853 struct device *dev = usbhs_priv_to_dev(priv); 793 - u32 *pipe_type = usbhs_get_dparam(priv, pipe_type); 854 + struct renesas_usbhs_driver_pipe_config *pipe_configs = 855 + usbhs_get_dparam(priv, pipe_configs); 794 856 int pipe_size = usbhs_get_dparam(priv, pipe_size); 795 857 int i; 796 858 797 859 /* This driver expects 1st pipe is DCP */ 798 - if (pipe_type[0] != USB_ENDPOINT_XFER_CONTROL) { 860 + if (pipe_configs[0].type != USB_ENDPOINT_XFER_CONTROL) { 799 861 dev_err(dev, "1st PIPE is not DCP\n"); 800 862 return -EINVAL; 801 863 } ··· 816 876 pipe->priv = priv; 817 877 818 878 usbhs_pipe_type(pipe) = 819 - pipe_type[i] & USB_ENDPOINT_XFERTYPE_MASK; 879 + pipe_configs[i].type & USB_ENDPOINT_XFERTYPE_MASK; 820 880 821 881 dev_dbg(dev, "pipe %x\t: %s\n", 822 - i, usbhsp_pipe_name[pipe_type[i]]); 882 + i, usbhsp_pipe_name[pipe_configs[i].type]); 823 883 } 824 884 825 885 return 0;
-1
drivers/usb/renesas_usbhs/pipe.h
··· 46 46 struct usbhs_pipe_info { 47 47 struct usbhs_pipe *pipe; 48 48 int size; /* array size of "pipe" */ 49 - int bufnmb_last; /* FIXME : driver needs good allocator */ 50 49 51 50 int (*dma_map_ctrl)(struct usbhs_pkt *pkt, int map); 52 51 };
-28
include/linux/platform_data/usb-rcar-phy.h
··· 1 - /* 2 - * Copyright (C) 2013 Renesas Solutions Corp. 3 - * Copyright (C) 2013 Cogent Embedded, Inc. 4 - * 5 - * This program is free software; you can redistribute it and/or modify 6 - * it under the terms of the GNU General Public License version 2 as 7 - * published by the Free Software Foundation. 8 - */ 9 - 10 - #ifndef __USB_RCAR_PHY_H 11 - #define __USB_RCAR_PHY_H 12 - 13 - #include <linux/types.h> 14 - 15 - struct rcar_phy_platform_data { 16 - bool ferrite_bead:1; /* (R8A7778 only) */ 17 - 18 - bool port1_func:1; /* true: port 1 used by function, false: host */ 19 - unsigned penc1:1; /* Output of the PENC1 pin in function mode */ 20 - struct { /* Overcurrent pin control for ports 0..2 */ 21 - bool select_3_3v:1; /* true: USB_OVCn pin, false: OVCn pin */ 22 - /* Set to false on port 1 in function mode */ 23 - bool active_high:1; /* true: active high, false: active low */ 24 - /* Set to true on port 1 in function mode */ 25 - } ovc_pin[3]; /* (R8A7778 only has 2 ports) */ 26 - }; 27 - 28 - #endif /* __USB_RCAR_PHY_H */
+9 -2
include/linux/usb/gadget.h
··· 402 402 static inline int usb_ep_queue(struct usb_ep *ep, 403 403 struct usb_request *req, gfp_t gfp_flags) 404 404 { 405 + if (WARN_ON_ONCE(!ep->enabled && ep->address)) 406 + return -ESHUTDOWN; 407 + 405 408 return ep->ops->queue(ep, req, gfp_flags); 406 409 } 407 410 ··· 1015 1012 * @reset: Invoked on USB bus reset. It is mandatory for all gadget drivers 1016 1013 * and should be called in_interrupt. 1017 1014 * @driver: Driver model state for this driver. 1015 + * @udc_name: A name of UDC this driver should be bound to. If udc_name is NULL, 1016 + * this driver will be bound to any available UDC. 1017 + * @pending: UDC core private data used for deferred probe of this driver. 1018 1018 * 1019 1019 * Devices are disabled till a gadget driver successfully bind()s, which 1020 1020 * means the driver will handle setup() requests needed to enumerate (and ··· 1078 1072 1079 1073 /* FIXME support safe rmmod */ 1080 1074 struct device_driver driver; 1075 + 1076 + char *udc_name; 1077 + struct list_head pending; 1081 1078 }; 1082 1079 1083 1080 ··· 1126 1117 struct usb_gadget *gadget, void (*release)(struct device *dev)); 1127 1118 extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget); 1128 1119 extern void usb_del_gadget_udc(struct usb_gadget *gadget); 1129 - extern int usb_udc_attach_driver(const char *name, 1130 - struct usb_gadget_driver *driver); 1131 1120 1132 1121 /*-------------------------------------------------------------------------*/ 1133 1122
-30
include/linux/usb/musb-omap.h
··· 1 - /* 2 - * Copyright (C) 2011-2012 by Texas Instruments 3 - * 4 - * The Inventra Controller Driver for Linux is free software; you 5 - * can redistribute it and/or modify it under the terms of the GNU 6 - * General Public License version 2 as published by the Free Software 7 - * Foundation. 8 - */ 9 - 10 - #ifndef __MUSB_OMAP_H__ 11 - #define __MUSB_OMAP_H__ 12 - 13 - enum omap_musb_vbus_id_status { 14 - OMAP_MUSB_UNKNOWN = 0, 15 - OMAP_MUSB_ID_GROUND, 16 - OMAP_MUSB_ID_FLOAT, 17 - OMAP_MUSB_VBUS_VALID, 18 - OMAP_MUSB_VBUS_OFF, 19 - }; 20 - 21 - #if (defined(CONFIG_USB_MUSB_OMAP2PLUS) || \ 22 - defined(CONFIG_USB_MUSB_OMAP2PLUS_MODULE)) 23 - void omap_musb_mailbox(enum omap_musb_vbus_id_status status); 24 - #else 25 - static inline void omap_musb_mailbox(enum omap_musb_vbus_id_status status) 26 - { 27 - } 28 - #endif 29 - 30 - #endif /* __MUSB_OMAP_H__ */
+15
include/linux/usb/musb.h
··· 133 133 const void *platform_ops; 134 134 }; 135 135 136 + enum musb_vbus_id_status { 137 + MUSB_UNKNOWN = 0, 138 + MUSB_ID_GROUND, 139 + MUSB_ID_FLOAT, 140 + MUSB_VBUS_VALID, 141 + MUSB_VBUS_OFF, 142 + }; 143 + 144 + #if IS_ENABLED(CONFIG_USB_MUSB_HDRC) 145 + void musb_mailbox(enum musb_vbus_id_status status); 146 + #else 147 + static inline void musb_mailbox(enum musb_vbus_id_status status) 148 + { 149 + } 150 + #endif 136 151 137 152 /* TUSB 6010 support */ 138 153
+6
include/linux/usb/of.h
··· 12 12 #include <linux/usb/phy.h> 13 13 14 14 #if IS_ENABLED(CONFIG_OF) 15 + enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np); 15 16 bool of_usb_host_tpl_support(struct device_node *np); 16 17 int of_usb_update_otg_caps(struct device_node *np, 17 18 struct usb_otg_caps *otg_caps); 18 19 #else 20 + static inline enum usb_dr_mode 21 + of_usb_get_dr_mode_by_phy(struct device_node *phy_np) 22 + { 23 + return USB_DR_MODE_UNKNOWN; 24 + } 19 25 static inline bool of_usb_host_tpl_support(struct device_node *np) 20 26 { 21 27 return false;
+16 -2
include/linux/usb/renesas_usbhs.h
··· 105 105 * some register needs USB chip specific parameters. 106 106 * This struct show it to driver 107 107 */ 108 + 109 + struct renesas_usbhs_driver_pipe_config { 110 + u8 type; /* USB_ENDPOINT_XFER_xxx */ 111 + u16 bufsize; 112 + u8 bufnum; 113 + bool double_buf; 114 + }; 115 + #define RENESAS_USBHS_PIPE(_type, _size, _num, _double_buf) { \ 116 + .type = (_type), \ 117 + .bufsize = (_size), \ 118 + .bufnum = (_num), \ 119 + .double_buf = (_double_buf), \ 120 + } 121 + 108 122 struct renesas_usbhs_driver_param { 109 123 /* 110 124 * pipe settings 111 125 */ 112 - u32 *pipe_type; /* array of USB_ENDPOINT_XFER_xxx (from ep0) */ 113 - int pipe_size; /* pipe_type array size */ 126 + struct renesas_usbhs_driver_pipe_config *pipe_configs; 127 + int pipe_size; /* pipe_configs array size */ 114 128 115 129 /* 116 130 * option: