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

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

Felipe writes:

USB: changes for v5.10 merge window

Most of changes are on dwc3 (38.8%) with cdns3 falling close
behind (24.1%).

The biggest changes here are a series of non-critical fixes to corner
cases on dwc3, produced by Thinh N, and a series of major improvements
to cdns3 produced by Peter C.

We also have the traditional set of new device support (Intel Keem
Bay, Hikey 970) on dwc3. A series of sparse/coccinelle and checkpatch
fixes on dwc3 by yours truly and a set of minor changes all over the
stack.

* tag 'usb-for-v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb: (117 commits)
usb: dwc2: Fix INTR OUT transfers in DDMA mode.
usb: dwc2: don't use ID/Vbus detection if usb-role-switch on STM32MP15 SoCs
usb: dwc2: override PHY input signals with usb role switch support
dt-bindings: usb: dwc2: add optional usb-role-switch property
usb: dwc3: of-simple: Add compatible string for Intel Keem Bay platform
dt-bindings: usb: Add Intel Keem Bay USB controller bindings
usb: dwc3: gadget: Support up to max stream id
usb: dwc3: gadget: Return early if no TRB update
usb: dwc3: gadget: Keep TRBs in request order
usb: dwc3: gadget: Revise setting IOC when no TRB left
usb: dwc3: gadget: Look ahead when setting IOC
usb: dwc3: gadget: Allow restarting a transfer
usb: bdc: remove duplicated error message
usb: dwc3: Stop active transfers before halting the controller
usb: cdns3: gadget: enlarge the TRB ring length
usb: cdns3: gadget: sg_support is only for DEV_VER_V2 or above
usb: cdns3: gadget: need to handle sg case for workaround 2 case
usb: cdns3: gadget: handle sg list use case at completion correctly
usb: cdns3: gadget: add CHAIN and ISP bit for sg list use case
usb: cdns3: gadget: improve the dump TRB operation at cdns3_ep_run_transfer
...

+2062 -765
+21 -1
Documentation/devicetree/bindings/usb/amlogic,meson-g12a-usb-ctrl.yaml
··· 25 25 The Amlogic A1 embeds a DWC3 USB IP Core configured for USB2 in 26 26 host-only mode. 27 27 28 - The Amlogic GXL & GXM SoCs doesn't embed an USB3 PHY. 28 + The Amlogic GXL, GXM & AXG SoCs doesn't embed an USB3 PHY. 29 29 30 30 properties: 31 31 compatible: 32 32 enum: 33 33 - amlogic,meson-gxl-usb-ctrl 34 34 - amlogic,meson-gxm-usb-ctrl 35 + - amlogic,meson-axg-usb-ctrl 35 36 - amlogic,meson-g12a-usb-ctrl 36 37 - amlogic,meson-a1-usb-ctrl 37 38 ··· 150 149 - const: usb2-phy1 # USB2 PHY1 if USBOTG_B port is used 151 150 - const: usb2-phy2 # USB2 PHY2 if USBOTG_C port is used 152 151 152 + required: 153 + - clock-names 154 + - if: 155 + properties: 156 + compatible: 157 + enum: 158 + - amlogic,meson-axg-usb-ctrl 159 + 160 + then: 161 + properties: 162 + phy-names: 163 + items: 164 + - const: usb2-phy1 # USB2 PHY1 if USBOTG_B port is used 165 + clocks: 166 + minItems: 2 167 + clock-names: 168 + items: 169 + - const: usb_ctrl 170 + - const: ddr 153 171 required: 154 172 - clock-names 155 173 - if:
+1
Documentation/devicetree/bindings/usb/atmel-usb.txt
··· 82 82 "atmel,at91sam9rl-udc" 83 83 "atmel,at91sam9g45-udc" 84 84 "atmel,sama5d3-udc" 85 + "microchip,sam9x60-udc" 85 86 - reg: Address and length of the register set for the device 86 87 - interrupts: Should contain usba interrupt 87 88 - clocks: Should reference the peripheral and host clocks
+96
Documentation/devicetree/bindings/usb/cdns,usb3.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/usb/cdns,usb3.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Cadence USBSS-DRD controller bindings 8 + 9 + maintainers: 10 + - Pawel Laszczak <pawell@cadence.com> 11 + 12 + properties: 13 + compatible: 14 + const: cdns,usb3 15 + 16 + reg: 17 + items: 18 + - description: OTG controller registers 19 + - description: XHCI Host controller registers 20 + - description: DEVICE controller registers 21 + 22 + reg-names: 23 + items: 24 + - const: otg 25 + - const: xhci 26 + - const: dev 27 + 28 + interrupts: 29 + items: 30 + - description: OTG/DRD controller interrupt 31 + - description: XHCI host controller interrupt 32 + - description: Device controller interrupt 33 + 34 + interrupt-names: 35 + items: 36 + - const: host 37 + - const: peripheral 38 + - const: otg 39 + 40 + dr_mode: 41 + enum: [host, otg, peripheral] 42 + 43 + maximum-speed: 44 + enum: [super-speed, high-speed, full-speed] 45 + 46 + phys: 47 + minItems: 1 48 + maxItems: 2 49 + 50 + phy-names: 51 + minItems: 1 52 + maxItems: 2 53 + items: 54 + anyOf: 55 + - const: cdns3,usb2-phy 56 + - const: cdns3,usb3-phy 57 + 58 + cdns,on-chip-buff-size: 59 + description: 60 + size of memory intended as internal memory for endpoints 61 + buffers expressed in KB 62 + $ref: /schemas/types.yaml#/definitions/uint32 63 + 64 + cdns,phyrst-a-enable: 65 + description: Enable resetting of PHY if Rx fail is detected 66 + type: boolean 67 + 68 + required: 69 + - compatible 70 + - reg 71 + - reg-names 72 + - interrupts 73 + 74 + additionalProperties: false 75 + 76 + examples: 77 + - | 78 + #include <dt-bindings/interrupt-controller/arm-gic.h> 79 + bus { 80 + #address-cells = <2>; 81 + #size-cells = <2>; 82 + 83 + usb@6000000 { 84 + compatible = "cdns,usb3"; 85 + reg = <0x00 0x6000000 0x00 0x10000>, 86 + <0x00 0x6010000 0x00 0x10000>, 87 + <0x00 0x6020000 0x00 0x10000>; 88 + reg-names = "otg", "xhci", "dev"; 89 + interrupts = <GIC_SPI 96 IRQ_TYPE_LEVEL_HIGH>, 90 + <GIC_SPI 102 IRQ_TYPE_LEVEL_HIGH>, 91 + <GIC_SPI 120 IRQ_TYPE_LEVEL_HIGH>; 92 + interrupt-names = "host", "peripheral", "otg"; 93 + maximum-speed = "super-speed"; 94 + dr_mode = "otg"; 95 + }; 96 + };
-45
Documentation/devicetree/bindings/usb/cdns-usb3.txt
··· 1 - Binding for the Cadence USBSS-DRD controller 2 - 3 - Required properties: 4 - - reg: Physical base address and size of the controller's register areas. 5 - Controller has 3 different regions: 6 - - HOST registers area 7 - - DEVICE registers area 8 - - OTG/DRD registers area 9 - - reg-names - register memory area names: 10 - "xhci" - for HOST registers space 11 - "dev" - for DEVICE registers space 12 - "otg" - for OTG/DRD registers space 13 - - compatible: Should contain: "cdns,usb3" 14 - - interrupts: Interrupts used by cdns3 controller: 15 - "host" - interrupt used by XHCI driver. 16 - "peripheral" - interrupt used by device driver 17 - "otg" - interrupt used by DRD/OTG part of driver 18 - 19 - Optional properties: 20 - - maximum-speed : valid arguments are "super-speed", "high-speed" and 21 - "full-speed"; refer to usb/generic.txt 22 - - dr_mode: Should be one of "host", "peripheral" or "otg". 23 - - phys: reference to the USB PHY 24 - - phy-names: from the *Generic PHY* bindings; 25 - Supported names are: 26 - - cdns3,usb2-phy 27 - - cdns3,usb3-phy 28 - 29 - - cdns,on-chip-buff-size : size of memory intended as internal memory for endpoints 30 - buffers expressed in KB 31 - 32 - Example: 33 - usb@f3000000 { 34 - compatible = "cdns,usb3"; 35 - interrupts = <GIC_USB_IRQ 7 IRQ_TYPE_LEVEL_HIGH>, 36 - <GIC_USB_IRQ 7 IRQ_TYPE_LEVEL_HIGH>, 37 - <GIC_USB_IRQ 8 IRQ_TYPE_LEVEL_HIGH>; 38 - interrupt-names = "host", "peripheral", "otg"; 39 - reg = <0xf3000000 0x10000>, /* memory area for HOST registers */ 40 - <0xf3010000 0x10000>, /* memory area for DEVICE registers */ 41 - <0xf3020000 0x10000>; /* memory area for OTG/DRD registers */ 42 - reg-names = "xhci", "dev", "otg"; 43 - phys = <&usb2_phy>, <&usb3_phy>; 44 - phy-names = "cdns3,usb2-phy", "cnds3,usb3-phy"; 45 - };
+5
Documentation/devicetree/bindings/usb/dwc2.yaml
··· 39 39 - amlogic,meson-g12a-usb 40 40 - const: snps,dwc2 41 41 - const: amcc,dwc-otg 42 + - const: apm,apm82181-dwc-otg 42 43 - const: snps,dwc2 43 44 - const: st,stm32f4x9-fsotg 44 45 - const: st,stm32f4x9-hsotg ··· 102 101 103 102 dr_mode: 104 103 enum: [host, peripheral, otg] 104 + 105 + usb-role-switch: 106 + $ref: /schemas/types.yaml#/definitions/flag 107 + description: Support role switch. 105 108 106 109 g-rx-fifo-size: 107 110 $ref: /schemas/types.yaml#/definitions/uint32
+3
Documentation/devicetree/bindings/usb/dwc3.txt
··· 78 78 park mode are disabled. 79 79 - snps,dis_metastability_quirk: when set, disable metastability workaround. 80 80 CAUTION: use only if you are absolutely sure of it. 81 + - snps,dis-split-quirk: when set, change the way URBs are handled by the 82 + driver. Needed to avoid -EPROTO errors with usbhid 83 + on some devices (Hikey 970). 81 84 - snps,is-utmi-l1-suspend: true when DWC3 asserts output signal 82 85 utmi_l1_suspend_n, false when asserts utmi_sleep_n 83 86 - snps,hird-threshold: HIRD threshold
+77
Documentation/devicetree/bindings/usb/intel,keembay-dwc3.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/usb/intel,keembay-dwc3.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Intel Keem Bay DWC3 USB controller 8 + 9 + maintainers: 10 + - Wan Ahmad Zainie <wan.ahmad.zainie.wan.mohamad@intel.com> 11 + 12 + properties: 13 + compatible: 14 + const: intel,keembay-dwc3 15 + 16 + clocks: 17 + maxItems: 4 18 + 19 + clock-names: 20 + items: 21 + - const: async_master 22 + - const: ref 23 + - const: alt_ref 24 + - const: suspend 25 + 26 + ranges: true 27 + 28 + '#address-cells': 29 + enum: [ 1, 2 ] 30 + 31 + '#size-cells': 32 + enum: [ 1, 2 ] 33 + 34 + # Required child node: 35 + 36 + patternProperties: 37 + "^dwc3@[0-9a-f]+$": 38 + type: object 39 + description: 40 + A child node must exist to represent the core DWC3 IP block. 41 + The content of the node is defined in dwc3.txt. 42 + 43 + required: 44 + - compatible 45 + - clocks 46 + - clock-names 47 + - ranges 48 + 49 + additionalProperties: false 50 + 51 + examples: 52 + - | 53 + #include <dt-bindings/interrupt-controller/arm-gic.h> 54 + #include <dt-bindings/interrupt-controller/irq.h> 55 + #define KEEM_BAY_A53_AUX_USB 56 + #define KEEM_BAY_A53_AUX_USB_REF 57 + #define KEEM_BAY_A53_AUX_USB_ALT_REF 58 + #define KEEM_BAY_A53_AUX_USB_SUSPEND 59 + 60 + usb { 61 + compatible = "intel,keembay-dwc3"; 62 + clocks = <&scmi_clk KEEM_BAY_A53_AUX_USB>, 63 + <&scmi_clk KEEM_BAY_A53_AUX_USB_REF>, 64 + <&scmi_clk KEEM_BAY_A53_AUX_USB_ALT_REF>, 65 + <&scmi_clk KEEM_BAY_A53_AUX_USB_SUSPEND>; 66 + clock-names = "async_master", "ref", "alt_ref", "suspend"; 67 + ranges; 68 + #address-cells = <1>; 69 + #size-cells = <1>; 70 + 71 + dwc3@34000000 { 72 + compatible = "snps,dwc3"; 73 + reg = <0x34000000 0x10000>; 74 + interrupts = <GIC_SPI 91 IRQ_TYPE_LEVEL_HIGH>; 75 + dr_mode = "peripheral"; 76 + }; 77 + };
+18
MAINTAINERS
··· 3475 3475 F: drivers/pci/controller/pcie-brcmstb.c 3476 3476 N: brcmstb 3477 3477 3478 + BROADCOM BDC DRIVER 3479 + M: Al Cooper <alcooperx@gmail.com> 3480 + L: linux-usb@vger.kernel.org 3481 + L: bcm-kernel-feedback-list@broadcom.com 3482 + S: Maintained 3483 + F: Documentation/devicetree/bindings/usb/brcm,bdc.txt 3484 + F: drivers/usb/gadget/udc/bdc/ 3485 + 3478 3486 BROADCOM BMIPS CPUFREQ DRIVER 3479 3487 M: Markus Mayer <mmayer@broadcom.com> 3480 3488 M: bcm-kernel-feedback-list@broadcom.com ··· 3855 3847 S: Orphan 3856 3848 F: Documentation/devicetree/bindings/mtd/cadence-nand-controller.txt 3857 3849 F: drivers/mtd/nand/raw/cadence-nand-controller.c 3850 + 3851 + CADENCE USB3 DRD IP DRIVER 3852 + M: Peter Chen <peter.chen@nxp.com> 3853 + M: Pawel Laszczak <pawell@cadence.com> 3854 + M: Roger Quadros <rogerq@ti.com> 3855 + L: linux-usb@vger.kernel.org 3856 + S: Maintained 3857 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git 3858 + F: Documentation/devicetree/bindings/usb/cdns-usb3.txt 3859 + F: drivers/usb/cdns3/ 3858 3860 3859 3861 CADET FM/AM RADIO RECEIVER DRIVER 3860 3862 M: Hans Verkuil <hverkuil@xs4all.nl>
+13
arch/arm/boot/dts/at91-sam9x60ek.dts
··· 563 563 atmel,pins = <AT91_PIOD 18 AT91_PERIPH_GPIO AT91_PINCTRL_NONE>; 564 564 }; 565 565 }; 566 + 567 + usb0 { 568 + pinctrl_usba_vbus: usba_vbus { 569 + atmel,pins = <AT91_PIOB 16 AT91_PERIPH_GPIO AT91_PINCTRL_NONE>; 570 + }; 571 + }; 566 572 }; /* pinctrl */ 567 573 568 574 &pmc { ··· 670 664 compatible = "atmel,tcb-timer"; 671 665 reg = <1>; 672 666 }; 667 + }; 668 + 669 + &usb0 { 670 + atmel,vbus-gpio = <&pioB 16 GPIO_ACTIVE_HIGH>; 671 + pinctrl-names = "default"; 672 + pinctrl-0 = <&pinctrl_usba_vbus>; 673 + status = "okay"; 673 674 }; 674 675 675 676 &usb1 {
+14
arch/arm/boot/dts/sam9x60.dtsi
··· 69 69 #size-cells = <1>; 70 70 ranges; 71 71 72 + usb0: gadget@500000 { 73 + #address-cells = <1>; 74 + #size-cells = <0>; 75 + compatible = "microchip,sam9x60-udc"; 76 + reg = <0x00500000 0x100000 77 + 0xf803c000 0x400>; 78 + interrupts = <23 IRQ_TYPE_LEVEL_HIGH 2>; 79 + clocks = <&pmc PMC_TYPE_PERIPHERAL 23>, <&pmc PMC_TYPE_CORE PMC_UTMI>; 80 + clock-names = "pclk", "hclk"; 81 + assigned-clocks = <&pmc PMC_TYPE_CORE PMC_UTMI>; 82 + assigned-clock-rates = <480000000>; 83 + status = "disabled"; 84 + }; 85 + 72 86 usb1: ohci@600000 { 73 87 compatible = "atmel,at91rm9200-ohci", "usb-ohci"; 74 88 reg = <0x00600000 0x100000>;
+186 -5
drivers/usb/cdns3/cdns3-imx.c
··· 15 15 #include <linux/io.h> 16 16 #include <linux/of_platform.h> 17 17 #include <linux/iopoll.h> 18 + #include <linux/pm_runtime.h> 19 + #include "core.h" 18 20 19 21 #define USB3_CORE_CTRL1 0x00 20 22 #define USB3_CORE_CTRL2 0x04 ··· 34 32 /* Register bits definition */ 35 33 36 34 /* USB3_CORE_CTRL1 */ 37 - #define SW_RESET_MASK (0x3f << 26) 35 + #define SW_RESET_MASK GENMASK(31, 26) 38 36 #define PWR_SW_RESET BIT(31) 39 37 #define APB_SW_RESET BIT(30) 40 38 #define AXI_SW_RESET BIT(29) ··· 55 53 #define LPM_CLK_REQ BIT(28) 56 54 #define DEVU3_WAEKUP_EN BIT(14) 57 55 #define OTG_WAKEUP_EN BIT(12) 58 - #define DEV_INT_EN (3 << 8) /* DEV INT b9:8 */ 59 - #define HOST_INT1_EN (1 << 0) /* HOST INT b7:0 */ 56 + #define DEV_INT_EN (3 << 8) /* DEV INT b9:8 */ 57 + #define HOST_INT1_EN (1 << 0) /* HOST INT b7:0 */ 60 58 61 59 /* USB3_CORE_STATUS */ 62 60 #define MDCTRL_CLK_STATUS BIT(15) ··· 68 66 #define CLK_VALID_COMPARE_BITS (0xf << 28) 69 67 #define PHY_REFCLK_REQ (1 << 0) 70 68 69 + /* OTG registers definition */ 70 + #define OTGSTS 0x4 71 + /* OTGSTS */ 72 + #define OTG_NRDY BIT(11) 73 + 74 + /* xHCI registers definition */ 75 + #define XECP_PM_PMCSR 0x8018 76 + #define XECP_AUX_CTRL_REG1 0x8120 77 + 78 + /* Register bits definition */ 79 + /* XECP_AUX_CTRL_REG1 */ 80 + #define CFG_RXDET_P3_EN BIT(15) 81 + 82 + /* XECP_PM_PMCSR */ 83 + #define PS_MASK GENMASK(1, 0) 84 + #define PS_D0 0 85 + #define PS_D1 1 86 + 71 87 struct cdns_imx { 72 88 struct device *dev; 73 89 void __iomem *noncore; 74 90 struct clk_bulk_data *clks; 75 91 int num_clks; 92 + struct platform_device *cdns3_pdev; 76 93 }; 77 94 78 95 static inline u32 cdns_imx_readl(struct cdns_imx *data, u32 offset) ··· 147 126 return ret; 148 127 } 149 128 129 + static int cdns_imx_platform_suspend(struct device *dev, 130 + bool suspend, bool wakeup); 131 + static struct cdns3_platform_data cdns_imx_pdata = { 132 + .platform_suspend = cdns_imx_platform_suspend, 133 + }; 134 + 135 + static const struct of_dev_auxdata cdns_imx_auxdata[] = { 136 + { 137 + .compatible = "cdns,usb3", 138 + .platform_data = &cdns_imx_pdata, 139 + }, 140 + {}, 141 + }; 142 + 150 143 static int cdns_imx_probe(struct platform_device *pdev) 151 144 { 152 145 struct device *dev = &pdev->dev; ··· 197 162 if (ret) 198 163 goto err; 199 164 200 - ret = of_platform_populate(node, NULL, NULL, dev); 165 + ret = of_platform_populate(node, NULL, cdns_imx_auxdata, dev); 201 166 if (ret) { 202 167 dev_err(dev, "failed to create children: %d\n", ret); 203 168 goto err; 204 169 } 205 170 206 - return ret; 171 + device_set_wakeup_capable(dev, true); 172 + pm_runtime_set_active(dev); 173 + pm_runtime_enable(dev); 174 + pm_runtime_forbid(dev); 207 175 176 + return ret; 208 177 err: 209 178 clk_bulk_disable_unprepare(data->num_clks, data->clks); 210 179 return ret; ··· 233 194 return 0; 234 195 } 235 196 197 + #ifdef CONFIG_PM 198 + static void cdns3_set_wakeup(struct cdns_imx *data, bool enable) 199 + { 200 + u32 value; 201 + 202 + value = cdns_imx_readl(data, USB3_INT_REG); 203 + if (enable) 204 + value |= OTG_WAKEUP_EN | DEVU3_WAEKUP_EN; 205 + else 206 + value &= ~(OTG_WAKEUP_EN | DEVU3_WAEKUP_EN); 207 + 208 + cdns_imx_writel(data, USB3_INT_REG, value); 209 + } 210 + 211 + static int cdns_imx_platform_suspend(struct device *dev, 212 + bool suspend, bool wakeup) 213 + { 214 + struct cdns3 *cdns = dev_get_drvdata(dev); 215 + struct device *parent = dev->parent; 216 + struct cdns_imx *data = dev_get_drvdata(parent); 217 + void __iomem *otg_regs = (void __iomem *)(cdns->otg_regs); 218 + void __iomem *xhci_regs = cdns->xhci_regs; 219 + u32 value; 220 + int ret = 0; 221 + 222 + if (cdns->role != USB_ROLE_HOST) 223 + return 0; 224 + 225 + if (suspend) { 226 + /* SW request low power when all usb ports allow to it ??? */ 227 + value = readl(xhci_regs + XECP_PM_PMCSR); 228 + value &= ~PS_MASK; 229 + value |= PS_D1; 230 + writel(value, xhci_regs + XECP_PM_PMCSR); 231 + 232 + /* mdctrl_clk_sel */ 233 + value = cdns_imx_readl(data, USB3_CORE_CTRL1); 234 + value |= MDCTRL_CLK_SEL; 235 + cdns_imx_writel(data, USB3_CORE_CTRL1, value); 236 + 237 + /* wait for mdctrl_clk_status */ 238 + value = cdns_imx_readl(data, USB3_CORE_STATUS); 239 + ret = readl_poll_timeout(data->noncore + USB3_CORE_STATUS, value, 240 + (value & MDCTRL_CLK_STATUS) == MDCTRL_CLK_STATUS, 241 + 10, 100000); 242 + if (ret) 243 + dev_warn(parent, "wait mdctrl_clk_status timeout\n"); 244 + 245 + /* wait lpm_clk_req to be 0 */ 246 + value = cdns_imx_readl(data, USB3_INT_REG); 247 + ret = readl_poll_timeout(data->noncore + USB3_INT_REG, value, 248 + (value & LPM_CLK_REQ) != LPM_CLK_REQ, 249 + 10, 100000); 250 + if (ret) 251 + dev_warn(parent, "wait lpm_clk_req timeout\n"); 252 + 253 + /* wait phy_refclk_req to be 0 */ 254 + value = cdns_imx_readl(data, USB3_SSPHY_STATUS); 255 + ret = readl_poll_timeout(data->noncore + USB3_SSPHY_STATUS, value, 256 + (value & PHY_REFCLK_REQ) != PHY_REFCLK_REQ, 257 + 10, 100000); 258 + if (ret) 259 + dev_warn(parent, "wait phy_refclk_req timeout\n"); 260 + 261 + cdns3_set_wakeup(data, wakeup); 262 + } else { 263 + cdns3_set_wakeup(data, false); 264 + 265 + /* SW request D0 */ 266 + value = readl(xhci_regs + XECP_PM_PMCSR); 267 + value &= ~PS_MASK; 268 + value |= PS_D0; 269 + writel(value, xhci_regs + XECP_PM_PMCSR); 270 + 271 + /* clr CFG_RXDET_P3_EN */ 272 + value = readl(xhci_regs + XECP_AUX_CTRL_REG1); 273 + value &= ~CFG_RXDET_P3_EN; 274 + writel(value, xhci_regs + XECP_AUX_CTRL_REG1); 275 + 276 + /* clear mdctrl_clk_sel */ 277 + value = cdns_imx_readl(data, USB3_CORE_CTRL1); 278 + value &= ~MDCTRL_CLK_SEL; 279 + cdns_imx_writel(data, USB3_CORE_CTRL1, value); 280 + 281 + /* wait CLK_125_REQ to be 1 */ 282 + value = cdns_imx_readl(data, USB3_INT_REG); 283 + ret = readl_poll_timeout(data->noncore + USB3_INT_REG, value, 284 + (value & CLK_125_REQ) == CLK_125_REQ, 285 + 10, 100000); 286 + if (ret) 287 + dev_warn(parent, "wait CLK_125_REQ timeout\n"); 288 + 289 + /* wait for mdctrl_clk_status is cleared */ 290 + value = cdns_imx_readl(data, USB3_CORE_STATUS); 291 + ret = readl_poll_timeout(data->noncore + USB3_CORE_STATUS, value, 292 + (value & MDCTRL_CLK_STATUS) != MDCTRL_CLK_STATUS, 293 + 10, 100000); 294 + if (ret) 295 + dev_warn(parent, "wait mdctrl_clk_status cleared timeout\n"); 296 + 297 + /* Wait until OTG_NRDY is 0 */ 298 + value = readl(otg_regs + OTGSTS); 299 + ret = readl_poll_timeout(otg_regs + OTGSTS, value, 300 + (value & OTG_NRDY) != OTG_NRDY, 301 + 10, 100000); 302 + if (ret) 303 + dev_warn(parent, "wait OTG ready timeout\n"); 304 + } 305 + 306 + return ret; 307 + 308 + } 309 + 310 + static int cdns_imx_resume(struct device *dev) 311 + { 312 + struct cdns_imx *data = dev_get_drvdata(dev); 313 + 314 + return clk_bulk_prepare_enable(data->num_clks, data->clks); 315 + } 316 + 317 + static int cdns_imx_suspend(struct device *dev) 318 + { 319 + struct cdns_imx *data = dev_get_drvdata(dev); 320 + 321 + clk_bulk_disable_unprepare(data->num_clks, data->clks); 322 + 323 + return 0; 324 + } 325 + #else 326 + static int cdns_imx_platform_suspend(struct device *dev, 327 + bool suspend, bool wakeup) 328 + { 329 + return 0; 330 + } 331 + 332 + #endif /* CONFIG_PM */ 333 + 334 + static const struct dev_pm_ops cdns_imx_pm_ops = { 335 + SET_RUNTIME_PM_OPS(cdns_imx_suspend, cdns_imx_resume, NULL) 336 + }; 337 + 236 338 static const struct of_device_id cdns_imx_of_match[] = { 237 339 { .compatible = "fsl,imx8qm-usb3", }, 238 340 {}, ··· 386 206 .driver = { 387 207 .name = "cdns3-imx", 388 208 .of_match_table = cdns_imx_of_match, 209 + .pm = &cdns_imx_pm_ops, 389 210 }, 390 211 }; 391 212 module_platform_driver(cdns_imx_driver);
+171 -33
drivers/usb/cdns3/core.c
··· 280 280 enum usb_role real_role, current_role; 281 281 int ret = 0; 282 282 283 + /* Depends on role switch class */ 284 + if (cdns->role_sw) 285 + return 0; 286 + 283 287 pm_runtime_get_sync(cdns->dev); 284 288 285 289 current_role = cdns->role; ··· 375 371 return ret; 376 372 } 377 373 374 + static int set_phy_power_on(struct cdns3 *cdns) 375 + { 376 + int ret; 377 + 378 + ret = phy_power_on(cdns->usb2_phy); 379 + if (ret) 380 + return ret; 381 + 382 + ret = phy_power_on(cdns->usb3_phy); 383 + if (ret) 384 + phy_power_off(cdns->usb2_phy); 385 + 386 + return ret; 387 + } 388 + 389 + static void set_phy_power_off(struct cdns3 *cdns) 390 + { 391 + phy_power_off(cdns->usb3_phy); 392 + phy_power_off(cdns->usb2_phy); 393 + } 394 + 395 + /** 396 + * cdns3_wakeup_irq - interrupt handler for wakeup events 397 + * @irq: irq number for cdns3 core device 398 + * @data: structure of cdns3 399 + * 400 + * Returns IRQ_HANDLED or IRQ_NONE 401 + */ 402 + static irqreturn_t cdns3_wakeup_irq(int irq, void *data) 403 + { 404 + struct cdns3 *cdns = data; 405 + 406 + if (cdns->in_lpm) { 407 + disable_irq_nosync(irq); 408 + cdns->wakeup_pending = true; 409 + if ((cdns->role == USB_ROLE_HOST) && cdns->host_dev) 410 + pm_request_resume(&cdns->host_dev->dev); 411 + 412 + return IRQ_HANDLED; 413 + } 414 + 415 + return IRQ_NONE; 416 + } 417 + 378 418 /** 379 419 * cdns3_probe - probe for cdns3 core device 380 420 * @pdev: Pointer to cdns3 core platform device ··· 445 397 return -ENOMEM; 446 398 447 399 cdns->dev = dev; 400 + cdns->pdata = dev_get_platdata(dev); 448 401 449 402 platform_set_drvdata(pdev, cdns); 450 403 ··· 492 443 return -ENXIO; 493 444 } 494 445 446 + cdns->phyrst_a_enable = device_property_read_bool(dev, "cdns,phyrst-a-enable"); 447 + 495 448 cdns->otg_res = *res; 449 + 450 + cdns->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup"); 451 + if (cdns->wakeup_irq == -EPROBE_DEFER) 452 + return cdns->wakeup_irq; 453 + else if (cdns->wakeup_irq == 0) 454 + return -EINVAL; 455 + 456 + if (cdns->wakeup_irq < 0) { 457 + dev_dbg(dev, "couldn't get wakeup irq\n"); 458 + cdns->wakeup_irq = 0x0; 459 + } 496 460 497 461 mutex_init(&cdns->mutex); 498 462 ··· 525 463 if (ret) 526 464 goto err1; 527 465 528 - ret = phy_power_on(cdns->usb2_phy); 466 + ret = set_phy_power_on(cdns); 529 467 if (ret) 530 468 goto err2; 531 - 532 - ret = phy_power_on(cdns->usb3_phy); 533 - if (ret) 534 - goto err3; 535 469 536 470 sw_desc.set = cdns3_role_set; 537 471 sw_desc.get = cdns3_role_get; ··· 540 482 if (IS_ERR(cdns->role_sw)) { 541 483 ret = PTR_ERR(cdns->role_sw); 542 484 dev_warn(dev, "Unable to register Role Switch\n"); 543 - goto err4; 485 + goto err3; 486 + } 487 + 488 + if (cdns->wakeup_irq) { 489 + ret = devm_request_irq(cdns->dev, cdns->wakeup_irq, 490 + cdns3_wakeup_irq, 491 + IRQF_SHARED, 492 + dev_name(cdns->dev), cdns); 493 + 494 + if (ret) { 495 + dev_err(cdns->dev, "couldn't register wakeup irq handler\n"); 496 + goto err3; 497 + } 544 498 } 545 499 546 500 ret = cdns3_drd_init(cdns); 547 501 if (ret) 548 - goto err5; 502 + goto err4; 549 503 550 504 ret = cdns3_core_init_role(cdns); 551 505 if (ret) 552 - goto err5; 506 + goto err4; 553 507 508 + spin_lock_init(&cdns->lock); 554 509 device_set_wakeup_capable(dev, true); 555 510 pm_runtime_set_active(dev); 556 511 pm_runtime_enable(dev); 512 + pm_runtime_forbid(dev); 557 513 558 514 /* 559 515 * The controller needs less time between bus and controller suspend, ··· 580 508 dev_dbg(dev, "Cadence USB3 core: probe succeed\n"); 581 509 582 510 return 0; 583 - err5: 511 + err4: 584 512 cdns3_drd_exit(cdns); 585 513 usb_role_switch_unregister(cdns->role_sw); 586 - err4: 587 - phy_power_off(cdns->usb3_phy); 588 - 589 514 err3: 590 - phy_power_off(cdns->usb2_phy); 515 + set_phy_power_off(cdns); 591 516 err2: 592 517 phy_exit(cdns->usb3_phy); 593 518 err1: ··· 608 539 pm_runtime_put_noidle(&pdev->dev); 609 540 cdns3_exit_roles(cdns); 610 541 usb_role_switch_unregister(cdns->role_sw); 611 - phy_power_off(cdns->usb2_phy); 612 - phy_power_off(cdns->usb3_phy); 542 + set_phy_power_off(cdns); 613 543 phy_exit(cdns->usb2_phy); 614 544 phy_exit(cdns->usb3_phy); 615 545 return 0; 616 546 } 617 547 548 + #ifdef CONFIG_PM 549 + 550 + static int cdns3_set_platform_suspend(struct device *dev, 551 + bool suspend, bool wakeup) 552 + { 553 + struct cdns3 *cdns = dev_get_drvdata(dev); 554 + int ret = 0; 555 + 556 + if (cdns->pdata && cdns->pdata->platform_suspend) 557 + ret = cdns->pdata->platform_suspend(dev, suspend, wakeup); 558 + 559 + return ret; 560 + } 561 + 562 + static int cdns3_controller_suspend(struct device *dev, pm_message_t msg) 563 + { 564 + struct cdns3 *cdns = dev_get_drvdata(dev); 565 + bool wakeup; 566 + unsigned long flags; 567 + 568 + if (cdns->in_lpm) 569 + return 0; 570 + 571 + if (PMSG_IS_AUTO(msg)) 572 + wakeup = true; 573 + else 574 + wakeup = device_may_wakeup(dev); 575 + 576 + cdns3_set_platform_suspend(cdns->dev, true, wakeup); 577 + set_phy_power_off(cdns); 578 + spin_lock_irqsave(&cdns->lock, flags); 579 + cdns->in_lpm = true; 580 + spin_unlock_irqrestore(&cdns->lock, flags); 581 + dev_dbg(cdns->dev, "%s ends\n", __func__); 582 + 583 + return 0; 584 + } 585 + 586 + static int cdns3_controller_resume(struct device *dev, pm_message_t msg) 587 + { 588 + struct cdns3 *cdns = dev_get_drvdata(dev); 589 + int ret; 590 + unsigned long flags; 591 + 592 + if (!cdns->in_lpm) 593 + return 0; 594 + 595 + ret = set_phy_power_on(cdns); 596 + if (ret) 597 + return ret; 598 + 599 + cdns3_set_platform_suspend(cdns->dev, false, false); 600 + 601 + spin_lock_irqsave(&cdns->lock, flags); 602 + if (cdns->roles[cdns->role]->resume && !PMSG_IS_AUTO(msg)) 603 + cdns->roles[cdns->role]->resume(cdns, false); 604 + 605 + cdns->in_lpm = false; 606 + spin_unlock_irqrestore(&cdns->lock, flags); 607 + if (cdns->wakeup_pending) { 608 + cdns->wakeup_pending = false; 609 + enable_irq(cdns->wakeup_irq); 610 + } 611 + dev_dbg(cdns->dev, "%s ends\n", __func__); 612 + 613 + return ret; 614 + } 615 + 616 + static int cdns3_runtime_suspend(struct device *dev) 617 + { 618 + return cdns3_controller_suspend(dev, PMSG_AUTO_SUSPEND); 619 + } 620 + 621 + static int cdns3_runtime_resume(struct device *dev) 622 + { 623 + return cdns3_controller_resume(dev, PMSG_AUTO_RESUME); 624 + } 618 625 #ifdef CONFIG_PM_SLEEP 619 626 620 627 static int cdns3_suspend(struct device *dev) ··· 698 553 struct cdns3 *cdns = dev_get_drvdata(dev); 699 554 unsigned long flags; 700 555 701 - if (cdns->role == USB_ROLE_HOST) 702 - return 0; 703 - 704 556 if (pm_runtime_status_suspended(dev)) 705 557 pm_runtime_resume(dev); 706 558 707 559 if (cdns->roles[cdns->role]->suspend) { 708 - spin_lock_irqsave(&cdns->gadget_dev->lock, flags); 560 + spin_lock_irqsave(&cdns->lock, flags); 709 561 cdns->roles[cdns->role]->suspend(cdns, false); 710 - spin_unlock_irqrestore(&cdns->gadget_dev->lock, flags); 562 + spin_unlock_irqrestore(&cdns->lock, flags); 711 563 } 712 564 713 - return 0; 565 + return cdns3_controller_suspend(dev, PMSG_SUSPEND); 714 566 } 715 567 716 568 static int cdns3_resume(struct device *dev) 717 569 { 718 - struct cdns3 *cdns = dev_get_drvdata(dev); 719 - unsigned long flags; 570 + int ret; 720 571 721 - if (cdns->role == USB_ROLE_HOST) 722 - return 0; 723 - 724 - if (cdns->roles[cdns->role]->resume) { 725 - spin_lock_irqsave(&cdns->gadget_dev->lock, flags); 726 - cdns->roles[cdns->role]->resume(cdns, false); 727 - spin_unlock_irqrestore(&cdns->gadget_dev->lock, flags); 728 - } 572 + ret = cdns3_controller_resume(dev, PMSG_RESUME); 573 + if (ret) 574 + return ret; 729 575 730 576 pm_runtime_disable(dev); 731 577 pm_runtime_set_active(dev); 732 578 pm_runtime_enable(dev); 733 579 734 - return 0; 580 + return ret; 735 581 } 736 - #endif 582 + #endif /* CONFIG_PM_SLEEP */ 583 + #endif /* CONFIG_PM */ 737 584 738 585 static const struct dev_pm_ops cdns3_pm_ops = { 739 586 SET_SYSTEM_SLEEP_PM_OPS(cdns3_suspend, cdns3_resume) 587 + SET_RUNTIME_PM_OPS(cdns3_runtime_suspend, cdns3_runtime_resume, NULL) 740 588 }; 741 589 742 590 #ifdef CONFIG_OF
+17
drivers/usb/cdns3/core.h
··· 38 38 }; 39 39 40 40 #define CDNS3_XHCI_RESOURCES_NUM 2 41 + 42 + struct cdns3_platform_data { 43 + int (*platform_suspend)(struct device *dev, 44 + bool suspend, bool wakeup); 45 + }; 46 + 41 47 /** 42 48 * struct cdns3 - Representation of Cadence USB3 DRD controller. 43 49 * @dev: pointer to Cadence device struct ··· 56 50 * @otg_regs: pointer to base of otg registers 57 51 * @otg_irq: irq number for otg controller 58 52 * @dev_irq: irq number for device controller 53 + * @wakeup_irq: irq number for wakeup event, it is optional 59 54 * @roles: array of supported roles for this controller 60 55 * @role: current role 61 56 * @host_dev: the child host device pointer for cdns3 core ··· 69 62 * This field based on firmware setting, kernel configuration 70 63 * and hardware configuration. 71 64 * @role_sw: pointer to role switch object. 65 + * @in_lpm: indicate the controller is in low power mode 66 + * @wakeup_pending: wakeup interrupt pending 67 + * @pdata: platform data from glue layer 68 + * @lock: spinlock structure 72 69 */ 73 70 struct cdns3 { 74 71 struct device *dev; ··· 87 76 #define CDNS3_CONTROLLER_V0 0 88 77 #define CDNS3_CONTROLLER_V1 1 89 78 u32 version; 79 + bool phyrst_a_enable; 90 80 91 81 int otg_irq; 92 82 int dev_irq; 83 + int wakeup_irq; 93 84 struct cdns3_role_driver *roles[USB_ROLE_DEVICE + 1]; 94 85 enum usb_role role; 95 86 struct platform_device *host_dev; ··· 102 89 struct mutex mutex; 103 90 enum usb_dr_mode dr_mode; 104 91 struct usb_role_switch *role_sw; 92 + bool in_lpm; 93 + bool wakeup_pending; 94 + struct cdns3_platform_data *pdata; 95 + spinlock_t lock; 105 96 }; 106 97 107 98 int cdns3_hw_role_switch(struct cdns3 *cdns);
+20
drivers/usb/cdns3/drd.c
··· 15 15 #include <linux/delay.h> 16 16 #include <linux/iopoll.h> 17 17 #include <linux/usb/otg.h> 18 + #include <linux/phy/phy.h> 18 19 19 20 #include "gadget.h" 20 21 #include "drd.h" ··· 43 42 reg = readl(&cdns->otg_v1_regs->override); 44 43 reg |= OVERRIDE_IDPULLUP; 45 44 writel(reg, &cdns->otg_v1_regs->override); 45 + 46 + /* 47 + * Enable work around feature built into the 48 + * controller to address issue with RX Sensitivity 49 + * est (EL_17) for USB2 PHY. The issue only occures 50 + * for 0x0002450D controller version. 51 + */ 52 + if (cdns->phyrst_a_enable) { 53 + reg = readl(&cdns->otg_v1_regs->phyrst_cfg); 54 + reg |= PHYRST_CFG_PHYRST_A_ENABLE; 55 + writel(reg, &cdns->otg_v1_regs->phyrst_cfg); 56 + } 46 57 } else { 47 58 reg = readl(&cdns->otg_v0_regs->ctrl1); 48 59 reg |= OVERRIDE_IDPULLUP_V0; ··· 158 145 if (ret) 159 146 dev_err(cdns->dev, "timeout waiting for xhci_ready\n"); 160 147 148 + phy_set_mode(cdns->usb3_phy, PHY_MODE_USB_HOST); 161 149 return ret; 162 150 } 163 151 ··· 178 164 readl_poll_timeout_atomic(&cdns->otg_regs->state, val, 179 165 !(val & OTGSTATE_HOST_STATE_MASK), 180 166 1, 2000000); 167 + phy_set_mode(cdns->usb3_phy, PHY_MODE_INVALID); 181 168 } 182 169 183 170 /** ··· 205 190 return ret; 206 191 } 207 192 193 + phy_set_mode(cdns->usb3_phy, PHY_MODE_USB_DEVICE); 208 194 return 0; 209 195 } 210 196 ··· 229 213 readl_poll_timeout_atomic(&cdns->otg_regs->state, val, 230 214 !(val & OTGSTATE_DEV_STATE_MASK), 231 215 1, 2000000); 216 + phy_set_mode(cdns->usb3_phy, PHY_MODE_INVALID); 232 217 } 233 218 234 219 /** ··· 309 292 310 293 if (cdns->dr_mode != USB_DR_MODE_OTG) 311 294 return IRQ_NONE; 295 + 296 + if (cdns->in_lpm) 297 + return ret; 312 298 313 299 reg = readl(&cdns->otg_regs->ivect); 314 300
+4 -1
drivers/usb/cdns3/drd.h
··· 31 31 __le32 simulate; 32 32 __le32 override; 33 33 __le32 susp_ctrl; 34 - __le32 reserved4; 34 + __le32 phyrst_cfg; 35 35 __le32 anasts; 36 36 __le32 adp_ramp_time; 37 37 __le32 ctrl1; ··· 152 152 #define OVERRIDE_IDPULLUP BIT(0) 153 153 /* Only for CDNS3_CONTROLLER_V0 version */ 154 154 #define OVERRIDE_IDPULLUP_V0 BIT(24) 155 + 156 + /* PHYRST_CFG - bitmasks */ 157 + #define PHYRST_CFG_PHYRST_A_ENABLE BIT(0) 155 158 156 159 #define CDNS3_ID_PERIPHERAL 1 157 160 #define CDNS3_ID_HOST 0
+9 -1
drivers/usb/cdns3/ep0.c
··· 717 717 718 718 /* send STATUS stage. Should be called only for SET_CONFIGURATION */ 719 719 if (priv_dev->ep0_stage == CDNS3_STATUS_STAGE) { 720 + u32 val; 721 + 720 722 cdns3_select_ep(priv_dev, 0x00); 721 723 cdns3_set_hw_configuration(priv_dev); 722 724 cdns3_ep0_complete_setup(priv_dev, 0, 1); 725 + /* wait until configuration set */ 726 + ret = readl_poll_timeout_atomic(&priv_dev->regs->usb_sts, val, 727 + val & USB_STS_CFGSTS_MASK, 1, 100); 728 + if (ret == -ETIMEDOUT) 729 + dev_warn(priv_dev->dev, "timeout for waiting configuration set\n"); 730 + 723 731 request->actual = 0; 724 732 priv_dev->status_completion_no_call = true; 725 733 priv_dev->pending_status_request = request; ··· 739 731 * ep0_queue is back. 740 732 */ 741 733 queue_work(system_freezable_wq, &priv_dev->pending_status_wq); 742 - return 0; 734 + return ret; 743 735 } 744 736 745 737 if (!list_empty(&priv_ep->pending_req_list)) {
+185 -95
drivers/usb/cdns3/gadget.c
··· 261 261 */ 262 262 link_trb->control = 0; 263 263 } else { 264 - link_trb->buffer = TRB_BUFFER(priv_ep->trb_pool_dma); 265 - link_trb->control = TRB_CYCLE | TRB_TYPE(TRB_LINK) | TRB_TOGGLE; 264 + link_trb->buffer = cpu_to_le32(TRB_BUFFER(priv_ep->trb_pool_dma)); 265 + link_trb->control = cpu_to_le32(TRB_CYCLE | TRB_TYPE(TRB_LINK) | TRB_TOGGLE); 266 266 } 267 267 return 0; 268 268 } ··· 462 462 (reg) |= EP_STS_EN_DESCMISEN; \ 463 463 } } while (0) 464 464 465 + static void __cdns3_descmiss_copy_data(struct usb_request *request, 466 + struct usb_request *descmiss_req) 467 + { 468 + int length = request->actual + descmiss_req->actual; 469 + struct scatterlist *s = request->sg; 470 + 471 + if (!s) { 472 + if (length <= request->length) { 473 + memcpy(&((u8 *)request->buf)[request->actual], 474 + descmiss_req->buf, 475 + descmiss_req->actual); 476 + request->actual = length; 477 + } else { 478 + /* It should never occures */ 479 + request->status = -ENOMEM; 480 + } 481 + } else { 482 + if (length <= sg_dma_len(s)) { 483 + void *p = phys_to_virt(sg_dma_address(s)); 484 + 485 + memcpy(&((u8 *)p)[request->actual], 486 + descmiss_req->buf, 487 + descmiss_req->actual); 488 + request->actual = length; 489 + } else { 490 + request->status = -ENOMEM; 491 + } 492 + } 493 + } 494 + 465 495 /** 466 496 * cdns3_wa2_descmiss_copy_data copy data from internal requests to 467 497 * request queued by class driver. ··· 518 488 519 489 chunk_end = descmiss_priv_req->flags & REQUEST_INTERNAL_CH; 520 490 length = request->actual + descmiss_req->actual; 521 - 522 491 request->status = descmiss_req->status; 523 - 524 - if (length <= request->length) { 525 - memcpy(&((u8 *)request->buf)[request->actual], 526 - descmiss_req->buf, 527 - descmiss_req->actual); 528 - request->actual = length; 529 - } else { 530 - /* It should never occures */ 531 - request->status = -ENOMEM; 532 - } 533 - 492 + __cdns3_descmiss_copy_data(request, descmiss_req); 534 493 list_del_init(&descmiss_priv_req->list); 535 - 536 494 kfree(descmiss_req->buf); 537 495 cdns3_gadget_ep_free_request(&priv_ep->endpoint, descmiss_req); 538 496 --priv_ep->wa2_counter; ··· 835 817 request->length); 836 818 837 819 priv_req->flags &= ~(REQUEST_PENDING | REQUEST_UNALIGNED); 820 + /* All TRBs have finished, clear the counter */ 821 + priv_req->finished_trb = 0; 838 822 trace_cdns3_gadget_giveback(priv_req); 839 823 840 824 if (priv_dev->dev_ver < DEV_VER_V2) { ··· 867 847 priv_ep->wa1_trb_index = 0xFFFF; 868 848 if (priv_ep->wa1_cycle_bit) { 869 849 priv_ep->wa1_trb->control = 870 - priv_ep->wa1_trb->control | 0x1; 850 + priv_ep->wa1_trb->control | cpu_to_le32(0x1); 871 851 } else { 872 852 priv_ep->wa1_trb->control = 873 - priv_ep->wa1_trb->control & ~0x1; 853 + priv_ep->wa1_trb->control & cpu_to_le32(~0x1); 874 854 } 875 855 } 876 856 } ··· 1028 1008 TRB_STREAM_ID(priv_req->request.stream_id) | TRB_ISP; 1029 1009 1030 1010 if (!request->num_sgs) { 1031 - trb->buffer = TRB_BUFFER(trb_dma); 1011 + trb->buffer = cpu_to_le32(TRB_BUFFER(trb_dma)); 1032 1012 length = request->length; 1033 1013 } else { 1034 - trb->buffer = TRB_BUFFER(request->sg[sg_idx].dma_address); 1014 + trb->buffer = cpu_to_le32(TRB_BUFFER(request->sg[sg_idx].dma_address)); 1035 1015 length = request->sg[sg_idx].length; 1036 1016 } 1037 1017 1038 1018 tdl = DIV_ROUND_UP(length, priv_ep->endpoint.maxpacket); 1039 1019 1040 - trb->length = TRB_BURST_LEN(16 /*priv_ep->trb_burst_size*/) | 1041 - TRB_LEN(length); 1020 + trb->length = cpu_to_le32(TRB_BURST_LEN(16) | TRB_LEN(length)); 1042 1021 1043 1022 /* 1044 1023 * For DEV_VER_V2 controller version we have enabled ··· 1046 1027 */ 1047 1028 if (priv_dev->dev_ver >= DEV_VER_V2) { 1048 1029 if (priv_dev->gadget.speed == USB_SPEED_SUPER) 1049 - trb->length |= TRB_TDL_SS_SIZE(tdl); 1030 + trb->length |= cpu_to_le32(TRB_TDL_SS_SIZE(tdl)); 1050 1031 } 1051 1032 priv_req->flags |= REQUEST_PENDING; 1052 1033 1053 - trb->control = control; 1034 + trb->control = cpu_to_le32(control); 1054 1035 1055 1036 trace_cdns3_prepare_trb(priv_ep, priv_req->trb); 1056 1037 ··· 1110 1091 struct cdns3_device *priv_dev = priv_ep->cdns3_dev; 1111 1092 struct cdns3_request *priv_req; 1112 1093 struct cdns3_trb *trb; 1094 + struct cdns3_trb *link_trb; 1113 1095 dma_addr_t trb_dma; 1114 1096 u32 togle_pcs = 1; 1115 1097 int sg_iter = 0; ··· 1119 1099 u32 control; 1120 1100 int pcs; 1121 1101 u16 total_tdl = 0; 1102 + struct scatterlist *s = NULL; 1103 + bool sg_supported = !!(request->num_mapped_sgs); 1122 1104 1123 1105 if (priv_ep->type == USB_ENDPOINT_XFER_ISOC) 1124 1106 num_trb = priv_ep->interval; 1125 1107 else 1126 - num_trb = request->num_sgs ? request->num_sgs : 1; 1108 + num_trb = sg_supported ? request->num_mapped_sgs : 1; 1127 1109 1128 1110 if (num_trb > priv_ep->free_trbs) { 1129 1111 priv_ep->flags |= EP_RING_FULL; ··· 1151 1129 1152 1130 /* prepare ring */ 1153 1131 if ((priv_ep->enqueue + num_trb) >= (priv_ep->num_trbs - 1)) { 1154 - struct cdns3_trb *link_trb; 1155 1132 int doorbell, dma_index; 1156 1133 u32 ch_bit = 0; 1157 1134 ··· 1177 1156 TRBS_PER_SEGMENT > 2) 1178 1157 ch_bit = TRB_CHAIN; 1179 1158 1180 - link_trb->control = ((priv_ep->pcs) ? TRB_CYCLE : 0) | 1181 - TRB_TYPE(TRB_LINK) | TRB_TOGGLE | ch_bit; 1159 + link_trb->control = cpu_to_le32(((priv_ep->pcs) ? TRB_CYCLE : 0) | 1160 + TRB_TYPE(TRB_LINK) | TRB_TOGGLE | ch_bit); 1182 1161 } 1183 1162 1184 1163 if (priv_dev->dev_ver <= DEV_VER_V2) 1185 1164 togle_pcs = cdns3_wa1_update_guard(priv_ep, trb); 1165 + 1166 + if (sg_supported) 1167 + s = request->sg; 1186 1168 1187 1169 /* set incorrect Cycle Bit for first trb*/ 1188 1170 control = priv_ep->pcs ? 0 : TRB_CYCLE; ··· 1196 1172 1197 1173 /* fill TRB */ 1198 1174 control |= TRB_TYPE(TRB_NORMAL); 1199 - trb->buffer = TRB_BUFFER(request->num_sgs == 0 1200 - ? trb_dma : request->sg[sg_iter].dma_address); 1201 - 1202 - if (likely(!request->num_sgs)) 1175 + if (sg_supported) { 1176 + trb->buffer = cpu_to_le32(TRB_BUFFER(sg_dma_address(s))); 1177 + length = sg_dma_len(s); 1178 + } else { 1179 + trb->buffer = cpu_to_le32(TRB_BUFFER(trb_dma)); 1203 1180 length = request->length; 1204 - else 1205 - length = request->sg[sg_iter].length; 1181 + } 1206 1182 1207 1183 if (likely(priv_dev->dev_ver >= DEV_VER_V2)) 1208 1184 td_size = DIV_ROUND_UP(length, ··· 1211 1187 total_tdl += DIV_ROUND_UP(length, 1212 1188 priv_ep->endpoint.maxpacket); 1213 1189 1214 - trb->length = TRB_BURST_LEN(priv_ep->trb_burst_size) | 1215 - TRB_LEN(length); 1190 + trb->length = cpu_to_le32(TRB_BURST_LEN(priv_ep->trb_burst_size) | 1191 + TRB_LEN(length)); 1216 1192 if (priv_dev->gadget.speed == USB_SPEED_SUPER) 1217 - trb->length |= TRB_TDL_SS_SIZE(td_size); 1193 + trb->length |= cpu_to_le32(TRB_TDL_SS_SIZE(td_size)); 1218 1194 else 1219 1195 control |= TRB_TDL_HS_SIZE(td_size); 1220 1196 ··· 1236 1212 } 1237 1213 1238 1214 if (sg_iter) 1239 - trb->control = control; 1215 + trb->control = cpu_to_le32(control); 1240 1216 else 1241 - priv_req->trb->control = control; 1217 + priv_req->trb->control = cpu_to_le32(control); 1218 + 1219 + if (sg_supported) { 1220 + trb->control |= TRB_ISP; 1221 + /* Don't set chain bit for last TRB */ 1222 + if (sg_iter < num_trb - 1) 1223 + trb->control |= TRB_CHAIN; 1224 + 1225 + s = sg_next(s); 1226 + } 1242 1227 1243 1228 control = 0; 1244 1229 ++sg_iter; ··· 1259 1226 trb = priv_req->trb; 1260 1227 1261 1228 priv_req->flags |= REQUEST_PENDING; 1229 + priv_req->num_of_trb = num_trb; 1262 1230 1263 1231 if (sg_iter == 1) 1264 - trb->control |= TRB_IOC | TRB_ISP; 1232 + trb->control |= cpu_to_le32(TRB_IOC | TRB_ISP); 1265 1233 1266 1234 if (priv_dev->dev_ver < DEV_VER_V2 && 1267 1235 (priv_ep->flags & EP_TDLCHK_EN)) { ··· 1288 1254 1289 1255 /* give the TD to the consumer*/ 1290 1256 if (togle_pcs) 1291 - trb->control = trb->control ^ 1; 1257 + trb->control = trb->control ^ cpu_to_le32(1); 1292 1258 1293 1259 if (priv_dev->dev_ver <= DEV_VER_V2) 1294 1260 cdns3_wa1_tray_restore_cycle_bit(priv_dev, priv_ep); 1295 1261 1296 - trace_cdns3_prepare_trb(priv_ep, priv_req->trb); 1262 + if (num_trb > 1) { 1263 + int i = 0; 1264 + 1265 + while (i < num_trb) { 1266 + trace_cdns3_prepare_trb(priv_ep, trb + i); 1267 + if (trb + i == link_trb) { 1268 + trb = priv_ep->trb_pool; 1269 + num_trb = num_trb - i; 1270 + i = 0; 1271 + } else { 1272 + i++; 1273 + } 1274 + } 1275 + } else { 1276 + trace_cdns3_prepare_trb(priv_ep, priv_req->trb); 1277 + } 1297 1278 1298 1279 /* 1299 1280 * Memory barrier - Cycle Bit must be set before trb->length and ··· 1359 1310 { 1360 1311 struct cdns3_endpoint *priv_ep; 1361 1312 struct usb_ep *ep; 1362 - int val; 1363 1313 1364 1314 if (priv_dev->hw_configured_flag) 1365 1315 return; ··· 1367 1319 1368 1320 cdns3_set_register_bit(&priv_dev->regs->usb_conf, 1369 1321 USB_CONF_U1EN | USB_CONF_U2EN); 1370 - 1371 - /* wait until configuration set */ 1372 - readl_poll_timeout_atomic(&priv_dev->regs->usb_sts, val, 1373 - val & USB_STS_CFGSTS_MASK, 1, 100); 1374 1322 1375 1323 priv_dev->hw_configured_flag = 1; 1376 1324 ··· 1381 1337 } 1382 1338 1383 1339 /** 1384 - * cdns3_request_handled - check whether request has been handled by DMA 1340 + * cdns3_trb_handled - check whether trb has been handled by DMA 1385 1341 * 1386 1342 * @priv_ep: extended endpoint object. 1387 1343 * @priv_req: request object for checking ··· 1398 1354 * ET = priv_req->end_trb - index of last TRB in transfer ring 1399 1355 * CI = current_index - index of processed TRB by DMA. 1400 1356 * 1401 - * As first step, function checks if cycle bit for priv_req->start_trb is 1402 - * correct. 1357 + * As first step, we check if the TRB between the ST and ET. 1358 + * Then, we check if cycle bit for index priv_ep->dequeue 1359 + * is correct. 1403 1360 * 1404 1361 * some rules: 1405 - * 1. priv_ep->dequeue never exceed current_index. 1362 + * 1. priv_ep->dequeue never equals to current_index. 1406 1363 * 2 priv_ep->enqueue never exceed priv_ep->dequeue 1407 1364 * 3. exception: priv_ep->enqueue == priv_ep->dequeue 1408 1365 * and priv_ep->free_trbs is zero. 1409 1366 * This case indicate that TR is full. 1410 1367 * 1411 - * Then We can split recognition into two parts: 1368 + * At below two cases, the request have been handled. 1412 1369 * Case 1 - priv_ep->dequeue < current_index 1413 1370 * SR ... EQ ... DQ ... CI ... ER 1414 1371 * SR ... DQ ... CI ... EQ ... ER 1415 1372 * 1416 - * Request has been handled by DMA if ST and ET is between DQ and CI. 1417 - * 1418 1373 * Case 2 - priv_ep->dequeue > current_index 1419 - * This situation take place when CI go through the LINK TRB at the end of 1374 + * This situation takes place when CI go through the LINK TRB at the end of 1420 1375 * transfer ring. 1421 1376 * SR ... CI ... EQ ... DQ ... ER 1422 - * 1423 - * Request has been handled by DMA if ET is less then CI or 1424 - * ET is greater or equal DQ. 1425 1377 */ 1426 - static bool cdns3_request_handled(struct cdns3_endpoint *priv_ep, 1378 + static bool cdns3_trb_handled(struct cdns3_endpoint *priv_ep, 1427 1379 struct cdns3_request *priv_req) 1428 1380 { 1429 1381 struct cdns3_device *priv_dev = priv_ep->cdns3_dev; ··· 1431 1391 current_index = cdns3_get_dma_pos(priv_dev, priv_ep); 1432 1392 doorbell = !!(readl(&priv_dev->regs->ep_cmd) & EP_CMD_DRDY); 1433 1393 1434 - trb = &priv_ep->trb_pool[priv_req->start_trb]; 1394 + /* current trb doesn't belong to this request */ 1395 + if (priv_req->start_trb < priv_req->end_trb) { 1396 + if (priv_ep->dequeue > priv_req->end_trb) 1397 + goto finish; 1435 1398 1436 - if ((trb->control & TRB_CYCLE) != priv_ep->ccs) 1399 + if (priv_ep->dequeue < priv_req->start_trb) 1400 + goto finish; 1401 + } 1402 + 1403 + if ((priv_req->start_trb > priv_req->end_trb) && 1404 + (priv_ep->dequeue > priv_req->end_trb) && 1405 + (priv_ep->dequeue < priv_req->start_trb)) 1406 + goto finish; 1407 + 1408 + if ((priv_req->start_trb == priv_req->end_trb) && 1409 + (priv_ep->dequeue != priv_req->end_trb)) 1410 + goto finish; 1411 + 1412 + trb = &priv_ep->trb_pool[priv_ep->dequeue]; 1413 + 1414 + if ((le32_to_cpu(trb->control) & TRB_CYCLE) != priv_ep->ccs) 1437 1415 goto finish; 1438 1416 1439 1417 if (doorbell == 1 && current_index == priv_ep->dequeue) ··· 1471 1413 !priv_ep->dequeue) 1472 1414 goto finish; 1473 1415 1474 - if (priv_req->end_trb >= priv_ep->dequeue && 1475 - priv_req->end_trb < current_index) 1476 - handled = 1; 1416 + handled = 1; 1477 1417 } else if (priv_ep->dequeue > current_index) { 1478 - if (priv_req->end_trb < current_index || 1479 - priv_req->end_trb >= priv_ep->dequeue) 1480 1418 handled = 1; 1481 1419 } 1482 1420 ··· 1488 1434 struct cdns3_request *priv_req; 1489 1435 struct usb_request *request; 1490 1436 struct cdns3_trb *trb; 1437 + bool request_handled = false; 1438 + bool transfer_end = false; 1491 1439 1492 1440 while (!list_empty(&priv_ep->pending_req_list)) { 1493 1441 request = cdns3_next_request(&priv_ep->pending_req_list); ··· 1498 1442 trb = priv_ep->trb_pool + priv_ep->dequeue; 1499 1443 1500 1444 /* Request was dequeued and TRB was changed to TRB_LINK. */ 1501 - if (TRB_FIELD_TO_TYPE(trb->control) == TRB_LINK) { 1445 + if (TRB_FIELD_TO_TYPE(le32_to_cpu(trb->control)) == TRB_LINK) { 1502 1446 trace_cdns3_complete_trb(priv_ep, trb); 1503 1447 cdns3_move_deq_to_next_trb(priv_req); 1504 1448 } ··· 1509 1453 */ 1510 1454 cdns3_select_ep(priv_dev, priv_ep->endpoint.address); 1511 1455 1512 - if (!cdns3_request_handled(priv_ep, priv_req)) 1456 + while (cdns3_trb_handled(priv_ep, priv_req)) { 1457 + priv_req->finished_trb++; 1458 + if (priv_req->finished_trb >= priv_req->num_of_trb) 1459 + request_handled = true; 1460 + 1461 + trb = priv_ep->trb_pool + priv_ep->dequeue; 1462 + trace_cdns3_complete_trb(priv_ep, trb); 1463 + 1464 + if (!transfer_end) 1465 + request->actual += 1466 + TRB_LEN(le32_to_cpu(trb->length)); 1467 + 1468 + if (priv_req->num_of_trb > 1 && 1469 + le32_to_cpu(trb->control) & TRB_SMM) 1470 + transfer_end = true; 1471 + 1472 + cdns3_ep_inc_deq(priv_ep); 1473 + } 1474 + 1475 + if (request_handled) { 1476 + cdns3_gadget_giveback(priv_ep, priv_req, 0); 1477 + request_handled = false; 1478 + transfer_end = false; 1479 + } else { 1513 1480 goto prepare_next_td; 1514 - 1515 - trb = priv_ep->trb_pool + priv_ep->dequeue; 1516 - trace_cdns3_complete_trb(priv_ep, trb); 1517 - 1518 - if (trb != priv_req->trb) 1519 - dev_warn(priv_dev->dev, 1520 - "request_trb=0x%p, queue_trb=0x%p\n", 1521 - priv_req->trb, trb); 1522 - 1523 - request->actual = TRB_LEN(le32_to_cpu(trb->length)); 1524 - cdns3_move_deq_to_next_trb(priv_req); 1525 - cdns3_gadget_giveback(priv_ep, priv_req, 0); 1481 + } 1526 1482 1527 1483 if (priv_ep->type != USB_ENDPOINT_XFER_ISOC && 1528 1484 TRBS_PER_SEGMENT == 2) ··· 1642 1574 * that host ignore the ERDY packet and driver has to send it 1643 1575 * again. 1644 1576 */ 1645 - if (tdl && (dbusy | !EP_STS_BUFFEMPTY(ep_sts_reg) | 1577 + if (tdl && (dbusy || !EP_STS_BUFFEMPTY(ep_sts_reg) || 1646 1578 EP_STS_HOSTPP(ep_sts_reg))) { 1647 1579 writel(EP_CMD_ERDY | 1648 1580 EP_CMD_ERDY_SID(priv_ep->last_stream_id), ··· 1837 1769 static irqreturn_t cdns3_device_irq_handler(int irq, void *data) 1838 1770 { 1839 1771 struct cdns3_device *priv_dev = data; 1772 + struct cdns3 *cdns = dev_get_drvdata(priv_dev->dev); 1840 1773 irqreturn_t ret = IRQ_NONE; 1841 1774 u32 reg; 1775 + 1776 + if (cdns->in_lpm) 1777 + return ret; 1842 1778 1843 1779 /* check USB device interrupt */ 1844 1780 reg = readl(&priv_dev->regs->usb_ists); ··· 2624 2552 2625 2553 /* Update ring only if removed request is on pending_req_list list */ 2626 2554 if (req_on_hw_ring && link_trb) { 2627 - link_trb->buffer = TRB_BUFFER(priv_ep->trb_pool_dma + 2628 - ((priv_req->end_trb + 1) * TRB_SIZE)); 2629 - link_trb->control = (link_trb->control & TRB_CYCLE) | 2630 - TRB_TYPE(TRB_LINK) | TRB_CHAIN; 2555 + link_trb->buffer = cpu_to_le32(TRB_BUFFER(priv_ep->trb_pool_dma + 2556 + ((priv_req->end_trb + 1) * TRB_SIZE))); 2557 + link_trb->control = cpu_to_le32((le32_to_cpu(link_trb->control) & TRB_CYCLE) | 2558 + TRB_TYPE(TRB_LINK) | TRB_CHAIN); 2631 2559 2632 2560 if (priv_ep->wa1_trb == priv_req->trb) 2633 2561 cdns3_wa1_restore_cycle_bit(priv_ep); ··· 2682 2610 priv_req = to_cdns3_request(request); 2683 2611 trb = priv_req->trb; 2684 2612 if (trb) 2685 - trb->control = trb->control ^ TRB_CYCLE; 2613 + trb->control = trb->control ^ cpu_to_le32(TRB_CYCLE); 2686 2614 } 2687 2615 2688 2616 writel(EP_CMD_CSTALL | EP_CMD_EPRST, &priv_dev->regs->ep_cmd); ··· 2697 2625 2698 2626 if (request) { 2699 2627 if (trb) 2700 - trb->control = trb->control ^ TRB_CYCLE; 2628 + trb->control = trb->control ^ cpu_to_le32(TRB_CYCLE); 2629 + 2701 2630 cdns3_rearm_transfer(priv_ep, 1); 2702 2631 } 2703 2632 ··· 2808 2735 { 2809 2736 struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); 2810 2737 2811 - if (is_on) 2738 + if (is_on) { 2812 2739 writel(USB_CONF_DEVEN, &priv_dev->regs->usb_conf); 2813 - else 2740 + } else { 2741 + writel(~0, &priv_dev->regs->ep_ists); 2742 + writel(~0, &priv_dev->regs->usb_ists); 2814 2743 writel(USB_CONF_DEVDS, &priv_dev->regs->usb_conf); 2744 + } 2815 2745 2816 2746 return 0; 2817 2747 } ··· 2855 2779 /* enable generic interrupt*/ 2856 2780 writel(USB_IEN_INIT, &regs->usb_ien); 2857 2781 writel(USB_CONF_CLK2OFFDS | USB_CONF_L1DS, &regs->usb_conf); 2782 + /* keep Fast Access bit */ 2783 + writel(PUSB_PWR_FST_REG_ACCESS, &priv_dev->regs->usb_pwr); 2858 2784 2859 2785 cdns3_configure_dmult(priv_dev, NULL); 2860 2786 } ··· 2940 2862 2941 2863 /* disable interrupt for device */ 2942 2864 writel(0, &priv_dev->regs->usb_ien); 2865 + writel(0, &priv_dev->regs->usb_pwr); 2943 2866 writel(USB_CONF_DEVDS, &priv_dev->regs->usb_conf); 2944 2867 2945 2868 return 0; ··· 3063 2984 return -ENOMEM; 3064 2985 } 3065 2986 2987 + static void cdns3_gadget_release(struct device *dev) 2988 + { 2989 + struct cdns3_device *priv_dev = container_of(dev, 2990 + struct cdns3_device, gadget.dev); 2991 + 2992 + kfree(priv_dev); 2993 + } 2994 + 3066 2995 void cdns3_gadget_exit(struct cdns3 *cdns) 3067 2996 { 3068 2997 struct cdns3_device *priv_dev; 3069 2998 3070 2999 priv_dev = cdns->gadget_dev; 3071 3000 3072 - devm_free_irq(cdns->dev, cdns->dev_irq, priv_dev); 3073 3001 3074 3002 pm_runtime_mark_last_busy(cdns->dev); 3075 3003 pm_runtime_put_autosuspend(cdns->dev); 3076 3004 3077 - usb_del_gadget_udc(&priv_dev->gadget); 3005 + usb_del_gadget(&priv_dev->gadget); 3006 + devm_free_irq(cdns->dev, cdns->dev_irq, priv_dev); 3078 3007 3079 3008 cdns3_free_all_eps(priv_dev); 3080 3009 ··· 3102 3015 priv_dev->setup_dma); 3103 3016 3104 3017 kfree(priv_dev->zlp_buf); 3105 - kfree(priv_dev); 3018 + usb_put_gadget(&priv_dev->gadget); 3106 3019 cdns->gadget_dev = NULL; 3107 3020 cdns3_drd_gadget_off(cdns); 3108 3021 } ··· 3117 3030 if (!priv_dev) 3118 3031 return -ENOMEM; 3119 3032 3033 + usb_initialize_gadget(cdns->dev, &priv_dev->gadget, 3034 + cdns3_gadget_release); 3120 3035 cdns->gadget_dev = priv_dev; 3121 3036 priv_dev->sysdev = cdns->dev; 3122 3037 priv_dev->dev = cdns->dev; ··· 3159 3070 priv_dev->gadget.speed = USB_SPEED_UNKNOWN; 3160 3071 priv_dev->gadget.ops = &cdns3_gadget_ops; 3161 3072 priv_dev->gadget.name = "usb-ss-gadget"; 3162 - priv_dev->gadget.sg_supported = 1; 3163 3073 priv_dev->gadget.quirk_avoids_skb_reserve = 1; 3164 3074 priv_dev->gadget.irq = cdns->dev_irq; 3165 3075 ··· 3197 3109 readl(&priv_dev->regs->usb_cap2)); 3198 3110 3199 3111 priv_dev->dev_ver = GET_DEV_BASE_VERSION(priv_dev->dev_ver); 3112 + if (priv_dev->dev_ver >= DEV_VER_V2) 3113 + priv_dev->gadget.sg_supported = 1; 3200 3114 3201 3115 priv_dev->zlp_buf = kzalloc(CDNS3_EP_ZLP_BUF_SIZE, GFP_KERNEL); 3202 3116 if (!priv_dev->zlp_buf) { ··· 3207 3117 } 3208 3118 3209 3119 /* add USB gadget device */ 3210 - ret = usb_add_gadget_udc(priv_dev->dev, &priv_dev->gadget); 3120 + ret = usb_add_gadget(&priv_dev->gadget); 3211 3121 if (ret < 0) { 3212 - dev_err(priv_dev->dev, 3213 - "Failed to register USB device controller\n"); 3122 + dev_err(priv_dev->dev, "Failed to add gadget\n"); 3214 3123 goto err4; 3215 3124 } 3216 3125 ··· 3222 3133 err2: 3223 3134 cdns3_free_all_eps(priv_dev); 3224 3135 err1: 3136 + usb_put_gadget(&priv_dev->gadget); 3225 3137 cdns->gadget_dev = NULL; 3226 3138 return ret; 3227 3139 }
+10 -1
drivers/usb/cdns3/gadget.h
··· 966 966 /* 967 967 * USBSS-DEV DMA interface. 968 968 */ 969 - #define TRBS_PER_SEGMENT 40 969 + #define TRBS_PER_SEGMENT 600 970 970 971 971 #define ISO_MAX_INTERVAL 10 972 972 ··· 1030 1030 * When set to '1', the device will toggle its interpretation of the Cycle bit 1031 1031 */ 1032 1032 #define TRB_TOGGLE BIT(1) 1033 + /* 1034 + * The controller will set it if OUTSMM (OUT size mismatch) is detected, 1035 + * this bit is for normal TRB 1036 + */ 1037 + #define TRB_SMM BIT(1) 1033 1038 1034 1039 /* 1035 1040 * Short Packet (SP). OUT EPs at DMULT=1 only. Indicates if the TRB was ··· 1220 1215 * this endpoint 1221 1216 * @flags: flag specifying special usage of request 1222 1217 * @list: used by internally allocated request to add to wa2_descmiss_req_list. 1218 + * @finished_trb: number of trb has already finished per request 1219 + * @num_of_trb: how many trbs in this request 1223 1220 */ 1224 1221 struct cdns3_request { 1225 1222 struct usb_request request; ··· 1237 1230 #define REQUEST_UNALIGNED BIT(4) 1238 1231 u32 flags; 1239 1232 struct list_head list; 1233 + int finished_trb; 1234 + int num_of_trb; 1240 1235 }; 1241 1236 1242 1237 #define to_cdns3_request(r) (container_of(r, struct cdns3_request, request))
+7
drivers/usb/cdns3/host.c
··· 13 13 #include "core.h" 14 14 #include "drd.h" 15 15 #include "host-export.h" 16 + #include <linux/usb/hcd.h> 16 17 17 18 static int __cdns3_host_init(struct cdns3 *cdns) 18 19 { 19 20 struct platform_device *xhci; 20 21 int ret; 22 + struct usb_hcd *hcd; 21 23 22 24 cdns3_drd_host_on(cdns); 23 25 ··· 44 42 dev_err(cdns->dev, "failed to register xHCI device\n"); 45 43 goto err1; 46 44 } 45 + 46 + /* Glue needs to access xHCI region register for Power management */ 47 + hcd = platform_get_drvdata(xhci); 48 + if (hcd) 49 + cdns->xhci_regs = hcd->regs; 47 50 48 51 return 0; 49 52 err1:
+1
drivers/usb/dwc2/Kconfig
··· 5 5 depends on HAS_DMA 6 6 depends on USB || USB_GADGET 7 7 depends on HAS_IOMEM 8 + select USB_ROLE_SWITCH 8 9 help 9 10 Say Y here if your system has a Dual Role Hi-Speed USB 10 11 controller based on the DesignWare HSOTG IP Core.
+1 -1
drivers/usb/dwc2/Makefile
··· 3 3 ccflags-$(CONFIG_USB_DWC2_VERBOSE) += -DVERBOSE_DEBUG 4 4 5 5 obj-$(CONFIG_USB_DWC2) += dwc2.o 6 - dwc2-y := core.o core_intr.o platform.o 6 + dwc2-y := core.o core_intr.o platform.o drd.o 7 7 dwc2-y += params.o 8 8 9 9 ifneq ($(filter y,$(CONFIG_USB_DWC2_HOST) $(CONFIG_USB_DWC2_DUAL_ROLE)),)
+9
drivers/usb/dwc2/core.h
··· 860 860 * - USB_DR_MODE_PERIPHERAL 861 861 * - USB_DR_MODE_HOST 862 862 * - USB_DR_MODE_OTG 863 + * @role_sw: usb_role_switch handle 863 864 * @hcd_enabled: Host mode sub-driver initialization indicator. 864 865 * @gadget_enabled: Peripheral mode sub-driver initialization indicator. 865 866 * @ll_hw_enabled: Status of low-level hardware resources. ··· 1055 1054 struct dwc2_core_params params; 1056 1055 enum usb_otg_state op_state; 1057 1056 enum usb_dr_mode dr_mode; 1057 + struct usb_role_switch *role_sw; 1058 1058 unsigned int hcd_enabled:1; 1059 1059 unsigned int gadget_enabled:1; 1060 1060 unsigned int ll_hw_enabled:1; ··· 1378 1376 return (dwc2_readl(hsotg, GINTSTS) & GINTSTS_CURMODE_HOST) == 0; 1379 1377 } 1380 1378 1379 + int dwc2_drd_init(struct dwc2_hsotg *hsotg); 1380 + void dwc2_drd_suspend(struct dwc2_hsotg *hsotg); 1381 + void dwc2_drd_resume(struct dwc2_hsotg *hsotg); 1382 + void dwc2_drd_exit(struct dwc2_hsotg *hsotg); 1383 + 1381 1384 /* 1382 1385 * Dump core registers and SPRAM 1383 1386 */ ··· 1399 1392 int dwc2_gadget_init(struct dwc2_hsotg *hsotg); 1400 1393 void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2, 1401 1394 bool reset); 1395 + void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg); 1402 1396 void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg); 1403 1397 void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2); 1404 1398 int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode); ··· 1425 1417 { return 0; } 1426 1418 static inline void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2, 1427 1419 bool reset) {} 1420 + static inline void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg) {} 1428 1421 static inline void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg) {} 1429 1422 static inline void dwc2_hsotg_disconnect(struct dwc2_hsotg *dwc2) {} 1430 1423 static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
+180
drivers/usb/dwc2/drd.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * drd.c - DesignWare USB2 DRD Controller Dual-role support 4 + * 5 + * Copyright (C) 2020 STMicroelectronics 6 + * 7 + * Author(s): Amelie Delaunay <amelie.delaunay@st.com> 8 + */ 9 + 10 + #include <linux/iopoll.h> 11 + #include <linux/platform_device.h> 12 + #include <linux/usb/role.h> 13 + #include "core.h" 14 + 15 + static void dwc2_ovr_init(struct dwc2_hsotg *hsotg) 16 + { 17 + unsigned long flags; 18 + u32 gotgctl; 19 + 20 + spin_lock_irqsave(&hsotg->lock, flags); 21 + 22 + gotgctl = dwc2_readl(hsotg, GOTGCTL); 23 + gotgctl |= GOTGCTL_BVALOEN | GOTGCTL_AVALOEN | GOTGCTL_VBVALOEN; 24 + gotgctl |= GOTGCTL_DBNCE_FLTR_BYPASS; 25 + gotgctl &= ~(GOTGCTL_BVALOVAL | GOTGCTL_AVALOVAL | GOTGCTL_VBVALOVAL); 26 + dwc2_writel(hsotg, gotgctl, GOTGCTL); 27 + 28 + dwc2_force_mode(hsotg, false); 29 + 30 + spin_unlock_irqrestore(&hsotg->lock, flags); 31 + } 32 + 33 + static int dwc2_ovr_avalid(struct dwc2_hsotg *hsotg, bool valid) 34 + { 35 + u32 gotgctl = dwc2_readl(hsotg, GOTGCTL); 36 + 37 + /* Check if A-Session is already in the right state */ 38 + if ((valid && (gotgctl & GOTGCTL_ASESVLD)) || 39 + (!valid && !(gotgctl & GOTGCTL_ASESVLD))) 40 + return -EALREADY; 41 + 42 + if (valid) 43 + gotgctl |= GOTGCTL_AVALOVAL | GOTGCTL_VBVALOVAL; 44 + else 45 + gotgctl &= ~(GOTGCTL_AVALOVAL | GOTGCTL_VBVALOVAL); 46 + dwc2_writel(hsotg, gotgctl, GOTGCTL); 47 + 48 + return 0; 49 + } 50 + 51 + static int dwc2_ovr_bvalid(struct dwc2_hsotg *hsotg, bool valid) 52 + { 53 + u32 gotgctl = dwc2_readl(hsotg, GOTGCTL); 54 + 55 + /* Check if B-Session is already in the right state */ 56 + if ((valid && (gotgctl & GOTGCTL_BSESVLD)) || 57 + (!valid && !(gotgctl & GOTGCTL_BSESVLD))) 58 + return -EALREADY; 59 + 60 + if (valid) 61 + gotgctl |= GOTGCTL_BVALOVAL | GOTGCTL_VBVALOVAL; 62 + else 63 + gotgctl &= ~(GOTGCTL_BVALOVAL | GOTGCTL_VBVALOVAL); 64 + dwc2_writel(hsotg, gotgctl, GOTGCTL); 65 + 66 + return 0; 67 + } 68 + 69 + static int dwc2_drd_role_sw_set(struct usb_role_switch *sw, enum usb_role role) 70 + { 71 + struct dwc2_hsotg *hsotg = usb_role_switch_get_drvdata(sw); 72 + unsigned long flags; 73 + int already = 0; 74 + 75 + /* Skip session not in line with dr_mode */ 76 + if ((role == USB_ROLE_DEVICE && hsotg->dr_mode == USB_DR_MODE_HOST) || 77 + (role == USB_ROLE_HOST && hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)) 78 + return -EINVAL; 79 + 80 + #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \ 81 + IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) 82 + /* Skip session if core is in test mode */ 83 + if (role == USB_ROLE_NONE && hsotg->test_mode) { 84 + dev_dbg(hsotg->dev, "Core is in test mode\n"); 85 + return -EBUSY; 86 + } 87 + #endif 88 + 89 + spin_lock_irqsave(&hsotg->lock, flags); 90 + 91 + if (role == USB_ROLE_HOST) { 92 + already = dwc2_ovr_avalid(hsotg, true); 93 + } else if (role == USB_ROLE_DEVICE) { 94 + already = dwc2_ovr_bvalid(hsotg, true); 95 + /* This clear DCTL.SFTDISCON bit */ 96 + dwc2_hsotg_core_connect(hsotg); 97 + } else { 98 + if (dwc2_is_device_mode(hsotg)) { 99 + if (!dwc2_ovr_bvalid(hsotg, false)) 100 + /* This set DCTL.SFTDISCON bit */ 101 + dwc2_hsotg_core_disconnect(hsotg); 102 + } else { 103 + dwc2_ovr_avalid(hsotg, false); 104 + } 105 + } 106 + 107 + spin_unlock_irqrestore(&hsotg->lock, flags); 108 + 109 + if (!already && hsotg->dr_mode == USB_DR_MODE_OTG) 110 + /* This will raise a Connector ID Status Change Interrupt */ 111 + dwc2_force_mode(hsotg, role == USB_ROLE_HOST); 112 + 113 + dev_dbg(hsotg->dev, "%s-session valid\n", 114 + role == USB_ROLE_NONE ? "No" : 115 + role == USB_ROLE_HOST ? "A" : "B"); 116 + 117 + return 0; 118 + } 119 + 120 + int dwc2_drd_init(struct dwc2_hsotg *hsotg) 121 + { 122 + struct usb_role_switch_desc role_sw_desc = {0}; 123 + struct usb_role_switch *role_sw; 124 + int ret; 125 + 126 + if (!device_property_read_bool(hsotg->dev, "usb-role-switch")) 127 + return 0; 128 + 129 + role_sw_desc.driver_data = hsotg; 130 + role_sw_desc.fwnode = dev_fwnode(hsotg->dev); 131 + role_sw_desc.set = dwc2_drd_role_sw_set; 132 + role_sw_desc.allow_userspace_control = true; 133 + 134 + role_sw = usb_role_switch_register(hsotg->dev, &role_sw_desc); 135 + if (IS_ERR(role_sw)) { 136 + ret = PTR_ERR(role_sw); 137 + dev_err(hsotg->dev, 138 + "failed to register role switch: %d\n", ret); 139 + return ret; 140 + } 141 + 142 + hsotg->role_sw = role_sw; 143 + 144 + /* Enable override and initialize values */ 145 + dwc2_ovr_init(hsotg); 146 + 147 + return 0; 148 + } 149 + 150 + void dwc2_drd_suspend(struct dwc2_hsotg *hsotg) 151 + { 152 + u32 gintsts, gintmsk; 153 + 154 + if (hsotg->role_sw && !hsotg->params.external_id_pin_ctl) { 155 + gintmsk = dwc2_readl(hsotg, GINTMSK); 156 + gintmsk &= ~GINTSTS_CONIDSTSCHNG; 157 + dwc2_writel(hsotg, gintmsk, GINTMSK); 158 + gintsts = dwc2_readl(hsotg, GINTSTS); 159 + dwc2_writel(hsotg, gintsts | GINTSTS_CONIDSTSCHNG, GINTSTS); 160 + } 161 + } 162 + 163 + void dwc2_drd_resume(struct dwc2_hsotg *hsotg) 164 + { 165 + u32 gintsts, gintmsk; 166 + 167 + if (hsotg->role_sw && !hsotg->params.external_id_pin_ctl) { 168 + gintsts = dwc2_readl(hsotg, GINTSTS); 169 + dwc2_writel(hsotg, gintsts | GINTSTS_CONIDSTSCHNG, GINTSTS); 170 + gintmsk = dwc2_readl(hsotg, GINTMSK); 171 + gintmsk |= GINTSTS_CONIDSTSCHNG; 172 + dwc2_writel(hsotg, gintmsk, GINTMSK); 173 + } 174 + } 175 + 176 + void dwc2_drd_exit(struct dwc2_hsotg *hsotg) 177 + { 178 + if (hsotg->role_sw) 179 + usb_role_switch_unregister(hsotg->role_sw); 180 + }
+34 -8
drivers/usb/dwc2/gadget.c
··· 713 713 */ 714 714 static unsigned int dwc2_gadget_get_chain_limit(struct dwc2_hsotg_ep *hs_ep) 715 715 { 716 + const struct usb_endpoint_descriptor *ep_desc = hs_ep->ep.desc; 716 717 int is_isoc = hs_ep->isochronous; 717 718 unsigned int maxsize; 719 + u32 mps = hs_ep->ep.maxpacket; 720 + int dir_in = hs_ep->dir_in; 718 721 719 722 if (is_isoc) 720 723 maxsize = (hs_ep->dir_in ? DEV_DMA_ISOC_TX_NBYTES_LIMIT : ··· 725 722 MAX_DMA_DESC_NUM_HS_ISOC; 726 723 else 727 724 maxsize = DEV_DMA_NBYTES_LIMIT * MAX_DMA_DESC_NUM_GENERIC; 725 + 726 + /* Interrupt OUT EP with mps not multiple of 4 */ 727 + if (hs_ep->index) 728 + if (usb_endpoint_xfer_int(ep_desc) && !dir_in && (mps % 4)) 729 + maxsize = mps * MAX_DMA_DESC_NUM_GENERIC; 728 730 729 731 return maxsize; 730 732 } ··· 746 738 * Isochronous - descriptor rx/tx bytes bitfield limit, 747 739 * Control In/Bulk/Interrupt - multiple of mps. This will allow to not 748 740 * have concatenations from various descriptors within one packet. 741 + * Interrupt OUT - if mps not multiple of 4 then a single packet corresponds 742 + * to a single descriptor. 749 743 * 750 744 * Selects corresponding mask for RX/TX bytes as well. 751 745 */ 752 746 static u32 dwc2_gadget_get_desc_params(struct dwc2_hsotg_ep *hs_ep, u32 *mask) 753 747 { 748 + const struct usb_endpoint_descriptor *ep_desc = hs_ep->ep.desc; 754 749 u32 mps = hs_ep->ep.maxpacket; 755 750 int dir_in = hs_ep->dir_in; 756 751 u32 desc_size = 0; ··· 776 765 /* Round down desc_size to be mps multiple */ 777 766 desc_size -= desc_size % mps; 778 767 } 768 + 769 + /* Interrupt OUT EP with mps not multiple of 4 */ 770 + if (hs_ep->index) 771 + if (usb_endpoint_xfer_int(ep_desc) && !dir_in && (mps % 4)) { 772 + desc_size = mps; 773 + *mask = DEV_DMA_NBYTES_MASK; 774 + } 779 775 780 776 return desc_size; 781 777 } ··· 1141 1123 length += (mps - (length % mps)); 1142 1124 } 1143 1125 1144 - /* 1145 - * If more data to send, adjust DMA for EP0 out data stage. 1146 - * ureq->dma stays unchanged, hence increment it by already 1147 - * passed passed data count before starting new transaction. 1148 - */ 1149 - if (!index && hsotg->ep0_state == DWC2_EP0_DATA_OUT && 1150 - continuing) 1126 + if (continuing) 1151 1127 offset = ureq->actual; 1152 1128 1153 1129 /* Fill DDMA chain entries */ ··· 2332 2320 */ 2333 2321 static unsigned int dwc2_gadget_get_xfersize_ddma(struct dwc2_hsotg_ep *hs_ep) 2334 2322 { 2323 + const struct usb_endpoint_descriptor *ep_desc = hs_ep->ep.desc; 2335 2324 struct dwc2_hsotg *hsotg = hs_ep->parent; 2336 2325 unsigned int bytes_rem = 0; 2326 + unsigned int bytes_rem_correction = 0; 2337 2327 struct dwc2_dma_desc *desc = hs_ep->desc_list; 2338 2328 int i; 2339 2329 u32 status; 2330 + u32 mps = hs_ep->ep.maxpacket; 2331 + int dir_in = hs_ep->dir_in; 2340 2332 2341 2333 if (!desc) 2342 2334 return -EINVAL; 2343 2335 2336 + /* Interrupt OUT EP with mps not multiple of 4 */ 2337 + if (hs_ep->index) 2338 + if (usb_endpoint_xfer_int(ep_desc) && !dir_in && (mps % 4)) 2339 + bytes_rem_correction = 4 - (mps % 4); 2340 + 2344 2341 for (i = 0; i < hs_ep->desc_count; ++i) { 2345 2342 status = desc->status; 2346 2343 bytes_rem += status & DEV_DMA_NBYTES_MASK; 2344 + bytes_rem -= bytes_rem_correction; 2347 2345 2348 2346 if (status & DEV_DMA_STS_MASK) 2349 2347 dev_err(hsotg->dev, "descriptor %d closed with %x\n", 2350 2348 i, status & DEV_DMA_STS_MASK); 2349 + 2350 + if (status & DEV_DMA_L) 2351 + break; 2352 + 2351 2353 desc++; 2352 2354 } 2353 2355 ··· 3556 3530 dwc2_readl(hsotg, DOEPCTL0)); 3557 3531 } 3558 3532 3559 - static void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg) 3533 + void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg) 3560 3534 { 3561 3535 /* set the soft-disconnect bit */ 3562 3536 dwc2_set_bit(hsotg, DCTL, DCTL_SFTDISCON);
+3 -2
drivers/usb/dwc2/params.c
··· 185 185 struct dwc2_core_params *p = &hsotg->params; 186 186 187 187 p->otg_cap = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE; 188 - p->activate_stm_id_vb_detection = true; 188 + p->activate_stm_id_vb_detection = !device_property_read_bool(hsotg->dev, "usb-role-switch"); 189 189 p->host_rx_fifo_size = 440; 190 190 p->host_nperio_tx_fifo_size = 256; 191 191 p->host_perio_tx_fifo_size = 256; ··· 210 210 { .compatible = "amlogic,meson-g12a-usb", 211 211 .data = dwc2_set_amlogic_g12a_params }, 212 212 { .compatible = "amcc,dwc-otg", .data = dwc2_set_amcc_params }, 213 + { .compatible = "apm,apm82181-dwc-otg", .data = dwc2_set_amcc_params }, 213 214 { .compatible = "st,stm32f4x9-fsotg", 214 215 .data = dwc2_set_stm32f4x9_fsotg_params }, 215 216 { .compatible = "st,stm32f4x9-hsotg" }, ··· 861 860 int dwc2_init_params(struct dwc2_hsotg *hsotg) 862 861 { 863 862 const struct of_device_id *match; 864 - void (*set_params)(void *data); 863 + void (*set_params)(struct dwc2_hsotg *data); 865 864 866 865 dwc2_set_default_params(hsotg); 867 866 dwc2_get_device_properties(hsotg);
+23 -3
drivers/usb/dwc2/platform.c
··· 323 323 if (hsotg->gadget_enabled) 324 324 dwc2_hsotg_remove(hsotg); 325 325 326 + dwc2_drd_exit(hsotg); 327 + 326 328 if (hsotg->params.activate_stm_id_vb_detection) 327 329 regulator_disable(hsotg->usb33d); 328 330 ··· 544 542 dwc2_writel(hsotg, ggpio, GGPIO); 545 543 } 546 544 545 + retval = dwc2_drd_init(hsotg); 546 + if (retval) { 547 + if (retval != -EPROBE_DEFER) 548 + dev_err(hsotg->dev, "failed to initialize dual-role\n"); 549 + goto error_init; 550 + } 551 + 547 552 if (hsotg->dr_mode != USB_DR_MODE_HOST) { 548 553 retval = dwc2_gadget_init(hsotg); 549 554 if (retval) 550 - goto error_init; 555 + goto error_drd; 551 556 hsotg->gadget_enabled = 1; 552 557 } 553 558 ··· 580 571 if (retval) { 581 572 if (hsotg->gadget_enabled) 582 573 dwc2_hsotg_remove(hsotg); 583 - goto error_init; 574 + goto error_drd; 584 575 } 585 576 hsotg->hcd_enabled = 1; 586 577 } ··· 602 593 if (retval) { 603 594 hsotg->gadget.udc = NULL; 604 595 dwc2_hsotg_remove(hsotg); 605 - goto error_init; 596 + goto error_debugfs; 606 597 } 607 598 } 608 599 #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */ 609 600 return 0; 601 + 602 + error_debugfs: 603 + dwc2_debugfs_exit(hsotg); 604 + if (hsotg->hcd_enabled) 605 + dwc2_hcd_remove(hsotg); 606 + error_drd: 607 + dwc2_drd_exit(hsotg); 610 608 611 609 error_init: 612 610 if (hsotg->params.activate_stm_id_vb_detection) ··· 632 616 633 617 if (is_device_mode) 634 618 dwc2_hsotg_suspend(dwc2); 619 + 620 + dwc2_drd_suspend(dwc2); 635 621 636 622 if (dwc2->params.activate_stm_id_vb_detection) { 637 623 unsigned long flags; ··· 714 696 715 697 /* Need to restore FORCEDEVMODE/FORCEHOSTMODE */ 716 698 dwc2_force_dr_mode(dwc2); 699 + 700 + dwc2_drd_resume(dwc2); 717 701 718 702 if (dwc2_is_device_mode(dwc2)) 719 703 ret = dwc2_hsotg_resume(dwc2);
+68 -22
drivers/usb/dwc3/core.c
··· 119 119 struct dwc3 *dwc = work_to_dwc(work); 120 120 unsigned long flags; 121 121 int ret; 122 - 123 - if (dwc->dr_mode != USB_DR_MODE_OTG) 124 - return; 122 + u32 reg; 125 123 126 124 pm_runtime_get_sync(dwc->dev); 127 125 ··· 170 172 otg_set_vbus(dwc->usb2_phy->otg, true); 171 173 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST); 172 174 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST); 175 + if (dwc->dis_split_quirk) { 176 + reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); 177 + reg |= DWC3_GUCTL3_SPLITDISABLE; 178 + dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); 179 + } 173 180 } 174 181 break; 175 182 case DWC3_GCTL_PRTCAP_DEVICE: ··· 205 202 void dwc3_set_mode(struct dwc3 *dwc, u32 mode) 206 203 { 207 204 unsigned long flags; 205 + 206 + if (dwc->dr_mode != USB_DR_MODE_OTG) 207 + return; 208 208 209 209 spin_lock_irqsave(&dwc->lock, flags); 210 210 dwc->desired_dr_role = mode; ··· 935 929 */ 936 930 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE); 937 931 938 - /* Handle USB2.0-only core configuration */ 939 - if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) == 940 - DWC3_GHWPARAMS3_SSPHY_IFC_DIS) { 941 - if (dwc->maximum_speed == USB_SPEED_SUPER) 942 - dwc->maximum_speed = USB_SPEED_HIGH; 943 - } 944 - 945 932 ret = dwc3_phy_setup(dwc); 946 933 if (ret) 947 934 goto err0; ··· 1355 1356 dwc->dis_metastability_quirk = device_property_read_bool(dev, 1356 1357 "snps,dis_metastability_quirk"); 1357 1358 1359 + dwc->dis_split_quirk = device_property_read_bool(dev, 1360 + "snps,dis-split-quirk"); 1361 + 1358 1362 dwc->lpm_nyet_threshold = lpm_nyet_threshold; 1359 1363 dwc->tx_de_emphasis = tx_de_emphasis; 1360 1364 ··· 1383 1381 static void dwc3_check_params(struct dwc3 *dwc) 1384 1382 { 1385 1383 struct device *dev = dwc->dev; 1384 + unsigned int hwparam_gen = 1385 + DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3); 1386 1386 1387 1387 /* Check for proper value of imod_interval */ 1388 1388 if (dwc->imod_interval && !dwc3_has_imod(dwc)) { ··· 1408 1404 case USB_SPEED_LOW: 1409 1405 case USB_SPEED_FULL: 1410 1406 case USB_SPEED_HIGH: 1407 + break; 1411 1408 case USB_SPEED_SUPER: 1409 + if (hwparam_gen == DWC3_GHWPARAMS3_SSPHY_IFC_DIS) 1410 + dev_warn(dev, "UDC doesn't support Gen 1\n"); 1411 + break; 1412 1412 case USB_SPEED_SUPER_PLUS: 1413 + if ((DWC3_IP_IS(DWC32) && 1414 + hwparam_gen == DWC3_GHWPARAMS3_SSPHY_IFC_DIS) || 1415 + (!DWC3_IP_IS(DWC32) && 1416 + hwparam_gen != DWC3_GHWPARAMS3_SSPHY_IFC_GEN2)) 1417 + dev_warn(dev, "UDC doesn't support SSP\n"); 1413 1418 break; 1414 1419 default: 1415 1420 dev_err(dev, "invalid maximum_speed parameter %d\n", 1416 1421 dwc->maximum_speed); 1417 1422 fallthrough; 1418 1423 case USB_SPEED_UNKNOWN: 1419 - /* default to superspeed */ 1420 - dwc->maximum_speed = USB_SPEED_SUPER; 1421 - 1422 - /* 1423 - * default to superspeed plus if we are capable. 1424 - */ 1425 - if ((DWC3_IP_IS(DWC31) || DWC3_IP_IS(DWC32)) && 1426 - (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) == 1427 - DWC3_GHWPARAMS3_SSPHY_IFC_GEN2)) 1424 + switch (hwparam_gen) { 1425 + case DWC3_GHWPARAMS3_SSPHY_IFC_GEN2: 1428 1426 dwc->maximum_speed = USB_SPEED_SUPER_PLUS; 1429 - 1427 + break; 1428 + case DWC3_GHWPARAMS3_SSPHY_IFC_GEN1: 1429 + if (DWC3_IP_IS(DWC32)) 1430 + dwc->maximum_speed = USB_SPEED_SUPER_PLUS; 1431 + else 1432 + dwc->maximum_speed = USB_SPEED_SUPER; 1433 + break; 1434 + case DWC3_GHWPARAMS3_SSPHY_IFC_DIS: 1435 + dwc->maximum_speed = USB_SPEED_HIGH; 1436 + break; 1437 + default: 1438 + dwc->maximum_speed = USB_SPEED_SUPER; 1439 + break; 1440 + } 1430 1441 break; 1431 1442 } 1432 1443 } ··· 1573 1554 1574 1555 err5: 1575 1556 dwc3_event_buffers_cleanup(dwc); 1557 + 1558 + usb_phy_shutdown(dwc->usb2_phy); 1559 + usb_phy_shutdown(dwc->usb3_phy); 1560 + phy_exit(dwc->usb2_generic_phy); 1561 + phy_exit(dwc->usb3_generic_phy); 1562 + 1563 + usb_phy_set_suspend(dwc->usb2_phy, 1); 1564 + usb_phy_set_suspend(dwc->usb3_phy, 1); 1565 + phy_power_off(dwc->usb2_generic_phy); 1566 + phy_power_off(dwc->usb3_generic_phy); 1567 + 1576 1568 dwc3_ulpi_exit(dwc); 1577 1569 1578 1570 err4: ··· 1619 1589 dwc3_core_exit(dwc); 1620 1590 dwc3_ulpi_exit(dwc); 1621 1591 1622 - pm_runtime_put_sync(&pdev->dev); 1623 - pm_runtime_allow(&pdev->dev); 1624 1592 pm_runtime_disable(&pdev->dev); 1593 + pm_runtime_put_noidle(&pdev->dev); 1594 + pm_runtime_set_suspended(&pdev->dev); 1625 1595 1626 1596 dwc3_free_event_buffers(dwc); 1627 1597 dwc3_free_scratch_buffers(dwc); ··· 1895 1865 1896 1866 return 0; 1897 1867 } 1868 + 1869 + static void dwc3_complete(struct device *dev) 1870 + { 1871 + struct dwc3 *dwc = dev_get_drvdata(dev); 1872 + u32 reg; 1873 + 1874 + if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST && 1875 + dwc->dis_split_quirk) { 1876 + reg = dwc3_readl(dwc->regs, DWC3_GUCTL3); 1877 + reg |= DWC3_GUCTL3_SPLITDISABLE; 1878 + dwc3_writel(dwc->regs, DWC3_GUCTL3, reg); 1879 + } 1880 + } 1881 + #else 1882 + #define dwc3_complete NULL 1898 1883 #endif /* CONFIG_PM_SLEEP */ 1899 1884 1900 1885 static const struct dev_pm_ops dwc3_dev_pm_ops = { 1901 1886 SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume) 1887 + .complete = dwc3_complete, 1902 1888 SET_RUNTIME_PM_OPS(dwc3_runtime_suspend, dwc3_runtime_resume, 1903 1889 dwc3_runtime_idle) 1904 1890 };
+28 -19
drivers/usb/dwc3/core.h
··· 138 138 #define DWC3_GEVNTCOUNT(n) (0xc40c + ((n) * 0x10)) 139 139 140 140 #define DWC3_GHWPARAMS8 0xc600 141 + #define DWC3_GUCTL3 0xc60c 141 142 #define DWC3_GFLADJ 0xc630 142 143 143 144 /* Device Registers */ ··· 380 379 381 380 /* Global User Control Register 2 */ 382 381 #define DWC3_GUCTL2_RST_ACTBITLATER BIT(14) 382 + 383 + /* Global User Control Register 3 */ 384 + #define DWC3_GUCTL3_SPLITDISABLE BIT(14) 383 385 384 386 /* Device Configuration Register */ 385 387 #define DWC3_DCFG_DEVADDR(addr) ((addr) << 3) ··· 638 634 struct dwc3_event_buffer { 639 635 void *buf; 640 636 void *cache; 641 - unsigned length; 637 + unsigned int length; 642 638 unsigned int lpos; 643 639 unsigned int count; 644 640 unsigned int flags; ··· 698 694 struct dwc3 *dwc; 699 695 700 696 u32 saved_state; 701 - unsigned flags; 697 + unsigned int flags; 702 698 #define DWC3_EP_ENABLED BIT(0) 703 699 #define DWC3_EP_STALL BIT(1) 704 700 #define DWC3_EP_WEDGE BIT(2) ··· 710 706 #define DWC3_EP_IGNORE_NEXT_NOSTREAM BIT(8) 711 707 #define DWC3_EP_FORCE_RESTART_STREAM BIT(9) 712 708 #define DWC3_EP_FIRST_STREAM_PRIMED BIT(10) 709 + #define DWC3_EP_PENDING_CLEAR_STALL BIT(11) 713 710 714 711 /* This last one is specific to EP0 */ 715 712 #define DWC3_EP0_DIR_IN BIT(31) ··· 898 893 struct scatterlist *sg; 899 894 struct scatterlist *start_sg; 900 895 901 - unsigned num_pending_sgs; 896 + unsigned int num_pending_sgs; 902 897 unsigned int num_queued_sgs; 903 - unsigned remaining; 898 + unsigned int remaining; 904 899 905 900 unsigned int status; 906 901 #define DWC3_REQUEST_STATUS_QUEUED 0 ··· 913 908 struct dwc3_trb *trb; 914 909 dma_addr_t trb_dma; 915 910 916 - unsigned num_trbs; 911 + unsigned int num_trbs; 917 912 918 - unsigned needs_extra_trb:1; 919 - unsigned direction:1; 920 - unsigned mapped:1; 913 + unsigned int needs_extra_trb:1; 914 + unsigned int direction:1; 915 + unsigned int mapped:1; 921 916 }; 922 917 923 918 /* ··· 1015 1010 * @has_lpm_erratum: true when core was configured with LPM Erratum. Note that 1016 1011 * there's now way for software to detect this in runtime. 1017 1012 * @is_utmi_l1_suspend: the core asserts output signal 1018 - * 0 - utmi_sleep_n 1019 - * 1 - utmi_l1_suspend_n 1013 + * 0 - utmi_sleep_n 1014 + * 1 - utmi_l1_suspend_n 1020 1015 * @is_fpga: true when we are using the FPGA board 1021 1016 * @pending_events: true when we have pending IRQs to be handled 1022 1017 * @pullups_connected: true when Run/Stop bit is set ··· 1052 1047 * instances in park mode. 1053 1048 * @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk 1054 1049 * @tx_de_emphasis: Tx de-emphasis value 1055 - * 0 - -6dB de-emphasis 1056 - * 1 - -3.5dB de-emphasis 1057 - * 2 - No de-emphasis 1058 - * 3 - Reserved 1050 + * 0 - -6dB de-emphasis 1051 + * 1 - -3.5dB de-emphasis 1052 + * 2 - No de-emphasis 1053 + * 3 - Reserved 1059 1054 * @dis_metastability_quirk: set to disable metastability quirk. 1055 + * @dis_split_quirk: set to disable split boundary. 1060 1056 * @imod_interval: set the interrupt moderation interval in 250ns 1061 - * increments or 0 to disable. 1057 + * increments or 0 to disable. 1062 1058 */ 1063 1059 struct dwc3 { 1064 1060 struct work_struct drd_work; ··· 1085 1079 struct dwc3_event_buffer *ev_buf; 1086 1080 struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM]; 1087 1081 1088 - struct usb_gadget gadget; 1082 + struct usb_gadget *gadget; 1089 1083 struct usb_gadget_driver *gadget_driver; 1090 1084 1091 1085 struct clk_bulk_data *clks; ··· 1250 1244 unsigned tx_de_emphasis:2; 1251 1245 1252 1246 unsigned dis_metastability_quirk:1; 1247 + 1248 + unsigned dis_split_quirk:1; 1253 1249 1254 1250 u16 imod_interval; 1255 1251 }; ··· 1464 1456 int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode); 1465 1457 int dwc3_gadget_get_link_state(struct dwc3 *dwc); 1466 1458 int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state); 1467 - int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, 1459 + int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned int cmd, 1468 1460 struct dwc3_gadget_ep_cmd_params *params); 1469 - int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param); 1461 + int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned int cmd, 1462 + u32 param); 1470 1463 #else 1471 1464 static inline int dwc3_gadget_init(struct dwc3 *dwc) 1472 1465 { return 0; } ··· 1481 1472 enum dwc3_link_state state) 1482 1473 { return 0; } 1483 1474 1484 - static inline int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, 1475 + static inline int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned int cmd, 1485 1476 struct dwc3_gadget_ep_cmd_params *params) 1486 1477 { return 0; } 1487 1478 static inline int dwc3_send_gadget_generic_command(struct dwc3 *dwc,
+5 -3
drivers/usb/dwc3/debug.h
··· 371 371 static inline const char *dwc3_decode_event(char *str, size_t size, u32 event, 372 372 u32 ep0state) 373 373 { 374 - const union dwc3_event evt = (union dwc3_event) event; 374 + union dwc3_event evt; 375 + 376 + memcpy(&evt, &event, sizeof(event)); 375 377 376 378 if (evt.type.is_devspec) 377 379 return dwc3_gadget_event_string(str, size, &evt.devt); ··· 413 411 414 412 415 413 #ifdef CONFIG_DEBUG_FS 416 - extern void dwc3_debugfs_init(struct dwc3 *); 417 - extern void dwc3_debugfs_exit(struct dwc3 *); 414 + extern void dwc3_debugfs_init(struct dwc3 *d); 415 + extern void dwc3_debugfs_exit(struct dwc3 *d); 418 416 #else 419 417 static inline void dwc3_debugfs_init(struct dwc3 *d) 420 418 { }
+29 -30
drivers/usb/dwc3/debugfs.c
··· 397 397 398 398 switch (DWC3_GCTL_PRTCAP(reg)) { 399 399 case DWC3_GCTL_PRTCAP_HOST: 400 - seq_printf(s, "host\n"); 400 + seq_puts(s, "host\n"); 401 401 break; 402 402 case DWC3_GCTL_PRTCAP_DEVICE: 403 - seq_printf(s, "device\n"); 403 + seq_puts(s, "device\n"); 404 404 break; 405 405 case DWC3_GCTL_PRTCAP_OTG: 406 - seq_printf(s, "otg\n"); 406 + seq_puts(s, "otg\n"); 407 407 break; 408 408 default: 409 409 seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg)); ··· 427 427 428 428 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) 429 429 return -EFAULT; 430 + 431 + if (dwc->dr_mode != USB_DR_MODE_OTG) 432 + return count; 430 433 431 434 if (!strncmp(buf, "host", 4)) 432 435 mode = DWC3_GCTL_PRTCAP_HOST; ··· 467 464 468 465 switch (reg) { 469 466 case 0: 470 - seq_printf(s, "no test\n"); 467 + seq_puts(s, "no test\n"); 471 468 break; 472 469 case USB_TEST_J: 473 - seq_printf(s, "test_j\n"); 470 + seq_puts(s, "test_j\n"); 474 471 break; 475 472 case USB_TEST_K: 476 - seq_printf(s, "test_k\n"); 473 + seq_puts(s, "test_k\n"); 477 474 break; 478 475 case USB_TEST_SE0_NAK: 479 - seq_printf(s, "test_se0_nak\n"); 476 + seq_puts(s, "test_se0_nak\n"); 480 477 break; 481 478 case USB_TEST_PACKET: 482 - seq_printf(s, "test_packet\n"); 479 + seq_puts(s, "test_packet\n"); 483 480 break; 484 481 case USB_TEST_FORCE_ENABLE: 485 - seq_printf(s, "test_force_enable\n"); 482 + seq_puts(s, "test_force_enable\n"); 486 483 break; 487 484 default: 488 485 seq_printf(s, "UNKNOWN %d\n", reg); ··· 763 760 unsigned long flags; 764 761 765 762 spin_lock_irqsave(&dwc->lock, flags); 766 - if (!(dep->flags & DWC3_EP_ENABLED) || 767 - !dep->endpoint.desc) { 768 - seq_printf(s, "--\n"); 763 + if (!(dep->flags & DWC3_EP_ENABLED) || !dep->endpoint.desc) { 764 + seq_puts(s, "--\n"); 769 765 goto out; 770 766 } 771 767 772 768 switch (usb_endpoint_type(dep->endpoint.desc)) { 773 769 case USB_ENDPOINT_XFER_CONTROL: 774 - seq_printf(s, "control\n"); 770 + seq_puts(s, "control\n"); 775 771 break; 776 772 case USB_ENDPOINT_XFER_ISOC: 777 - seq_printf(s, "isochronous\n"); 773 + seq_puts(s, "isochronous\n"); 778 774 break; 779 775 case USB_ENDPOINT_XFER_BULK: 780 - seq_printf(s, "bulk\n"); 776 + seq_puts(s, "bulk\n"); 781 777 break; 782 778 case USB_ENDPOINT_XFER_INT: 783 - seq_printf(s, "interrupt\n"); 779 + seq_puts(s, "interrupt\n"); 784 780 break; 785 781 default: 786 - seq_printf(s, "--\n"); 782 + seq_puts(s, "--\n"); 787 783 } 788 784 789 785 out: ··· 800 798 801 799 spin_lock_irqsave(&dwc->lock, flags); 802 800 if (dep->number <= 1) { 803 - seq_printf(s, "--\n"); 801 + seq_puts(s, "--\n"); 804 802 goto out; 805 803 } 806 804 807 - seq_printf(s, "buffer_addr,size,type,ioc,isp_imi,csp,chn,lst,hwo\n"); 805 + seq_puts(s, "buffer_addr,size,type,ioc,isp_imi,csp,chn,lst,hwo\n"); 808 806 809 807 for (i = 0; i < DWC3_TRB_NUM; i++) { 810 808 struct dwc3_trb *trb = &dep->trb_pool[i]; ··· 886 884 const struct file_operations *fops = dwc3_ep_file_map[i].fops; 887 885 const char *name = dwc3_ep_file_map[i].name; 888 886 889 - debugfs_create_file(name, S_IRUGO, parent, dep, fops); 887 + debugfs_create_file(name, 0444, parent, dep, fops); 890 888 } 891 889 } 892 890 ··· 931 929 root = debugfs_create_dir(dev_name(dwc->dev), usb_debug_root); 932 930 dwc->root = root; 933 931 934 - debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset); 932 + debugfs_create_regset32("regdump", 0444, root, dwc->regset); 933 + debugfs_create_file("lsp_dump", 0644, root, dwc, &dwc3_lsp_fops); 935 934 936 - debugfs_create_file("lsp_dump", S_IRUGO | S_IWUSR, root, dwc, 937 - &dwc3_lsp_fops); 938 - 939 - if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) { 940 - debugfs_create_file("mode", S_IRUGO | S_IWUSR, root, dwc, 935 + if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) 936 + debugfs_create_file("mode", 0644, root, dwc, 941 937 &dwc3_mode_fops); 942 - } 943 938 944 939 if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) || 945 940 IS_ENABLED(CONFIG_USB_DWC3_GADGET)) { 946 - debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root, dwc, 947 - &dwc3_testmode_fops); 948 - debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root, dwc, 941 + debugfs_create_file("testmode", 0644, root, dwc, 942 + &dwc3_testmode_fops); 943 + debugfs_create_file("link_state", 0644, root, dwc, 949 944 &dwc3_link_state_fops); 950 945 dwc3_debugfs_create_endpoint_dirs(dwc, root); 951 946 }
+26 -15
drivers/usb/dwc3/dwc3-meson-g12a.c
··· 116 116 { .id = "xtal_usb_ctrl" }, 117 117 }; 118 118 119 - static const char *meson_gxm_phy_names[] = { 119 + static const char * const meson_gxm_phy_names[] = { 120 120 "usb2-phy0", "usb2-phy1", "usb2-phy2", 121 121 }; 122 122 123 - static const char *meson_g12a_phy_names[] = { 123 + static const char * const meson_g12a_phy_names[] = { 124 124 "usb2-phy0", "usb2-phy1", "usb3-phy0", 125 125 }; 126 126 127 127 /* 128 128 * Amlogic A1 has a single physical PHY, in slot 1, but still has the 129 129 * two U2 PHY controls register blocks like G12A. 130 + * AXG has the similar scheme, thus needs the same tweak. 130 131 * Handling the first PHY on slot 1 would need a large amount of code 131 132 * changes, and the current management is generic enough to handle it 132 133 * correctly when only the "usb2-phy1" phy is specified on-par with the 133 134 * DT bindings. 134 135 */ 135 - static const char *meson_a1_phy_names[] = { 136 + static const char * const meson_a1_phy_names[] = { 136 137 "usb2-phy0", "usb2-phy1" 137 138 }; 138 139 ··· 144 143 bool otg_phy_host_port_disable; 145 144 struct clk_bulk_data *clks; 146 145 int num_clks; 147 - const char **phy_names; 146 + const char * const *phy_names; 148 147 int num_phys; 149 148 int (*setup_regmaps)(struct dwc3_meson_g12a *priv, void __iomem *base); 150 149 int (*usb2_init_phy)(struct dwc3_meson_g12a *priv, int i, ··· 213 212 .usb2_init_phy = dwc3_meson_gxl_usb2_init_phy, 214 213 .set_phy_mode = dwc3_meson_gxl_set_phy_mode, 215 214 .usb_init = dwc3_meson_gxl_usb_init, 215 + .usb_post_init = dwc3_meson_gxl_usb_post_init, 216 + }; 217 + 218 + static struct dwc3_meson_g12a_drvdata axg_drvdata = { 219 + .otg_switch_supported = true, 220 + .clks = meson_gxl_clocks, 221 + .num_clks = ARRAY_SIZE(meson_gxl_clocks), 222 + .phy_names = meson_a1_phy_names, 223 + .num_phys = ARRAY_SIZE(meson_a1_phy_names), 224 + .setup_regmaps = dwc3_meson_gxl_setup_regmaps, 225 + .usb2_init_phy = dwc3_meson_gxl_usb2_init_phy, 226 + .set_phy_mode = dwc3_meson_gxl_set_phy_mode, 227 + .usb_init = dwc3_meson_g12a_usb_init, 216 228 .usb_post_init = dwc3_meson_gxl_usb_post_init, 217 229 }; 218 230 ··· 534 520 return 0; 535 521 536 522 if (priv->drvdata->otg_phy_host_port_disable) 537 - dev_warn_once(priv->dev, "Manual OTG switch is broken on this "\ 538 - "SoC, when manual switching from "\ 539 - "Host to device, DWC3 controller "\ 540 - "will need to be resetted in order "\ 541 - "to recover usage of the Host port"); 523 + dev_warn_once(priv->dev, "Broken manual OTG switch\n"); 542 524 543 525 return dwc3_meson_g12a_otg_mode_set(priv, mode); 544 526 } ··· 636 626 /* GXL controls the PHY mode in the PHY registers unlike G12A */ 637 627 priv->usb_glue_regmap = devm_regmap_init_mmio(priv->dev, base, 638 628 &phy_meson_g12a_usb_glue_regmap_conf); 639 - if (IS_ERR(priv->usb_glue_regmap)) 640 - return PTR_ERR(priv->usb_glue_regmap); 641 - 642 - return 0; 629 + return PTR_ERR_OR_ZERO(priv->usb_glue_regmap); 643 630 } 644 631 645 632 static int dwc3_meson_g12a_setup_regmaps(struct dwc3_meson_g12a *priv, ··· 913 906 return ret; 914 907 } 915 908 916 - if (priv->vbus && priv->otg_phy_mode == PHY_MODE_USB_HOST) { 917 - ret = regulator_enable(priv->vbus); 909 + if (priv->vbus && priv->otg_phy_mode == PHY_MODE_USB_HOST) { 910 + ret = regulator_enable(priv->vbus); 918 911 if (ret) 919 912 return ret; 920 913 } ··· 936 929 { 937 930 .compatible = "amlogic,meson-gxm-usb-ctrl", 938 931 .data = &gxm_drvdata, 932 + }, 933 + { 934 + .compatible = "amlogic,meson-axg-usb-ctrl", 935 + .data = &axg_drvdata, 939 936 }, 940 937 { 941 938 .compatible = "amlogic,meson-g12a-usb-ctrl",
+2
drivers/usb/dwc3/dwc3-of-simple.c
··· 176 176 { .compatible = "cavium,octeon-7130-usb-uctl" }, 177 177 { .compatible = "sprd,sc9860-dwc3" }, 178 178 { .compatible = "allwinner,sun50i-h6-dwc3" }, 179 + { .compatible = "hisilicon,hi3670-dwc3" }, 180 + { .compatible = "intel,keembay-dwc3" }, 179 181 { /* Sentinel */ } 180 182 }; 181 183 MODULE_DEVICE_TABLE(of, of_dwc3_simple_match);
+2 -1
drivers/usb/dwc3/dwc3-pci.c
··· 147 147 148 148 if (pdev->vendor == PCI_VENDOR_ID_INTEL) { 149 149 if (pdev->device == PCI_DEVICE_ID_INTEL_BXT || 150 - pdev->device == PCI_DEVICE_ID_INTEL_BXT_M) { 150 + pdev->device == PCI_DEVICE_ID_INTEL_BXT_M || 151 + pdev->device == PCI_DEVICE_ID_INTEL_EHLLP) { 151 152 guid_parse(PCI_INTEL_BXT_DSM_GUID, &dwc->guid); 152 153 dwc->has_dsm_for_pm = true; 153 154 }
+123 -5
drivers/usb/dwc3/dwc3-qcom.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/kernel.h> 15 15 #include <linux/extcon.h> 16 + #include <linux/interconnect.h> 16 17 #include <linux/of_platform.h> 17 18 #include <linux/platform_device.h> 18 19 #include <linux/phy/phy.h> ··· 43 42 #define SDM845_QSCRATCH_BASE_OFFSET 0xf8800 44 43 #define SDM845_QSCRATCH_SIZE 0x400 45 44 #define SDM845_DWC3_CORE_SIZE 0xcd00 45 + 46 + /* Interconnect path bandwidths in MBps */ 47 + #define USB_MEMORY_AVG_HS_BW MBps_to_icc(240) 48 + #define USB_MEMORY_PEAK_HS_BW MBps_to_icc(700) 49 + #define USB_MEMORY_AVG_SS_BW MBps_to_icc(1000) 50 + #define USB_MEMORY_PEAK_SS_BW MBps_to_icc(2500) 51 + #define APPS_USB_AVG_BW 0 52 + #define APPS_USB_PEAK_BW MBps_to_icc(40) 46 53 47 54 struct dwc3_acpi_pdata { 48 55 u32 qscratch_base_offset; ··· 85 76 enum usb_dr_mode mode; 86 77 bool is_suspended; 87 78 bool pm_suspended; 79 + struct icc_path *icc_path_ddr; 80 + struct icc_path *icc_path_apps; 88 81 }; 89 82 90 83 static inline void dwc3_qcom_setbits(void __iomem *base, u32 offset, u32 val) ··· 201 190 return 0; 202 191 } 203 192 193 + static int dwc3_qcom_interconnect_enable(struct dwc3_qcom *qcom) 194 + { 195 + int ret; 196 + 197 + ret = icc_enable(qcom->icc_path_ddr); 198 + if (ret) 199 + return ret; 200 + 201 + ret = icc_enable(qcom->icc_path_apps); 202 + if (ret) 203 + icc_disable(qcom->icc_path_ddr); 204 + 205 + return ret; 206 + } 207 + 208 + static int dwc3_qcom_interconnect_disable(struct dwc3_qcom *qcom) 209 + { 210 + int ret; 211 + 212 + ret = icc_disable(qcom->icc_path_ddr); 213 + if (ret) 214 + return ret; 215 + 216 + ret = icc_disable(qcom->icc_path_apps); 217 + if (ret) 218 + icc_enable(qcom->icc_path_ddr); 219 + 220 + return ret; 221 + } 222 + 223 + /** 224 + * dwc3_qcom_interconnect_init() - Get interconnect path handles 225 + * and set bandwidhth. 226 + * @qcom: Pointer to the concerned usb core. 227 + * 228 + */ 229 + static int dwc3_qcom_interconnect_init(struct dwc3_qcom *qcom) 230 + { 231 + struct device *dev = qcom->dev; 232 + int ret; 233 + 234 + qcom->icc_path_ddr = of_icc_get(dev, "usb-ddr"); 235 + if (IS_ERR(qcom->icc_path_ddr)) { 236 + dev_err(dev, "failed to get usb-ddr path: %ld\n", 237 + PTR_ERR(qcom->icc_path_ddr)); 238 + return PTR_ERR(qcom->icc_path_ddr); 239 + } 240 + 241 + qcom->icc_path_apps = of_icc_get(dev, "apps-usb"); 242 + if (IS_ERR(qcom->icc_path_apps)) { 243 + dev_err(dev, "failed to get apps-usb path: %ld\n", 244 + PTR_ERR(qcom->icc_path_apps)); 245 + return PTR_ERR(qcom->icc_path_apps); 246 + } 247 + 248 + if (usb_get_maximum_speed(&qcom->dwc3->dev) >= USB_SPEED_SUPER || 249 + usb_get_maximum_speed(&qcom->dwc3->dev) == USB_SPEED_UNKNOWN) 250 + ret = icc_set_bw(qcom->icc_path_ddr, 251 + USB_MEMORY_AVG_SS_BW, USB_MEMORY_PEAK_SS_BW); 252 + else 253 + ret = icc_set_bw(qcom->icc_path_ddr, 254 + USB_MEMORY_AVG_HS_BW, USB_MEMORY_PEAK_HS_BW); 255 + 256 + if (ret) { 257 + dev_err(dev, "failed to set bandwidth for usb-ddr path: %d\n", ret); 258 + return ret; 259 + } 260 + 261 + ret = icc_set_bw(qcom->icc_path_apps, 262 + APPS_USB_AVG_BW, APPS_USB_PEAK_BW); 263 + if (ret) { 264 + dev_err(dev, "failed to set bandwidth for apps-usb path: %d\n", ret); 265 + return ret; 266 + } 267 + 268 + return 0; 269 + } 270 + 271 + /** 272 + * dwc3_qcom_interconnect_exit() - Release interconnect path handles 273 + * @qcom: Pointer to the concerned usb core. 274 + * 275 + * This function is used to release interconnect path handle. 276 + */ 277 + static void dwc3_qcom_interconnect_exit(struct dwc3_qcom *qcom) 278 + { 279 + icc_put(qcom->icc_path_ddr); 280 + icc_put(qcom->icc_path_apps); 281 + } 282 + 204 283 static void dwc3_qcom_disable_interrupts(struct dwc3_qcom *qcom) 205 284 { 206 285 if (qcom->hs_phy_irq) { ··· 340 239 static int dwc3_qcom_suspend(struct dwc3_qcom *qcom) 341 240 { 342 241 u32 val; 343 - int i; 242 + int i, ret; 344 243 345 244 if (qcom->is_suspended) 346 245 return 0; ··· 351 250 352 251 for (i = qcom->num_clocks - 1; i >= 0; i--) 353 252 clk_disable_unprepare(qcom->clks[i]); 253 + 254 + ret = dwc3_qcom_interconnect_disable(qcom); 255 + if (ret) 256 + dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret); 354 257 355 258 qcom->is_suspended = true; 356 259 dwc3_qcom_enable_interrupts(qcom); ··· 380 275 return ret; 381 276 } 382 277 } 278 + 279 + ret = dwc3_qcom_interconnect_enable(qcom); 280 + if (ret) 281 + dev_warn(qcom->dev, "failed to enable interconnect: %d\n", ret); 383 282 384 283 /* Clear existing events from PHY related to L2 in/out */ 385 284 dwc3_qcom_setbits(qcom->qscratch_base, PWR_EVNT_IRQ_STAT_REG, ··· 444 335 { 445 336 struct dwc3_qcom *qcom = platform_get_drvdata(pdev); 446 337 const struct dwc3_acpi_pdata *pdata = qcom->acpi_pdata; 447 - int irq, ret; 338 + int irq; 339 + int ret; 340 + 448 341 irq = dwc3_qcom_get_irq(pdev, "hs_phy_irq", 449 342 pdata ? pdata->hs_phy_irq_index : -1); 450 343 if (irq > 0) { ··· 565 454 566 455 static int dwc3_qcom_acpi_register_core(struct platform_device *pdev) 567 456 { 568 - struct dwc3_qcom *qcom = platform_get_drvdata(pdev); 457 + struct dwc3_qcom *qcom = platform_get_drvdata(pdev); 569 458 struct device *dev = &pdev->dev; 570 459 struct resource *res, *child_res = NULL; 571 460 int irq; ··· 625 514 626 515 static int dwc3_qcom_of_register_core(struct platform_device *pdev) 627 516 { 628 - struct dwc3_qcom *qcom = platform_get_drvdata(pdev); 517 + struct dwc3_qcom *qcom = platform_get_drvdata(pdev); 629 518 struct device_node *np = pdev->dev.of_node, *dwc3_np; 630 519 struct device *dev = &pdev->dev; 631 520 int ret; ··· 749 638 goto depopulate; 750 639 } 751 640 641 + ret = dwc3_qcom_interconnect_init(qcom); 642 + if (ret) 643 + goto depopulate; 644 + 752 645 qcom->mode = usb_get_dr_mode(&qcom->dwc3->dev); 753 646 754 647 /* enable vbus override for device mode */ ··· 762 647 /* register extcon to override sw_vbus on Vbus change later */ 763 648 ret = dwc3_qcom_register_extcon(qcom); 764 649 if (ret) 765 - goto depopulate; 650 + goto interconnect_exit; 766 651 767 652 device_init_wakeup(&pdev->dev, 1); 768 653 qcom->is_suspended = false; ··· 772 657 773 658 return 0; 774 659 660 + interconnect_exit: 661 + dwc3_qcom_interconnect_exit(qcom); 775 662 depopulate: 776 663 if (np) 777 664 of_platform_depopulate(&pdev->dev); ··· 804 687 } 805 688 qcom->num_clocks = 0; 806 689 690 + dwc3_qcom_interconnect_exit(qcom); 807 691 reset_control_assert(qcom->resets); 808 692 809 693 pm_runtime_allow(dev);
+42 -19
drivers/usb/dwc3/ep0.c
··· 105 105 * IRQ we were waiting for is long gone. 106 106 */ 107 107 if (dep->flags & DWC3_EP_PENDING_REQUEST) { 108 - unsigned direction; 108 + unsigned int direction; 109 109 110 110 direction = !!(dep->flags & DWC3_EP0_DIR_IN); 111 111 ··· 127 127 * handle it here. 128 128 */ 129 129 if (dwc->delayed_status) { 130 - unsigned direction; 130 + unsigned int direction; 131 131 132 132 direction = !dwc->ep0_expect_in; 133 133 dwc->delayed_status = false; 134 - usb_gadget_set_state(&dwc->gadget, USB_STATE_CONFIGURED); 134 + usb_gadget_set_state(dwc->gadget, USB_STATE_CONFIGURED); 135 135 136 136 if (dwc->ep0state == EP0_STATUS_PHASE) 137 137 __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]); ··· 172 172 * XferNotReady(STATUS). 173 173 */ 174 174 if (dwc->three_stage_setup) { 175 - unsigned direction; 175 + unsigned int direction; 176 176 177 177 direction = dwc->ep0_expect_in; 178 178 dwc->ep0state = EP0_DATA_PHASE; ··· 197 197 int ret; 198 198 199 199 spin_lock_irqsave(&dwc->lock, flags); 200 - if (!dep->endpoint.desc) { 200 + if (!dep->endpoint.desc || !dwc->pullups_connected) { 201 201 dev_err(dwc->dev, "%s: can't queue to disabled endpoint\n", 202 202 dep->name); 203 203 ret = -ESHUTDOWN; ··· 325 325 /* 326 326 * LTM will be set once we know how to set this in HW. 327 327 */ 328 - usb_status |= dwc->gadget.is_selfpowered; 328 + usb_status |= dwc->gadget->is_selfpowered; 329 329 330 330 if ((dwc->speed == DWC3_DSTS_SUPERSPEED) || 331 331 (dwc->speed == DWC3_DSTS_SUPERSPEED_PLUS)) { ··· 450 450 451 451 wValue = le16_to_cpu(ctrl->wValue); 452 452 wIndex = le16_to_cpu(ctrl->wIndex); 453 - state = dwc->gadget.state; 453 + state = dwc->gadget->state; 454 454 455 455 switch (wValue) { 456 456 case USB_DEVICE_REMOTE_WAKEUP: ··· 524 524 ret = __dwc3_gadget_ep_set_halt(dep, set, true); 525 525 if (ret) 526 526 return -EINVAL; 527 + 528 + /* ClearFeature(Halt) may need delayed status */ 529 + if (!set && (dep->flags & DWC3_EP_END_TRANSFER_PENDING)) 530 + return USB_GADGET_DELAYED_STATUS; 531 + 527 532 break; 528 533 default: 529 534 return -EINVAL; ··· 564 559 565 560 static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 566 561 { 567 - enum usb_device_state state = dwc->gadget.state; 562 + enum usb_device_state state = dwc->gadget->state; 568 563 u32 addr; 569 564 u32 reg; 570 565 ··· 585 580 dwc3_writel(dwc->regs, DWC3_DCFG, reg); 586 581 587 582 if (addr) 588 - usb_gadget_set_state(&dwc->gadget, USB_STATE_ADDRESS); 583 + usb_gadget_set_state(dwc->gadget, USB_STATE_ADDRESS); 589 584 else 590 - usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT); 585 + usb_gadget_set_state(dwc->gadget, USB_STATE_DEFAULT); 591 586 592 587 return 0; 593 588 } ··· 597 592 int ret; 598 593 599 594 spin_unlock(&dwc->lock); 600 - ret = dwc->gadget_driver->setup(&dwc->gadget, ctrl); 595 + ret = dwc->gadget_driver->setup(dwc->gadget, ctrl); 601 596 spin_lock(&dwc->lock); 602 597 return ret; 603 598 } 604 599 605 600 static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 606 601 { 607 - enum usb_device_state state = dwc->gadget.state; 602 + enum usb_device_state state = dwc->gadget->state; 608 603 u32 cfg; 609 604 int ret; 610 605 u32 reg; ··· 627 622 * to change the state on the next usb_ep_queue() 628 623 */ 629 624 if (ret == 0) 630 - usb_gadget_set_state(&dwc->gadget, 625 + usb_gadget_set_state(dwc->gadget, 631 626 USB_STATE_CONFIGURED); 632 627 633 628 /* ··· 646 641 case USB_STATE_CONFIGURED: 647 642 ret = dwc3_ep0_delegate_req(dwc, ctrl); 648 643 if (!cfg && !ret) 649 - usb_gadget_set_state(&dwc->gadget, 644 + usb_gadget_set_state(dwc->gadget, 650 645 USB_STATE_ADDRESS); 651 646 break; 652 647 default: ··· 702 697 static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 703 698 { 704 699 struct dwc3_ep *dep; 705 - enum usb_device_state state = dwc->gadget.state; 700 + enum usb_device_state state = dwc->gadget->state; 706 701 u16 wLength; 707 702 708 703 if (state == USB_STATE_DEFAULT) ··· 746 741 if (wIndex || wLength) 747 742 return -EINVAL; 748 743 749 - dwc->gadget.isoch_delay = wValue; 744 + dwc->gadget->isoch_delay = wValue; 750 745 751 746 return 0; 752 747 } ··· 947 942 static void __dwc3_ep0_do_control_data(struct dwc3 *dwc, 948 943 struct dwc3_ep *dep, struct dwc3_request *req) 949 944 { 945 + unsigned int trb_length = 0; 950 946 int ret; 951 947 952 948 req->direction = !!dep->number; 953 949 954 950 if (req->request.length == 0) { 955 - dwc3_ep0_prepare_one_trb(dep, dwc->ep0_trb_addr, 0, 951 + if (!req->direction) 952 + trb_length = dep->endpoint.maxpacket; 953 + 954 + dwc3_ep0_prepare_one_trb(dep, dwc->bounce_addr, trb_length, 956 955 DWC3_TRBCTL_CONTROL_DATA, false); 957 956 ret = dwc3_ep0_start_trans(dep); 958 957 } else if (!IS_ALIGNED(req->request.length, dep->endpoint.maxpacket) ··· 1003 994 1004 995 req->trb = &dwc->ep0_trb[dep->trb_enqueue - 1]; 1005 996 997 + if (!req->direction) 998 + trb_length = dep->endpoint.maxpacket; 999 + 1006 1000 /* Now prepare one extra TRB to align transfer size */ 1007 1001 dwc3_ep0_prepare_one_trb(dep, dwc->bounce_addr, 1008 - 0, DWC3_TRBCTL_CONTROL_DATA, 1002 + trb_length, DWC3_TRBCTL_CONTROL_DATA, 1009 1003 false); 1010 1004 ret = dwc3_ep0_start_trans(dep); 1011 1005 } else { ··· 1052 1040 struct dwc3_ep *dep = dwc->eps[event->endpoint_number]; 1053 1041 1054 1042 __dwc3_ep0_do_control_status(dwc, dep); 1043 + } 1044 + 1045 + void dwc3_ep0_send_delayed_status(struct dwc3 *dwc) 1046 + { 1047 + unsigned int direction = !dwc->ep0_expect_in; 1048 + 1049 + if (dwc->ep0state != EP0_STATUS_PHASE) 1050 + return; 1051 + 1052 + dwc->delayed_status = false; 1053 + __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]); 1055 1054 } 1056 1055 1057 1056 static void dwc3_ep0_end_control_data(struct dwc3 *dwc, struct dwc3_ep *dep) ··· 1125 1102 */ 1126 1103 if (!list_empty(&dep->pending_list)) { 1127 1104 dwc->delayed_status = false; 1128 - usb_gadget_set_state(&dwc->gadget, 1105 + usb_gadget_set_state(dwc->gadget, 1129 1106 USB_STATE_CONFIGURED); 1130 1107 dwc3_ep0_do_control_status(dwc, event); 1131 1108 }
+350 -241
drivers/usb/dwc3/gadget.c
··· 227 227 * Caller should take care of locking. Issue @cmd with a given @param to @dwc 228 228 * and wait for its completion. 229 229 */ 230 - int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param) 230 + int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned int cmd, 231 + u32 param) 231 232 { 232 233 u32 timeout = 500; 233 234 int status = 0; ··· 269 268 * Caller should handle locking. This function will issue @cmd with given 270 269 * @params to @dep and wait for its completion. 271 270 */ 272 - int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, 271 + int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned int cmd, 273 272 struct dwc3_gadget_ep_cmd_params *params) 274 273 { 275 274 const struct usb_endpoint_descriptor *desc = dep->endpoint.desc; ··· 291 290 * 292 291 * DWC_usb3 3.30a and DWC_usb31 1.90a programming guide section 3.2.2 293 292 */ 294 - if (dwc->gadget.speed <= USB_SPEED_HIGH) { 293 + if (dwc->gadget->speed <= USB_SPEED_HIGH) { 295 294 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); 296 295 if (unlikely(reg & DWC3_GUSB2PHYCFG_SUSPHY)) { 297 296 saved_config |= DWC3_GUSB2PHYCFG_SUSPHY; ··· 423 422 */ 424 423 if (dep->direction && 425 424 !DWC3_VER_IS_PRIOR(DWC3, 260A) && 426 - (dwc->gadget.speed >= USB_SPEED_SUPER)) 425 + (dwc->gadget->speed >= USB_SPEED_SUPER)) 427 426 cmd |= DWC3_DEPCMD_CLEARPENDIN; 428 427 429 428 memset(&params, 0, sizeof(params)); ··· 563 562 | DWC3_DEPCFG_MAX_PACKET_SIZE(usb_endpoint_maxp(desc)); 564 563 565 564 /* Burst size is only needed in SuperSpeed mode */ 566 - if (dwc->gadget.speed >= USB_SPEED_SUPER) { 565 + if (dwc->gadget->speed >= USB_SPEED_SUPER) { 567 566 u32 burst = dep->endpoint.maxburst; 567 + 568 568 params.param0 |= DWC3_DEPCFG_BURST_SIZE(burst - 1); 569 569 } 570 570 ··· 944 942 } 945 943 946 944 static void __dwc3_prepare_one_trb(struct dwc3_ep *dep, struct dwc3_trb *trb, 947 - dma_addr_t dma, unsigned length, unsigned chain, unsigned node, 948 - unsigned stream_id, unsigned short_not_ok, 949 - unsigned no_interrupt, unsigned is_last) 945 + dma_addr_t dma, unsigned int length, unsigned int chain, 946 + unsigned int node, unsigned int stream_id, 947 + unsigned int short_not_ok, unsigned int no_interrupt, 948 + unsigned int is_last, bool must_interrupt) 950 949 { 951 950 struct dwc3 *dwc = dep->dwc; 952 - struct usb_gadget *gadget = &dwc->gadget; 951 + struct usb_gadget *gadget = dwc->gadget; 953 952 enum usb_device_speed speed = gadget->speed; 954 953 955 954 trb->size = DWC3_TRB_SIZE_LENGTH(length); ··· 1034 1031 trb->ctrl |= DWC3_TRB_CTRL_ISP_IMI; 1035 1032 } 1036 1033 1037 - if ((!no_interrupt && !chain) || 1038 - (dwc3_calc_trbs_left(dep) == 1)) 1034 + if ((!no_interrupt && !chain) || must_interrupt) 1039 1035 trb->ctrl |= DWC3_TRB_CTRL_IOC; 1040 1036 1041 1037 if (chain) ··· 1059 1057 * @trb_length: buffer size of the TRB 1060 1058 * @chain: should this TRB be chained to the next? 1061 1059 * @node: only for isochronous endpoints. First TRB needs different type. 1060 + * @use_bounce_buffer: set to use bounce buffer 1061 + * @must_interrupt: set to interrupt on TRB completion 1062 1062 */ 1063 1063 static void dwc3_prepare_one_trb(struct dwc3_ep *dep, 1064 1064 struct dwc3_request *req, unsigned int trb_length, 1065 - unsigned chain, unsigned node) 1065 + unsigned int chain, unsigned int node, bool use_bounce_buffer, 1066 + bool must_interrupt) 1066 1067 { 1067 1068 struct dwc3_trb *trb; 1068 1069 dma_addr_t dma; 1069 - unsigned stream_id = req->request.stream_id; 1070 - unsigned short_not_ok = req->request.short_not_ok; 1071 - unsigned no_interrupt = req->request.no_interrupt; 1072 - unsigned is_last = req->request.is_last; 1070 + unsigned int stream_id = req->request.stream_id; 1071 + unsigned int short_not_ok = req->request.short_not_ok; 1072 + unsigned int no_interrupt = req->request.no_interrupt; 1073 + unsigned int is_last = req->request.is_last; 1073 1074 1074 - if (req->request.num_sgs > 0) 1075 + if (use_bounce_buffer) 1076 + dma = dep->dwc->bounce_addr; 1077 + else if (req->request.num_sgs > 0) 1075 1078 dma = sg_dma_address(req->start_sg); 1076 1079 else 1077 1080 dma = req->request.dma; ··· 1092 1085 req->num_trbs++; 1093 1086 1094 1087 __dwc3_prepare_one_trb(dep, trb, dma, trb_length, chain, node, 1095 - stream_id, short_not_ok, no_interrupt, is_last); 1088 + stream_id, short_not_ok, no_interrupt, is_last, 1089 + must_interrupt); 1096 1090 } 1097 1091 1098 - static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep, 1092 + static bool dwc3_needs_extra_trb(struct dwc3_ep *dep, struct dwc3_request *req) 1093 + { 1094 + unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); 1095 + unsigned int rem = req->request.length % maxp; 1096 + 1097 + if ((req->request.length && req->request.zero && !rem && 1098 + !usb_endpoint_xfer_isoc(dep->endpoint.desc)) || 1099 + (!req->direction && rem)) 1100 + return true; 1101 + 1102 + return false; 1103 + } 1104 + 1105 + /** 1106 + * dwc3_prepare_last_sg - prepare TRBs for the last SG entry 1107 + * @dep: The endpoint that the request belongs to 1108 + * @req: The request to prepare 1109 + * @entry_length: The last SG entry size 1110 + * @node: Indicates whether this is not the first entry (for isoc only) 1111 + * 1112 + * Return the number of TRBs prepared. 1113 + */ 1114 + static int dwc3_prepare_last_sg(struct dwc3_ep *dep, 1115 + struct dwc3_request *req, unsigned int entry_length, 1116 + unsigned int node) 1117 + { 1118 + unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); 1119 + unsigned int rem = req->request.length % maxp; 1120 + unsigned int num_trbs = 1; 1121 + 1122 + if (dwc3_needs_extra_trb(dep, req)) 1123 + num_trbs++; 1124 + 1125 + if (dwc3_calc_trbs_left(dep) < num_trbs) 1126 + return 0; 1127 + 1128 + req->needs_extra_trb = num_trbs > 1; 1129 + 1130 + /* Prepare a normal TRB */ 1131 + if (req->direction || req->request.length) 1132 + dwc3_prepare_one_trb(dep, req, entry_length, 1133 + req->needs_extra_trb, node, false, false); 1134 + 1135 + /* Prepare extra TRBs for ZLP and MPS OUT transfer alignment */ 1136 + if ((!req->direction && !req->request.length) || req->needs_extra_trb) 1137 + dwc3_prepare_one_trb(dep, req, 1138 + req->direction ? 0 : maxp - rem, 1139 + false, 1, true, false); 1140 + 1141 + return num_trbs; 1142 + } 1143 + 1144 + static int dwc3_prepare_trbs_sg(struct dwc3_ep *dep, 1099 1145 struct dwc3_request *req) 1100 1146 { 1101 1147 struct scatterlist *sg = req->start_sg; ··· 1157 1097 unsigned int length = req->request.length; 1158 1098 unsigned int remaining = req->request.num_mapped_sgs 1159 1099 - req->num_queued_sgs; 1100 + unsigned int num_trbs = req->num_trbs; 1101 + bool needs_extra_trb = dwc3_needs_extra_trb(dep, req); 1160 1102 1161 1103 /* 1162 1104 * If we resume preparing the request, then get the remaining length of ··· 1168 1106 length -= sg_dma_len(s); 1169 1107 1170 1108 for_each_sg(sg, s, remaining, i) { 1171 - unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); 1172 - unsigned int rem = length % maxp; 1109 + unsigned int num_trbs_left = dwc3_calc_trbs_left(dep); 1173 1110 unsigned int trb_length; 1174 - unsigned chain = true; 1111 + bool must_interrupt = false; 1112 + bool last_sg = false; 1175 1113 1176 1114 trb_length = min_t(unsigned int, length, sg_dma_len(s)); 1177 1115 ··· 1185 1123 * mapped sg. 1186 1124 */ 1187 1125 if ((i == remaining - 1) || !length) 1188 - chain = false; 1126 + last_sg = true; 1189 1127 1190 - if (rem && usb_endpoint_dir_out(dep->endpoint.desc) && !chain) { 1191 - struct dwc3 *dwc = dep->dwc; 1192 - struct dwc3_trb *trb; 1128 + if (!num_trbs_left) 1129 + break; 1193 1130 1194 - req->needs_extra_trb = true; 1195 - 1196 - /* prepare normal TRB */ 1197 - dwc3_prepare_one_trb(dep, req, trb_length, true, i); 1198 - 1199 - /* Now prepare one extra TRB to align transfer size */ 1200 - trb = &dep->trb_pool[dep->trb_enqueue]; 1201 - req->num_trbs++; 1202 - __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, 1203 - maxp - rem, false, 1, 1204 - req->request.stream_id, 1205 - req->request.short_not_ok, 1206 - req->request.no_interrupt, 1207 - req->request.is_last); 1208 - } else if (req->request.zero && req->request.length && 1209 - !usb_endpoint_xfer_isoc(dep->endpoint.desc) && 1210 - !rem && !chain) { 1211 - struct dwc3 *dwc = dep->dwc; 1212 - struct dwc3_trb *trb; 1213 - 1214 - req->needs_extra_trb = true; 1215 - 1216 - /* Prepare normal TRB */ 1217 - dwc3_prepare_one_trb(dep, req, trb_length, true, i); 1218 - 1219 - /* Prepare one extra TRB to handle ZLP */ 1220 - trb = &dep->trb_pool[dep->trb_enqueue]; 1221 - req->num_trbs++; 1222 - __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, 0, 1223 - !req->direction, 1, 1224 - req->request.stream_id, 1225 - req->request.short_not_ok, 1226 - req->request.no_interrupt, 1227 - req->request.is_last); 1228 - 1229 - /* Prepare one more TRB to handle MPS alignment */ 1230 - if (!req->direction) { 1231 - trb = &dep->trb_pool[dep->trb_enqueue]; 1232 - req->num_trbs++; 1233 - __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, maxp, 1234 - false, 1, req->request.stream_id, 1235 - req->request.short_not_ok, 1236 - req->request.no_interrupt, 1237 - req->request.is_last); 1238 - } 1131 + if (last_sg) { 1132 + if (!dwc3_prepare_last_sg(dep, req, trb_length, i)) 1133 + break; 1239 1134 } else { 1240 - dwc3_prepare_one_trb(dep, req, trb_length, chain, i); 1135 + /* 1136 + * Look ahead to check if we have enough TRBs for the 1137 + * next SG entry. If not, set interrupt on this TRB to 1138 + * resume preparing the next SG entry when more TRBs are 1139 + * free. 1140 + */ 1141 + if (num_trbs_left == 1 || (needs_extra_trb && 1142 + num_trbs_left <= 2 && 1143 + sg_dma_len(sg_next(s)) >= length)) 1144 + must_interrupt = true; 1145 + 1146 + dwc3_prepare_one_trb(dep, req, trb_length, 1, i, false, 1147 + must_interrupt); 1241 1148 } 1242 1149 1243 1150 /* ··· 1216 1185 * we have free trbs we can continue queuing from where we 1217 1186 * previously stopped 1218 1187 */ 1219 - if (chain) 1188 + if (!last_sg) 1220 1189 req->start_sg = sg_next(s); 1221 1190 1222 1191 req->num_queued_sgs++; ··· 1231 1200 break; 1232 1201 } 1233 1202 1234 - if (!dwc3_calc_trbs_left(dep)) 1203 + if (must_interrupt) 1235 1204 break; 1236 1205 } 1206 + 1207 + return req->num_trbs - num_trbs; 1237 1208 } 1238 1209 1239 - static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, 1210 + static int dwc3_prepare_trbs_linear(struct dwc3_ep *dep, 1240 1211 struct dwc3_request *req) 1241 1212 { 1242 - unsigned int length = req->request.length; 1243 - unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); 1244 - unsigned int rem = length % maxp; 1245 - 1246 - if ((!length || rem) && usb_endpoint_dir_out(dep->endpoint.desc)) { 1247 - struct dwc3 *dwc = dep->dwc; 1248 - struct dwc3_trb *trb; 1249 - 1250 - req->needs_extra_trb = true; 1251 - 1252 - /* prepare normal TRB */ 1253 - dwc3_prepare_one_trb(dep, req, length, true, 0); 1254 - 1255 - /* Now prepare one extra TRB to align transfer size */ 1256 - trb = &dep->trb_pool[dep->trb_enqueue]; 1257 - req->num_trbs++; 1258 - __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, maxp - rem, 1259 - false, 1, req->request.stream_id, 1260 - req->request.short_not_ok, 1261 - req->request.no_interrupt, 1262 - req->request.is_last); 1263 - } else if (req->request.zero && req->request.length && 1264 - !usb_endpoint_xfer_isoc(dep->endpoint.desc) && 1265 - (IS_ALIGNED(req->request.length, maxp))) { 1266 - struct dwc3 *dwc = dep->dwc; 1267 - struct dwc3_trb *trb; 1268 - 1269 - req->needs_extra_trb = true; 1270 - 1271 - /* prepare normal TRB */ 1272 - dwc3_prepare_one_trb(dep, req, length, true, 0); 1273 - 1274 - /* Prepare one extra TRB to handle ZLP */ 1275 - trb = &dep->trb_pool[dep->trb_enqueue]; 1276 - req->num_trbs++; 1277 - __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, 0, 1278 - !req->direction, 1, req->request.stream_id, 1279 - req->request.short_not_ok, 1280 - req->request.no_interrupt, 1281 - req->request.is_last); 1282 - 1283 - /* Prepare one more TRB to handle MPS alignment for OUT */ 1284 - if (!req->direction) { 1285 - trb = &dep->trb_pool[dep->trb_enqueue]; 1286 - req->num_trbs++; 1287 - __dwc3_prepare_one_trb(dep, trb, dwc->bounce_addr, maxp, 1288 - false, 1, req->request.stream_id, 1289 - req->request.short_not_ok, 1290 - req->request.no_interrupt, 1291 - req->request.is_last); 1292 - } 1293 - } else { 1294 - dwc3_prepare_one_trb(dep, req, length, false, 0); 1295 - } 1213 + return dwc3_prepare_last_sg(dep, req, req->request.length, 0); 1296 1214 } 1297 1215 1298 1216 /* ··· 1251 1271 * The function goes through the requests list and sets up TRBs for the 1252 1272 * transfers. The function returns once there are no more TRBs available or 1253 1273 * it runs out of requests. 1274 + * 1275 + * Returns the number of TRBs prepared or negative errno. 1254 1276 */ 1255 - static void dwc3_prepare_trbs(struct dwc3_ep *dep) 1277 + static int dwc3_prepare_trbs(struct dwc3_ep *dep) 1256 1278 { 1257 1279 struct dwc3_request *req, *n; 1280 + int ret = 0; 1258 1281 1259 1282 BUILD_BUG_ON_NOT_POWER_OF_2(DWC3_TRB_NUM); 1260 1283 ··· 1272 1289 * break things. 1273 1290 */ 1274 1291 list_for_each_entry(req, &dep->started_list, list) { 1275 - if (req->num_pending_sgs > 0) 1276 - dwc3_prepare_one_trb_sg(dep, req); 1292 + if (req->num_pending_sgs > 0) { 1293 + ret = dwc3_prepare_trbs_sg(dep, req); 1294 + if (!ret || req->num_pending_sgs) 1295 + return ret; 1296 + } 1277 1297 1278 1298 if (!dwc3_calc_trbs_left(dep)) 1279 - return; 1299 + return ret; 1280 1300 1281 1301 /* 1282 1302 * Don't prepare beyond a transfer. In DWC_usb32, its transfer ··· 1287 1301 * active transfer instead of stopping. 1288 1302 */ 1289 1303 if (dep->stream_capable && req->request.is_last) 1290 - return; 1304 + return ret; 1291 1305 } 1292 1306 1293 1307 list_for_each_entry_safe(req, n, &dep->pending_list, list) { 1294 1308 struct dwc3 *dwc = dep->dwc; 1295 - int ret; 1296 1309 1297 1310 ret = usb_gadget_map_request_by_dev(dwc->sysdev, &req->request, 1298 1311 dep->direction); 1299 1312 if (ret) 1300 - return; 1313 + return ret; 1301 1314 1302 1315 req->sg = req->request.sg; 1303 1316 req->start_sg = req->sg; 1304 1317 req->num_queued_sgs = 0; 1305 1318 req->num_pending_sgs = req->request.num_mapped_sgs; 1306 1319 1307 - if (req->num_pending_sgs > 0) 1308 - dwc3_prepare_one_trb_sg(dep, req); 1309 - else 1310 - dwc3_prepare_one_trb_linear(dep, req); 1320 + if (req->num_pending_sgs > 0) { 1321 + ret = dwc3_prepare_trbs_sg(dep, req); 1322 + if (req->num_pending_sgs) 1323 + return ret; 1324 + } else { 1325 + ret = dwc3_prepare_trbs_linear(dep, req); 1326 + } 1311 1327 1312 - if (!dwc3_calc_trbs_left(dep)) 1313 - return; 1328 + if (!ret || !dwc3_calc_trbs_left(dep)) 1329 + return ret; 1314 1330 1315 1331 /* 1316 1332 * Don't prepare beyond a transfer. In DWC_usb32, its transfer ··· 1320 1332 * active transfer instead of stopping. 1321 1333 */ 1322 1334 if (dep->stream_capable && req->request.is_last) 1323 - return; 1335 + return ret; 1324 1336 } 1337 + 1338 + return ret; 1325 1339 } 1326 1340 1327 1341 static void dwc3_gadget_ep_cleanup_cancelled_requests(struct dwc3_ep *dep); ··· 1336 1346 int ret; 1337 1347 u32 cmd; 1338 1348 1339 - if (!dwc3_calc_trbs_left(dep)) 1340 - return 0; 1349 + /* 1350 + * Note that it's normal to have no new TRBs prepared (i.e. ret == 0). 1351 + * This happens when we need to stop and restart a transfer such as in 1352 + * the case of reinitiating a stream or retrying an isoc transfer. 1353 + */ 1354 + ret = dwc3_prepare_trbs(dep); 1355 + if (ret < 0) 1356 + return ret; 1341 1357 1342 1358 starting = !(dep->flags & DWC3_EP_TRANSFER_STARTED); 1343 1359 1344 - dwc3_prepare_trbs(dep); 1360 + /* 1361 + * If there's no new TRB prepared and we don't need to restart a 1362 + * transfer, there's no need to update the transfer. 1363 + */ 1364 + if (!ret && !starting) 1365 + return ret; 1366 + 1345 1367 req = next_request(&dep->started_list); 1346 1368 if (!req) { 1347 1369 dep->flags |= DWC3_EP_PENDING_REQUEST; ··· 1541 1539 if (!dwc->dis_start_transfer_quirk && 1542 1540 (DWC3_VER_IS_PRIOR(DWC31, 170A) || 1543 1541 DWC3_VER_TYPE_IS_WITHIN(DWC31, 170A, EA01, EA06))) { 1544 - if (dwc->gadget.speed <= USB_SPEED_HIGH && dep->direction) 1542 + if (dwc->gadget->speed <= USB_SPEED_HIGH && dep->direction) 1545 1543 return dwc3_gadget_start_isoc_quirk(dep); 1546 1544 } 1547 1545 1548 1546 if (desc->bInterval <= 14 && 1549 - dwc->gadget.speed >= USB_SPEED_HIGH) { 1547 + dwc->gadget->speed >= USB_SPEED_HIGH) { 1550 1548 u32 frame = __dwc3_gadget_get_frame(dwc); 1551 1549 bool rollover = frame < 1552 1550 (dep->frame_number & DWC3_FRNUMBER_MASK); ··· 1602 1600 { 1603 1601 struct dwc3 *dwc = dep->dwc; 1604 1602 1605 - if (!dep->endpoint.desc) { 1603 + if (!dep->endpoint.desc || !dwc->pullups_connected) { 1606 1604 dev_err(dwc->dev, "%s: can't queue to disabled endpoint\n", 1607 1605 dep->name); 1608 1606 return -ESHUTDOWN; ··· 1630 1628 if (dep->flags & DWC3_EP_WAIT_TRANSFER_COMPLETE) 1631 1629 return 0; 1632 1630 1633 - /* Start the transfer only after the END_TRANSFER is completed */ 1634 - if (dep->flags & DWC3_EP_END_TRANSFER_PENDING) { 1631 + /* 1632 + * Start the transfer only after the END_TRANSFER is completed 1633 + * and endpoint STALL is cleared. 1634 + */ 1635 + if ((dep->flags & DWC3_EP_END_TRANSFER_PENDING) || 1636 + (dep->flags & DWC3_EP_WEDGE) || 1637 + (dep->flags & DWC3_EP_STALL)) { 1635 1638 dep->flags |= DWC3_EP_DELAY_START; 1636 1639 return 0; 1637 1640 } ··· 1655 1648 return 0; 1656 1649 1657 1650 if ((dep->flags & DWC3_EP_PENDING_REQUEST)) { 1658 - if (!(dep->flags & DWC3_EP_TRANSFER_STARTED)) { 1651 + if (!(dep->flags & DWC3_EP_TRANSFER_STARTED)) 1659 1652 return __dwc3_gadget_start_isoc(dep); 1660 - } 1661 1653 } 1662 1654 } 1663 1655 ··· 1794 1788 if (value) { 1795 1789 struct dwc3_trb *trb; 1796 1790 1797 - unsigned transfer_in_flight; 1798 - unsigned started; 1791 + unsigned int transfer_in_flight; 1792 + unsigned int started; 1799 1793 1800 1794 if (dep->number > 1) 1801 1795 trb = dwc3_ep_prev_trb(dep, dep->trb_enqueue); ··· 1828 1822 return 0; 1829 1823 } 1830 1824 1825 + dwc3_stop_active_transfer(dep, true, true); 1826 + 1827 + list_for_each_entry_safe(req, tmp, &dep->started_list, list) 1828 + dwc3_gadget_move_cancelled_request(req); 1829 + 1830 + if (dep->flags & DWC3_EP_END_TRANSFER_PENDING) { 1831 + dep->flags |= DWC3_EP_PENDING_CLEAR_STALL; 1832 + return 0; 1833 + } 1834 + 1835 + dwc3_gadget_ep_cleanup_cancelled_requests(dep); 1836 + 1831 1837 ret = dwc3_send_clear_stall_ep_cmd(dep); 1832 1838 if (ret) { 1833 1839 dev_err(dwc->dev, "failed to clear STALL on %s\n", ··· 1849 1831 1850 1832 dep->flags &= ~(DWC3_EP_STALL | DWC3_EP_WEDGE); 1851 1833 1852 - dwc3_stop_active_transfer(dep, true, true); 1834 + if ((dep->flags & DWC3_EP_DELAY_START) && 1835 + !usb_endpoint_xfer_isoc(dep->endpoint.desc)) 1836 + __dwc3_gadget_kick_transfer(dep); 1853 1837 1854 - list_for_each_entry_safe(req, tmp, &dep->started_list, list) 1855 - dwc3_gadget_move_cancelled_request(req); 1856 - 1857 - list_for_each_entry_safe(req, tmp, &dep->pending_list, list) 1858 - dwc3_gadget_move_cancelled_request(req); 1859 - 1860 - if (!(dep->flags & DWC3_EP_END_TRANSFER_PENDING)) { 1861 - dep->flags &= ~DWC3_EP_DELAY_START; 1862 - dwc3_gadget_ep_cleanup_cancelled_requests(dep); 1863 - } 1838 + dep->flags &= ~DWC3_EP_DELAY_START; 1864 1839 } 1865 1840 1866 1841 return ret; ··· 2021 2010 return 0; 2022 2011 } 2023 2012 2013 + static void dwc3_stop_active_transfers(struct dwc3 *dwc) 2014 + { 2015 + u32 epnum; 2016 + 2017 + for (epnum = 2; epnum < dwc->num_eps; epnum++) { 2018 + struct dwc3_ep *dep; 2019 + 2020 + dep = dwc->eps[epnum]; 2021 + if (!dep) 2022 + continue; 2023 + 2024 + dwc3_remove_requests(dwc, dep); 2025 + } 2026 + } 2027 + 2024 2028 static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend) 2025 2029 { 2026 2030 u32 reg; ··· 2081 2055 return 0; 2082 2056 } 2083 2057 2058 + static void dwc3_gadget_disable_irq(struct dwc3 *dwc); 2059 + static void __dwc3_gadget_stop(struct dwc3 *dwc); 2060 + 2084 2061 static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) 2085 2062 { 2086 2063 struct dwc3 *dwc = gadget_to_dwc(g); ··· 2107 2078 } 2108 2079 } 2109 2080 2081 + /* 2082 + * Synchronize any pending event handling before executing the controller 2083 + * halt routine. 2084 + */ 2085 + if (!is_on) { 2086 + dwc3_gadget_disable_irq(dwc); 2087 + synchronize_irq(dwc->irq_gadget); 2088 + } 2089 + 2110 2090 spin_lock_irqsave(&dwc->lock, flags); 2091 + 2092 + if (!is_on) { 2093 + u32 count; 2094 + 2095 + /* 2096 + * In the Synopsis DesignWare Cores USB3 Databook Rev. 3.30a 2097 + * Section 4.1.8 Table 4-7, it states that for a device-initiated 2098 + * disconnect, the SW needs to ensure that it sends "a DEPENDXFER 2099 + * command for any active transfers" before clearing the RunStop 2100 + * bit. 2101 + */ 2102 + dwc3_stop_active_transfers(dwc); 2103 + __dwc3_gadget_stop(dwc); 2104 + 2105 + /* 2106 + * In the Synopsis DesignWare Cores USB3 Databook Rev. 3.30a 2107 + * Section 1.3.4, it mentions that for the DEVCTRLHLT bit, the 2108 + * "software needs to acknowledge the events that are generated 2109 + * (by writing to GEVNTCOUNTn) while it is waiting for this bit 2110 + * to be set to '1'." 2111 + */ 2112 + count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); 2113 + count &= DWC3_GEVNTCOUNT_MASK; 2114 + if (count > 0) { 2115 + dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), count); 2116 + dwc->ev_buf->lpos = (dwc->ev_buf->lpos + count) % 2117 + dwc->ev_buf->length; 2118 + } 2119 + } 2120 + 2111 2121 ret = dwc3_gadget_run_stop(dwc, is_on, false); 2112 2122 spin_unlock_irqrestore(&dwc->lock, flags); 2113 2123 ··· 2312 2244 spin_lock_irqsave(&dwc->lock, flags); 2313 2245 if (dwc->gadget_driver) { 2314 2246 dev_err(dwc->dev, "%s is already bound to %s\n", 2315 - dwc->gadget.name, 2247 + dwc->gadget->name, 2316 2248 dwc->gadget_driver->driver.name); 2317 2249 ret = -EBUSY; 2318 2250 goto err1; ··· 2484 2416 dep->endpoint.maxburst = 1; 2485 2417 dep->endpoint.ops = &dwc3_gadget_ep0_ops; 2486 2418 if (!dep->direction) 2487 - dwc->gadget.ep0 = &dep->endpoint; 2419 + dwc->gadget->ep0 = &dep->endpoint; 2488 2420 2489 2421 dep->endpoint.caps.type_control = true; 2490 2422 ··· 2527 2459 2528 2460 usb_ep_set_maxpacket_limit(&dep->endpoint, size); 2529 2461 2530 - dep->endpoint.max_streams = 15; 2462 + dep->endpoint.max_streams = 16; 2531 2463 dep->endpoint.ops = &dwc3_gadget_ep_ops; 2532 2464 list_add_tail(&dep->endpoint.ep_list, 2533 - &dwc->gadget.ep_list); 2465 + &dwc->gadget->ep_list); 2534 2466 dep->endpoint.caps.type_iso = true; 2535 2467 dep->endpoint.caps.type_bulk = true; 2536 2468 dep->endpoint.caps.type_int = true; ··· 2576 2508 size /= 3; 2577 2509 2578 2510 usb_ep_set_maxpacket_limit(&dep->endpoint, size); 2579 - dep->endpoint.max_streams = 15; 2511 + dep->endpoint.max_streams = 16; 2580 2512 dep->endpoint.ops = &dwc3_gadget_ep_ops; 2581 2513 list_add_tail(&dep->endpoint.ep_list, 2582 - &dwc->gadget.ep_list); 2514 + &dwc->gadget->ep_list); 2583 2515 dep->endpoint.caps.type_iso = true; 2584 2516 dep->endpoint.caps.type_bulk = true; 2585 2517 dep->endpoint.caps.type_int = true; ··· 2640 2572 { 2641 2573 u8 epnum; 2642 2574 2643 - INIT_LIST_HEAD(&dwc->gadget.ep_list); 2575 + INIT_LIST_HEAD(&dwc->gadget->ep_list); 2644 2576 2645 2577 for (epnum = 0; epnum < total; epnum++) { 2646 2578 int ret; ··· 2720 2652 } 2721 2653 2722 2654 /* 2723 - * If we're dealing with unaligned size OUT transfer, we will be left 2724 - * with one TRB pending in the ring. We need to manually clear HWO bit 2725 - * from that TRB. 2655 + * We use bounce buffer for requests that needs extra TRB or OUT ZLP. If 2656 + * this TRB points to the bounce buffer address, it's a MPS alignment 2657 + * TRB. Don't add it to req->remaining calculation. 2726 2658 */ 2727 - 2728 - if (req->needs_extra_trb && !(trb->ctrl & DWC3_TRB_CTRL_CHN)) { 2659 + if (trb->bpl == lower_32_bits(dep->dwc->bounce_addr) && 2660 + trb->bph == upper_32_bits(dep->dwc->bounce_addr)) { 2729 2661 trb->ctrl &= ~DWC3_TRB_CTRL_HWO; 2730 2662 return 1; 2731 2663 } ··· 2800 2732 ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event, 2801 2733 status); 2802 2734 2803 - if (req->needs_extra_trb) { 2804 - unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); 2805 - 2806 - ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event, 2807 - status); 2808 - 2809 - /* Reclaim MPS padding TRB for ZLP */ 2810 - if (!req->direction && req->request.zero && req->request.length && 2811 - !usb_endpoint_xfer_isoc(dep->endpoint.desc) && 2812 - (IS_ALIGNED(req->request.length, maxp))) 2813 - ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event, status); 2814 - 2815 - req->needs_extra_trb = false; 2816 - } 2817 - 2818 2735 req->request.actual = req->request.length - req->remaining; 2819 2736 2820 2737 if (!dwc3_gadget_ep_request_completed(req)) 2821 2738 goto out; 2739 + 2740 + if (req->needs_extra_trb) { 2741 + ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event, 2742 + status); 2743 + req->needs_extra_trb = false; 2744 + } 2822 2745 2823 2746 dwc3_gadget_giveback(dep, req, status); 2824 2747 ··· 2955 2896 (void) __dwc3_gadget_start_isoc(dep); 2956 2897 } 2957 2898 2899 + static void dwc3_gadget_endpoint_command_complete(struct dwc3_ep *dep, 2900 + const struct dwc3_event_depevt *event) 2901 + { 2902 + u8 cmd = DEPEVT_PARAMETER_CMD(event->parameters); 2903 + 2904 + if (cmd != DWC3_DEPCMD_ENDTRANSFER) 2905 + return; 2906 + 2907 + dep->flags &= ~DWC3_EP_END_TRANSFER_PENDING; 2908 + dep->flags &= ~DWC3_EP_TRANSFER_STARTED; 2909 + dwc3_gadget_ep_cleanup_cancelled_requests(dep); 2910 + 2911 + if (dep->flags & DWC3_EP_PENDING_CLEAR_STALL) { 2912 + struct dwc3 *dwc = dep->dwc; 2913 + 2914 + dep->flags &= ~DWC3_EP_PENDING_CLEAR_STALL; 2915 + if (dwc3_send_clear_stall_ep_cmd(dep)) { 2916 + struct usb_ep *ep0 = &dwc->eps[0]->endpoint; 2917 + 2918 + dev_err(dwc->dev, "failed to clear STALL on %s\n", dep->name); 2919 + if (dwc->delayed_status) 2920 + __dwc3_gadget_ep0_set_halt(ep0, 1); 2921 + return; 2922 + } 2923 + 2924 + dep->flags &= ~(DWC3_EP_STALL | DWC3_EP_WEDGE); 2925 + if (dwc->delayed_status) 2926 + dwc3_ep0_send_delayed_status(dwc); 2927 + } 2928 + 2929 + if ((dep->flags & DWC3_EP_DELAY_START) && 2930 + !usb_endpoint_xfer_isoc(dep->endpoint.desc)) 2931 + __dwc3_gadget_kick_transfer(dep); 2932 + 2933 + dep->flags &= ~DWC3_EP_DELAY_START; 2934 + } 2935 + 2958 2936 static void dwc3_gadget_endpoint_stream_event(struct dwc3_ep *dep, 2959 2937 const struct dwc3_event_depevt *event) 2960 2938 { ··· 3061 2965 { 3062 2966 struct dwc3_ep *dep; 3063 2967 u8 epnum = event->endpoint_number; 3064 - u8 cmd; 3065 2968 3066 2969 dep = dwc->eps[epnum]; 3067 2970 ··· 3086 2991 dwc3_gadget_endpoint_transfer_not_ready(dep, event); 3087 2992 break; 3088 2993 case DWC3_DEPEVT_EPCMDCMPLT: 3089 - cmd = DEPEVT_PARAMETER_CMD(event->parameters); 3090 - 3091 - if (cmd == DWC3_DEPCMD_ENDTRANSFER) { 3092 - dep->flags &= ~DWC3_EP_END_TRANSFER_PENDING; 3093 - dep->flags &= ~DWC3_EP_TRANSFER_STARTED; 3094 - dwc3_gadget_ep_cleanup_cancelled_requests(dep); 3095 - if ((dep->flags & DWC3_EP_DELAY_START) && 3096 - !usb_endpoint_xfer_isoc(dep->endpoint.desc)) 3097 - __dwc3_gadget_kick_transfer(dep); 3098 - 3099 - dep->flags &= ~DWC3_EP_DELAY_START; 3100 - } 2994 + dwc3_gadget_endpoint_command_complete(dep, event); 3101 2995 break; 3102 2996 case DWC3_DEPEVT_XFERCOMPLETE: 3103 2997 dwc3_gadget_endpoint_transfer_complete(dep, event); ··· 3103 3019 { 3104 3020 if (dwc->gadget_driver && dwc->gadget_driver->disconnect) { 3105 3021 spin_unlock(&dwc->lock); 3106 - dwc->gadget_driver->disconnect(&dwc->gadget); 3022 + dwc->gadget_driver->disconnect(dwc->gadget); 3107 3023 spin_lock(&dwc->lock); 3108 3024 } 3109 3025 } ··· 3112 3028 { 3113 3029 if (dwc->gadget_driver && dwc->gadget_driver->suspend) { 3114 3030 spin_unlock(&dwc->lock); 3115 - dwc->gadget_driver->suspend(&dwc->gadget); 3031 + dwc->gadget_driver->suspend(dwc->gadget); 3116 3032 spin_lock(&dwc->lock); 3117 3033 } 3118 3034 } ··· 3121 3037 { 3122 3038 if (dwc->gadget_driver && dwc->gadget_driver->resume) { 3123 3039 spin_unlock(&dwc->lock); 3124 - dwc->gadget_driver->resume(&dwc->gadget); 3040 + dwc->gadget_driver->resume(dwc->gadget); 3125 3041 spin_lock(&dwc->lock); 3126 3042 } 3127 3043 } ··· 3131 3047 if (!dwc->gadget_driver) 3132 3048 return; 3133 3049 3134 - if (dwc->gadget.speed != USB_SPEED_UNKNOWN) { 3050 + if (dwc->gadget->speed != USB_SPEED_UNKNOWN) { 3135 3051 spin_unlock(&dwc->lock); 3136 - usb_gadget_udc_reset(&dwc->gadget, dwc->gadget_driver); 3052 + usb_gadget_udc_reset(dwc->gadget, dwc->gadget_driver); 3137 3053 spin_lock(&dwc->lock); 3138 3054 } 3139 3055 } ··· 3234 3150 3235 3151 dwc3_disconnect_gadget(dwc); 3236 3152 3237 - dwc->gadget.speed = USB_SPEED_UNKNOWN; 3153 + dwc->gadget->speed = USB_SPEED_UNKNOWN; 3238 3154 dwc->setup_packet_pending = false; 3239 - usb_gadget_set_state(&dwc->gadget, USB_STATE_NOTATTACHED); 3155 + usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED); 3240 3156 3241 3157 dwc->connected = false; 3242 3158 } ··· 3279 3195 } 3280 3196 3281 3197 dwc3_reset_gadget(dwc); 3198 + /* 3199 + * In the Synopsis DesignWare Cores USB3 Databook Rev. 3.30a 3200 + * Section 4.1.2 Table 4-2, it states that during a USB reset, the SW 3201 + * needs to ensure that it sends "a DEPENDXFER command for any active 3202 + * transfers." 3203 + */ 3204 + dwc3_stop_active_transfers(dwc); 3282 3205 3283 3206 reg = dwc3_readl(dwc->regs, DWC3_DCTL); 3284 3207 reg &= ~DWC3_DCTL_TSTCTRL_MASK; ··· 3322 3231 switch (speed) { 3323 3232 case DWC3_DSTS_SUPERSPEED_PLUS: 3324 3233 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); 3325 - dwc->gadget.ep0->maxpacket = 512; 3326 - dwc->gadget.speed = USB_SPEED_SUPER_PLUS; 3234 + dwc->gadget->ep0->maxpacket = 512; 3235 + dwc->gadget->speed = USB_SPEED_SUPER_PLUS; 3327 3236 break; 3328 3237 case DWC3_DSTS_SUPERSPEED: 3329 3238 /* ··· 3343 3252 dwc3_gadget_reset_interrupt(dwc); 3344 3253 3345 3254 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); 3346 - dwc->gadget.ep0->maxpacket = 512; 3347 - dwc->gadget.speed = USB_SPEED_SUPER; 3255 + dwc->gadget->ep0->maxpacket = 512; 3256 + dwc->gadget->speed = USB_SPEED_SUPER; 3348 3257 break; 3349 3258 case DWC3_DSTS_HIGHSPEED: 3350 3259 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64); 3351 - dwc->gadget.ep0->maxpacket = 64; 3352 - dwc->gadget.speed = USB_SPEED_HIGH; 3260 + dwc->gadget->ep0->maxpacket = 64; 3261 + dwc->gadget->speed = USB_SPEED_HIGH; 3353 3262 break; 3354 3263 case DWC3_DSTS_FULLSPEED: 3355 3264 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64); 3356 - dwc->gadget.ep0->maxpacket = 64; 3357 - dwc->gadget.speed = USB_SPEED_FULL; 3265 + dwc->gadget->ep0->maxpacket = 64; 3266 + dwc->gadget->speed = USB_SPEED_FULL; 3358 3267 break; 3359 3268 case DWC3_DSTS_LOWSPEED: 3360 3269 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(8); 3361 - dwc->gadget.ep0->maxpacket = 8; 3362 - dwc->gadget.speed = USB_SPEED_LOW; 3270 + dwc->gadget->ep0->maxpacket = 8; 3271 + dwc->gadget->speed = USB_SPEED_LOW; 3363 3272 break; 3364 3273 } 3365 3274 3366 - dwc->eps[1]->endpoint.maxpacket = dwc->gadget.ep0->maxpacket; 3275 + dwc->eps[1]->endpoint.maxpacket = dwc->gadget->ep0->maxpacket; 3367 3276 3368 3277 /* Enable USB2 LPM Capability */ 3369 3278 ··· 3431 3340 3432 3341 if (dwc->gadget_driver && dwc->gadget_driver->resume) { 3433 3342 spin_unlock(&dwc->lock); 3434 - dwc->gadget_driver->resume(&dwc->gadget); 3343 + dwc->gadget_driver->resume(dwc->gadget); 3435 3344 spin_lock(&dwc->lock); 3436 3345 } 3437 3346 } ··· 3602 3511 * Ignore suspend event until the gadget enters into 3603 3512 * USB_STATE_CONFIGURED state. 3604 3513 */ 3605 - if (dwc->gadget.state >= USB_STATE_CONFIGURED) 3514 + if (dwc->gadget->state >= USB_STATE_CONFIGURED) 3606 3515 dwc3_gadget_suspend_interrupt(dwc, 3607 3516 event->event_info); 3608 3517 } ··· 3777 3686 return irq; 3778 3687 } 3779 3688 3689 + static void dwc_gadget_release(struct device *dev) 3690 + { 3691 + struct usb_gadget *gadget = container_of(dev, struct usb_gadget, dev); 3692 + 3693 + kfree(gadget); 3694 + } 3695 + 3780 3696 /** 3781 3697 * dwc3_gadget_init - initializes gadget related registers 3782 3698 * @dwc: pointer to our controller context structure ··· 3794 3696 { 3795 3697 int ret; 3796 3698 int irq; 3699 + struct device *dev; 3797 3700 3798 3701 irq = dwc3_gadget_get_irq(dwc); 3799 3702 if (irq < 0) { ··· 3827 3728 } 3828 3729 3829 3730 init_completion(&dwc->ep0_in_setup); 3731 + dwc->gadget = kzalloc(sizeof(struct usb_gadget), GFP_KERNEL); 3732 + if (!dwc->gadget) { 3733 + ret = -ENOMEM; 3734 + goto err3; 3735 + } 3830 3736 3831 - dwc->gadget.ops = &dwc3_gadget_ops; 3832 - dwc->gadget.speed = USB_SPEED_UNKNOWN; 3833 - dwc->gadget.sg_supported = true; 3834 - dwc->gadget.name = "dwc3-gadget"; 3835 - dwc->gadget.lpm_capable = true; 3737 + 3738 + usb_initialize_gadget(dwc->dev, dwc->gadget, dwc_gadget_release); 3739 + dev = &dwc->gadget->dev; 3740 + dev->platform_data = dwc; 3741 + dwc->gadget->ops = &dwc3_gadget_ops; 3742 + dwc->gadget->speed = USB_SPEED_UNKNOWN; 3743 + dwc->gadget->sg_supported = true; 3744 + dwc->gadget->name = "dwc3-gadget"; 3745 + dwc->gadget->lpm_capable = true; 3836 3746 3837 3747 /* 3838 3748 * FIXME We might be setting max_speed to <SUPER, however versions ··· 3864 3756 dev_info(dwc->dev, "changing max_speed on rev %08x\n", 3865 3757 dwc->revision); 3866 3758 3867 - dwc->gadget.max_speed = dwc->maximum_speed; 3759 + dwc->gadget->max_speed = dwc->maximum_speed; 3868 3760 3869 3761 /* 3870 3762 * REVISIT: Here we should clear all pending IRQs to be ··· 3873 3765 3874 3766 ret = dwc3_gadget_init_endpoints(dwc, dwc->num_eps); 3875 3767 if (ret) 3876 - goto err3; 3877 - 3878 - ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget); 3879 - if (ret) { 3880 - dev_err(dwc->dev, "failed to register udc\n"); 3881 3768 goto err4; 3769 + 3770 + ret = usb_add_gadget(dwc->gadget); 3771 + if (ret) { 3772 + dev_err(dwc->dev, "failed to add gadget\n"); 3773 + goto err5; 3882 3774 } 3883 3775 3884 - dwc3_gadget_set_speed(&dwc->gadget, dwc->maximum_speed); 3776 + dwc3_gadget_set_speed(dwc->gadget, dwc->maximum_speed); 3885 3777 3886 3778 return 0; 3887 3779 3888 - err4: 3780 + err5: 3889 3781 dwc3_gadget_free_endpoints(dwc); 3890 - 3782 + err4: 3783 + usb_put_gadget(dwc->gadget); 3891 3784 err3: 3892 3785 dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce, 3893 3786 dwc->bounce_addr); ··· 3908 3799 3909 3800 void dwc3_gadget_exit(struct dwc3 *dwc) 3910 3801 { 3911 - usb_del_gadget_udc(&dwc->gadget); 3802 + usb_del_gadget_udc(dwc->gadget); 3912 3803 dwc3_gadget_free_endpoints(dwc); 3913 3804 dma_free_coherent(dwc->sysdev, DWC3_BOUNCE_SIZE, dwc->bounce, 3914 3805 dwc->bounce_addr);
+2 -1
drivers/usb/dwc3/gadget.h
··· 17 17 18 18 struct dwc3; 19 19 #define to_dwc3_ep(ep) (container_of(ep, struct dwc3_ep, endpoint)) 20 - #define gadget_to_dwc(g) (container_of(g, struct dwc3, gadget)) 20 + #define gadget_to_dwc(g) (dev_get_platdata(&g->dev)) 21 21 22 22 /* DEPCFG parameter 1 */ 23 23 #define DWC3_DEPCFG_INT_NUM(n) (((n) & 0x1f) << 0) ··· 113 113 int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request, 114 114 gfp_t gfp_flags); 115 115 int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol); 116 + void dwc3_ep0_send_delayed_status(struct dwc3 *dwc); 116 117 117 118 /** 118 119 * dwc3_gadget_ep_get_transfer_index - Gets transfer index from HW
+9 -8
drivers/usb/dwc3/trace.h
··· 104 104 TP_STRUCT__entry( 105 105 __string(name, req->dep->name) 106 106 __field(struct dwc3_request *, req) 107 - __field(unsigned, actual) 108 - __field(unsigned, length) 107 + __field(unsigned int, actual) 108 + __field(unsigned int, length) 109 109 __field(int, status) 110 110 __field(int, zero) 111 111 __field(int, short_not_ok) ··· 246 246 __entry->dequeue, __entry->bph, __entry->bpl, 247 247 ({char *s; 248 248 int pcm = ((__entry->size >> 24) & 3) + 1; 249 + 249 250 switch (__entry->type) { 250 251 case USB_ENDPOINT_XFER_INT: 251 252 case USB_ENDPOINT_XFER_ISOC: ··· 292 291 TP_ARGS(dep), 293 292 TP_STRUCT__entry( 294 293 __string(name, dep->name) 295 - __field(unsigned, maxpacket) 296 - __field(unsigned, maxpacket_limit) 297 - __field(unsigned, max_streams) 298 - __field(unsigned, maxburst) 299 - __field(unsigned, flags) 300 - __field(unsigned, direction) 294 + __field(unsigned int, maxpacket) 295 + __field(unsigned int, maxpacket_limit) 296 + __field(unsigned int, max_streams) 297 + __field(unsigned int, maxburst) 298 + __field(unsigned int, flags) 299 + __field(unsigned int, direction) 301 300 __field(u8, trb_enqueue) 302 301 __field(u8, trb_dequeue) 303 302 ),
+1 -1
drivers/usb/dwc3/ulpi.c
··· 19 19 20 20 static int dwc3_ulpi_busyloop(struct dwc3 *dwc) 21 21 { 22 - unsigned count = 1000; 22 + unsigned int count = 1000; 23 23 u32 reg; 24 24 25 25 while (count--) {
+5 -3
drivers/usb/gadget/function/f_acm.c
··· 425 425 /* we know alt == 0, so this is an activation or a reset */ 426 426 427 427 if (intf == acm->ctrl_id) { 428 - dev_vdbg(&cdev->gadget->dev, 429 - "reset acm control interface %d\n", intf); 430 - usb_ep_disable(acm->notify); 428 + if (acm->notify->enabled) { 429 + dev_vdbg(&cdev->gadget->dev, 430 + "reset acm control interface %d\n", intf); 431 + usb_ep_disable(acm->notify); 432 + } 431 433 432 434 if (!acm->notify->desc) 433 435 if (config_ep_by_speed(cdev->gadget, f, acm->notify))
+8 -32
drivers/usb/gadget/function/f_ncm.c
··· 85 85 /* peak (theoretical) bulk transfer rate in bits-per-second */ 86 86 static inline unsigned ncm_bitrate(struct usb_gadget *g) 87 87 { 88 - if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER) 89 - return 13 * 1024 * 8 * 1000 * 8; 88 + if (gadget_is_superspeed(g) && g->speed >= USB_SPEED_SUPER_PLUS) 89 + return 4250000000U; 90 + else if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER) 91 + return 3750000000U; 90 92 else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) 91 93 return 13 * 512 * 8 * 1000 * 8; 92 94 else ··· 378 376 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 379 377 380 378 /* the following 2 values can be tweaked if necessary */ 381 - /* .bMaxBurst = 0, */ 379 + .bMaxBurst = 15, 382 380 /* .bmAttributes = 0, */ 383 381 }; 384 382 ··· 1191 1189 const struct ndp_parser_opts *opts = ncm->parser_opts; 1192 1190 unsigned crc_len = ncm->is_crc ? sizeof(uint32_t) : 0; 1193 1191 int dgram_counter; 1194 - bool ndp_after_header; 1195 1192 1196 1193 /* dwSignature */ 1197 1194 if (get_unaligned_le32(tmp) != opts->nth_sign) { ··· 1217 1216 } 1218 1217 1219 1218 ndp_index = get_ncm(&tmp, opts->ndp_index); 1220 - ndp_after_header = false; 1221 1219 1222 1220 /* Run through all the NDP's in the NTB */ 1223 1221 do { ··· 1232 1232 ndp_index); 1233 1233 goto err; 1234 1234 } 1235 - if (ndp_index == opts->nth_size) 1236 - ndp_after_header = true; 1237 1235 1238 1236 /* 1239 1237 * walk through NDP ··· 1310 1312 index2 = get_ncm(&tmp, opts->dgram_item_len); 1311 1313 dg_len2 = get_ncm(&tmp, opts->dgram_item_len); 1312 1314 1313 - if (index2 == 0 || dg_len2 == 0) 1314 - break; 1315 - 1316 1315 /* wDatagramIndex[1] */ 1317 - if (ndp_after_header) { 1318 - if (index2 < opts->nth_size + opts->ndp_size) { 1319 - INFO(port->func.config->cdev, 1320 - "Bad index: %#X\n", index2); 1321 - goto err; 1322 - } 1323 - } else { 1324 - if (index2 < opts->nth_size + opts->dpe_size) { 1325 - INFO(port->func.config->cdev, 1326 - "Bad index: %#X\n", index2); 1327 - goto err; 1328 - } 1329 - } 1330 1316 if (index2 > block_len - opts->dpe_size) { 1331 1317 INFO(port->func.config->cdev, 1332 1318 "Bad index: %#X\n", index2); 1333 - goto err; 1334 - } 1335 - 1336 - /* wDatagramLength[1] */ 1337 - if ((dg_len2 < 14 + crc_len) || 1338 - (dg_len2 > frame_max)) { 1339 - INFO(port->func.config->cdev, 1340 - "Bad dgram length: %#X\n", dg_len); 1341 1319 goto err; 1342 1320 } 1343 1321 ··· 1333 1359 ndp_len -= 2 * (opts->dgram_item_len * 2); 1334 1360 1335 1361 dgram_counter++; 1362 + if (index2 == 0 || dg_len2 == 0) 1363 + break; 1336 1364 } while (ndp_len > 2 * (opts->dgram_item_len * 2)); 1337 1365 } while (ndp_index); 1338 1366 ··· 1536 1560 fs_ncm_notify_desc.bEndpointAddress; 1537 1561 1538 1562 status = usb_assign_descriptors(f, ncm_fs_function, ncm_hs_function, 1539 - ncm_ss_function, NULL); 1563 + ncm_ss_function, ncm_ss_function); 1540 1564 if (status) 1541 1565 goto fail; 1542 1566
+14 -2
drivers/usb/gadget/function/f_printer.c
··· 31 31 #include <linux/types.h> 32 32 #include <linux/ctype.h> 33 33 #include <linux/cdev.h> 34 + #include <linux/kref.h> 34 35 35 36 #include <asm/byteorder.h> 36 37 #include <linux/io.h> ··· 65 64 struct usb_gadget *gadget; 66 65 s8 interface; 67 66 struct usb_ep *in_ep, *out_ep; 68 - 67 + struct kref kref; 69 68 struct list_head rx_reqs; /* List of free RX structs */ 70 69 struct list_head rx_reqs_active; /* List of Active RX xfers */ 71 70 struct list_head rx_buffers; /* List of completed xfers */ ··· 219 218 220 219 /*-------------------------------------------------------------------------*/ 221 220 221 + static void printer_dev_free(struct kref *kref) 222 + { 223 + struct printer_dev *dev = container_of(kref, struct printer_dev, kref); 224 + 225 + kfree(dev); 226 + } 227 + 222 228 static struct usb_request * 223 229 printer_req_alloc(struct usb_ep *ep, unsigned len, gfp_t gfp_flags) 224 230 { ··· 361 353 362 354 spin_unlock_irqrestore(&dev->lock, flags); 363 355 356 + kref_get(&dev->kref); 364 357 DBG(dev, "printer_open returned %x\n", ret); 365 358 return ret; 366 359 } ··· 379 370 dev->printer_status &= ~PRINTER_SELECTED; 380 371 spin_unlock_irqrestore(&dev->lock, flags); 381 372 373 + kref_put(&dev->kref, printer_dev_free); 382 374 DBG(dev, "printer_close\n"); 383 375 384 376 return 0; ··· 1396 1386 struct f_printer_opts *opts; 1397 1387 1398 1388 opts = container_of(f->fi, struct f_printer_opts, func_inst); 1399 - kfree(dev); 1389 + 1390 + kref_put(&dev->kref, printer_dev_free); 1400 1391 mutex_lock(&opts->lock); 1401 1392 --opts->refcnt; 1402 1393 mutex_unlock(&opts->lock); ··· 1466 1455 return ERR_PTR(-ENOMEM); 1467 1456 } 1468 1457 1458 + kref_init(&dev->kref); 1469 1459 ++opts->refcnt; 1470 1460 dev->minor = opts->minor; 1471 1461 dev->pnp_string = opts->pnp_string;
+6 -6
drivers/usb/gadget/function/f_tcm.c
··· 392 392 393 393 fu->flags = USBG_IS_BOT; 394 394 395 - config_ep_by_speed(gadget, f, fu->ep_in); 395 + config_ep_by_speed_and_alt(gadget, f, fu->ep_in, USB_G_ALT_INT_BBB); 396 396 ret = usb_ep_enable(fu->ep_in); 397 397 if (ret) 398 398 goto err_b_in; 399 399 400 - config_ep_by_speed(gadget, f, fu->ep_out); 400 + config_ep_by_speed_and_alt(gadget, f, fu->ep_out, USB_G_ALT_INT_BBB); 401 401 ret = usb_ep_enable(fu->ep_out); 402 402 if (ret) 403 403 goto err_b_out; ··· 852 852 if (gadget->speed >= USB_SPEED_SUPER) 853 853 fu->flags |= USBG_USE_STREAMS; 854 854 855 - config_ep_by_speed(gadget, f, fu->ep_in); 855 + config_ep_by_speed_and_alt(gadget, f, fu->ep_in, USB_G_ALT_INT_UAS); 856 856 ret = usb_ep_enable(fu->ep_in); 857 857 if (ret) 858 858 goto err_b_in; 859 859 860 - config_ep_by_speed(gadget, f, fu->ep_out); 860 + config_ep_by_speed_and_alt(gadget, f, fu->ep_out, USB_G_ALT_INT_UAS); 861 861 ret = usb_ep_enable(fu->ep_out); 862 862 if (ret) 863 863 goto err_b_out; 864 864 865 - config_ep_by_speed(gadget, f, fu->ep_cmd); 865 + config_ep_by_speed_and_alt(gadget, f, fu->ep_cmd, USB_G_ALT_INT_UAS); 866 866 ret = usb_ep_enable(fu->ep_cmd); 867 867 if (ret) 868 868 goto err_cmd; 869 - config_ep_by_speed(gadget, f, fu->ep_status); 869 + config_ep_by_speed_and_alt(gadget, f, fu->ep_status, USB_G_ALT_INT_UAS); 870 870 ret = usb_ep_enable(fu->ep_status); 871 871 if (ret) 872 872 goto err_status;
+4 -4
drivers/usb/gadget/function/f_uvc.c
··· 740 740 /* Initialise video. */ 741 741 ret = uvcg_video_init(&uvc->video, uvc); 742 742 if (ret < 0) 743 - goto error; 743 + goto v4l2_error; 744 744 745 745 /* Register a V4L2 device. */ 746 746 ret = uvc_register_video(uvc); 747 747 if (ret < 0) { 748 748 uvcg_err(f, "failed to register video device\n"); 749 - goto error; 749 + goto v4l2_error; 750 750 } 751 751 752 752 return 0; 753 753 754 - error: 754 + v4l2_error: 755 755 v4l2_device_unregister(&uvc->v4l2_dev); 756 - 756 + error: 757 757 if (uvc->control_req) 758 758 usb_ep_free_request(cdev->gadget->ep0, uvc->control_req); 759 759 kfree(uvc->control_buf);
+1 -1
drivers/usb/gadget/function/u_ether.c
··· 93 93 static inline int qlen(struct usb_gadget *gadget, unsigned qmult) 94 94 { 95 95 if (gadget_is_dualspeed(gadget) && (gadget->speed == USB_SPEED_HIGH || 96 - gadget->speed == USB_SPEED_SUPER)) 96 + gadget->speed >= USB_SPEED_SUPER)) 97 97 return qmult * DEFAULT_QLEN; 98 98 else 99 99 return DEFAULT_QLEN;
+1
drivers/usb/gadget/function/u_serial.c
··· 1391 1391 if (port->port.tty) 1392 1392 tty_hangup(port->port.tty); 1393 1393 } 1394 + port->suspended = false; 1394 1395 spin_unlock_irqrestore(&port->port_lock, flags); 1395 1396 1396 1397 /* disable endpoints, aborting down any active I/O */
+3 -7
drivers/usb/gadget/udc/aspeed-vhub/core.c
··· 135 135 136 136 /* Handle device interrupts */ 137 137 if (istat & vhub->port_irq_mask) { 138 - unsigned long bitmap = istat; 139 - int offset = VHUB_IRQ_DEV1_BIT; 140 - int size = VHUB_IRQ_DEV1_BIT + vhub->max_ports; 141 - 142 - for_each_set_bit_from(offset, &bitmap, size) { 143 - i = offset - VHUB_IRQ_DEV1_BIT; 144 - ast_vhub_dev_irq(&vhub->ports[i].dev); 138 + for (i = 0; i < vhub->max_ports; i++) { 139 + if (istat & VHUB_DEV_IRQ(i)) 140 + ast_vhub_dev_irq(&vhub->ports[i].dev); 145 141 } 146 142 } 147 143
+3
drivers/usb/gadget/udc/aspeed-vhub/vhub.h
··· 67 67 #define VHUB_IRQ_HUB_EP0_SETUP (1 << 0) 68 68 #define VHUB_IRQ_ACK_ALL 0x1ff 69 69 70 + /* Downstream device IRQ mask. */ 71 + #define VHUB_DEV_IRQ(n) (VHUB_IRQ_DEVICE1 << (n)) 72 + 70 73 /* SW reset reg */ 71 74 #define VHUB_SW_RESET_EP_POOL (1 << 9) 72 75 #define VHUB_SW_RESET_DMA_CONTROLLER (1 << 8)
+45 -23
drivers/usb/gadget/udc/atmel_usba_udc.c
··· 1056 1056 1057 1057 switch (usb_endpoint_type(desc)) { 1058 1058 case USB_ENDPOINT_XFER_CONTROL: 1059 + ep->nr_banks = 1; 1059 1060 break; 1060 1061 1061 1062 case USB_ENDPOINT_XFER_ISOC: 1062 1063 ep->fifo_size = 1024; 1063 - ep->nr_banks = 2; 1064 + if (ep->udc->ep_prealloc) 1065 + ep->nr_banks = 2; 1064 1066 break; 1065 1067 1066 1068 case USB_ENDPOINT_XFER_BULK: 1067 1069 ep->fifo_size = 512; 1068 - ep->nr_banks = 1; 1070 + if (ep->udc->ep_prealloc) 1071 + ep->nr_banks = 1; 1069 1072 break; 1070 1073 1071 1074 case USB_ENDPOINT_XFER_INT: ··· 1078 1075 else 1079 1076 ep->fifo_size = 1080 1077 roundup_pow_of_two(le16_to_cpu(desc->wMaxPacketSize)); 1081 - ep->nr_banks = 1; 1078 + if (ep->udc->ep_prealloc) 1079 + ep->nr_banks = 1; 1082 1080 break; 1083 1081 } 1084 1082 ··· 1095 1091 USBA_BF(EPT_SIZE, fls(ep->fifo_size - 1) - 3); 1096 1092 1097 1093 ep->ept_cfg |= USBA_BF(BK_NUMBER, ep->nr_banks); 1098 - 1099 - ep->udc->configured_ep++; 1100 1094 } 1101 1095 1102 1096 return _ep; ··· 1788 1786 1789 1787 if (status & USBA_END_OF_RESET) { 1790 1788 struct usba_ep *ep0, *ep; 1791 - int i, n; 1789 + int i; 1792 1790 1793 1791 usba_writel(udc, INT_CLR, 1794 1792 USBA_END_OF_RESET|USBA_END_OF_RESUME ··· 1836 1834 "ODD: EP0 configuration is invalid!\n"); 1837 1835 1838 1836 /* Preallocate other endpoints */ 1839 - n = fifo_mode ? udc->num_ep : udc->configured_ep; 1840 - for (i = 1; i < n; i++) { 1837 + for (i = 1; i < udc->num_ep; i++) { 1841 1838 ep = &udc->usba_ep[i]; 1842 - usba_ep_writel(ep, CFG, ep->ept_cfg); 1843 - if (!(usba_ep_readl(ep, CFG) & USBA_EPT_MAPPED)) 1844 - dev_err(&udc->pdev->dev, 1845 - "ODD: EP%d configuration is invalid!\n", i); 1839 + if (ep->ep.claimed) { 1840 + usba_ep_writel(ep, CFG, ep->ept_cfg); 1841 + if (!(usba_ep_readl(ep, CFG) & USBA_EPT_MAPPED)) 1842 + dev_err(&udc->pdev->dev, 1843 + "ODD: EP%d configuration is invalid!\n", i); 1844 + } 1846 1845 } 1847 1846 } 1848 1847 ··· 2028 2025 if (udc->vbus_pin) 2029 2026 disable_irq(gpiod_to_irq(udc->vbus_pin)); 2030 2027 2031 - if (fifo_mode == 0) 2032 - udc->configured_ep = 1; 2033 - 2034 2028 udc->suspended = false; 2035 2029 usba_stop(udc); 2036 2030 ··· 2090 2090 .errata = &at91sam9rl_errata, 2091 2091 .config = ep_config_sam9, 2092 2092 .num_ep = ARRAY_SIZE(ep_config_sam9), 2093 + .ep_prealloc = true, 2093 2094 }; 2094 2095 2095 2096 static const struct usba_udc_config udc_at91sam9g45_cfg = { 2096 2097 .errata = &at91sam9g45_errata, 2097 2098 .config = ep_config_sam9, 2098 2099 .num_ep = ARRAY_SIZE(ep_config_sam9), 2100 + .ep_prealloc = true, 2099 2101 }; 2100 2102 2101 2103 static const struct usba_udc_config udc_sama5d3_cfg = { 2102 2104 .config = ep_config_sama5, 2103 2105 .num_ep = ARRAY_SIZE(ep_config_sama5), 2106 + .ep_prealloc = true, 2107 + }; 2108 + 2109 + static const struct usba_udc_config udc_sam9x60_cfg = { 2110 + .num_ep = ARRAY_SIZE(ep_config_sam9), 2111 + .config = ep_config_sam9, 2112 + .ep_prealloc = false, 2104 2113 }; 2105 2114 2106 2115 static const struct of_device_id atmel_udc_dt_ids[] = { 2107 2116 { .compatible = "atmel,at91sam9rl-udc", .data = &udc_at91sam9rl_cfg }, 2108 2117 { .compatible = "atmel,at91sam9g45-udc", .data = &udc_at91sam9g45_cfg }, 2109 2118 { .compatible = "atmel,sama5d3-udc", .data = &udc_sama5d3_cfg }, 2119 + { .compatible = "microchip,sam9x60-udc", .data = &udc_sam9x60_cfg }, 2110 2120 { /* sentinel */ } 2111 2121 }; 2112 2122 2113 2123 MODULE_DEVICE_TABLE(of, atmel_udc_dt_ids); 2124 + 2125 + static const struct of_device_id atmel_pmc_dt_ids[] = { 2126 + { .compatible = "atmel,at91sam9g45-pmc" }, 2127 + { .compatible = "atmel,at91sam9rl-pmc" }, 2128 + { .compatible = "atmel,at91sam9x5-pmc" }, 2129 + { /* sentinel */ } 2130 + }; 2114 2131 2115 2132 static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev, 2116 2133 struct usba_udc *udc) 2117 2134 { 2118 2135 struct device_node *np = pdev->dev.of_node; 2119 2136 const struct of_device_id *match; 2137 + struct device_node *pp; 2120 2138 int i, ret; 2121 2139 struct usba_ep *eps, *ep; 2122 2140 const struct usba_udc_config *udc_config; ··· 2144 2126 return ERR_PTR(-EINVAL); 2145 2127 2146 2128 udc_config = match->data; 2129 + udc->ep_prealloc = udc_config->ep_prealloc; 2147 2130 udc->errata = udc_config->errata; 2148 - udc->pmc = syscon_regmap_lookup_by_compatible("atmel,at91sam9g45-pmc"); 2149 - if (IS_ERR(udc->pmc)) 2150 - udc->pmc = syscon_regmap_lookup_by_compatible("atmel,at91sam9rl-pmc"); 2151 - if (IS_ERR(udc->pmc)) 2152 - udc->pmc = syscon_regmap_lookup_by_compatible("atmel,at91sam9x5-pmc"); 2153 - if (udc->errata && IS_ERR(udc->pmc)) 2154 - return ERR_CAST(udc->pmc); 2131 + if (udc->errata) { 2132 + pp = of_find_matching_node_and_match(NULL, atmel_pmc_dt_ids, 2133 + NULL); 2134 + if (!pp) 2135 + return ERR_PTR(-ENODEV); 2136 + 2137 + udc->pmc = syscon_node_to_regmap(pp); 2138 + of_node_put(pp); 2139 + if (IS_ERR(udc->pmc)) 2140 + return ERR_CAST(udc->pmc); 2141 + } 2155 2142 2156 2143 udc->num_ep = 0; 2157 2144 ··· 2165 2142 2166 2143 if (fifo_mode == 0) { 2167 2144 udc->num_ep = udc_config->num_ep; 2168 - udc->configured_ep = 1; 2169 2145 } else { 2170 2146 udc->num_ep = usba_config_fifo_table(udc); 2171 2147 }
+2 -1
drivers/usb/gadget/udc/atmel_usba_udc.h
··· 317 317 const struct usba_udc_errata *errata; 318 318 const struct usba_ep_config *config; 319 319 const int num_ep; 320 + const bool ep_prealloc; 320 321 }; 321 322 322 323 struct usba_udc { ··· 337 336 int irq; 338 337 struct gpio_desc *vbus_pin; 339 338 int num_ep; 340 - int configured_ep; 341 339 struct usba_fifo_cfg *fifo_cfg; 342 340 struct clk *pclk; 343 341 struct clk *hclk; ··· 344 344 bool bias_pulse_needed; 345 345 bool clocked; 346 346 bool suspended; 347 + bool ep_prealloc; 347 348 348 349 u16 devstatus; 349 350
+1
drivers/usb/gadget/udc/bcm63xx_udc.c
··· 26 26 #include <linux/seq_file.h> 27 27 #include <linux/slab.h> 28 28 #include <linux/timer.h> 29 + #include <linux/usb.h> 29 30 #include <linux/usb/ch9.h> 30 31 #include <linux/usb/gadget.h> 31 32 #include <linux/workqueue.h>
+4 -5
drivers/usb/gadget/udc/bdc/bdc_core.c
··· 484 484 static int bdc_probe(struct platform_device *pdev) 485 485 { 486 486 struct bdc *bdc; 487 - int ret = -ENOMEM; 487 + int ret; 488 488 int irq; 489 489 u32 temp; 490 490 struct device *dev = &pdev->dev; ··· 510 510 bdc->clk = clk; 511 511 512 512 bdc->regs = devm_platform_ioremap_resource(pdev, 0); 513 - if (IS_ERR(bdc->regs)) { 514 - dev_err(dev, "ioremap error\n"); 515 - return -ENOMEM; 516 - } 513 + if (IS_ERR(bdc->regs)) 514 + return PTR_ERR(bdc->regs); 515 + 517 516 irq = platform_get_irq(pdev, 0); 518 517 if (irq < 0) 519 518 return irq;
+66 -16
drivers/usb/gadget/udc/core.c
··· 715 715 goto out; 716 716 } 717 717 718 + if (!gadget->connected) 719 + goto out; 720 + 718 721 if (gadget->deactivated) { 719 722 /* 720 723 * If gadget is deactivated we only save new state. ··· 1167 1164 } 1168 1165 1169 1166 /** 1170 - * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list 1167 + * usb_initialize_gadget - initialize a gadget and its embedded struct device 1171 1168 * @parent: the parent device to this udc. Usually the controller driver's 1172 1169 * device. 1173 - * @gadget: the gadget to be added to the list. 1170 + * @gadget: the gadget to be initialized. 1174 1171 * @release: a gadget release function. 1175 1172 * 1176 1173 * Returns zero on success, negative errno otherwise. 1177 1174 * Calls the gadget release function in the latter case. 1178 1175 */ 1179 - int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, 1176 + void usb_initialize_gadget(struct device *parent, struct usb_gadget *gadget, 1180 1177 void (*release)(struct device *dev)) 1181 1178 { 1182 - struct usb_udc *udc; 1183 - int ret = -ENOMEM; 1184 - 1185 1179 dev_set_name(&gadget->dev, "gadget"); 1186 1180 INIT_WORK(&gadget->work, usb_gadget_state_work); 1187 1181 gadget->dev.parent = parent; ··· 1189 1189 gadget->dev.release = usb_udc_nop_release; 1190 1190 1191 1191 device_initialize(&gadget->dev); 1192 + } 1193 + EXPORT_SYMBOL_GPL(usb_initialize_gadget); 1194 + 1195 + /** 1196 + * usb_add_gadget - adds a new gadget to the udc class driver list 1197 + * @gadget: the gadget to be added to the list. 1198 + * 1199 + * Returns zero on success, negative errno otherwise. 1200 + * Does not do a final usb_put_gadget() if an error occurs. 1201 + */ 1202 + int usb_add_gadget(struct usb_gadget *gadget) 1203 + { 1204 + struct usb_udc *udc; 1205 + int ret = -ENOMEM; 1192 1206 1193 1207 udc = kzalloc(sizeof(*udc), GFP_KERNEL); 1194 1208 if (!udc) 1195 - goto err_put_gadget; 1209 + goto error; 1196 1210 1197 1211 device_initialize(&udc->dev); 1198 1212 udc->dev.release = usb_udc_release; 1199 1213 udc->dev.class = udc_class; 1200 1214 udc->dev.groups = usb_udc_attr_groups; 1201 - udc->dev.parent = parent; 1202 - ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj)); 1215 + udc->dev.parent = gadget->dev.parent; 1216 + ret = dev_set_name(&udc->dev, "%s", 1217 + kobject_name(&gadget->dev.parent->kobj)); 1203 1218 if (ret) 1204 1219 goto err_put_udc; 1205 1220 ··· 1257 1242 err_put_udc: 1258 1243 put_device(&udc->dev); 1259 1244 1260 - err_put_gadget: 1261 - put_device(&gadget->dev); 1245 + error: 1246 + return ret; 1247 + } 1248 + EXPORT_SYMBOL_GPL(usb_add_gadget); 1249 + 1250 + /** 1251 + * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list 1252 + * @parent: the parent device to this udc. Usually the controller driver's 1253 + * device. 1254 + * @gadget: the gadget to be added to the list. 1255 + * @release: a gadget release function. 1256 + * 1257 + * Returns zero on success, negative errno otherwise. 1258 + * Calls the gadget release function in the latter case. 1259 + */ 1260 + int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, 1261 + void (*release)(struct device *dev)) 1262 + { 1263 + int ret; 1264 + 1265 + usb_initialize_gadget(parent, gadget, release); 1266 + ret = usb_add_gadget(gadget); 1267 + if (ret) 1268 + usb_put_gadget(gadget); 1262 1269 return ret; 1263 1270 } 1264 1271 EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release); ··· 1348 1311 } 1349 1312 1350 1313 /** 1351 - * usb_del_gadget_udc - deletes @udc from udc_list 1314 + * usb_del_gadget - deletes @udc from udc_list 1352 1315 * @gadget: the gadget to be removed. 1353 1316 * 1354 - * This, will call usb_gadget_unregister_driver() if 1317 + * This will call usb_gadget_unregister_driver() if 1355 1318 * the @udc is still busy. 1319 + * It will not do a final usb_put_gadget(). 1356 1320 */ 1357 - void usb_del_gadget_udc(struct usb_gadget *gadget) 1321 + void usb_del_gadget(struct usb_gadget *gadget) 1358 1322 { 1359 1323 struct usb_udc *udc = gadget->udc; 1360 1324 ··· 1378 1340 kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); 1379 1341 flush_work(&gadget->work); 1380 1342 device_unregister(&udc->dev); 1381 - device_unregister(&gadget->dev); 1382 - memset(&gadget->dev, 0x00, sizeof(gadget->dev)); 1343 + device_del(&gadget->dev); 1344 + } 1345 + EXPORT_SYMBOL_GPL(usb_del_gadget); 1346 + 1347 + /** 1348 + * usb_del_gadget_udc - deletes @udc from udc_list 1349 + * @gadget: the gadget to be removed. 1350 + * 1351 + * Calls usb_del_gadget() and does a final usb_put_gadget(). 1352 + */ 1353 + void usb_del_gadget_udc(struct usb_gadget *gadget) 1354 + { 1355 + usb_del_gadget(gadget); 1356 + usb_put_gadget(gadget); 1383 1357 } 1384 1358 EXPORT_SYMBOL_GPL(usb_del_gadget_udc); 1385 1359
+5 -4
drivers/usb/gadget/udc/fsl_udc_core.c
··· 2061 2061 "Sleep Enable: %d SOF Received Enable: %d " 2062 2062 "Reset Enable: %d\n" 2063 2063 "System Error Enable: %d " 2064 - "Port Change Dectected Enable: %d\n" 2064 + "Port Change Detected Enable: %d\n" 2065 2065 "USB Error Intr Enable: %d USB Intr Enable: %d\n\n", 2066 2066 (tmp_reg & USB_INTR_DEVICE_SUSPEND) ? 1 : 0, 2067 2067 (tmp_reg & USB_INTR_SOF_EN) ? 1 : 0, ··· 2439 2439 /* DEN is bidirectional ep number, max_ep doubles the number */ 2440 2440 udc_controller->max_ep = (dccparams & DCCPARAMS_DEN_MASK) * 2; 2441 2441 2442 - udc_controller->irq = platform_get_irq(pdev, 0); 2443 - if (udc_controller->irq <= 0) { 2444 - ret = udc_controller->irq ? : -ENODEV; 2442 + ret = platform_get_irq(pdev, 0); 2443 + if (ret <= 0) { 2444 + ret = ret ? : -ENODEV; 2445 2445 goto err_iounmap; 2446 2446 } 2447 + udc_controller->irq = ret; 2447 2448 2448 2449 ret = request_irq(udc_controller->irq, fsl_udc_irq, IRQF_SHARED, 2449 2450 driver_name, udc_controller);
+3 -14
drivers/usb/gadget/udc/lpc32xx_udc.c
··· 495 495 } 496 496 } 497 497 498 - static int proc_udc_show(struct seq_file *s, void *unused) 498 + static int udc_show(struct seq_file *s, void *unused) 499 499 { 500 500 struct lpc32xx_udc *udc = s->private; 501 501 struct lpc32xx_ep *ep; ··· 524 524 return 0; 525 525 } 526 526 527 - static int proc_udc_open(struct inode *inode, struct file *file) 528 - { 529 - return single_open(file, proc_udc_show, PDE_DATA(inode)); 530 - } 531 - 532 - static const struct file_operations proc_ops = { 533 - .owner = THIS_MODULE, 534 - .open = proc_udc_open, 535 - .read = seq_read, 536 - .llseek = seq_lseek, 537 - .release = single_release, 538 - }; 527 + DEFINE_SHOW_ATTRIBUTE(udc); 539 528 540 529 static void create_debug_file(struct lpc32xx_udc *udc) 541 530 { 542 - udc->pde = debugfs_create_file(debug_filename, 0, NULL, udc, &proc_ops); 531 + udc->pde = debugfs_create_file(debug_filename, 0, NULL, udc, &udc_fops); 543 532 } 544 533 545 534 static void remove_debug_file(struct lpc32xx_udc *udc)
+13 -11
drivers/usb/gadget/udc/net2272.c
··· 9 9 #include <linux/delay.h> 10 10 #include <linux/device.h> 11 11 #include <linux/errno.h> 12 - #include <linux/gpio.h> 13 12 #include <linux/init.h> 14 13 #include <linux/interrupt.h> 15 14 #include <linux/io.h> ··· 2195 2196 static void 2196 2197 net2272_gadget_release(struct device *_dev) 2197 2198 { 2198 - struct net2272 *dev = dev_get_drvdata(_dev); 2199 + struct net2272 *dev = container_of(_dev, struct net2272, gadget.dev); 2200 + 2199 2201 kfree(dev); 2200 2202 } 2201 2203 ··· 2205 2205 static void 2206 2206 net2272_remove(struct net2272 *dev) 2207 2207 { 2208 - usb_del_gadget_udc(&dev->gadget); 2208 + if (dev->added) 2209 + usb_del_gadget(&dev->gadget); 2209 2210 free_irq(dev->irq, dev); 2210 2211 iounmap(dev->base_addr); 2211 2212 device_remove_file(dev->dev, &dev_attr_registers); ··· 2236 2235 2237 2236 /* the "gadget" abstracts/virtualizes the controller */ 2238 2237 ret->gadget.name = driver_name; 2238 + usb_initialize_gadget(dev, &ret->gadget, net2272_gadget_release); 2239 2239 2240 2240 return ret; 2241 2241 } ··· 2275 2273 if (ret) 2276 2274 goto err_irq; 2277 2275 2278 - ret = usb_add_gadget_udc_release(dev->dev, &dev->gadget, 2279 - net2272_gadget_release); 2276 + ret = usb_add_gadget(&dev->gadget); 2280 2277 if (ret) 2281 2278 goto err_add_udc; 2279 + dev->added = 1; 2282 2280 2283 2281 return 0; 2284 2282 ··· 2453 2451 2454 2452 if (pci_enable_device(pdev) < 0) { 2455 2453 ret = -ENODEV; 2456 - goto err_free; 2454 + goto err_put; 2457 2455 } 2458 2456 2459 2457 pci_set_master(pdev); ··· 2476 2474 2477 2475 err_pci: 2478 2476 pci_disable_device(pdev); 2479 - err_free: 2480 - kfree(dev); 2477 + err_put: 2478 + usb_put_gadget(&dev->gadget); 2481 2479 2482 2480 return ret; 2483 2481 } ··· 2538 2536 2539 2537 pci_disable_device(pdev); 2540 2538 2541 - kfree(dev); 2539 + usb_put_gadget(&dev->gadget); 2542 2540 } 2543 2541 2544 2542 /* Table of matching PCI IDs */ ··· 2651 2649 err_req: 2652 2650 release_mem_region(base, len); 2653 2651 err: 2654 - kfree(dev); 2652 + usb_put_gadget(&dev->gadget); 2655 2653 2656 2654 return ret; 2657 2655 } ··· 2666 2664 release_mem_region(pdev->resource[0].start, 2667 2665 resource_size(&pdev->resource[0])); 2668 2666 2669 - kfree(dev); 2667 + usb_put_gadget(&dev->gadget); 2670 2668 2671 2669 return 0; 2672 2670 }
+1
drivers/usb/gadget/udc/net2272.h
··· 441 441 unsigned protocol_stall:1, 442 442 softconnect:1, 443 443 wakeup:1, 444 + added:1, 444 445 dma_eot_polarity:1, 445 446 dma_dack_polarity:1, 446 447 dma_dreq_polarity:1,
+7 -4
drivers/usb/gadget/udc/net2280.c
··· 3560 3560 3561 3561 static void gadget_release(struct device *_dev) 3562 3562 { 3563 - struct net2280 *dev = dev_get_drvdata(_dev); 3563 + struct net2280 *dev = container_of(_dev, struct net2280, gadget.dev); 3564 3564 3565 3565 kfree(dev); 3566 3566 } ··· 3571 3571 { 3572 3572 struct net2280 *dev = pci_get_drvdata(pdev); 3573 3573 3574 - usb_del_gadget_udc(&dev->gadget); 3574 + if (dev->added) 3575 + usb_del_gadget(&dev->gadget); 3575 3576 3576 3577 BUG_ON(dev->driver); 3577 3578 ··· 3603 3602 device_remove_file(&pdev->dev, &dev_attr_registers); 3604 3603 3605 3604 ep_info(dev, "unbind\n"); 3605 + usb_put_gadget(&dev->gadget); 3606 3606 } 3607 3607 3608 3608 /* wrap this driver around the specified device, but ··· 3625 3623 } 3626 3624 3627 3625 pci_set_drvdata(pdev, dev); 3626 + usb_initialize_gadget(&pdev->dev, &dev->gadget, gadget_release); 3628 3627 spin_lock_init(&dev->lock); 3629 3628 dev->quirks = id->driver_data; 3630 3629 dev->pdev = pdev; ··· 3776 3773 if (retval) 3777 3774 goto done; 3778 3775 3779 - retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget, 3780 - gadget_release); 3776 + retval = usb_add_gadget(&dev->gadget); 3781 3777 if (retval) 3782 3778 goto done; 3779 + dev->added = 1; 3783 3780 return 0; 3784 3781 3785 3782 done:
+1
drivers/usb/gadget/udc/net2280.h
··· 156 156 softconnect : 1, 157 157 got_irq : 1, 158 158 region:1, 159 + added:1, 159 160 u1_enable:1, 160 161 u2_enable:1, 161 162 ltm_enable:1,
+22 -33
drivers/usb/gadget/udc/pch_udc.c
··· 12 12 #include <linux/interrupt.h> 13 13 #include <linux/usb/ch9.h> 14 14 #include <linux/usb/gadget.h> 15 - #include <linux/gpio.h> 15 + #include <linux/gpio/consumer.h> 16 16 #include <linux/irq.h> 17 - 18 - /* GPIO port for VBUS detecting */ 19 - static int vbus_gpio_port = -1; /* GPIO port number (-1:Not used) */ 20 17 21 18 #define PCH_VBUS_PERIOD 3000 /* VBUS polling period (msec) */ 22 19 #define PCH_VBUS_INTERVAL 10 /* VBUS polling interval (msec) */ ··· 298 301 /** 299 302 * struct pch_vbus_gpio_data - Structure holding GPIO informaton 300 303 * for detecting VBUS 301 - * @port: gpio port number 304 + * @port: gpio descriptor for the VBUS GPIO 302 305 * @intr: gpio interrupt number 303 306 * @irq_work_fall: Structure for WorkQueue 304 307 * @irq_work_rise: Structure for WorkQueue 305 308 */ 306 309 struct pch_vbus_gpio_data { 307 - int port; 310 + struct gpio_desc *port; 308 311 int intr; 309 312 struct work_struct irq_work_fall; 310 313 struct work_struct irq_work_rise; ··· 1251 1254 int vbus = 0; 1252 1255 1253 1256 if (dev->vbus_gpio.port) 1254 - vbus = gpio_get_value(dev->vbus_gpio.port) ? 1 : 0; 1257 + vbus = gpiod_get_value(dev->vbus_gpio.port) ? 1 : 0; 1255 1258 else 1256 1259 vbus = -1; 1257 1260 ··· 1353 1356 /** 1354 1357 * pch_vbus_gpio_init() - This API initializes GPIO port detecting VBUS. 1355 1358 * @dev: Reference to the driver structure 1356 - * @vbus_gpio_port: Number of GPIO port to detect gpio 1357 1359 * 1358 1360 * Return codes: 1359 1361 * 0: Success 1360 1362 * -EINVAL: GPIO port is invalid or can't be initialized. 1361 1363 */ 1362 - static int pch_vbus_gpio_init(struct pch_udc_dev *dev, int vbus_gpio_port) 1364 + static int pch_vbus_gpio_init(struct pch_udc_dev *dev) 1363 1365 { 1364 1366 int err; 1365 1367 int irq_num = 0; 1368 + struct gpio_desc *gpiod; 1366 1369 1367 - dev->vbus_gpio.port = 0; 1370 + dev->vbus_gpio.port = NULL; 1368 1371 dev->vbus_gpio.intr = 0; 1369 1372 1370 - if (vbus_gpio_port <= -1) 1371 - return -EINVAL; 1373 + /* Retrieve the GPIO line from the USB gadget device */ 1374 + gpiod = devm_gpiod_get(dev->gadget.dev.parent, NULL, GPIOD_IN); 1375 + if (IS_ERR(gpiod)) 1376 + return PTR_ERR(gpiod); 1377 + gpiod_set_consumer_name(gpiod, "pch_vbus"); 1372 1378 1373 - err = gpio_is_valid(vbus_gpio_port); 1374 - if (!err) { 1375 - pr_err("%s: gpio port %d is invalid\n", 1376 - __func__, vbus_gpio_port); 1377 - return -EINVAL; 1378 - } 1379 - 1380 - err = gpio_request(vbus_gpio_port, "pch_vbus"); 1381 - if (err) { 1382 - pr_err("%s: can't request gpio port %d, err: %d\n", 1383 - __func__, vbus_gpio_port, err); 1384 - return -EINVAL; 1385 - } 1386 - 1387 - dev->vbus_gpio.port = vbus_gpio_port; 1388 - gpio_direction_input(vbus_gpio_port); 1379 + dev->vbus_gpio.port = gpiod; 1389 1380 INIT_WORK(&dev->vbus_gpio.irq_work_fall, pch_vbus_gpio_work_fall); 1390 1381 1391 - irq_num = gpio_to_irq(vbus_gpio_port); 1382 + irq_num = gpiod_to_irq(gpiod); 1392 1383 if (irq_num > 0) { 1393 1384 irq_set_irq_type(irq_num, IRQ_TYPE_EDGE_BOTH); 1394 1385 err = request_irq(irq_num, pch_vbus_gpio_irq, 0, ··· 1402 1417 { 1403 1418 if (dev->vbus_gpio.intr) 1404 1419 free_irq(dev->vbus_gpio.intr, dev); 1405 - 1406 - if (dev->vbus_gpio.port) 1407 - gpio_free(dev->vbus_gpio.port); 1408 1420 } 1409 1421 1410 1422 /** ··· 2876 2894 { 2877 2895 pch_udc_init(dev); 2878 2896 pch_udc_pcd_reinit(dev); 2879 - pch_vbus_gpio_init(dev, vbus_gpio_port); 2897 + pch_vbus_gpio_init(dev); 2880 2898 return 0; 2881 2899 } 2882 2900 ··· 3077 3095 return retval; 3078 3096 3079 3097 dev->base_addr = pcim_iomap_table(pdev)[bar]; 3098 + 3099 + /* 3100 + * FIXME: add a GPIO descriptor table to pdev.dev using 3101 + * gpiod_add_descriptor_table() from <linux/gpio/machine.h> based on 3102 + * the PCI subsystem ID. The system-dependent GPIO is necessary for 3103 + * VBUS operation. 3104 + */ 3080 3105 3081 3106 /* initialize the hardware */ 3082 3107 if (pch_udc_pcd_init(dev))
-3
drivers/usb/gadget/udc/s3c2410_udc.c
··· 1270 1270 static int s3c2410_udc_dequeue(struct usb_ep *_ep, struct usb_request *_req) 1271 1271 { 1272 1272 struct s3c2410_ep *ep = to_s3c2410_ep(_ep); 1273 - struct s3c2410_udc *udc; 1274 1273 int retval = -EINVAL; 1275 1274 unsigned long flags; 1276 1275 struct s3c2410_request *req = NULL; ··· 1281 1282 1282 1283 if (!_ep || !_req) 1283 1284 return retval; 1284 - 1285 - udc = to_s3c2410_udc(ep->gadget); 1286 1285 1287 1286 local_irq_save(flags); 1288 1287
+31 -29
drivers/usb/gadget/udc/tegra-xudc.c
··· 705 705 706 706 err = phy_power_on(xudc->curr_utmi_phy); 707 707 if (err < 0) 708 - dev_err(xudc->dev, "utmi power on failed %d\n", err); 708 + dev_err(xudc->dev, "UTMI power on failed: %d\n", err); 709 709 710 710 err = phy_power_on(xudc->curr_usb3_phy); 711 711 if (err < 0) 712 - dev_err(xudc->dev, "usb3 phy power on failed %d\n", err); 712 + dev_err(xudc->dev, "USB3 PHY power on failed: %d\n", err); 713 713 714 714 dev_dbg(xudc->dev, "device mode on\n"); 715 715 ··· 759 759 760 760 err = phy_power_off(xudc->curr_utmi_phy); 761 761 if (err < 0) 762 - dev_err(xudc->dev, "utmi_phy power off failed %d\n", err); 762 + dev_err(xudc->dev, "UTMI PHY power off failed: %d\n", err); 763 763 764 764 err = phy_power_off(xudc->curr_usb3_phy); 765 765 if (err < 0) 766 - dev_err(xudc->dev, "usb3_phy power off failed %d\n", err); 766 + dev_err(xudc->dev, "USB3 PHY power off failed: %d\n", err); 767 767 768 768 pm_runtime_put(xudc->dev); 769 769 } ··· 1539 1539 return -EINVAL; 1540 1540 1541 1541 if (usb_endpoint_xfer_isoc(ep->desc)) { 1542 - dev_err(xudc->dev, "can't halt isoc EP\n"); 1542 + dev_err(xudc->dev, "can't halt isochronous EP\n"); 1543 1543 return -ENOTSUPP; 1544 1544 } 1545 1545 ··· 1788 1788 1789 1789 if (usb_endpoint_xfer_isoc(desc)) { 1790 1790 if (xudc->nr_isoch_eps > XUDC_MAX_ISOCH_EPS) { 1791 - dev_err(xudc->dev, "too many isoch endpoints\n"); 1791 + dev_err(xudc->dev, "too many isochronous endpoints\n"); 1792 1792 return -EBUSY; 1793 1793 } 1794 1794 xudc->nr_isoch_eps++; ··· 3509 3509 if (IS_ERR(xudc->utmi_phy[i])) { 3510 3510 err = PTR_ERR(xudc->utmi_phy[i]); 3511 3511 if (err != -EPROBE_DEFER) 3512 - dev_err(xudc->dev, "failed to get usb2-%d phy: %d\n", 3512 + dev_err(xudc->dev, "failed to get usb2-%d PHY: %d\n", 3513 3513 i, err); 3514 3514 3515 3515 goto clean_up; ··· 3539 3539 if (IS_ERR(xudc->usb3_phy[i])) { 3540 3540 err = PTR_ERR(xudc->usb3_phy[i]); 3541 3541 if (err != -EPROBE_DEFER) 3542 - dev_err(xudc->dev, "failed to get usb3-%d phy: %d\n", 3542 + dev_err(xudc->dev, "failed to get usb3-%d PHY: %d\n", 3543 3543 usb3, err); 3544 3544 3545 3545 goto clean_up; 3546 3546 } else if (xudc->usb3_phy[i]) 3547 - dev_dbg(xudc->dev, "usb3_phy-%d registered", usb3); 3547 + dev_dbg(xudc->dev, "usb3-%d PHY registered", usb3); 3548 3548 } 3549 3549 3550 3550 return err; ··· 3577 3577 for (i = 0; i < xudc->soc->num_phys; i++) { 3578 3578 err = phy_init(xudc->utmi_phy[i]); 3579 3579 if (err < 0) { 3580 - dev_err(xudc->dev, "utmi phy init failed: %d\n", err); 3580 + dev_err(xudc->dev, "UTMI PHY #%u initialization failed: %d\n", i, err); 3581 3581 goto exit_phy; 3582 3582 } 3583 3583 3584 3584 err = phy_init(xudc->usb3_phy[i]); 3585 3585 if (err < 0) { 3586 - dev_err(xudc->dev, "usb3 phy init failed: %d\n", err); 3586 + dev_err(xudc->dev, "USB3 PHY #%u initialization failed: %d\n", i, err); 3587 3587 goto exit_phy; 3588 3588 } 3589 3589 } ··· 3692 3692 struct device *dev = xudc->dev; 3693 3693 int err; 3694 3694 3695 - xudc->genpd_dev_device = dev_pm_domain_attach_by_name(dev, 3696 - "dev"); 3695 + xudc->genpd_dev_device = dev_pm_domain_attach_by_name(dev, "dev"); 3697 3696 if (IS_ERR(xudc->genpd_dev_device)) { 3698 3697 err = PTR_ERR(xudc->genpd_dev_device); 3699 - dev_err(dev, "failed to get dev pm-domain: %d\n", err); 3698 + dev_err(dev, "failed to get device power domain: %d\n", err); 3700 3699 return err; 3701 3700 } 3702 3701 3703 3702 xudc->genpd_dev_ss = dev_pm_domain_attach_by_name(dev, "ss"); 3704 3703 if (IS_ERR(xudc->genpd_dev_ss)) { 3705 3704 err = PTR_ERR(xudc->genpd_dev_ss); 3706 - dev_err(dev, "failed to get superspeed pm-domain: %d\n", err); 3705 + dev_err(dev, "failed to get SuperSpeed power domain: %d\n", err); 3707 3706 return err; 3708 3707 } 3709 3708 3710 3709 xudc->genpd_dl_device = device_link_add(dev, xudc->genpd_dev_device, 3711 - DL_FLAG_PM_RUNTIME | 3712 - DL_FLAG_STATELESS); 3710 + DL_FLAG_PM_RUNTIME | 3711 + DL_FLAG_STATELESS); 3713 3712 if (!xudc->genpd_dl_device) { 3714 - dev_err(dev, "adding usb device device link failed!\n"); 3713 + dev_err(dev, "failed to add USB device link\n"); 3715 3714 return -ENODEV; 3716 3715 } 3717 3716 3718 3717 xudc->genpd_dl_ss = device_link_add(dev, xudc->genpd_dev_ss, 3719 - DL_FLAG_PM_RUNTIME | 3720 - DL_FLAG_STATELESS); 3718 + DL_FLAG_PM_RUNTIME | 3719 + DL_FLAG_STATELESS); 3721 3720 if (!xudc->genpd_dl_ss) { 3722 - dev_err(dev, "adding superspeed device link failed!\n"); 3721 + dev_err(dev, "failed to add SuperSpeed device link\n"); 3723 3722 return -ENODEV; 3724 3723 } 3725 3724 ··· 3732 3733 unsigned int i; 3733 3734 int err; 3734 3735 3735 - xudc = devm_kzalloc(&pdev->dev, sizeof(*xudc), GFP_ATOMIC); 3736 + xudc = devm_kzalloc(&pdev->dev, sizeof(*xudc), GFP_KERNEL); 3736 3737 if (!xudc) 3737 3738 return -ENOMEM; 3738 3739 ··· 3771 3772 return err; 3772 3773 } 3773 3774 3774 - xudc->clks = devm_kcalloc(&pdev->dev, xudc->soc->num_clks, 3775 - sizeof(*xudc->clks), GFP_KERNEL); 3775 + xudc->clks = devm_kcalloc(&pdev->dev, xudc->soc->num_clks, sizeof(*xudc->clks), 3776 + GFP_KERNEL); 3776 3777 if (!xudc->clks) 3777 3778 return -ENOMEM; 3778 3779 3779 3780 for (i = 0; i < xudc->soc->num_clks; i++) 3780 3781 xudc->clks[i].id = xudc->soc->clock_names[i]; 3781 3782 3782 - err = devm_clk_bulk_get(&pdev->dev, xudc->soc->num_clks, 3783 - xudc->clks); 3783 + err = devm_clk_bulk_get(&pdev->dev, xudc->soc->num_clks, xudc->clks); 3784 3784 if (err) { 3785 - dev_err(xudc->dev, "failed to request clks %d\n", err); 3785 + if (err != -EPROBE_DEFER) 3786 + dev_err(xudc->dev, "failed to request clocks: %d\n", err); 3787 + 3786 3788 return err; 3787 3789 } 3788 3790 ··· 3798 3798 err = devm_regulator_bulk_get(&pdev->dev, xudc->soc->num_supplies, 3799 3799 xudc->supplies); 3800 3800 if (err) { 3801 - dev_err(xudc->dev, "failed to request regulators %d\n", err); 3801 + if (err != -EPROBE_DEFER) 3802 + dev_err(xudc->dev, "failed to request regulators: %d\n", err); 3803 + 3802 3804 return err; 3803 3805 } 3804 3806 ··· 3810 3808 3811 3809 err = regulator_bulk_enable(xudc->soc->num_supplies, xudc->supplies); 3812 3810 if (err) { 3813 - dev_err(xudc->dev, "failed to enable regulators %d\n", err); 3811 + dev_err(xudc->dev, "failed to enable regulators: %d\n", err); 3814 3812 goto put_padctl; 3815 3813 } 3816 3814
+21 -6
include/linux/usb/gadget.h
··· 436 436 }; 437 437 #define work_to_gadget(w) (container_of((w), struct usb_gadget, work)) 438 438 439 + /* Interface to the device model */ 439 440 static inline void set_gadget_data(struct usb_gadget *gadget, void *data) 440 441 { dev_set_drvdata(&gadget->dev, data); } 441 442 static inline void *get_gadget_data(struct usb_gadget *gadget) ··· 445 444 { 446 445 return container_of(dev, struct usb_gadget, dev); 447 446 } 447 + static inline struct usb_gadget *usb_get_gadget(struct usb_gadget *gadget) 448 + { 449 + get_device(&gadget->dev); 450 + return gadget; 451 + } 452 + static inline void usb_put_gadget(struct usb_gadget *gadget) 453 + { 454 + put_device(&gadget->dev); 455 + } 456 + extern void usb_initialize_gadget(struct device *parent, 457 + struct usb_gadget *gadget, void (*release)(struct device *dev)); 458 + extern int usb_add_gadget(struct usb_gadget *gadget); 459 + extern void usb_del_gadget(struct usb_gadget *gadget); 460 + 461 + /* Legacy device-model interface */ 462 + extern int usb_add_gadget_udc_release(struct device *parent, 463 + struct usb_gadget *gadget, void (*release)(struct device *dev)); 464 + extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget); 465 + extern void usb_del_gadget_udc(struct usb_gadget *gadget); 466 + extern char *usb_get_gadget_udc_name(void); 448 467 449 468 /* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */ 450 469 #define gadget_for_each_ep(tmp, gadget) \ ··· 755 734 * will be in exit sections, so may not be linked in some kernels. 756 735 */ 757 736 int usb_gadget_unregister_driver(struct usb_gadget_driver *driver); 758 - 759 - extern int usb_add_gadget_udc_release(struct device *parent, 760 - struct usb_gadget *gadget, void (*release)(struct device *dev)); 761 - extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget); 762 - extern void usb_del_gadget_udc(struct usb_gadget *gadget); 763 - extern char *usb_get_gadget_udc_name(void); 764 737 765 738 /*-------------------------------------------------------------------------*/ 766 739