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

Merge tag 'usb-4.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB updates from Greg KH:
"Here is the big USB drivers update for 4.5-rc1.

Lots of gadget driver updates and fixes, like usual, and a mix of
other USB driver updates as well. Full details in the shortlog. All
of these have been in linux-next for a while"

* tag 'usb-4.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (191 commits)
MAINTAINERS: change my email address
USB: usbmon: remove assignment from IS_ERR argument
USB: mxu11x0: drop redundant function name from error messages
USB: mxu11x0: fix debug-message typos
USB: mxu11x0: rename usb-serial driver
USB: mxu11x0: fix modem-control handling on B0-transitions
USB: mxu11x0: fix memory leak on firmware download
USB: mxu11x0: fix memory leak in port-probe error path
USB: serial: add Moxa UPORT 11x0 driver
USB: cp210x: add ID for ELV Marble Sound Board 1
usb: chipidea: otg: use usb autosuspend to suspend bus for HNP
usb: chipidea: host: set host to be null after hcd is freed
usb: chipidea: removing of_find_property
usb: chipidea: implement platform shutdown callback
usb: chipidea: clean up CONFIG_USB_CHIPIDEA_DEBUG reference
usb: chipidea: delete static debug support
usb: chipidea: support debugfs without CONFIG_USB_CHIPIDEA_DEBUG
usb: chipidea: udc: improve error handling on _hardware_enqueue
usb: chipidea: udc: _ep_queue and _hw_queue cleanup
usb: dwc3: of-simple: fix build warning on !PM
...

+9147 -2053
+2
Documentation/ABI/testing/configfs-usb-gadget-sourcesink
··· 10 10 isoc_mult - 0..2 (hs/ss only) 11 11 isoc_maxburst - 0..15 (ss only) 12 12 buflen - buffer length 13 + bulk_qlen - depth of queue for bulk 14 + iso_qlen - depth of queue for iso
+20 -7
Documentation/ABI/testing/sysfs-bus-usb
··· 134 134 enabled for the device. Developer can write y/Y/1 or n/N/0 to 135 135 the file to enable/disable the feature. 136 136 137 - What: /sys/bus/usb/devices/.../power/usb3_hardware_lpm 138 - Date: June 2015 137 + What: /sys/bus/usb/devices/.../power/usb3_hardware_lpm_u1 138 + /sys/bus/usb/devices/.../power/usb3_hardware_lpm_u2 139 + Date: November 2015 139 140 Contact: Kevin Strasser <kevin.strasser@linux.intel.com> 141 + Lu Baolu <baolu.lu@linux.intel.com> 140 142 Description: 141 143 If CONFIG_PM is set and a USB 3.0 lpm-capable device is plugged 142 144 in to a xHCI host which supports link PM, it will check if U1 143 145 and U2 exit latencies have been set in the BOS descriptor; if 144 - the check is is passed and the host supports USB3 hardware LPM, 146 + the check is passed and the host supports USB3 hardware LPM, 145 147 USB3 hardware LPM will be enabled for the device and the USB 146 - device directory will contain a file named 147 - power/usb3_hardware_lpm. The file holds a string value (enable 148 - or disable) indicating whether or not USB3 hardware LPM is 149 - enabled for the device. 148 + device directory will contain two files named 149 + power/usb3_hardware_lpm_u1 and power/usb3_hardware_lpm_u2. These 150 + files hold a string value (enable or disable) indicating whether 151 + or not USB3 hardware LPM U1 or U2 is enabled for the device. 150 152 151 153 What: /sys/bus/usb/devices/.../removable 152 154 Date: February 2012 ··· 188 186 This attribute is to expose these information to user space. 189 187 The file will read "hotplug", "wired" and "not used" if the 190 188 information is available, and "unknown" otherwise. 189 + 190 + What: /sys/bus/usb/devices/.../(hub interface)/portX/usb3_lpm_permit 191 + Date: November 2015 192 + Contact: Lu Baolu <baolu.lu@linux.intel.com> 193 + Description: 194 + Some USB3.0 devices are not friendly to USB3 LPM. usb3_lpm_permit 195 + attribute allows enabling/disabling usb3 lpm of a port. It takes 196 + effect both before and after a usb device is enumerated. Supported 197 + values are "0" if both u1 and u2 are NOT permitted, "u1" if only u1 198 + is permitted, "u2" if only u2 is permitted, "u1_u2" if both u1 and 199 + u2 are permitted. 191 200 192 201 What: /sys/bus/usb/devices/.../power/usb2_lpm_l1_timeout 193 202 Date: May 2013
+1
Documentation/devicetree/bindings/phy/brcm,brcmstb-sata-phy.txt
··· 2 2 3 3 Required properties: 4 4 - compatible: should be one or more of 5 + "brcm,bcm7425-sata-phy" 5 6 "brcm,bcm7445-sata-phy" 6 7 "brcm,phy-sata3" 7 8 - address-cells: should be 1
+16
Documentation/devicetree/bindings/phy/phy-hi6220-usb.txt
··· 1 + Hisilicon hi6220 usb PHY 2 + ----------------------- 3 + 4 + Required properties: 5 + - compatible: should be "hisilicon,hi6220-usb-phy" 6 + - #phy-cells: must be 0 7 + - hisilicon,peripheral-syscon: phandle of syscon used to control phy. 8 + Refer to phy/phy-bindings.txt for the generic PHY binding properties 9 + 10 + Example: 11 + usb_phy: usbphy { 12 + compatible = "hisilicon,hi6220-usb-phy"; 13 + #phy-cells = <0>; 14 + phy-supply = <&fixed_5v_hub>; 15 + hisilicon,peripheral-syscon = <&sys_ctrl>; 16 + };
+39
Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
··· 1 + * Renesas R-Car generation 3 USB 2.0 PHY 2 + 3 + This file provides information on what the device node for the R-Car generation 4 + 3 USB 2.0 PHY contains. 5 + 6 + Required properties: 7 + - compatible: "renesas,usb2-phy-r8a7795" if the device is a part of an R8A7795 8 + SoC. 9 + - reg: offset and length of the partial USB 2.0 Host register block. 10 + - reg-names: must be "usb2_host". 11 + - clocks: clock phandle and specifier pair(s). 12 + - #phy-cells: see phy-bindings.txt in the same directory, must be <0>. 13 + 14 + Optional properties: 15 + To use a USB channel where USB 2.0 Host and HSUSB (USB 2.0 Peripheral) are 16 + combined, the device tree node should set HSUSB properties to reg and reg-names 17 + properties. This is because HSUSB has registers to select USB 2.0 host or 18 + peripheral at that channel: 19 + - reg: offset and length of the partial HSUSB register block. 20 + - reg-names: must be "hsusb". 21 + - interrupts: interrupt specifier for the PHY. 22 + 23 + Example (R-Car H3): 24 + 25 + usb-phy@ee080200 { 26 + compatible = "renesas,usb2-phy-r8a7795"; 27 + reg = <0 0xee080200 0 0x700>, <0 0xe6590100 0 0x100>; 28 + reg-names = "usb2_host", "hsusb"; 29 + interrupts = <GIC_SPI 108 IRQ_TYPE_LEVEL_HIGH>; 30 + clocks = <&mstp7_clks R8A7795_CLK_EHCI0>, 31 + <&mstp7_clks R8A7795_CLK_HSUSB>; 32 + }; 33 + 34 + usb-phy@ee0a0200 { 35 + compatible = "renesas,usb2-phy-r8a7795"; 36 + reg = <0 0xee0a0200 0 0x700>; 37 + reg-names = "usb2_host"; 38 + clocks = <&mstp7_clks R8A7795_CLK_EHCI0>; 39 + };
+5 -1
Documentation/devicetree/bindings/phy/rockchip-usb-phy.txt
··· 1 1 ROCKCHIP USB2 PHY 2 2 3 3 Required properties: 4 - - compatible: rockchip,rk3288-usb-phy 4 + - compatible: matching the soc type, one of 5 + "rockchip,rk3066a-usb-phy" 6 + "rockchip,rk3188-usb-phy" 7 + "rockchip,rk3288-usb-phy" 5 8 - rockchip,grf : phandle to the syscon managing the "general 6 9 register files" 7 10 - #address-cells: should be 1 ··· 24 21 Optional Properties: 25 22 - clocks : phandle + clock specifier for the phy clocks 26 23 - clock-names: string, clock name, must be "phyclk" 24 + - #clock-cells: for users of the phy-pll, should be 0 27 25 28 26 Example: 29 27
+1
Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
··· 9 9 * allwinner,sun7i-a20-usb-phy 10 10 * allwinner,sun8i-a23-usb-phy 11 11 * allwinner,sun8i-a33-usb-phy 12 + * allwinner,sun8i-h3-usb-phy 12 13 - reg : a list of offset + length pairs 13 14 - reg-names : 14 15 * "phy_ctrl"
+17 -3
Documentation/devicetree/bindings/phy/ti-phy.txt
··· 31 31 32 32 Required properties: 33 33 - compatible: Should be "ti,omap-usb2" 34 + Should be "ti,dra7x-usb2-phy2" for the 2nd instance of USB2 PHY 35 + in DRA7x 34 36 - reg : Address and length of the register set for the device. 35 37 - #phy-cells: determine the number of cells that should be given in the 36 38 phandle while referencing this phy. ··· 42 40 * "wkupclk" - wakeup clock. 43 41 * "refclk" - reference clock (optional). 44 42 45 - Optional properties: 43 + Deprecated properties: 46 44 - ctrl-module : phandle of the control module used by PHY driver to power on 47 45 the PHY. 46 + 47 + Recommended properies: 48 + - syscon-phy-power : phandle/offset pair. Phandle to the system control 49 + module and the register offset to power on/off the PHY. 48 50 49 51 This is usually a subnode of ocp2scp to which it is connected. 50 52 ··· 83 77 * "div-clk" - apll clock 84 78 85 79 Optional properties: 86 - - ctrl-module : phandle of the control module used by PHY driver to power on 87 - the PHY. 88 80 - id: If there are multiple instance of the same type, in order to 89 81 differentiate between each instance "id" can be used (e.g., multi-lane PCIe 90 82 PHY). If "id" is not provided, it is set to default value of '1'. 91 83 - syscon-pllreset: Handle to system control region that contains the 92 84 CTRL_CORE_SMA_SW_0 register and register offset to the CTRL_CORE_SMA_SW_0 93 85 register that contains the SATA_PLL_SOFT_RESET bit. Only valid for sata_phy. 86 + - syscon-pcs : phandle/offset pair. Phandle to the system control module and the 87 + register offset to write the PCS delay value. 88 + 89 + Deprecated properties: 90 + - ctrl-module : phandle of the control module used by PHY driver to power on 91 + the PHY. 92 + 93 + Recommended properies: 94 + - syscon-phy-power : phandle/offset pair. Phandle to the system control 95 + module and the register offset to power on/off the PHY. 94 96 95 97 This is usually a subnode of ocp2scp to which it is connected. 96 98
+1
Documentation/devicetree/bindings/usb/dwc2.txt
··· 4 4 Required properties: 5 5 - compatible : One of: 6 6 - brcm,bcm2835-usb: The DWC2 USB controller instance in the BCM2835 SoC. 7 + - hisilicon,hi6220-usb: The DWC2 USB controller instance in the hi6220 SoC. 7 8 - rockchip,rk3066-usb: The DWC2 USB controller instance in the rk3066 Soc; 8 9 - "rockchip,rk3188-usb", "rockchip,rk3066-usb", "snps,dwc2": for rk3188 Soc; 9 10 - "rockchip,rk3288-usb", "rockchip,rk3066-usb", "snps,dwc2": for rk3288 Soc;
+33
Documentation/devicetree/bindings/usb/dwc3-xilinx.txt
··· 1 + Xilinx SuperSpeed DWC3 USB SoC controller 2 + 3 + Required properties: 4 + - compatible: Should contain "xlnx,zynqmp-dwc3" 5 + - clocks: A list of phandles for the clocks listed in clock-names 6 + - clock-names: Should contain the following: 7 + "bus_clk" Master/Core clock, have to be >= 125 MHz for SS 8 + operation and >= 60MHz for HS operation 9 + 10 + "ref_clk" Clock source to core during PHY power down 11 + 12 + Required child node: 13 + A child node must exist to represent the core DWC3 IP block. The name of 14 + the node is not important. The content of the node is defined in dwc3.txt. 15 + 16 + Example device node: 17 + 18 + usb@0 { 19 + #address-cells = <0x2>; 20 + #size-cells = <0x1>; 21 + status = "okay"; 22 + compatible = "xlnx,zynqmp-dwc3"; 23 + clock-names = "bus_clk" "ref_clk"; 24 + clocks = <&clk125>, <&clk125>; 25 + ranges; 26 + 27 + dwc3@fe200000 { 28 + compatible = "snps,dwc3"; 29 + reg = <0x0 0xfe200000 0x40000>; 30 + interrupts = <0x0 0x41 0x4>; 31 + dr_mode = "host"; 32 + }; 33 + };
+51
Documentation/devicetree/bindings/usb/mt8173-xhci.txt
··· 1 + MT8173 xHCI 2 + 3 + The device node for Mediatek SOC USB3.0 host controller 4 + 5 + Required properties: 6 + - compatible : should contain "mediatek,mt8173-xhci" 7 + - reg : specifies physical base address and size of the registers, 8 + the first one for MAC, the second for IPPC 9 + - interrupts : interrupt used by the controller 10 + - power-domains : a phandle to USB power domain node to control USB's 11 + mtcmos 12 + - vusb33-supply : regulator of USB avdd3.3v 13 + 14 + - clocks : a list of phandle + clock-specifier pairs, one for each 15 + entry in clock-names 16 + - clock-names : must contain 17 + "sys_ck": for clock of xHCI MAC 18 + "wakeup_deb_p0": for USB wakeup debounce clock of port0 19 + "wakeup_deb_p1": for USB wakeup debounce clock of port1 20 + 21 + - phys : a list of phandle + phy specifier pairs 22 + 23 + Optional properties: 24 + - mediatek,wakeup-src : 1: ip sleep wakeup mode; 2: line state wakeup 25 + mode; 26 + - mediatek,syscon-wakeup : phandle to syscon used to access USB wakeup 27 + control register, it depends on "mediatek,wakeup-src". 28 + - vbus-supply : reference to the VBUS regulator; 29 + - usb3-lpm-capable : supports USB3.0 LPM 30 + 31 + Example: 32 + usb30: usb@11270000 { 33 + compatible = "mediatek,mt8173-xhci"; 34 + reg = <0 0x11270000 0 0x1000>, 35 + <0 0x11280700 0 0x0100>; 36 + interrupts = <GIC_SPI 115 IRQ_TYPE_LEVEL_LOW>; 37 + power-domains = <&scpsys MT8173_POWER_DOMAIN_USB>; 38 + clocks = <&topckgen CLK_TOP_USB30_SEL>, 39 + <&pericfg CLK_PERI_USB0>, 40 + <&pericfg CLK_PERI_USB1>; 41 + clock-names = "sys_ck", 42 + "wakeup_deb_p0", 43 + "wakeup_deb_p1"; 44 + phys = <&phy_port0 PHY_TYPE_USB3>, 45 + <&phy_port1 PHY_TYPE_USB2>; 46 + vusb33-supply = <&mt6397_vusb_reg>; 47 + vbus-supply = <&usb_p1_vbus>; 48 + usb3-lpm-capable; 49 + mediatek,syscon-wakeup = <&pericfg>; 50 + mediatek,wakeup-src = <1>; 51 + };
+23
Documentation/devicetree/bindings/usb/renesas_usb3.txt
··· 1 + Renesas Electronics USB3.0 Peripheral driver 2 + 3 + Required properties: 4 + - compatible: Must contain one of the following: 5 + - "renesas,r8a7795-usb3-peri" 6 + - reg: Base address and length of the register for the USB3.0 Peripheral 7 + - interrupts: Interrupt specifier for the USB3.0 Peripheral 8 + - clocks: clock phandle and specifier pair 9 + 10 + Example: 11 + usb3_peri0: usb@ee020000 { 12 + compatible = "renesas,r8a7795-usb3-peri"; 13 + reg = <0 0xee020000 0 0x400>; 14 + interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>; 15 + clocks = <&cpg CPG_MOD 328>; 16 + }; 17 + 18 + usb3_peri1: usb@ee060000 { 19 + compatible = "renesas,r8a7795-usb3-peri"; 20 + reg = <0 0xee060000 0 0x400>; 21 + interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>; 22 + clocks = <&cpg CPG_MOD 327>; 23 + };
+16 -6
Documentation/devicetree/bindings/usb/renesas_usbhs.txt
··· 1 1 Renesas Electronics USBHS driver 2 2 3 3 Required properties: 4 - - compatible: Must contain one of the following: 5 - - "renesas,usbhs-r8a7790" 6 - - "renesas,usbhs-r8a7791" 7 - - "renesas,usbhs-r8a7794" 8 - - "renesas,usbhs-r8a7795" 4 + - compatible: Must contain one or more of the following: 5 + 6 + - "renesas,usbhs-r8a7790" for r8a7790 (R-Car H2) compatible device 7 + - "renesas,usbhs-r8a7791" for r8a7791 (R-Car M2-W) compatible device 8 + - "renesas,usbhs-r8a7792" for r8a7792 (R-Car V2H) compatible device 9 + - "renesas,usbhs-r8a7793" for r8a7793 (R-Car M2-N) compatible device 10 + - "renesas,usbhs-r8a7794" for r8a7794 (R-Car E2) compatible device 11 + - "renesas,usbhs-r8a7795" for r8a7795 (R-Car H3) compatible device 12 + - "renesas,rcar-gen2-usbhs" for R-Car Gen2 compatible device 13 + - "renesas,rcar-gen3-usbhs" for R-Car Gen3 compatible device 14 + 15 + When compatible with the generic version, nodes must list the 16 + SoC-specific version corresponding to the platform first followed 17 + by the generic version. 18 + 9 19 - reg: Base address and length of the register for the USBHS 10 20 - interrupts: Interrupt specifier for the USBHS 11 21 - clocks: A list of phandle + clock specifier pairs ··· 32 22 33 23 Example: 34 24 usbhs: usb@e6590000 { 35 - compatible = "renesas,usbhs-r8a7790"; 25 + compatible = "renesas,usbhs-r8a7790", "renesas,rcar-gen2-usbhs"; 36 26 reg = <0 0xe6590000 0 0x100>; 37 27 interrupts = <0 107 IRQ_TYPE_LEVEL_HIGH>; 38 28 clocks = <&mstp7_clks R8A7790_CLK_HSUSB>;
+2 -2
Documentation/devicetree/bindings/usb/usb-xhci.txt
··· 3 3 Required properties: 4 4 - compatible: should be one of "generic-xhci", 5 5 "marvell,armada-375-xhci", "marvell,armada-380-xhci", 6 - "renesas,xhci-r8a7790", "renesas,xhci-r8a7791" (deprecated: 7 - "xhci-platform"). 6 + "renesas,xhci-r8a7790", "renesas,xhci-r8a7791", "renesas,xhci-r8a7793", 7 + "renesas,xhci-r8a7795" (deprecated: "xhci-platform"). 8 8 - reg: should contain address and length of the standard XHCI 9 9 register set for the device. 10 10 - interrupts: one XHCI interrupt should be described here.
+6 -2
Documentation/kernel-parameters.txt
··· 2584 2584 2585 2585 notsc [BUGS=X86-32] Disable Time Stamp Counter 2586 2586 2587 - nousb [USB] Disable the USB subsystem 2588 - 2589 2587 nowatchdog [KNL] Disable both lockup detectors, i.e. 2590 2588 soft-lockup and NMI watchdog (hard-lockup). 2591 2589 ··· 3898 3900 usbcore.usbfs_snoop= 3899 3901 [USB] Set to log all usbfs traffic (default 0 = off). 3900 3902 3903 + usbcore.usbfs_snoop_max= 3904 + [USB] Maximum number of bytes to snoop in each URB 3905 + (default = 65536). 3906 + 3901 3907 usbcore.blinkenlights= 3902 3908 [USB] Set to cycle leds on hubs (default 0 = off). 3903 3909 ··· 3921 3919 [USB] Specifies timeout for the initial 64-byte 3922 3920 USB_REQ_GET_DESCRIPTOR request in milliseconds 3923 3921 (default 5000 = 5.0 seconds). 3922 + 3923 + usbcore.nousb [USB] Disable the USB subsystem 3924 3924 3925 3925 usbhid.mousepoll= 3926 3926 [USBHID] The interval which mice are to be polled at.
+2 -2
Documentation/usb/chipidea.txt
··· 7 7 --------------------------------------- 8 8 Select CONFIG_USB_OTG_FSM, rebuild kernel Image and modules. 9 9 If you want to check some internal variables for otg fsm, 10 - select CONFIG_USB_CHIPIDEA_DEBUG, there are 2 files which 11 - can show otg fsm variables and some controller registers value: 10 + mount debugfs, there are 2 files which can show otg fsm 11 + variables and some controller registers value: 12 12 cat /sys/kernel/debug/ci_hdrc.0/otg 13 13 cat /sys/kernel/debug/ci_hdrc.0/registers 14 14
+3 -1
Documentation/usb/gadget-testing.txt
··· 434 434 435 435 where seriald and serialc are Felipe's utilities found here: 436 436 437 - https://git.gitorious.org/usb/usb-tools.git master 437 + https://github.com/felipebalbi/usb-tools.git master 438 438 439 439 12. PHONET function 440 440 =================== ··· 579 579 isoc_mult - 0..2 (hs/ss only) 580 580 isoc_maxburst - 0..15 (ss only) 581 581 bulk_buflen - buffer length 582 + bulk_qlen - depth of queue for bulk 583 + iso_qlen - depth of queue for iso 582 584 583 585 Testing the SOURCESINK function 584 586 -------------------------------
+6 -5
Documentation/usb/power-management.txt
··· 537 537 can write y/Y/1 or n/N/0 to the file to enable/disable 538 538 USB2 hardware LPM manually. This is for test purpose mainly. 539 539 540 - power/usb3_hardware_lpm 540 + power/usb3_hardware_lpm_u1 541 + power/usb3_hardware_lpm_u2 541 542 542 543 When a USB 3.0 lpm-capable device is plugged in to a 543 544 xHCI host which supports link PM, it will check if U1 544 545 and U2 exit latencies have been set in the BOS 545 546 descriptor; if the check is is passed and the host 546 547 supports USB3 hardware LPM, USB3 hardware LPM will be 547 - enabled for the device and this file will be created. 548 - The file holds a string value (enable or disable) 549 - indicating whether or not USB3 hardware LPM is 550 - enabled for the device. 548 + enabled for the device and these files will be created. 549 + The files hold a string value (enable or disable) 550 + indicating whether or not USB3 hardware LPM U1 or U2 551 + is enabled for the device. 551 552 552 553 USB Port Power Control 553 554 ----------------------
+8 -2
MAINTAINERS
··· 2767 2767 F: Documentation/zh_CN/ 2768 2768 2769 2769 CHIPIDEA USB HIGH SPEED DUAL ROLE CONTROLLER 2770 - M: Peter Chen <Peter.Chen@freescale.com> 2770 + M: Peter Chen <Peter.Chen@nxp.com> 2771 2771 T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git 2772 2772 L: linux-usb@vger.kernel.org 2773 2773 S: Maintained ··· 8992 8992 F: drivers/net/ethernet/renesas/ 8993 8993 F: include/linux/sh_eth.h 8994 8994 8995 + RENESAS USB2 PHY DRIVER 8996 + M: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> 8997 + L: linux-sh@vger.kernel.org 8998 + S: Maintained 8999 + F: drivers/phy/phy-rcar-gen3-usb2.c 9000 + 8995 9001 RESET CONTROLLER FRAMEWORK 8996 9002 M: Philipp Zabel <p.zabel@pengutronix.de> 8997 9003 S: Maintained ··· 11194 11188 F: drivers/usb/host/ohci* 11195 11189 11196 11190 USB OTG FSM (Finite State Machine) 11197 - M: Peter Chen <Peter.Chen@freescale.com> 11191 + M: Peter Chen <Peter.Chen@nxp.com> 11198 11192 T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git 11199 11193 L: linux-usb@vger.kernel.org 11200 11194 S: Maintained
+16
arch/arm64/boot/dts/mediatek/mt8173-evb.dts
··· 13 13 */ 14 14 15 15 /dts-v1/; 16 + #include <dt-bindings/gpio/gpio.h> 16 17 #include "mt8173.dtsi" 17 18 18 19 / { ··· 33 32 }; 34 33 35 34 chosen { }; 35 + 36 + usb_p1_vbus: regulator@0 { 37 + compatible = "regulator-fixed"; 38 + regulator-name = "usb_vbus"; 39 + regulator-min-microvolt = <5000000>; 40 + regulator-max-microvolt = <5000000>; 41 + gpio = <&pio 130 GPIO_ACTIVE_HIGH>; 42 + enable-active-high; 43 + }; 36 44 }; 37 45 38 46 &i2c1 { ··· 417 407 418 408 &uart0 { 419 409 status = "okay"; 410 + }; 411 + 412 + &usb30 { 413 + vusb33-supply = <&mt6397_vusb_reg>; 414 + vbus-supply = <&usb_p1_vbus>; 415 + mediatek,wakeup-src = <1>; 420 416 };
+42
arch/arm64/boot/dts/mediatek/mt8173.dtsi
··· 14 14 #include <dt-bindings/clock/mt8173-clk.h> 15 15 #include <dt-bindings/interrupt-controller/irq.h> 16 16 #include <dt-bindings/interrupt-controller/arm-gic.h> 17 + #include <dt-bindings/phy/phy.h> 17 18 #include <dt-bindings/power/mt8173-power.h> 18 19 #include <dt-bindings/reset-controller/mt8173-resets.h> 19 20 #include "mt8173-pinfunc.h" ··· 509 508 <&topckgen CLK_TOP_MSDC50_2_H_SEL>; 510 509 clock-names = "source", "hclk"; 511 510 status = "disabled"; 511 + }; 512 + 513 + usb30: usb@11270000 { 514 + compatible = "mediatek,mt8173-xhci"; 515 + reg = <0 0x11270000 0 0x1000>, 516 + <0 0x11280700 0 0x0100>; 517 + interrupts = <GIC_SPI 115 IRQ_TYPE_LEVEL_LOW>; 518 + power-domains = <&scpsys MT8173_POWER_DOMAIN_USB>; 519 + clocks = <&topckgen CLK_TOP_USB30_SEL>, 520 + <&pericfg CLK_PERI_USB0>, 521 + <&pericfg CLK_PERI_USB1>; 522 + clock-names = "sys_ck", 523 + "wakeup_deb_p0", 524 + "wakeup_deb_p1"; 525 + phys = <&phy_port0 PHY_TYPE_USB3>, 526 + <&phy_port1 PHY_TYPE_USB2>; 527 + mediatek,syscon-wakeup = <&pericfg>; 528 + status = "okay"; 529 + }; 530 + 531 + u3phy: usb-phy@11290000 { 532 + compatible = "mediatek,mt8173-u3phy"; 533 + reg = <0 0x11290000 0 0x800>; 534 + clocks = <&apmixedsys CLK_APMIXED_REF2USB_TX>; 535 + clock-names = "u3phya_ref"; 536 + #address-cells = <2>; 537 + #size-cells = <2>; 538 + ranges; 539 + status = "okay"; 540 + 541 + phy_port0: port@11290800 { 542 + reg = <0 0x11290800 0 0x800>; 543 + #phy-cells = <1>; 544 + status = "okay"; 545 + }; 546 + 547 + phy_port1: port@11291000 { 548 + reg = <0 0x11291000 0 0x800>; 549 + #phy-cells = <1>; 550 + status = "okay"; 551 + }; 512 552 }; 513 553 514 554 mmsys: clock-controller@14000000 {
+18 -2
drivers/phy/Kconfig
··· 118 118 help 119 119 Support for USB PHY found on Renesas R-Car generation 2 SoCs. 120 120 121 + config PHY_RCAR_GEN3_USB2 122 + tristate "Renesas R-Car generation 3 USB 2.0 PHY driver" 123 + depends on OF && ARCH_SHMOBILE 124 + select GENERIC_PHY 125 + help 126 + Support for USB 2.0 PHY found on Renesas R-Car generation 3 SoCs. 127 + 121 128 config OMAP_CONTROL_PHY 122 129 tristate "OMAP CONTROL PHY Driver" 123 130 depends on ARCH_OMAP2PLUS || COMPILE_TEST ··· 221 214 Say 'Y' here to add support for Mediatek USB3.0 PHY driver 222 215 for mt65xx SoCs. it supports two usb2.0 ports and 223 216 one usb3.0 port. 217 + 218 + config PHY_HI6220_USB 219 + tristate "hi6220 USB PHY support" 220 + select GENERIC_PHY 221 + select MFD_SYSCON 222 + help 223 + Enable this to support the HISILICON HI6220 USB PHY. 224 + 225 + To compile this driver as a module, choose M here. 224 226 225 227 config PHY_SUN4I_USB 226 228 tristate "Allwinner sunxi SoC USB PHY driver" ··· 390 374 391 375 config PHY_BRCMSTB_SATA 392 376 tristate "Broadcom STB SATA PHY driver" 393 - depends on ARCH_BRCMSTB 377 + depends on ARCH_BRCMSTB || BMIPS_GENERIC 394 378 depends on OF 395 379 select GENERIC_PHY 396 380 help 397 - Enable this to support the SATA3 PHY on 28nm Broadcom STB SoCs. 381 + Enable this to support the SATA3 PHY on 28nm or 40nm Broadcom STB SoCs. 398 382 Likely useful only with CONFIG_SATA_BRCMSTB enabled. 399 383 400 384 config PHY_CYGNUS_PCIE
+2
drivers/phy/Makefile
··· 17 17 obj-$(CONFIG_PHY_MIPHY28LP) += phy-miphy28lp.o 18 18 obj-$(CONFIG_PHY_MIPHY365X) += phy-miphy365x.o 19 19 obj-$(CONFIG_PHY_RCAR_GEN2) += phy-rcar-gen2.o 20 + obj-$(CONFIG_PHY_RCAR_GEN3_USB2) += phy-rcar-gen3-usb2.o 20 21 obj-$(CONFIG_OMAP_CONTROL_PHY) += phy-omap-control.o 21 22 obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o 22 23 obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o 23 24 obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o 24 25 obj-$(CONFIG_PHY_EXYNOS5250_SATA) += phy-exynos5250-sata.o 25 26 obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o 27 + obj-$(CONFIG_PHY_HI6220_USB) += phy-hi6220-usb.o 26 28 obj-$(CONFIG_PHY_MT65XX_USB3) += phy-mt65xx-usb3.o 27 29 obj-$(CONFIG_PHY_SUN4I_USB) += phy-sun4i-usb.o 28 30 obj-$(CONFIG_PHY_SUN9I_USB) += phy-sun9i-usb.o
-3
drivers/phy/phy-berlin-usb.c
··· 9 9 * warranty of any kind, whether express or implied. 10 10 */ 11 11 12 - #include <linux/gpio.h> 13 12 #include <linux/io.h> 14 13 #include <linux/module.h> 15 14 #include <linux/of_device.h> 16 - #include <linux/of_gpio.h> 17 15 #include <linux/phy/phy.h> 18 16 #include <linux/platform_device.h> 19 17 #include <linux/reset.h> ··· 193 195 return PTR_ERR(phy); 194 196 } 195 197 196 - platform_set_drvdata(pdev, priv); 197 198 phy_set_drvdata(phy, priv); 198 199 199 200 phy_provider =
+37 -10
drivers/phy/phy-brcmstb-sata.c
··· 26 26 27 27 #define SATA_MDIO_BANK_OFFSET 0x23c 28 28 #define SATA_MDIO_REG_OFFSET(ofs) ((ofs) * 4) 29 - #define SATA_MDIO_REG_SPACE_SIZE 0x1000 30 - #define SATA_MDIO_REG_LENGTH 0x1f00 31 29 32 30 #define MAX_PORTS 2 33 31 34 32 /* Register offset between PHYs in PCB space */ 35 - #define SATA_MDIO_REG_SPACE_SIZE 0x1000 33 + #define SATA_MDIO_REG_28NM_SPACE_SIZE 0x1000 34 + 35 + /* The older SATA PHY registers duplicated per port registers within the map, 36 + * rather than having a separate map per port. 37 + */ 38 + #define SATA_MDIO_REG_40NM_SPACE_SIZE 0x10 39 + 40 + enum brcm_sata_phy_version { 41 + BRCM_SATA_PHY_28NM, 42 + BRCM_SATA_PHY_40NM, 43 + }; 36 44 37 45 struct brcm_sata_port { 38 46 int portnum; ··· 52 44 struct brcm_sata_phy { 53 45 struct device *dev; 54 46 void __iomem *phy_base; 47 + enum brcm_sata_phy_version version; 55 48 56 49 struct brcm_sata_port phys[MAX_PORTS]; 57 50 }; 58 51 59 - enum sata_mdio_phy_regs_28nm { 52 + enum sata_mdio_phy_regs { 60 53 PLL_REG_BANK_0 = 0x50, 61 54 PLL_REG_BANK_0_PLLCONTROL_0 = 0x81, 62 55 ··· 75 66 static inline void __iomem *brcm_sata_phy_base(struct brcm_sata_port *port) 76 67 { 77 68 struct brcm_sata_phy *priv = port->phy_priv; 69 + u32 offset = 0; 78 70 79 - return priv->phy_base + (port->portnum * SATA_MDIO_REG_SPACE_SIZE); 71 + if (priv->version == BRCM_SATA_PHY_28NM) 72 + offset = SATA_MDIO_REG_28NM_SPACE_SIZE; 73 + else if (priv->version == BRCM_SATA_PHY_40NM) 74 + offset = SATA_MDIO_REG_40NM_SPACE_SIZE; 75 + else 76 + dev_err(priv->dev, "invalid phy version\n"); 77 + 78 + return priv->phy_base + (port->portnum * offset); 80 79 } 81 80 82 81 static void brcm_sata_mdio_wr(void __iomem *addr, u32 bank, u32 ofs, ··· 103 86 #define FMAX_VAL_DEFAULT 0x3df 104 87 #define FMAX_VAL_SSC 0x83 105 88 106 - static void brcm_sata_cfg_ssc_28nm(struct brcm_sata_port *port) 89 + static void brcm_sata_cfg_ssc(struct brcm_sata_port *port) 107 90 { 108 91 void __iomem *base = brcm_sata_phy_base(port); 109 92 struct brcm_sata_phy *priv = port->phy_priv; ··· 134 117 { 135 118 struct brcm_sata_port *port = phy_get_drvdata(phy); 136 119 137 - brcm_sata_cfg_ssc_28nm(port); 120 + brcm_sata_cfg_ssc(port); 138 121 139 122 return 0; 140 123 } 141 124 142 - static const struct phy_ops phy_ops_28nm = { 125 + static const struct phy_ops phy_ops = { 143 126 .init = brcm_sata_phy_init, 144 127 .owner = THIS_MODULE, 145 128 }; 146 129 147 130 static const struct of_device_id brcm_sata_phy_of_match[] = { 148 - { .compatible = "brcm,bcm7445-sata-phy" }, 131 + { .compatible = "brcm,bcm7445-sata-phy", 132 + .data = (void *)BRCM_SATA_PHY_28NM }, 133 + { .compatible = "brcm,bcm7425-sata-phy", 134 + .data = (void *)BRCM_SATA_PHY_40NM }, 149 135 {}, 150 136 }; 151 137 MODULE_DEVICE_TABLE(of, brcm_sata_phy_of_match); ··· 157 137 { 158 138 struct device *dev = &pdev->dev; 159 139 struct device_node *dn = dev->of_node, *child; 140 + const struct of_device_id *of_id; 160 141 struct brcm_sata_phy *priv; 161 142 struct resource *res; 162 143 struct phy_provider *provider; ··· 176 155 priv->phy_base = devm_ioremap_resource(dev, res); 177 156 if (IS_ERR(priv->phy_base)) 178 157 return PTR_ERR(priv->phy_base); 158 + 159 + of_id = of_match_node(brcm_sata_phy_of_match, dn); 160 + if (of_id) 161 + priv->version = (enum brcm_sata_phy_version)of_id->data; 162 + else 163 + priv->version = BRCM_SATA_PHY_28NM; 179 164 180 165 for_each_available_child_of_node(dn, child) { 181 166 unsigned int id; ··· 208 181 port = &priv->phys[id]; 209 182 port->portnum = id; 210 183 port->phy_priv = priv; 211 - port->phy = devm_phy_create(dev, child, &phy_ops_28nm); 184 + port->phy = devm_phy_create(dev, child, &phy_ops); 212 185 port->ssc_en = of_property_read_bool(child, "brcm,enable-ssc"); 213 186 if (IS_ERR(port->phy)) { 214 187 dev_err(dev, "failed to create PHY\n");
+168
drivers/phy/phy-hi6220-usb.c
··· 1 + /* 2 + * Copyright (c) 2015 Linaro Ltd. 3 + * Copyright (c) 2015 Hisilicon Limited. 4 + * 5 + * This program is free software; you can redistribute it and/or modify 6 + * it under the terms of the GNU General Public License as published by 7 + * the Free Software Foundation; either version 2 of the License, or 8 + * (at your option) any later version. 9 + */ 10 + 11 + #include <linux/mfd/syscon.h> 12 + #include <linux/module.h> 13 + #include <linux/platform_device.h> 14 + #include <linux/phy/phy.h> 15 + #include <linux/regmap.h> 16 + 17 + #define SC_PERIPH_CTRL4 0x00c 18 + 19 + #define CTRL4_PICO_SIDDQ BIT(6) 20 + #define CTRL4_PICO_OGDISABLE BIT(8) 21 + #define CTRL4_PICO_VBUSVLDEXT BIT(10) 22 + #define CTRL4_PICO_VBUSVLDEXTSEL BIT(11) 23 + #define CTRL4_OTG_PHY_SEL BIT(21) 24 + 25 + #define SC_PERIPH_CTRL5 0x010 26 + 27 + #define CTRL5_USBOTG_RES_SEL BIT(3) 28 + #define CTRL5_PICOPHY_ACAENB BIT(4) 29 + #define CTRL5_PICOPHY_BC_MODE BIT(5) 30 + #define CTRL5_PICOPHY_CHRGSEL BIT(6) 31 + #define CTRL5_PICOPHY_VDATSRCEND BIT(7) 32 + #define CTRL5_PICOPHY_VDATDETENB BIT(8) 33 + #define CTRL5_PICOPHY_DCDENB BIT(9) 34 + #define CTRL5_PICOPHY_IDDIG BIT(10) 35 + 36 + #define SC_PERIPH_CTRL8 0x018 37 + #define SC_PERIPH_RSTEN0 0x300 38 + #define SC_PERIPH_RSTDIS0 0x304 39 + 40 + #define RST0_USBOTG_BUS BIT(4) 41 + #define RST0_POR_PICOPHY BIT(5) 42 + #define RST0_USBOTG BIT(6) 43 + #define RST0_USBOTG_32K BIT(7) 44 + 45 + #define EYE_PATTERN_PARA 0x7053348c 46 + 47 + struct hi6220_priv { 48 + struct regmap *reg; 49 + struct device *dev; 50 + }; 51 + 52 + static void hi6220_phy_init(struct hi6220_priv *priv) 53 + { 54 + struct regmap *reg = priv->reg; 55 + u32 val, mask; 56 + 57 + val = RST0_USBOTG_BUS | RST0_POR_PICOPHY | 58 + RST0_USBOTG | RST0_USBOTG_32K; 59 + mask = val; 60 + regmap_update_bits(reg, SC_PERIPH_RSTEN0, mask, val); 61 + regmap_update_bits(reg, SC_PERIPH_RSTDIS0, mask, val); 62 + } 63 + 64 + static int hi6220_phy_setup(struct hi6220_priv *priv, bool on) 65 + { 66 + struct regmap *reg = priv->reg; 67 + u32 val, mask; 68 + int ret; 69 + 70 + if (on) { 71 + val = CTRL5_USBOTG_RES_SEL | CTRL5_PICOPHY_ACAENB; 72 + mask = val | CTRL5_PICOPHY_BC_MODE; 73 + ret = regmap_update_bits(reg, SC_PERIPH_CTRL5, mask, val); 74 + if (ret) 75 + goto out; 76 + 77 + val = CTRL4_PICO_VBUSVLDEXT | CTRL4_PICO_VBUSVLDEXTSEL | 78 + CTRL4_OTG_PHY_SEL; 79 + mask = val | CTRL4_PICO_SIDDQ | CTRL4_PICO_OGDISABLE; 80 + ret = regmap_update_bits(reg, SC_PERIPH_CTRL4, mask, val); 81 + if (ret) 82 + goto out; 83 + 84 + ret = regmap_write(reg, SC_PERIPH_CTRL8, EYE_PATTERN_PARA); 85 + if (ret) 86 + goto out; 87 + } else { 88 + val = CTRL4_PICO_SIDDQ; 89 + mask = val; 90 + ret = regmap_update_bits(reg, SC_PERIPH_CTRL4, mask, val); 91 + if (ret) 92 + goto out; 93 + } 94 + 95 + return 0; 96 + out: 97 + dev_err(priv->dev, "failed to setup phy ret: %d\n", ret); 98 + return ret; 99 + } 100 + 101 + static int hi6220_phy_start(struct phy *phy) 102 + { 103 + struct hi6220_priv *priv = phy_get_drvdata(phy); 104 + 105 + return hi6220_phy_setup(priv, true); 106 + } 107 + 108 + static int hi6220_phy_exit(struct phy *phy) 109 + { 110 + struct hi6220_priv *priv = phy_get_drvdata(phy); 111 + 112 + return hi6220_phy_setup(priv, false); 113 + } 114 + 115 + static struct phy_ops hi6220_phy_ops = { 116 + .init = hi6220_phy_start, 117 + .exit = hi6220_phy_exit, 118 + .owner = THIS_MODULE, 119 + }; 120 + 121 + static int hi6220_phy_probe(struct platform_device *pdev) 122 + { 123 + struct phy_provider *phy_provider; 124 + struct device *dev = &pdev->dev; 125 + struct phy *phy; 126 + struct hi6220_priv *priv; 127 + 128 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 129 + if (!priv) 130 + return -ENOMEM; 131 + 132 + priv->dev = dev; 133 + priv->reg = syscon_regmap_lookup_by_phandle(dev->of_node, 134 + "hisilicon,peripheral-syscon"); 135 + if (IS_ERR(priv->reg)) { 136 + dev_err(dev, "no hisilicon,peripheral-syscon\n"); 137 + return PTR_ERR(priv->reg); 138 + } 139 + 140 + hi6220_phy_init(priv); 141 + 142 + phy = devm_phy_create(dev, NULL, &hi6220_phy_ops); 143 + if (IS_ERR(phy)) 144 + return PTR_ERR(phy); 145 + 146 + phy_set_drvdata(phy, priv); 147 + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 148 + return PTR_ERR_OR_ZERO(phy_provider); 149 + } 150 + 151 + static const struct of_device_id hi6220_phy_of_match[] = { 152 + {.compatible = "hisilicon,hi6220-usb-phy",}, 153 + { }, 154 + }; 155 + MODULE_DEVICE_TABLE(of, hi6220_phy_of_match); 156 + 157 + static struct platform_driver hi6220_phy_driver = { 158 + .probe = hi6220_phy_probe, 159 + .driver = { 160 + .name = "hi6220-usb-phy", 161 + .of_match_table = hi6220_phy_of_match, 162 + } 163 + }; 164 + module_platform_driver(hi6220_phy_driver); 165 + 166 + MODULE_DESCRIPTION("HISILICON HI6220 USB PHY driver"); 167 + MODULE_ALIAS("platform:hi6220-usb-phy"); 168 + MODULE_LICENSE("GPL");
+101 -5
drivers/phy/phy-mt65xx-usb3.c
··· 17 17 #include <linux/clk.h> 18 18 #include <linux/delay.h> 19 19 #include <linux/io.h> 20 + #include <linux/iopoll.h> 20 21 #include <linux/module.h> 21 22 #include <linux/of_address.h> 22 23 #include <linux/phy/phy.h> ··· 28 27 * relative to USB3_SIF2_BASE base address 29 28 */ 30 29 #define SSUSB_SIFSLV_SPLLC 0x0000 30 + #define SSUSB_SIFSLV_U2FREQ 0x0100 31 31 32 32 /* offsets of sub-segment in each port registers */ 33 33 #define SSUSB_SIFSLV_U2PHY_COM_BASE 0x0000 ··· 43 41 #define PA2_RG_SIF_U2PLL_FORCE_EN BIT(18) 44 42 45 43 #define U3P_USBPHYACR5 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0014) 44 + #define PA5_RG_U2_HSTX_SRCAL_EN BIT(15) 46 45 #define PA5_RG_U2_HSTX_SRCTRL GENMASK(14, 12) 47 46 #define PA5_RG_U2_HSTX_SRCTRL_VAL(x) ((0x7 & (x)) << 12) 48 47 #define PA5_RG_U2_HS_100U_U3_EN BIT(11) ··· 52 49 #define PA6_RG_U2_ISO_EN BIT(31) 53 50 #define PA6_RG_U2_BC11_SW_EN BIT(23) 54 51 #define PA6_RG_U2_OTG_VBUSCMP_EN BIT(20) 52 + #define PA6_RG_U2_SQTH GENMASK(3, 0) 53 + #define PA6_RG_U2_SQTH_VAL(x) (0xf & (x)) 55 54 56 55 #define U3P_U2PHYACR4 (SSUSB_SIFSLV_U2PHY_COM_BASE + 0x0020) 57 56 #define P2C_RG_USB20_GPIO_CTL BIT(9) ··· 116 111 #define XC3_RG_U3_XTAL_RX_PWD BIT(9) 117 112 #define XC3_RG_U3_FRC_XTAL_RX_PWD BIT(8) 118 113 114 + #define U3P_U2FREQ_FMCR0 (SSUSB_SIFSLV_U2FREQ + 0x00) 115 + #define P2F_RG_MONCLK_SEL GENMASK(27, 26) 116 + #define P2F_RG_MONCLK_SEL_VAL(x) ((0x3 & (x)) << 26) 117 + #define P2F_RG_FREQDET_EN BIT(24) 118 + #define P2F_RG_CYCLECNT GENMASK(23, 0) 119 + #define P2F_RG_CYCLECNT_VAL(x) ((P2F_RG_CYCLECNT) & (x)) 120 + 121 + #define U3P_U2FREQ_VALUE (SSUSB_SIFSLV_U2FREQ + 0x0c) 122 + 123 + #define U3P_U2FREQ_FMMONR1 (SSUSB_SIFSLV_U2FREQ + 0x10) 124 + #define P2F_USB_FM_VALID BIT(0) 125 + #define P2F_RG_FRCK_EN BIT(8) 126 + 127 + #define U3P_REF_CLK 26 /* MHZ */ 128 + #define U3P_SLEW_RATE_COEF 28 129 + #define U3P_SR_COEF_DIVISOR 1000 130 + #define U3P_FM_DET_CYCLE_CNT 1024 131 + 119 132 struct mt65xx_phy_instance { 120 133 struct phy *phy; 121 134 void __iomem *port_base; ··· 148 125 struct mt65xx_phy_instance **phys; 149 126 int nphys; 150 127 }; 128 + 129 + static void hs_slew_rate_calibrate(struct mt65xx_u3phy *u3phy, 130 + struct mt65xx_phy_instance *instance) 131 + { 132 + void __iomem *sif_base = u3phy->sif_base; 133 + int calibration_val; 134 + int fm_out; 135 + u32 tmp; 136 + 137 + /* enable USB ring oscillator */ 138 + tmp = readl(instance->port_base + U3P_USBPHYACR5); 139 + tmp |= PA5_RG_U2_HSTX_SRCAL_EN; 140 + writel(tmp, instance->port_base + U3P_USBPHYACR5); 141 + udelay(1); 142 + 143 + /*enable free run clock */ 144 + tmp = readl(sif_base + U3P_U2FREQ_FMMONR1); 145 + tmp |= P2F_RG_FRCK_EN; 146 + writel(tmp, sif_base + U3P_U2FREQ_FMMONR1); 147 + 148 + /* set cycle count as 1024, and select u2 channel */ 149 + tmp = readl(sif_base + U3P_U2FREQ_FMCR0); 150 + tmp &= ~(P2F_RG_CYCLECNT | P2F_RG_MONCLK_SEL); 151 + tmp |= P2F_RG_CYCLECNT_VAL(U3P_FM_DET_CYCLE_CNT); 152 + tmp |= P2F_RG_MONCLK_SEL_VAL(instance->index); 153 + writel(tmp, sif_base + U3P_U2FREQ_FMCR0); 154 + 155 + /* enable frequency meter */ 156 + tmp = readl(sif_base + U3P_U2FREQ_FMCR0); 157 + tmp |= P2F_RG_FREQDET_EN; 158 + writel(tmp, sif_base + U3P_U2FREQ_FMCR0); 159 + 160 + /* ignore return value */ 161 + readl_poll_timeout(sif_base + U3P_U2FREQ_FMMONR1, tmp, 162 + (tmp & P2F_USB_FM_VALID), 10, 200); 163 + 164 + fm_out = readl(sif_base + U3P_U2FREQ_VALUE); 165 + 166 + /* disable frequency meter */ 167 + tmp = readl(sif_base + U3P_U2FREQ_FMCR0); 168 + tmp &= ~P2F_RG_FREQDET_EN; 169 + writel(tmp, sif_base + U3P_U2FREQ_FMCR0); 170 + 171 + /*disable free run clock */ 172 + tmp = readl(sif_base + U3P_U2FREQ_FMMONR1); 173 + tmp &= ~P2F_RG_FRCK_EN; 174 + writel(tmp, sif_base + U3P_U2FREQ_FMMONR1); 175 + 176 + if (fm_out) { 177 + /* ( 1024 / FM_OUT ) x reference clock frequency x 0.028 */ 178 + tmp = U3P_FM_DET_CYCLE_CNT * U3P_REF_CLK * U3P_SLEW_RATE_COEF; 179 + tmp /= fm_out; 180 + calibration_val = DIV_ROUND_CLOSEST(tmp, U3P_SR_COEF_DIVISOR); 181 + } else { 182 + /* if FM detection fail, set default value */ 183 + calibration_val = 4; 184 + } 185 + dev_dbg(u3phy->dev, "phy:%d, fm_out:%d, calib:%d\n", 186 + instance->index, fm_out, calibration_val); 187 + 188 + /* set HS slew rate */ 189 + tmp = readl(instance->port_base + U3P_USBPHYACR5); 190 + tmp &= ~PA5_RG_U2_HSTX_SRCTRL; 191 + tmp |= PA5_RG_U2_HSTX_SRCTRL_VAL(calibration_val); 192 + writel(tmp, instance->port_base + U3P_USBPHYACR5); 193 + 194 + /* disable USB ring oscillator */ 195 + tmp = readl(instance->port_base + U3P_USBPHYACR5); 196 + tmp &= ~PA5_RG_U2_HSTX_SRCAL_EN; 197 + writel(tmp, instance->port_base + U3P_USBPHYACR5); 198 + } 151 199 152 200 static void phy_instance_init(struct mt65xx_u3phy *u3phy, 153 201 struct mt65xx_phy_instance *instance) ··· 259 165 writel(tmp, port_base + U3P_U2PHYDTM0); 260 166 } 261 167 262 - /* DP/DM BC1.1 path Disable */ 263 168 tmp = readl(port_base + U3P_USBPHYACR6); 264 - tmp &= ~PA6_RG_U2_BC11_SW_EN; 169 + tmp &= ~PA6_RG_U2_BC11_SW_EN; /* DP/DM BC1.1 path Disable */ 170 + tmp &= ~PA6_RG_U2_SQTH; 171 + tmp |= PA6_RG_U2_SQTH_VAL(2); 265 172 writel(tmp, port_base + U3P_USBPHYACR6); 266 173 267 174 tmp = readl(port_base + U3P_U3PHYA_DA_REG0); ··· 318 223 tmp |= XC3_RG_U3_XTAL_RX_PWD | XC3_RG_U3_FRC_XTAL_RX_PWD; 319 224 writel(tmp, u3phy->sif_base + U3P_XTALCTL3); 320 225 321 - /* [mt8173]disable Change 100uA current from SSUSB */ 226 + /* [mt8173]switch 100uA current to SSUSB */ 322 227 tmp = readl(port_base + U3P_USBPHYACR5); 323 - tmp &= ~PA5_RG_U2_HS_100U_U3_EN; 228 + tmp |= PA5_RG_U2_HS_100U_U3_EN; 324 229 writel(tmp, port_base + U3P_USBPHYACR5); 325 230 } 326 231 ··· 365 270 writel(tmp, port_base + U3P_USBPHYACR6); 366 271 367 272 if (!index) { 368 - /* (also disable)Change 100uA current switch to USB2.0 */ 273 + /* switch 100uA current back to USB2.0 */ 369 274 tmp = readl(port_base + U3P_USBPHYACR5); 370 275 tmp &= ~PA5_RG_U2_HS_100U_U3_EN; 371 276 writel(tmp, port_base + U3P_USBPHYACR5); ··· 435 340 struct mt65xx_u3phy *u3phy = dev_get_drvdata(phy->dev.parent); 436 341 437 342 phy_instance_power_on(u3phy, instance); 343 + hs_slew_rate_calibrate(u3phy, instance); 438 344 return 0; 439 345 } 440 346
+76 -18
drivers/phy/phy-omap-usb2.c
··· 29 29 #include <linux/delay.h> 30 30 #include <linux/phy/omap_control_phy.h> 31 31 #include <linux/phy/phy.h> 32 + #include <linux/mfd/syscon.h> 33 + #include <linux/regmap.h> 32 34 #include <linux/of_platform.h> 33 35 34 36 #define USB2PHY_DISCON_BYP_LATCH (1 << 31) ··· 99 97 return 0; 100 98 } 101 99 100 + static int omap_usb_phy_power(struct omap_usb *phy, int on) 101 + { 102 + u32 val; 103 + int ret; 104 + 105 + if (!phy->syscon_phy_power) { 106 + omap_control_phy_power(phy->control_dev, on); 107 + return 0; 108 + } 109 + 110 + if (on) 111 + val = phy->power_on; 112 + else 113 + val = phy->power_off; 114 + 115 + ret = regmap_update_bits(phy->syscon_phy_power, phy->power_reg, 116 + phy->mask, val); 117 + return ret; 118 + } 119 + 102 120 static int omap_usb_power_off(struct phy *x) 103 121 { 104 122 struct omap_usb *phy = phy_get_drvdata(x); 105 123 106 - omap_control_phy_power(phy->control_dev, 0); 107 - 108 - return 0; 124 + return omap_usb_phy_power(phy, false); 109 125 } 110 126 111 127 static int omap_usb_power_on(struct phy *x) 112 128 { 113 129 struct omap_usb *phy = phy_get_drvdata(x); 114 130 115 - omap_control_phy_power(phy->control_dev, 1); 116 - 117 - return 0; 131 + return omap_usb_phy_power(phy, true); 118 132 } 119 133 120 134 static int omap_usb_init(struct phy *x) ··· 165 147 static const struct usb_phy_data omap_usb2_data = { 166 148 .label = "omap_usb2", 167 149 .flags = OMAP_USB2_HAS_START_SRP | OMAP_USB2_HAS_SET_VBUS, 150 + .mask = OMAP_DEV_PHY_PD, 151 + .power_off = OMAP_DEV_PHY_PD, 168 152 }; 169 153 170 154 static const struct usb_phy_data omap5_usb2_data = { 171 155 .label = "omap5_usb2", 172 156 .flags = 0, 157 + .mask = OMAP_DEV_PHY_PD, 158 + .power_off = OMAP_DEV_PHY_PD, 173 159 }; 174 160 175 161 static const struct usb_phy_data dra7x_usb2_data = { 176 162 .label = "dra7x_usb2", 177 163 .flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT, 164 + .mask = OMAP_DEV_PHY_PD, 165 + .power_off = OMAP_DEV_PHY_PD, 166 + }; 167 + 168 + static const struct usb_phy_data dra7x_usb2_phy2_data = { 169 + .label = "dra7x_usb2_phy2", 170 + .flags = OMAP_USB2_CALIBRATE_FALSE_DISCONNECT, 171 + .mask = OMAP_USB2_PHY_PD, 172 + .power_off = OMAP_USB2_PHY_PD, 178 173 }; 179 174 180 175 static const struct usb_phy_data am437x_usb2_data = { 181 176 .label = "am437x_usb2", 182 177 .flags = 0, 178 + .mask = AM437X_USB2_PHY_PD | AM437X_USB2_OTG_PD | 179 + AM437X_USB2_OTGVDET_EN | AM437X_USB2_OTGSESSEND_EN, 180 + .power_on = AM437X_USB2_OTGVDET_EN | AM437X_USB2_OTGSESSEND_EN, 181 + .power_off = AM437X_USB2_PHY_PD | AM437X_USB2_OTG_PD, 183 182 }; 184 183 185 184 static const struct of_device_id omap_usb2_id_table[] = { ··· 211 176 { 212 177 .compatible = "ti,dra7x-usb2", 213 178 .data = &dra7x_usb2_data, 179 + }, 180 + { 181 + .compatible = "ti,dra7x-usb2-phy2", 182 + .data = &dra7x_usb2_phy2_data, 214 183 }, 215 184 { 216 185 .compatible = "ti,am437x-usb2", ··· 258 219 phy->phy.label = phy_data->label; 259 220 phy->phy.otg = otg; 260 221 phy->phy.type = USB_PHY_TYPE_USB2; 222 + phy->mask = phy_data->mask; 223 + phy->power_on = phy_data->power_on; 224 + phy->power_off = phy_data->power_off; 261 225 262 226 if (phy_data->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) { 263 227 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 270 228 phy->flags |= OMAP_USB2_CALIBRATE_FALSE_DISCONNECT; 271 229 } 272 230 273 - control_node = of_parse_phandle(node, "ctrl-module", 0); 274 - if (!control_node) { 275 - dev_err(&pdev->dev, "Failed to get control device phandle\n"); 276 - return -EINVAL; 277 - } 231 + phy->syscon_phy_power = syscon_regmap_lookup_by_phandle(node, 232 + "syscon-phy-power"); 233 + if (IS_ERR(phy->syscon_phy_power)) { 234 + dev_dbg(&pdev->dev, 235 + "can't get syscon-phy-power, using control device\n"); 236 + phy->syscon_phy_power = NULL; 278 237 279 - control_pdev = of_find_device_by_node(control_node); 280 - if (!control_pdev) { 281 - dev_err(&pdev->dev, "Failed to get control device\n"); 282 - return -EINVAL; 283 - } 238 + control_node = of_parse_phandle(node, "ctrl-module", 0); 239 + if (!control_node) { 240 + dev_err(&pdev->dev, 241 + "Failed to get control device phandle\n"); 242 + return -EINVAL; 243 + } 284 244 285 - phy->control_dev = &control_pdev->dev; 286 - omap_control_phy_power(phy->control_dev, 0); 245 + control_pdev = of_find_device_by_node(control_node); 246 + if (!control_pdev) { 247 + dev_err(&pdev->dev, "Failed to get control device\n"); 248 + return -EINVAL; 249 + } 250 + phy->control_dev = &control_pdev->dev; 251 + } else { 252 + if (of_property_read_u32_index(node, 253 + "syscon-phy-power", 1, 254 + &phy->power_reg)) { 255 + dev_err(&pdev->dev, 256 + "couldn't get power reg. offset\n"); 257 + return -EINVAL; 258 + } 259 + } 287 260 288 261 otg->set_host = omap_usb_set_host; 289 262 otg->set_peripheral = omap_usb_set_peripheral; ··· 318 261 } 319 262 320 263 phy_set_drvdata(generic_phy, phy); 264 + omap_usb_power_off(generic_phy); 321 265 322 266 phy_provider = devm_of_phy_provider_register(phy->dev, 323 267 of_phy_simple_xlate);
+378
drivers/phy/phy-rcar-gen3-usb2.c
··· 1 + /* 2 + * Renesas R-Car Gen3 for USB2.0 PHY driver 3 + * 4 + * Copyright (C) 2015 Renesas Electronics Corporation 5 + * 6 + * This is based on the phy-rcar-gen2 driver: 7 + * Copyright (C) 2014 Renesas Solutions Corp. 8 + * Copyright (C) 2014 Cogent Embedded, Inc. 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License version 2 as 12 + * published by the Free Software Foundation. 13 + */ 14 + 15 + #include <linux/interrupt.h> 16 + #include <linux/io.h> 17 + #include <linux/module.h> 18 + #include <linux/of.h> 19 + #include <linux/of_address.h> 20 + #include <linux/phy/phy.h> 21 + #include <linux/platform_device.h> 22 + 23 + /******* USB2.0 Host registers (original offset is +0x200) *******/ 24 + #define USB2_INT_ENABLE 0x000 25 + #define USB2_USBCTR 0x00c 26 + #define USB2_SPD_RSM_TIMSET 0x10c 27 + #define USB2_OC_TIMSET 0x110 28 + #define USB2_COMMCTRL 0x600 29 + #define USB2_OBINTSTA 0x604 30 + #define USB2_OBINTEN 0x608 31 + #define USB2_VBCTRL 0x60c 32 + #define USB2_LINECTRL1 0x610 33 + #define USB2_ADPCTRL 0x630 34 + 35 + /* INT_ENABLE */ 36 + #define USB2_INT_ENABLE_UCOM_INTEN BIT(3) 37 + #define USB2_INT_ENABLE_USBH_INTB_EN BIT(2) 38 + #define USB2_INT_ENABLE_USBH_INTA_EN BIT(1) 39 + #define USB2_INT_ENABLE_INIT (USB2_INT_ENABLE_UCOM_INTEN | \ 40 + USB2_INT_ENABLE_USBH_INTB_EN | \ 41 + USB2_INT_ENABLE_USBH_INTA_EN) 42 + 43 + /* USBCTR */ 44 + #define USB2_USBCTR_DIRPD BIT(2) 45 + #define USB2_USBCTR_PLL_RST BIT(1) 46 + 47 + /* SPD_RSM_TIMSET */ 48 + #define USB2_SPD_RSM_TIMSET_INIT 0x014e029b 49 + 50 + /* OC_TIMSET */ 51 + #define USB2_OC_TIMSET_INIT 0x000209ab 52 + 53 + /* COMMCTRL */ 54 + #define USB2_COMMCTRL_OTG_PERI BIT(31) /* 1 = Peripheral mode */ 55 + 56 + /* OBINTSTA and OBINTEN */ 57 + #define USB2_OBINT_SESSVLDCHG BIT(12) 58 + #define USB2_OBINT_IDDIGCHG BIT(11) 59 + #define USB2_OBINT_BITS (USB2_OBINT_SESSVLDCHG | \ 60 + USB2_OBINT_IDDIGCHG) 61 + 62 + /* VBCTRL */ 63 + #define USB2_VBCTRL_DRVVBUSSEL BIT(8) 64 + 65 + /* LINECTRL1 */ 66 + #define USB2_LINECTRL1_DPRPD_EN BIT(19) 67 + #define USB2_LINECTRL1_DP_RPD BIT(18) 68 + #define USB2_LINECTRL1_DMRPD_EN BIT(17) 69 + #define USB2_LINECTRL1_DM_RPD BIT(16) 70 + 71 + /* ADPCTRL */ 72 + #define USB2_ADPCTRL_OTGSESSVLD BIT(20) 73 + #define USB2_ADPCTRL_IDDIG BIT(19) 74 + #define USB2_ADPCTRL_IDPULLUP BIT(5) /* 1 = ID sampling is enabled */ 75 + #define USB2_ADPCTRL_DRVVBUS BIT(4) 76 + 77 + /******* HSUSB registers (original offset is +0x100) *******/ 78 + #define HSUSB_LPSTS 0x02 79 + #define HSUSB_UGCTRL2 0x84 80 + 81 + /* Low Power Status register (LPSTS) */ 82 + #define HSUSB_LPSTS_SUSPM 0x4000 83 + 84 + /* USB General control register 2 (UGCTRL2) */ 85 + #define HSUSB_UGCTRL2_MASK 0x00000031 /* bit[31:6] should be 0 */ 86 + #define HSUSB_UGCTRL2_USB0SEL 0x00000030 87 + #define HSUSB_UGCTRL2_USB0SEL_HOST 0x00000010 88 + #define HSUSB_UGCTRL2_USB0SEL_HS_USB 0x00000020 89 + #define HSUSB_UGCTRL2_USB0SEL_OTG 0x00000030 90 + 91 + struct rcar_gen3_data { 92 + void __iomem *base; 93 + struct clk *clk; 94 + }; 95 + 96 + struct rcar_gen3_chan { 97 + struct rcar_gen3_data usb2; 98 + struct rcar_gen3_data hsusb; 99 + struct phy *phy; 100 + }; 101 + 102 + static void rcar_gen3_set_host_mode(struct rcar_gen3_chan *ch, int host) 103 + { 104 + void __iomem *usb2_base = ch->usb2.base; 105 + u32 val = readl(usb2_base + USB2_COMMCTRL); 106 + 107 + dev_vdbg(&ch->phy->dev, "%s: %08x, %d\n", __func__, val, host); 108 + if (host) 109 + val &= ~USB2_COMMCTRL_OTG_PERI; 110 + else 111 + val |= USB2_COMMCTRL_OTG_PERI; 112 + writel(val, usb2_base + USB2_COMMCTRL); 113 + } 114 + 115 + static void rcar_gen3_set_linectrl(struct rcar_gen3_chan *ch, int dp, int dm) 116 + { 117 + void __iomem *usb2_base = ch->usb2.base; 118 + u32 val = readl(usb2_base + USB2_LINECTRL1); 119 + 120 + dev_vdbg(&ch->phy->dev, "%s: %08x, %d, %d\n", __func__, val, dp, dm); 121 + val &= ~(USB2_LINECTRL1_DP_RPD | USB2_LINECTRL1_DM_RPD); 122 + if (dp) 123 + val |= USB2_LINECTRL1_DP_RPD; 124 + if (dm) 125 + val |= USB2_LINECTRL1_DM_RPD; 126 + writel(val, usb2_base + USB2_LINECTRL1); 127 + } 128 + 129 + static void rcar_gen3_enable_vbus_ctrl(struct rcar_gen3_chan *ch, int vbus) 130 + { 131 + void __iomem *usb2_base = ch->usb2.base; 132 + u32 val = readl(usb2_base + USB2_ADPCTRL); 133 + 134 + dev_vdbg(&ch->phy->dev, "%s: %08x, %d\n", __func__, val, vbus); 135 + if (vbus) 136 + val |= USB2_ADPCTRL_DRVVBUS; 137 + else 138 + val &= ~USB2_ADPCTRL_DRVVBUS; 139 + writel(val, usb2_base + USB2_ADPCTRL); 140 + } 141 + 142 + static void rcar_gen3_init_for_host(struct rcar_gen3_chan *ch) 143 + { 144 + rcar_gen3_set_linectrl(ch, 1, 1); 145 + rcar_gen3_set_host_mode(ch, 1); 146 + rcar_gen3_enable_vbus_ctrl(ch, 1); 147 + } 148 + 149 + static void rcar_gen3_init_for_peri(struct rcar_gen3_chan *ch) 150 + { 151 + rcar_gen3_set_linectrl(ch, 0, 1); 152 + rcar_gen3_set_host_mode(ch, 0); 153 + rcar_gen3_enable_vbus_ctrl(ch, 0); 154 + } 155 + 156 + static bool rcar_gen3_check_vbus(struct rcar_gen3_chan *ch) 157 + { 158 + return !!(readl(ch->usb2.base + USB2_ADPCTRL) & 159 + USB2_ADPCTRL_OTGSESSVLD); 160 + } 161 + 162 + static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch) 163 + { 164 + return !!(readl(ch->usb2.base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG); 165 + } 166 + 167 + static void rcar_gen3_device_recognition(struct rcar_gen3_chan *ch) 168 + { 169 + bool is_host = true; 170 + 171 + /* B-device? */ 172 + if (rcar_gen3_check_id(ch) && rcar_gen3_check_vbus(ch)) 173 + is_host = false; 174 + 175 + if (is_host) 176 + rcar_gen3_init_for_host(ch); 177 + else 178 + rcar_gen3_init_for_peri(ch); 179 + } 180 + 181 + static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch) 182 + { 183 + void __iomem *usb2_base = ch->usb2.base; 184 + u32 val; 185 + 186 + val = readl(usb2_base + USB2_VBCTRL); 187 + writel(val | USB2_VBCTRL_DRVVBUSSEL, usb2_base + USB2_VBCTRL); 188 + writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA); 189 + val = readl(usb2_base + USB2_OBINTEN); 190 + writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN); 191 + val = readl(usb2_base + USB2_ADPCTRL); 192 + writel(val | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL); 193 + val = readl(usb2_base + USB2_LINECTRL1); 194 + rcar_gen3_set_linectrl(ch, 0, 0); 195 + writel(val | USB2_LINECTRL1_DPRPD_EN | USB2_LINECTRL1_DMRPD_EN, 196 + usb2_base + USB2_LINECTRL1); 197 + 198 + rcar_gen3_device_recognition(ch); 199 + } 200 + 201 + static int rcar_gen3_phy_usb2_init(struct phy *p) 202 + { 203 + struct rcar_gen3_chan *channel = phy_get_drvdata(p); 204 + void __iomem *usb2_base = channel->usb2.base; 205 + void __iomem *hsusb_base = channel->hsusb.base; 206 + u32 val; 207 + 208 + /* Initialize USB2 part */ 209 + writel(USB2_INT_ENABLE_INIT, usb2_base + USB2_INT_ENABLE); 210 + writel(USB2_SPD_RSM_TIMSET_INIT, usb2_base + USB2_SPD_RSM_TIMSET); 211 + writel(USB2_OC_TIMSET_INIT, usb2_base + USB2_OC_TIMSET); 212 + 213 + /* Initialize HSUSB part */ 214 + if (hsusb_base) { 215 + val = readl(hsusb_base + HSUSB_UGCTRL2); 216 + val = (val & ~HSUSB_UGCTRL2_USB0SEL) | 217 + HSUSB_UGCTRL2_USB0SEL_OTG; 218 + writel(val & HSUSB_UGCTRL2_MASK, hsusb_base + HSUSB_UGCTRL2); 219 + 220 + /* Initialize otg part */ 221 + rcar_gen3_init_otg(channel); 222 + } 223 + 224 + return 0; 225 + } 226 + 227 + static int rcar_gen3_phy_usb2_exit(struct phy *p) 228 + { 229 + struct rcar_gen3_chan *channel = phy_get_drvdata(p); 230 + 231 + writel(0, channel->usb2.base + USB2_INT_ENABLE); 232 + 233 + return 0; 234 + } 235 + 236 + static int rcar_gen3_phy_usb2_power_on(struct phy *p) 237 + { 238 + struct rcar_gen3_chan *channel = phy_get_drvdata(p); 239 + void __iomem *usb2_base = channel->usb2.base; 240 + void __iomem *hsusb_base = channel->hsusb.base; 241 + u32 val; 242 + 243 + val = readl(usb2_base + USB2_USBCTR); 244 + val |= USB2_USBCTR_PLL_RST; 245 + writel(val, usb2_base + USB2_USBCTR); 246 + val &= ~USB2_USBCTR_PLL_RST; 247 + writel(val, usb2_base + USB2_USBCTR); 248 + 249 + /* 250 + * TODO: To reduce power consuming, this driver should set the SUSPM 251 + * after the PHY detects ID pin as peripheral. 252 + */ 253 + if (hsusb_base) { 254 + /* Power on HSUSB PHY */ 255 + val = readw(hsusb_base + HSUSB_LPSTS); 256 + val |= HSUSB_LPSTS_SUSPM; 257 + writew(val, hsusb_base + HSUSB_LPSTS); 258 + } 259 + 260 + return 0; 261 + } 262 + 263 + static int rcar_gen3_phy_usb2_power_off(struct phy *p) 264 + { 265 + struct rcar_gen3_chan *channel = phy_get_drvdata(p); 266 + void __iomem *hsusb_base = channel->hsusb.base; 267 + u32 val; 268 + 269 + if (hsusb_base) { 270 + /* Power off HSUSB PHY */ 271 + val = readw(hsusb_base + HSUSB_LPSTS); 272 + val &= ~HSUSB_LPSTS_SUSPM; 273 + writew(val, hsusb_base + HSUSB_LPSTS); 274 + } 275 + 276 + return 0; 277 + } 278 + 279 + static struct phy_ops rcar_gen3_phy_usb2_ops = { 280 + .init = rcar_gen3_phy_usb2_init, 281 + .exit = rcar_gen3_phy_usb2_exit, 282 + .power_on = rcar_gen3_phy_usb2_power_on, 283 + .power_off = rcar_gen3_phy_usb2_power_off, 284 + .owner = THIS_MODULE, 285 + }; 286 + 287 + static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch) 288 + { 289 + struct rcar_gen3_chan *ch = _ch; 290 + void __iomem *usb2_base = ch->usb2.base; 291 + u32 status = readl(usb2_base + USB2_OBINTSTA); 292 + irqreturn_t ret = IRQ_NONE; 293 + 294 + if (status & USB2_OBINT_BITS) { 295 + dev_vdbg(&ch->phy->dev, "%s: %08x\n", __func__, status); 296 + writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA); 297 + rcar_gen3_device_recognition(ch); 298 + ret = IRQ_HANDLED; 299 + } 300 + 301 + return ret; 302 + } 303 + 304 + static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = { 305 + { .compatible = "renesas,usb2-phy-r8a7795" }, 306 + { } 307 + }; 308 + MODULE_DEVICE_TABLE(of, rcar_gen3_phy_usb2_match_table); 309 + 310 + static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) 311 + { 312 + struct device *dev = &pdev->dev; 313 + struct rcar_gen3_chan *channel; 314 + struct phy_provider *provider; 315 + struct resource *res; 316 + 317 + if (!dev->of_node) { 318 + dev_err(dev, "This driver needs device tree\n"); 319 + return -EINVAL; 320 + } 321 + 322 + channel = devm_kzalloc(dev, sizeof(*channel), GFP_KERNEL); 323 + if (!channel) 324 + return -ENOMEM; 325 + 326 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "usb2_host"); 327 + channel->usb2.base = devm_ioremap_resource(dev, res); 328 + if (IS_ERR(channel->usb2.base)) 329 + return PTR_ERR(channel->usb2.base); 330 + 331 + /* "hsusb" memory resource is optional */ 332 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hsusb"); 333 + 334 + /* To avoid error message by devm_ioremap_resource() */ 335 + if (res) { 336 + int irq; 337 + 338 + channel->hsusb.base = devm_ioremap_resource(dev, res); 339 + if (IS_ERR(channel->hsusb.base)) 340 + channel->hsusb.base = NULL; 341 + /* call request_irq for OTG */ 342 + irq = platform_get_irq(pdev, 0); 343 + if (irq >= 0) 344 + irq = devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq, 345 + IRQF_SHARED, dev_name(dev), 346 + channel); 347 + if (irq < 0) 348 + dev_err(dev, "No irq handler (%d)\n", irq); 349 + } 350 + 351 + /* devm_phy_create() will call pm_runtime_enable(dev); */ 352 + channel->phy = devm_phy_create(dev, NULL, &rcar_gen3_phy_usb2_ops); 353 + if (IS_ERR(channel->phy)) { 354 + dev_err(dev, "Failed to create USB2 PHY\n"); 355 + return PTR_ERR(channel->phy); 356 + } 357 + 358 + phy_set_drvdata(channel->phy, channel); 359 + 360 + provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 361 + if (IS_ERR(provider)) 362 + dev_err(dev, "Failed to register PHY provider\n"); 363 + 364 + return PTR_ERR_OR_ZERO(provider); 365 + } 366 + 367 + static struct platform_driver rcar_gen3_phy_usb2_driver = { 368 + .driver = { 369 + .name = "phy_rcar_gen3_usb2", 370 + .of_match_table = rcar_gen3_phy_usb2_match_table, 371 + }, 372 + .probe = rcar_gen3_phy_usb2_probe, 373 + }; 374 + module_platform_driver(rcar_gen3_phy_usb2_driver); 375 + 376 + MODULE_LICENSE("GPL v2"); 377 + MODULE_DESCRIPTION("Renesas R-Car Gen3 USB 2.0 PHY"); 378 + MODULE_AUTHOR("Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>");
+226 -63
drivers/phy/phy-rockchip-usb.c
··· 15 15 */ 16 16 17 17 #include <linux/clk.h> 18 + #include <linux/clk-provider.h> 18 19 #include <linux/io.h> 19 20 #include <linux/kernel.h> 20 21 #include <linux/module.h> 21 22 #include <linux/mutex.h> 22 23 #include <linux/of.h> 23 24 #include <linux/of_address.h> 25 + #include <linux/of_platform.h> 24 26 #include <linux/phy/phy.h> 25 27 #include <linux/platform_device.h> 26 28 #include <linux/regulator/consumer.h> ··· 38 36 #define SIDDQ_ON BIT(13) 39 37 #define SIDDQ_OFF (0 << 13) 40 38 39 + struct rockchip_usb_phys { 40 + int reg; 41 + const char *pll_name; 42 + }; 43 + 44 + struct rockchip_usb_phy_pdata { 45 + struct rockchip_usb_phys *phys; 46 + }; 47 + 48 + struct rockchip_usb_phy_base { 49 + struct device *dev; 50 + struct regmap *reg_base; 51 + const struct rockchip_usb_phy_pdata *pdata; 52 + }; 53 + 41 54 struct rockchip_usb_phy { 55 + struct rockchip_usb_phy_base *base; 56 + struct device_node *np; 42 57 unsigned int reg_offset; 43 - struct regmap *reg_base; 44 58 struct clk *clk; 59 + struct clk *clk480m; 60 + struct clk_hw clk480m_hw; 45 61 struct phy *phy; 46 62 }; 47 63 48 64 static int rockchip_usb_phy_power(struct rockchip_usb_phy *phy, 49 65 bool siddq) 50 66 { 51 - return regmap_write(phy->reg_base, phy->reg_offset, 67 + return regmap_write(phy->base->reg_base, phy->reg_offset, 52 68 SIDDQ_WRITE_ENA | (siddq ? SIDDQ_ON : SIDDQ_OFF)); 53 69 } 70 + 71 + static unsigned long rockchip_usb_phy480m_recalc_rate(struct clk_hw *hw, 72 + unsigned long parent_rate) 73 + { 74 + return 480000000; 75 + } 76 + 77 + static void rockchip_usb_phy480m_disable(struct clk_hw *hw) 78 + { 79 + struct rockchip_usb_phy *phy = container_of(hw, 80 + struct rockchip_usb_phy, 81 + clk480m_hw); 82 + 83 + /* Power down usb phy analog blocks by set siddq 1 */ 84 + rockchip_usb_phy_power(phy, 1); 85 + } 86 + 87 + static int rockchip_usb_phy480m_enable(struct clk_hw *hw) 88 + { 89 + struct rockchip_usb_phy *phy = container_of(hw, 90 + struct rockchip_usb_phy, 91 + clk480m_hw); 92 + 93 + /* Power up usb phy analog blocks by set siddq 0 */ 94 + return rockchip_usb_phy_power(phy, 0); 95 + } 96 + 97 + static int rockchip_usb_phy480m_is_enabled(struct clk_hw *hw) 98 + { 99 + struct rockchip_usb_phy *phy = container_of(hw, 100 + struct rockchip_usb_phy, 101 + clk480m_hw); 102 + int ret; 103 + u32 val; 104 + 105 + ret = regmap_read(phy->base->reg_base, phy->reg_offset, &val); 106 + if (ret < 0) 107 + return ret; 108 + 109 + return (val & SIDDQ_ON) ? 0 : 1; 110 + } 111 + 112 + static const struct clk_ops rockchip_usb_phy480m_ops = { 113 + .enable = rockchip_usb_phy480m_enable, 114 + .disable = rockchip_usb_phy480m_disable, 115 + .is_enabled = rockchip_usb_phy480m_is_enabled, 116 + .recalc_rate = rockchip_usb_phy480m_recalc_rate, 117 + }; 54 118 55 119 static int rockchip_usb_phy_power_off(struct phy *_phy) 56 120 { 57 121 struct rockchip_usb_phy *phy = phy_get_drvdata(_phy); 58 - int ret = 0; 59 122 60 - /* Power down usb phy analog blocks by set siddq 1 */ 61 - ret = rockchip_usb_phy_power(phy, 1); 62 - if (ret) 63 - return ret; 64 - 65 - clk_disable_unprepare(phy->clk); 123 + clk_disable_unprepare(phy->clk480m); 66 124 67 125 return 0; 68 126 } ··· 130 68 static int rockchip_usb_phy_power_on(struct phy *_phy) 131 69 { 132 70 struct rockchip_usb_phy *phy = phy_get_drvdata(_phy); 133 - int ret = 0; 134 71 135 - ret = clk_prepare_enable(phy->clk); 136 - if (ret) 137 - return ret; 138 - 139 - /* Power up usb phy analog blocks by set siddq 0 */ 140 - ret = rockchip_usb_phy_power(phy, 0); 141 - if (ret) { 142 - clk_disable_unprepare(phy->clk); 143 - return ret; 144 - } 145 - 146 - return 0; 72 + return clk_prepare_enable(phy->clk480m); 147 73 } 148 74 149 75 static const struct phy_ops ops = { ··· 140 90 .owner = THIS_MODULE, 141 91 }; 142 92 93 + static void rockchip_usb_phy_action(void *data) 94 + { 95 + struct rockchip_usb_phy *rk_phy = data; 96 + 97 + of_clk_del_provider(rk_phy->np); 98 + clk_unregister(rk_phy->clk480m); 99 + 100 + if (rk_phy->clk) 101 + clk_put(rk_phy->clk); 102 + } 103 + 104 + static int rockchip_usb_phy_init(struct rockchip_usb_phy_base *base, 105 + struct device_node *child) 106 + { 107 + struct rockchip_usb_phy *rk_phy; 108 + unsigned int reg_offset; 109 + const char *clk_name; 110 + struct clk_init_data init; 111 + int err, i; 112 + 113 + rk_phy = devm_kzalloc(base->dev, sizeof(*rk_phy), GFP_KERNEL); 114 + if (!rk_phy) 115 + return -ENOMEM; 116 + 117 + rk_phy->base = base; 118 + rk_phy->np = child; 119 + 120 + if (of_property_read_u32(child, "reg", &reg_offset)) { 121 + dev_err(base->dev, "missing reg property in node %s\n", 122 + child->name); 123 + return -EINVAL; 124 + } 125 + 126 + rk_phy->reg_offset = reg_offset; 127 + 128 + rk_phy->clk = of_clk_get_by_name(child, "phyclk"); 129 + if (IS_ERR(rk_phy->clk)) 130 + rk_phy->clk = NULL; 131 + 132 + i = 0; 133 + init.name = NULL; 134 + while (base->pdata->phys[i].reg) { 135 + if (base->pdata->phys[i].reg == reg_offset) { 136 + init.name = base->pdata->phys[i].pll_name; 137 + break; 138 + } 139 + i++; 140 + } 141 + 142 + if (!init.name) { 143 + dev_err(base->dev, "phy data not found\n"); 144 + return -EINVAL; 145 + } 146 + 147 + if (rk_phy->clk) { 148 + clk_name = __clk_get_name(rk_phy->clk); 149 + init.flags = 0; 150 + init.parent_names = &clk_name; 151 + init.num_parents = 1; 152 + } else { 153 + init.flags = CLK_IS_ROOT; 154 + init.parent_names = NULL; 155 + init.num_parents = 0; 156 + } 157 + 158 + init.ops = &rockchip_usb_phy480m_ops; 159 + rk_phy->clk480m_hw.init = &init; 160 + 161 + rk_phy->clk480m = clk_register(base->dev, &rk_phy->clk480m_hw); 162 + if (IS_ERR(rk_phy->clk480m)) { 163 + err = PTR_ERR(rk_phy->clk480m); 164 + goto err_clk; 165 + } 166 + 167 + err = of_clk_add_provider(child, of_clk_src_simple_get, 168 + rk_phy->clk480m); 169 + if (err < 0) 170 + goto err_clk_prov; 171 + 172 + err = devm_add_action(base->dev, rockchip_usb_phy_action, rk_phy); 173 + if (err) 174 + goto err_devm_action; 175 + 176 + rk_phy->phy = devm_phy_create(base->dev, child, &ops); 177 + if (IS_ERR(rk_phy->phy)) { 178 + dev_err(base->dev, "failed to create PHY\n"); 179 + return PTR_ERR(rk_phy->phy); 180 + } 181 + phy_set_drvdata(rk_phy->phy, rk_phy); 182 + 183 + /* only power up usb phy when it use, so disable it when init*/ 184 + return rockchip_usb_phy_power(rk_phy, 1); 185 + 186 + err_devm_action: 187 + of_clk_del_provider(child); 188 + err_clk_prov: 189 + clk_unregister(rk_phy->clk480m); 190 + err_clk: 191 + if (rk_phy->clk) 192 + clk_put(rk_phy->clk); 193 + return err; 194 + } 195 + 196 + static const struct rockchip_usb_phy_pdata rk3066a_pdata = { 197 + .phys = (struct rockchip_usb_phys[]){ 198 + { .reg = 0x17c, .pll_name = "sclk_otgphy0_480m" }, 199 + { .reg = 0x188, .pll_name = "sclk_otgphy1_480m" }, 200 + { /* sentinel */ } 201 + }, 202 + }; 203 + 204 + static const struct rockchip_usb_phy_pdata rk3188_pdata = { 205 + .phys = (struct rockchip_usb_phys[]){ 206 + { .reg = 0x10c, .pll_name = "sclk_otgphy0_480m" }, 207 + { .reg = 0x11c, .pll_name = "sclk_otgphy1_480m" }, 208 + { /* sentinel */ } 209 + }, 210 + }; 211 + 212 + static const struct rockchip_usb_phy_pdata rk3288_pdata = { 213 + .phys = (struct rockchip_usb_phys[]){ 214 + { .reg = 0x320, .pll_name = "sclk_otgphy0_480m" }, 215 + { .reg = 0x334, .pll_name = "sclk_otgphy1_480m" }, 216 + { .reg = 0x348, .pll_name = "sclk_otgphy2_480m" }, 217 + { /* sentinel */ } 218 + }, 219 + }; 220 + 143 221 static int rockchip_usb_phy_probe(struct platform_device *pdev) 144 222 { 145 223 struct device *dev = &pdev->dev; 146 - struct rockchip_usb_phy *rk_phy; 224 + struct rockchip_usb_phy_base *phy_base; 147 225 struct phy_provider *phy_provider; 226 + const struct of_device_id *match; 148 227 struct device_node *child; 149 - struct regmap *grf; 150 - unsigned int reg_offset; 151 228 int err; 152 229 153 - grf = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,grf"); 154 - if (IS_ERR(grf)) { 230 + phy_base = devm_kzalloc(dev, sizeof(*phy_base), GFP_KERNEL); 231 + if (!phy_base) 232 + return -ENOMEM; 233 + 234 + match = of_match_device(dev->driver->of_match_table, dev); 235 + if (!match || !match->data) { 236 + dev_err(dev, "missing phy data\n"); 237 + return -EINVAL; 238 + } 239 + 240 + phy_base->pdata = match->data; 241 + 242 + phy_base->dev = dev; 243 + phy_base->reg_base = syscon_regmap_lookup_by_phandle(dev->of_node, 244 + "rockchip,grf"); 245 + if (IS_ERR(phy_base->reg_base)) { 155 246 dev_err(&pdev->dev, "Missing rockchip,grf property\n"); 156 - return PTR_ERR(grf); 247 + return PTR_ERR(phy_base->reg_base); 157 248 } 158 249 159 250 for_each_available_child_of_node(dev->of_node, child) { 160 - rk_phy = devm_kzalloc(dev, sizeof(*rk_phy), GFP_KERNEL); 161 - if (!rk_phy) { 162 - err = -ENOMEM; 163 - goto put_child; 251 + err = rockchip_usb_phy_init(phy_base, child); 252 + if (err) { 253 + of_node_put(child); 254 + return err; 164 255 } 165 - 166 - if (of_property_read_u32(child, "reg", &reg_offset)) { 167 - dev_err(dev, "missing reg property in node %s\n", 168 - child->name); 169 - err = -EINVAL; 170 - goto put_child; 171 - } 172 - 173 - rk_phy->reg_offset = reg_offset; 174 - rk_phy->reg_base = grf; 175 - 176 - rk_phy->clk = of_clk_get_by_name(child, "phyclk"); 177 - if (IS_ERR(rk_phy->clk)) 178 - rk_phy->clk = NULL; 179 - 180 - rk_phy->phy = devm_phy_create(dev, child, &ops); 181 - if (IS_ERR(rk_phy->phy)) { 182 - dev_err(dev, "failed to create PHY\n"); 183 - err = PTR_ERR(rk_phy->phy); 184 - goto put_child; 185 - } 186 - phy_set_drvdata(rk_phy->phy, rk_phy); 187 - 188 - /* only power up usb phy when it use, so disable it when init*/ 189 - err = rockchip_usb_phy_power(rk_phy, 1); 190 - if (err) 191 - goto put_child; 192 256 } 193 257 194 258 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 195 259 return PTR_ERR_OR_ZERO(phy_provider); 196 - put_child: 197 - of_node_put(child); 198 - return err; 199 260 } 200 261 201 262 static const struct of_device_id rockchip_usb_phy_dt_ids[] = { 202 - { .compatible = "rockchip,rk3288-usb-phy" }, 263 + { .compatible = "rockchip,rk3066a-usb-phy", .data = &rk3066a_pdata }, 264 + { .compatible = "rockchip,rk3188-usb-phy", .data = &rk3188_pdata }, 265 + { .compatible = "rockchip,rk3288-usb-phy", .data = &rk3288_pdata }, 203 266 {} 204 267 }; 205 268
+109 -49
drivers/phy/phy-sun4i-usb.c
··· 32 32 #include <linux/mutex.h> 33 33 #include <linux/of.h> 34 34 #include <linux/of_address.h> 35 + #include <linux/of_device.h> 35 36 #include <linux/of_gpio.h> 36 37 #include <linux/phy/phy.h> 37 38 #include <linux/phy/phy-sun4i-usb.h> ··· 47 46 #define REG_PHYBIST 0x08 48 47 #define REG_PHYTUNE 0x0c 49 48 #define REG_PHYCTL_A33 0x10 49 + #define REG_PHY_UNK_H3 0x20 50 + 51 + #define REG_PMU_UNK_H3 0x10 50 52 51 53 #define PHYCTL_DATA BIT(7) 52 54 ··· 83 79 #define PHY_DISCON_TH_SEL 0x2a 84 80 #define PHY_SQUELCH_DETECT 0x3c 85 81 86 - #define MAX_PHYS 3 82 + #define MAX_PHYS 4 87 83 88 84 /* 89 85 * Note do not raise the debounce time, we must report Vusb high within 100ms ··· 92 88 #define DEBOUNCE_TIME msecs_to_jiffies(50) 93 89 #define POLL_TIME msecs_to_jiffies(250) 94 90 91 + enum sun4i_usb_phy_type { 92 + sun4i_a10_phy, 93 + sun8i_a33_phy, 94 + sun8i_h3_phy, 95 + }; 96 + 97 + struct sun4i_usb_phy_cfg { 98 + int num_phys; 99 + enum sun4i_usb_phy_type type; 100 + u32 disc_thresh; 101 + u8 phyctl_offset; 102 + bool dedicated_clocks; 103 + }; 104 + 95 105 struct sun4i_usb_phy_data { 96 106 void __iomem *base; 107 + const struct sun4i_usb_phy_cfg *cfg; 97 108 struct mutex mutex; 98 - int num_phys; 99 - u32 disc_thresh; 100 - bool has_a33_phyctl; 101 109 struct sun4i_usb_phy { 102 110 struct phy *phy; 103 111 void __iomem *pmu; ··· 175 159 { 176 160 struct sun4i_usb_phy_data *phy_data = to_sun4i_usb_phy_data(phy); 177 161 u32 temp, usbc_bit = BIT(phy->index * 2); 178 - void *phyctl; 162 + void *phyctl = phy_data->base + phy_data->cfg->phyctl_offset; 179 163 int i; 180 164 181 165 mutex_lock(&phy_data->mutex); 182 166 183 - if (phy_data->has_a33_phyctl) { 184 - phyctl = phy_data->base + REG_PHYCTL_A33; 167 + if (phy_data->cfg->type == sun8i_a33_phy) { 185 168 /* A33 needs us to set phyctl to 0 explicitly */ 186 169 writel(0, phyctl); 187 - } else { 188 - phyctl = phy_data->base + REG_PHYCTL_A10; 189 170 } 190 171 191 172 for (i = 0; i < len; i++) { ··· 243 230 struct sun4i_usb_phy *phy = phy_get_drvdata(_phy); 244 231 struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy); 245 232 int ret; 233 + u32 val; 246 234 247 235 ret = clk_prepare_enable(phy->clk); 248 236 if (ret) ··· 255 241 return ret; 256 242 } 257 243 258 - /* Enable USB 45 Ohm resistor calibration */ 259 - if (phy->index == 0) 260 - sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1); 244 + if (data->cfg->type == sun8i_h3_phy) { 245 + if (phy->index == 0) { 246 + val = readl(data->base + REG_PHY_UNK_H3); 247 + writel(val & ~1, data->base + REG_PHY_UNK_H3); 248 + } 261 249 262 - /* Adjust PHY's magnitude and rate */ 263 - sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5); 250 + val = readl(phy->pmu + REG_PMU_UNK_H3); 251 + writel(val & ~2, phy->pmu + REG_PMU_UNK_H3); 252 + } else { 253 + /* Enable USB 45 Ohm resistor calibration */ 254 + if (phy->index == 0) 255 + sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1); 264 256 265 - /* Disconnect threshold adjustment */ 266 - sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL, data->disc_thresh, 2); 257 + /* Adjust PHY's magnitude and rate */ 258 + sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5); 259 + 260 + /* Disconnect threshold adjustment */ 261 + sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL, 262 + data->cfg->disc_thresh, 2); 263 + } 267 264 268 265 sun4i_usb_phy_passby(phy, 1); 269 266 ··· 501 476 { 502 477 struct sun4i_usb_phy_data *data = dev_get_drvdata(dev); 503 478 504 - if (args->args[0] >= data->num_phys) 479 + if (args->args[0] >= data->cfg->num_phys) 505 480 return ERR_PTR(-ENODEV); 506 481 507 482 return data->phys[args->args[0]].phy; ··· 536 511 struct device *dev = &pdev->dev; 537 512 struct device_node *np = dev->of_node; 538 513 struct phy_provider *phy_provider; 539 - bool dedicated_clocks; 540 514 struct resource *res; 541 515 int i, ret; 542 516 ··· 546 522 mutex_init(&data->mutex); 547 523 INIT_DELAYED_WORK(&data->detect, sun4i_usb_phy0_id_vbus_det_scan); 548 524 dev_set_drvdata(dev, data); 549 - 550 - if (of_device_is_compatible(np, "allwinner,sun5i-a13-usb-phy") || 551 - of_device_is_compatible(np, "allwinner,sun8i-a23-usb-phy") || 552 - of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy")) 553 - data->num_phys = 2; 554 - else 555 - data->num_phys = 3; 556 - 557 - if (of_device_is_compatible(np, "allwinner,sun5i-a13-usb-phy") || 558 - of_device_is_compatible(np, "allwinner,sun7i-a20-usb-phy")) 559 - data->disc_thresh = 2; 560 - else 561 - data->disc_thresh = 3; 562 - 563 - if (of_device_is_compatible(np, "allwinner,sun6i-a31-usb-phy") || 564 - of_device_is_compatible(np, "allwinner,sun8i-a23-usb-phy") || 565 - of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy")) 566 - dedicated_clocks = true; 567 - else 568 - dedicated_clocks = false; 569 - 570 - if (of_device_is_compatible(np, "allwinner,sun8i-a33-usb-phy")) 571 - data->has_a33_phyctl = true; 525 + data->cfg = of_device_get_match_data(dev); 526 + if (!data->cfg) 527 + return -EINVAL; 572 528 573 529 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy_ctrl"); 574 530 data->base = devm_ioremap_resource(dev, res); ··· 594 590 } 595 591 } 596 592 597 - for (i = 0; i < data->num_phys; i++) { 593 + for (i = 0; i < data->cfg->num_phys; i++) { 598 594 struct sun4i_usb_phy *phy = data->phys + i; 599 595 char name[16]; 600 596 ··· 606 602 phy->vbus = NULL; 607 603 } 608 604 609 - if (dedicated_clocks) 605 + if (data->cfg->dedicated_clocks) 610 606 snprintf(name, sizeof(name), "usb%d_phy", i); 611 607 else 612 608 strlcpy(name, "usb_phy", sizeof(name)); ··· 693 689 return 0; 694 690 } 695 691 692 + static const struct sun4i_usb_phy_cfg sun4i_a10_cfg = { 693 + .num_phys = 3, 694 + .type = sun4i_a10_phy, 695 + .disc_thresh = 3, 696 + .phyctl_offset = REG_PHYCTL_A10, 697 + .dedicated_clocks = false, 698 + }; 699 + 700 + static const struct sun4i_usb_phy_cfg sun5i_a13_cfg = { 701 + .num_phys = 2, 702 + .type = sun4i_a10_phy, 703 + .disc_thresh = 2, 704 + .phyctl_offset = REG_PHYCTL_A10, 705 + .dedicated_clocks = false, 706 + }; 707 + 708 + static const struct sun4i_usb_phy_cfg sun6i_a31_cfg = { 709 + .num_phys = 3, 710 + .type = sun4i_a10_phy, 711 + .disc_thresh = 3, 712 + .phyctl_offset = REG_PHYCTL_A10, 713 + .dedicated_clocks = true, 714 + }; 715 + 716 + static const struct sun4i_usb_phy_cfg sun7i_a20_cfg = { 717 + .num_phys = 3, 718 + .type = sun4i_a10_phy, 719 + .disc_thresh = 2, 720 + .phyctl_offset = REG_PHYCTL_A10, 721 + .dedicated_clocks = false, 722 + }; 723 + 724 + static const struct sun4i_usb_phy_cfg sun8i_a23_cfg = { 725 + .num_phys = 2, 726 + .type = sun4i_a10_phy, 727 + .disc_thresh = 3, 728 + .phyctl_offset = REG_PHYCTL_A10, 729 + .dedicated_clocks = true, 730 + }; 731 + 732 + static const struct sun4i_usb_phy_cfg sun8i_a33_cfg = { 733 + .num_phys = 2, 734 + .type = sun8i_a33_phy, 735 + .disc_thresh = 3, 736 + .phyctl_offset = REG_PHYCTL_A33, 737 + .dedicated_clocks = true, 738 + }; 739 + 740 + static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = { 741 + .num_phys = 4, 742 + .type = sun8i_h3_phy, 743 + .disc_thresh = 3, 744 + .dedicated_clocks = true, 745 + }; 746 + 696 747 static const struct of_device_id sun4i_usb_phy_of_match[] = { 697 - { .compatible = "allwinner,sun4i-a10-usb-phy" }, 698 - { .compatible = "allwinner,sun5i-a13-usb-phy" }, 699 - { .compatible = "allwinner,sun6i-a31-usb-phy" }, 700 - { .compatible = "allwinner,sun7i-a20-usb-phy" }, 701 - { .compatible = "allwinner,sun8i-a23-usb-phy" }, 702 - { .compatible = "allwinner,sun8i-a33-usb-phy" }, 748 + { .compatible = "allwinner,sun4i-a10-usb-phy", .data = &sun4i_a10_cfg }, 749 + { .compatible = "allwinner,sun5i-a13-usb-phy", .data = &sun5i_a13_cfg }, 750 + { .compatible = "allwinner,sun6i-a31-usb-phy", .data = &sun6i_a31_cfg }, 751 + { .compatible = "allwinner,sun7i-a20-usb-phy", .data = &sun7i_a20_cfg }, 752 + { .compatible = "allwinner,sun8i-a23-usb-phy", .data = &sun8i_a23_cfg }, 753 + { .compatible = "allwinner,sun8i-a33-usb-phy", .data = &sun8i_a33_cfg }, 754 + { .compatible = "allwinner,sun8i-h3-usb-phy", .data = &sun8i_h3_cfg }, 703 755 { }, 704 756 }; 705 757 MODULE_DEVICE_TABLE(of, sun4i_usb_phy_of_match);
+218 -86
drivers/phy/phy-ti-pipe3.c
··· 56 56 57 57 #define SATA_PLL_SOFT_RESET BIT(18) 58 58 59 + #define PIPE3_PHY_PWRCTL_CLK_CMD_MASK 0x003FC000 60 + #define PIPE3_PHY_PWRCTL_CLK_CMD_SHIFT 14 61 + 62 + #define PIPE3_PHY_PWRCTL_CLK_FREQ_MASK 0xFFC00000 63 + #define PIPE3_PHY_PWRCTL_CLK_FREQ_SHIFT 22 64 + 65 + #define PIPE3_PHY_TX_RX_POWERON 0x3 66 + #define PIPE3_PHY_TX_RX_POWEROFF 0x0 67 + 68 + #define PCIE_PCS_MASK 0xFF0000 69 + #define PCIE_PCS_DELAY_COUNT_SHIFT 0x10 70 + 59 71 /* 60 72 * This is an Empirical value that works, need to confirm the actual 61 73 * value required for the PIPE3PHY_PLL_CONFIGURATION2.PLL_IDLE status ··· 98 86 struct clk *refclk; 99 87 struct clk *div_clk; 100 88 struct pipe3_dpll_map *dpll_map; 89 + struct regmap *phy_power_syscon; /* ctrl. reg. acces */ 90 + struct regmap *pcs_syscon; /* ctrl. reg. acces */ 101 91 struct regmap *dpll_reset_syscon; /* ctrl. reg. acces */ 102 92 unsigned int dpll_reset_reg; /* reg. index within syscon */ 93 + unsigned int power_reg; /* power reg. index within syscon */ 94 + unsigned int pcie_pcs_reg; /* pcs reg. index in syscon */ 103 95 bool sata_refclk_enabled; 104 96 }; 105 97 ··· 160 144 161 145 static int ti_pipe3_power_off(struct phy *x) 162 146 { 147 + u32 val; 148 + int ret; 163 149 struct ti_pipe3 *phy = phy_get_drvdata(x); 164 150 165 - omap_control_phy_power(phy->control_dev, 0); 151 + if (!phy->phy_power_syscon) { 152 + omap_control_phy_power(phy->control_dev, 0); 153 + return 0; 154 + } 166 155 167 - return 0; 156 + val = PIPE3_PHY_TX_RX_POWEROFF << PIPE3_PHY_PWRCTL_CLK_CMD_SHIFT; 157 + 158 + ret = regmap_update_bits(phy->phy_power_syscon, phy->power_reg, 159 + PIPE3_PHY_PWRCTL_CLK_CMD_MASK, val); 160 + return ret; 168 161 } 169 162 170 163 static int ti_pipe3_power_on(struct phy *x) 171 164 { 165 + u32 val; 166 + u32 mask; 167 + int ret; 168 + unsigned long rate; 172 169 struct ti_pipe3 *phy = phy_get_drvdata(x); 173 170 174 - omap_control_phy_power(phy->control_dev, 1); 171 + if (!phy->phy_power_syscon) { 172 + omap_control_phy_power(phy->control_dev, 1); 173 + return 0; 174 + } 175 175 176 - return 0; 176 + rate = clk_get_rate(phy->sys_clk); 177 + if (!rate) { 178 + dev_err(phy->dev, "Invalid clock rate\n"); 179 + return -EINVAL; 180 + } 181 + rate = rate / 1000000; 182 + mask = OMAP_CTRL_PIPE3_PHY_PWRCTL_CLK_CMD_MASK | 183 + OMAP_CTRL_PIPE3_PHY_PWRCTL_CLK_FREQ_MASK; 184 + val = PIPE3_PHY_TX_RX_POWERON << PIPE3_PHY_PWRCTL_CLK_CMD_SHIFT; 185 + val |= rate << OMAP_CTRL_PIPE3_PHY_PWRCTL_CLK_FREQ_SHIFT; 186 + 187 + ret = regmap_update_bits(phy->phy_power_syscon, phy->power_reg, 188 + mask, val); 189 + return ret; 177 190 } 178 191 179 192 static int ti_pipe3_dpll_wait_lock(struct ti_pipe3 *phy) ··· 274 229 * 18-1804. 275 230 */ 276 231 if (of_device_is_compatible(phy->dev->of_node, "ti,phy-pipe3-pcie")) { 277 - omap_control_pcie_pcs(phy->control_dev, 0x96); 278 - return 0; 232 + if (!phy->pcs_syscon) { 233 + omap_control_pcie_pcs(phy->control_dev, 0x96); 234 + return 0; 235 + } 236 + 237 + val = 0x96 << OMAP_CTRL_PCIE_PCS_DELAY_COUNT_SHIFT; 238 + ret = regmap_update_bits(phy->pcs_syscon, phy->pcie_pcs_reg, 239 + PCIE_PCS_MASK, val); 240 + return ret; 279 241 } 280 242 281 243 /* Bring it out of IDLE if it is IDLE */ ··· 360 308 361 309 static const struct of_device_id ti_pipe3_id_table[]; 362 310 363 - static int ti_pipe3_probe(struct platform_device *pdev) 311 + static int ti_pipe3_get_clk(struct ti_pipe3 *phy) 364 312 { 365 - struct ti_pipe3 *phy; 366 - struct phy *generic_phy; 367 - struct phy_provider *phy_provider; 368 - struct resource *res; 369 - struct device_node *node = pdev->dev.of_node; 370 - struct device_node *control_node; 371 - struct platform_device *control_pdev; 372 - const struct of_device_id *match; 373 313 struct clk *clk; 314 + struct device *dev = phy->dev; 315 + struct device_node *node = dev->of_node; 374 316 375 - phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL); 376 - if (!phy) 377 - return -ENOMEM; 378 - 379 - phy->dev = &pdev->dev; 380 - 381 - if (!of_device_is_compatible(node, "ti,phy-pipe3-pcie")) { 382 - match = of_match_device(ti_pipe3_id_table, &pdev->dev); 383 - if (!match) 384 - return -EINVAL; 385 - 386 - phy->dpll_map = (struct pipe3_dpll_map *)match->data; 387 - if (!phy->dpll_map) { 388 - dev_err(&pdev->dev, "no DPLL data\n"); 389 - return -EINVAL; 390 - } 391 - 392 - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 393 - "pll_ctrl"); 394 - phy->pll_ctrl_base = devm_ioremap_resource(&pdev->dev, res); 395 - if (IS_ERR(phy->pll_ctrl_base)) 396 - return PTR_ERR(phy->pll_ctrl_base); 397 - 398 - phy->sys_clk = devm_clk_get(phy->dev, "sysclk"); 399 - if (IS_ERR(phy->sys_clk)) { 400 - dev_err(&pdev->dev, "unable to get sysclk\n"); 401 - return -EINVAL; 402 - } 403 - } 404 - 405 - phy->refclk = devm_clk_get(phy->dev, "refclk"); 317 + phy->refclk = devm_clk_get(dev, "refclk"); 406 318 if (IS_ERR(phy->refclk)) { 407 - dev_err(&pdev->dev, "unable to get refclk\n"); 319 + dev_err(dev, "unable to get refclk\n"); 408 320 /* older DTBs have missing refclk in SATA PHY 409 321 * so don't bail out in case of SATA PHY. 410 322 */ ··· 377 361 } 378 362 379 363 if (!of_device_is_compatible(node, "ti,phy-pipe3-sata")) { 380 - phy->wkupclk = devm_clk_get(phy->dev, "wkupclk"); 364 + phy->wkupclk = devm_clk_get(dev, "wkupclk"); 381 365 if (IS_ERR(phy->wkupclk)) { 382 - dev_err(&pdev->dev, "unable to get wkupclk\n"); 366 + dev_err(dev, "unable to get wkupclk\n"); 383 367 return PTR_ERR(phy->wkupclk); 384 368 } 385 369 } else { 386 370 phy->wkupclk = ERR_PTR(-ENODEV); 387 - phy->dpll_reset_syscon = syscon_regmap_lookup_by_phandle(node, 388 - "syscon-pllreset"); 389 - if (IS_ERR(phy->dpll_reset_syscon)) { 390 - dev_info(&pdev->dev, 391 - "can't get syscon-pllreset, sata dpll won't idle\n"); 392 - phy->dpll_reset_syscon = NULL; 393 - } else { 394 - if (of_property_read_u32_index(node, 395 - "syscon-pllreset", 1, 396 - &phy->dpll_reset_reg)) { 397 - dev_err(&pdev->dev, 398 - "couldn't get pllreset reg. offset\n"); 399 - return -EINVAL; 400 - } 371 + } 372 + 373 + if (!of_device_is_compatible(node, "ti,phy-pipe3-pcie") || 374 + phy->phy_power_syscon) { 375 + phy->sys_clk = devm_clk_get(dev, "sysclk"); 376 + if (IS_ERR(phy->sys_clk)) { 377 + dev_err(dev, "unable to get sysclk\n"); 378 + return -EINVAL; 401 379 } 402 380 } 403 381 404 382 if (of_device_is_compatible(node, "ti,phy-pipe3-pcie")) { 405 - 406 - clk = devm_clk_get(phy->dev, "dpll_ref"); 383 + clk = devm_clk_get(dev, "dpll_ref"); 407 384 if (IS_ERR(clk)) { 408 - dev_err(&pdev->dev, "unable to get dpll ref clk\n"); 385 + dev_err(dev, "unable to get dpll ref clk\n"); 409 386 return PTR_ERR(clk); 410 387 } 411 388 clk_set_rate(clk, 1500000000); 412 389 413 - clk = devm_clk_get(phy->dev, "dpll_ref_m2"); 390 + clk = devm_clk_get(dev, "dpll_ref_m2"); 414 391 if (IS_ERR(clk)) { 415 - dev_err(&pdev->dev, "unable to get dpll ref m2 clk\n"); 392 + dev_err(dev, "unable to get dpll ref m2 clk\n"); 416 393 return PTR_ERR(clk); 417 394 } 418 395 clk_set_rate(clk, 100000000); 419 396 420 - clk = devm_clk_get(phy->dev, "phy-div"); 397 + clk = devm_clk_get(dev, "phy-div"); 421 398 if (IS_ERR(clk)) { 422 - dev_err(&pdev->dev, "unable to get phy-div clk\n"); 399 + dev_err(dev, "unable to get phy-div clk\n"); 423 400 return PTR_ERR(clk); 424 401 } 425 402 clk_set_rate(clk, 100000000); 426 403 427 - phy->div_clk = devm_clk_get(phy->dev, "div-clk"); 404 + phy->div_clk = devm_clk_get(dev, "div-clk"); 428 405 if (IS_ERR(phy->div_clk)) { 429 - dev_err(&pdev->dev, "unable to get div-clk\n"); 406 + dev_err(dev, "unable to get div-clk\n"); 430 407 return PTR_ERR(phy->div_clk); 431 408 } 432 409 } else { 433 410 phy->div_clk = ERR_PTR(-ENODEV); 434 411 } 435 412 436 - control_node = of_parse_phandle(node, "ctrl-module", 0); 437 - if (!control_node) { 438 - dev_err(&pdev->dev, "Failed to get control device phandle\n"); 413 + return 0; 414 + } 415 + 416 + static int ti_pipe3_get_sysctrl(struct ti_pipe3 *phy) 417 + { 418 + struct device *dev = phy->dev; 419 + struct device_node *node = dev->of_node; 420 + struct device_node *control_node; 421 + struct platform_device *control_pdev; 422 + 423 + phy->phy_power_syscon = syscon_regmap_lookup_by_phandle(node, 424 + "syscon-phy-power"); 425 + if (IS_ERR(phy->phy_power_syscon)) { 426 + dev_dbg(dev, 427 + "can't get syscon-phy-power, using control device\n"); 428 + phy->phy_power_syscon = NULL; 429 + } else { 430 + if (of_property_read_u32_index(node, 431 + "syscon-phy-power", 1, 432 + &phy->power_reg)) { 433 + dev_err(dev, "couldn't get power reg. offset\n"); 434 + return -EINVAL; 435 + } 436 + } 437 + 438 + if (!phy->phy_power_syscon) { 439 + control_node = of_parse_phandle(node, "ctrl-module", 0); 440 + if (!control_node) { 441 + dev_err(dev, "Failed to get control device phandle\n"); 442 + return -EINVAL; 443 + } 444 + 445 + control_pdev = of_find_device_by_node(control_node); 446 + if (!control_pdev) { 447 + dev_err(dev, "Failed to get control device\n"); 448 + return -EINVAL; 449 + } 450 + 451 + phy->control_dev = &control_pdev->dev; 452 + } 453 + 454 + if (of_device_is_compatible(node, "ti,phy-pipe3-pcie")) { 455 + phy->pcs_syscon = syscon_regmap_lookup_by_phandle(node, 456 + "syscon-pcs"); 457 + if (IS_ERR(phy->pcs_syscon)) { 458 + dev_dbg(dev, 459 + "can't get syscon-pcs, using omap control\n"); 460 + phy->pcs_syscon = NULL; 461 + } else { 462 + if (of_property_read_u32_index(node, 463 + "syscon-pcs", 1, 464 + &phy->pcie_pcs_reg)) { 465 + dev_err(dev, 466 + "couldn't get pcie pcs reg. offset\n"); 467 + return -EINVAL; 468 + } 469 + } 470 + } 471 + 472 + if (of_device_is_compatible(node, "ti,phy-pipe3-sata")) { 473 + phy->dpll_reset_syscon = syscon_regmap_lookup_by_phandle(node, 474 + "syscon-pllreset"); 475 + if (IS_ERR(phy->dpll_reset_syscon)) { 476 + dev_info(dev, 477 + "can't get syscon-pllreset, sata dpll won't idle\n"); 478 + phy->dpll_reset_syscon = NULL; 479 + } else { 480 + if (of_property_read_u32_index(node, 481 + "syscon-pllreset", 1, 482 + &phy->dpll_reset_reg)) { 483 + dev_err(dev, 484 + "couldn't get pllreset reg. offset\n"); 485 + return -EINVAL; 486 + } 487 + } 488 + } 489 + 490 + return 0; 491 + } 492 + 493 + static int ti_pipe3_get_pll_base(struct ti_pipe3 *phy) 494 + { 495 + struct resource *res; 496 + const struct of_device_id *match; 497 + struct device *dev = phy->dev; 498 + struct device_node *node = dev->of_node; 499 + struct platform_device *pdev = to_platform_device(dev); 500 + 501 + if (of_device_is_compatible(node, "ti,phy-pipe3-pcie")) 502 + return 0; 503 + 504 + match = of_match_device(ti_pipe3_id_table, dev); 505 + if (!match) 506 + return -EINVAL; 507 + 508 + phy->dpll_map = (struct pipe3_dpll_map *)match->data; 509 + if (!phy->dpll_map) { 510 + dev_err(dev, "no DPLL data\n"); 439 511 return -EINVAL; 440 512 } 441 513 442 - control_pdev = of_find_device_by_node(control_node); 443 - if (!control_pdev) { 444 - dev_err(&pdev->dev, "Failed to get control device\n"); 445 - return -EINVAL; 446 - } 514 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 515 + "pll_ctrl"); 516 + phy->pll_ctrl_base = devm_ioremap_resource(dev, res); 517 + if (IS_ERR(phy->pll_ctrl_base)) 518 + return PTR_ERR(phy->pll_ctrl_base); 447 519 448 - phy->control_dev = &control_pdev->dev; 520 + return 0; 521 + } 449 522 450 - omap_control_phy_power(phy->control_dev, 0); 523 + static int ti_pipe3_probe(struct platform_device *pdev) 524 + { 525 + struct ti_pipe3 *phy; 526 + struct phy *generic_phy; 527 + struct phy_provider *phy_provider; 528 + struct device_node *node = pdev->dev.of_node; 529 + struct device *dev = &pdev->dev; 530 + int ret; 531 + 532 + phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL); 533 + if (!phy) 534 + return -ENOMEM; 535 + 536 + phy->dev = dev; 537 + 538 + ret = ti_pipe3_get_pll_base(phy); 539 + if (ret) 540 + return ret; 541 + 542 + ret = ti_pipe3_get_sysctrl(phy); 543 + if (ret) 544 + return ret; 545 + 546 + ret = ti_pipe3_get_clk(phy); 547 + if (ret) 548 + return ret; 451 549 452 550 platform_set_drvdata(pdev, phy); 453 - pm_runtime_enable(phy->dev); 551 + pm_runtime_enable(dev); 454 552 455 553 /* 456 554 * Prevent auto-disable of refclk for SATA PHY due to Errata i783 ··· 576 446 } 577 447 } 578 448 579 - generic_phy = devm_phy_create(phy->dev, NULL, &ops); 449 + generic_phy = devm_phy_create(dev, NULL, &ops); 580 450 if (IS_ERR(generic_phy)) 581 451 return PTR_ERR(generic_phy); 582 452 583 453 phy_set_drvdata(generic_phy, phy); 584 - phy_provider = devm_of_phy_provider_register(phy->dev, 585 - of_phy_simple_xlate); 454 + 455 + ti_pipe3_power_off(generic_phy); 456 + 457 + phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 586 458 if (IS_ERR(phy_provider)) 587 459 return PTR_ERR(phy_provider); 588 460
+16 -16
drivers/phy/phy-twl4030-usb.c
··· 34 34 #include <linux/usb/otg.h> 35 35 #include <linux/phy/phy.h> 36 36 #include <linux/pm_runtime.h> 37 - #include <linux/usb/musb-omap.h> 37 + #include <linux/usb/musb.h> 38 38 #include <linux/usb/ulpi.h> 39 39 #include <linux/i2c/twl.h> 40 40 #include <linux/regulator/consumer.h> ··· 148 148 * If VBUS is valid or ID is ground, then we know a 149 149 * cable is present and we need to be runtime-enabled 150 150 */ 151 - static inline bool cable_present(enum omap_musb_vbus_id_status stat) 151 + static inline bool cable_present(enum musb_vbus_id_status stat) 152 152 { 153 - return stat == OMAP_MUSB_VBUS_VALID || 154 - stat == OMAP_MUSB_ID_GROUND; 153 + return stat == MUSB_VBUS_VALID || 154 + stat == MUSB_ID_GROUND; 155 155 } 156 156 157 157 struct twl4030_usb { ··· 170 170 enum twl4030_usb_mode usb_mode; 171 171 172 172 int irq; 173 - enum omap_musb_vbus_id_status linkstat; 173 + enum musb_vbus_id_status linkstat; 174 174 bool vbus_supplied; 175 175 176 176 struct delayed_work id_workaround_work; ··· 276 276 return (ret & (ULPI_OTG_DRVVBUS | ULPI_OTG_CHRGVBUS)) ? true : false; 277 277 } 278 278 279 - static enum omap_musb_vbus_id_status 279 + static enum musb_vbus_id_status 280 280 twl4030_usb_linkstat(struct twl4030_usb *twl) 281 281 { 282 282 int status; 283 - enum omap_musb_vbus_id_status linkstat = OMAP_MUSB_UNKNOWN; 283 + enum musb_vbus_id_status linkstat = MUSB_UNKNOWN; 284 284 285 285 twl->vbus_supplied = false; 286 286 ··· 306 306 } 307 307 308 308 if (status & BIT(2)) 309 - linkstat = OMAP_MUSB_ID_GROUND; 309 + linkstat = MUSB_ID_GROUND; 310 310 else if (status & BIT(7)) 311 - linkstat = OMAP_MUSB_VBUS_VALID; 311 + linkstat = MUSB_VBUS_VALID; 312 312 else 313 - linkstat = OMAP_MUSB_VBUS_OFF; 313 + linkstat = MUSB_VBUS_OFF; 314 314 } else { 315 - if (twl->linkstat != OMAP_MUSB_UNKNOWN) 316 - linkstat = OMAP_MUSB_VBUS_OFF; 315 + if (twl->linkstat != MUSB_UNKNOWN) 316 + linkstat = MUSB_VBUS_OFF; 317 317 } 318 318 319 319 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n", ··· 535 535 static irqreturn_t twl4030_usb_irq(int irq, void *_twl) 536 536 { 537 537 struct twl4030_usb *twl = _twl; 538 - enum omap_musb_vbus_id_status status; 538 + enum musb_vbus_id_status status; 539 539 bool status_changed = false; 540 540 541 541 status = twl4030_usb_linkstat(twl); ··· 567 567 pm_runtime_mark_last_busy(twl->dev); 568 568 pm_runtime_put_autosuspend(twl->dev); 569 569 } 570 - omap_musb_mailbox(status); 570 + musb_mailbox(status); 571 571 } 572 572 573 573 /* don't schedule during sleep - irq works right then */ 574 - if (status == OMAP_MUSB_ID_GROUND && pm_runtime_active(twl->dev)) { 574 + if (status == MUSB_ID_GROUND && pm_runtime_active(twl->dev)) { 575 575 cancel_delayed_work(&twl->id_workaround_work); 576 576 schedule_delayed_work(&twl->id_workaround_work, HZ); 577 577 } ··· 670 670 twl->dev = &pdev->dev; 671 671 twl->irq = platform_get_irq(pdev, 0); 672 672 twl->vbus_supplied = false; 673 - twl->linkstat = OMAP_MUSB_UNKNOWN; 673 + twl->linkstat = MUSB_UNKNOWN; 674 674 675 675 twl->phy.dev = twl->dev; 676 676 twl->phy.label = "twl4030";
-5
drivers/usb/chipidea/Kconfig
··· 37 37 Say Y here to enable host controller functionality of the 38 38 ChipIdea driver. 39 39 40 - config USB_CHIPIDEA_DEBUG 41 - bool "ChipIdea driver debug" 42 - help 43 - Say Y here to enable debugging output of the ChipIdea driver. 44 - 45 40 endif
+1 -4
drivers/usb/chipidea/Makefile
··· 1 - ccflags-$(CONFIG_USB_CHIPIDEA_DEBUG) := -DDEBUG 2 - 3 1 obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc.o 4 2 5 - ci_hdrc-y := core.o otg.o 3 + ci_hdrc-y := core.o otg.o debug.o 6 4 ci_hdrc-$(CONFIG_USB_CHIPIDEA_UDC) += udc.o 7 5 ci_hdrc-$(CONFIG_USB_CHIPIDEA_HOST) += host.o 8 - ci_hdrc-$(CONFIG_USB_CHIPIDEA_DEBUG) += debug.o 9 6 ci_hdrc-$(CONFIG_USB_OTG_FSM) += otg_fsm.o 10 7 11 8 # Glue/Bridge layers go here
+3
drivers/usb/chipidea/ci.h
··· 433 433 434 434 void ci_platform_configure(struct ci_hdrc *ci); 435 435 436 + int dbg_create_files(struct ci_hdrc *ci); 437 + 438 + void dbg_remove_files(struct ci_hdrc *ci); 436 439 #endif /* __DRIVERS_USB_CHIPIDEA_CI_H */
+6
drivers/usb/chipidea/ci_hdrc_imx.c
··· 345 345 return 0; 346 346 } 347 347 348 + static void ci_hdrc_imx_shutdown(struct platform_device *pdev) 349 + { 350 + ci_hdrc_imx_remove(pdev); 351 + } 352 + 348 353 #ifdef CONFIG_PM 349 354 static int imx_controller_suspend(struct device *dev) 350 355 { ··· 467 462 static struct platform_driver ci_hdrc_imx_driver = { 468 463 .probe = ci_hdrc_imx_probe, 469 464 .remove = ci_hdrc_imx_remove, 465 + .shutdown = ci_hdrc_imx_shutdown, 470 466 .driver = { 471 467 .name = "imx_usb", 472 468 .of_match_table = ci_hdrc_imx_dt_ids,
+2 -1
drivers/usb/chipidea/ci_hdrc_msm.c
··· 25 25 case CI_HDRC_CONTROLLER_RESET_EVENT: 26 26 dev_dbg(dev, "CI_HDRC_CONTROLLER_RESET_EVENT received\n"); 27 27 writel(0, USB_AHBBURST); 28 - writel(0, USB_AHBMODE); 28 + /* use AHB transactor, allow posted data writes */ 29 + writel(0x8, USB_AHBMODE); 29 30 usb_phy_init(ci->usb_phy); 30 31 break; 31 32 case CI_HDRC_CONTROLLER_STOPPED_EVENT:
+22 -37
drivers/usb/chipidea/core.c
··· 23 23 * - BUS: bus glue code, bus abstraction layer 24 24 * 25 25 * Compile Options 26 - * - CONFIG_USB_CHIPIDEA_DEBUG: enable debug facilities 27 26 * - STALL_IN: non-empty bulk-in pipes cannot be halted 28 27 * if defined mass storage compliance succeeds but with warnings 29 28 * => case 4: Hi > Dn ··· 70 71 #include "udc.h" 71 72 #include "bits.h" 72 73 #include "host.h" 73 - #include "debug.h" 74 74 #include "otg.h" 75 75 #include "otg_fsm.h" 76 76 ··· 686 688 if (usb_get_maximum_speed(dev) == USB_SPEED_FULL) 687 689 platdata->flags |= CI_HDRC_FORCE_FULLSPEED; 688 690 689 - if (of_find_property(dev->of_node, "phy-clkgate-delay-us", NULL)) 690 - of_property_read_u32(dev->of_node, "phy-clkgate-delay-us", 691 + of_property_read_u32(dev->of_node, "phy-clkgate-delay-us", 691 692 &platdata->phy_clkgate_delay_us); 692 693 693 694 platdata->itc_setting = 1; 694 - if (of_find_property(dev->of_node, "itc-setting", NULL)) { 695 - ret = of_property_read_u32(dev->of_node, "itc-setting", 696 - &platdata->itc_setting); 697 - if (ret) { 698 - dev_err(dev, 699 - "failed to get itc-setting\n"); 700 - return ret; 701 - } 702 - } 703 695 704 - if (of_find_property(dev->of_node, "ahb-burst-config", NULL)) { 705 - ret = of_property_read_u32(dev->of_node, "ahb-burst-config", 706 - &platdata->ahb_burst_config); 707 - if (ret) { 708 - dev_err(dev, 709 - "failed to get ahb-burst-config\n"); 710 - return ret; 711 - } 696 + of_property_read_u32(dev->of_node, "itc-setting", 697 + &platdata->itc_setting); 698 + 699 + ret = of_property_read_u32(dev->of_node, "ahb-burst-config", 700 + &platdata->ahb_burst_config); 701 + if (!ret) { 712 702 platdata->flags |= CI_HDRC_OVERRIDE_AHB_BURST; 703 + } else if (ret != -EINVAL) { 704 + dev_err(dev, "failed to get ahb-burst-config\n"); 705 + return ret; 713 706 } 714 707 715 - if (of_find_property(dev->of_node, "tx-burst-size-dword", NULL)) { 716 - ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword", 717 - &platdata->tx_burst_size); 718 - if (ret) { 719 - dev_err(dev, 720 - "failed to get tx-burst-size-dword\n"); 721 - return ret; 722 - } 708 + ret = of_property_read_u32(dev->of_node, "tx-burst-size-dword", 709 + &platdata->tx_burst_size); 710 + if (!ret) { 723 711 platdata->flags |= CI_HDRC_OVERRIDE_TX_BURST; 712 + } else if (ret != -EINVAL) { 713 + dev_err(dev, "failed to get tx-burst-size-dword\n"); 714 + return ret; 724 715 } 725 716 726 - if (of_find_property(dev->of_node, "rx-burst-size-dword", NULL)) { 727 - ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword", 728 - &platdata->rx_burst_size); 729 - if (ret) { 730 - dev_err(dev, 731 - "failed to get rx-burst-size-dword\n"); 732 - return ret; 733 - } 717 + ret = of_property_read_u32(dev->of_node, "rx-burst-size-dword", 718 + &platdata->rx_burst_size); 719 + if (!ret) { 734 720 platdata->flags |= CI_HDRC_OVERRIDE_RX_BURST; 721 + } else if (ret != -EINVAL) { 722 + dev_err(dev, "failed to get rx-burst-size-dword\n"); 723 + return ret; 735 724 } 736 725 737 726 ext_id = ERR_PTR(-ENODEV);
-1
drivers/usb/chipidea/debug.c
··· 15 15 #include "ci.h" 16 16 #include "udc.h" 17 17 #include "bits.h" 18 - #include "debug.h" 19 18 #include "otg.h" 20 19 21 20 /**
-30
drivers/usb/chipidea/debug.h
··· 1 - /* 2 - * debug.h - ChipIdea USB driver debug interfaces 3 - * 4 - * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved. 5 - * 6 - * Author: David Lopo 7 - * 8 - * This program is free software; you can redistribute it and/or modify 9 - * it under the terms of the GNU General Public License version 2 as 10 - * published by the Free Software Foundation. 11 - */ 12 - 13 - #ifndef __DRIVERS_USB_CHIPIDEA_DEBUG_H 14 - #define __DRIVERS_USB_CHIPIDEA_DEBUG_H 15 - 16 - #ifdef CONFIG_USB_CHIPIDEA_DEBUG 17 - int dbg_create_files(struct ci_hdrc *ci); 18 - void dbg_remove_files(struct ci_hdrc *ci); 19 - #else 20 - static inline int dbg_create_files(struct ci_hdrc *ci) 21 - { 22 - return 0; 23 - } 24 - 25 - static inline void dbg_remove_files(struct ci_hdrc *ci) 26 - { 27 - } 28 - #endif 29 - 30 - #endif /* __DRIVERS_USB_CHIPIDEA_DEBUG_H */
+2
drivers/usb/chipidea/host.c
··· 190 190 (ci->platdata->flags & CI_HDRC_TURN_VBUS_EARLY_ON)) 191 191 regulator_disable(ci->platdata->reg_vbus); 192 192 } 193 + ci->hcd = NULL; 194 + ci->otg.host = NULL; 193 195 } 194 196 195 197
+18 -8
drivers/usb/chipidea/otg_fsm.c
··· 485 485 486 486 /* 487 487 * Generate SOF by host. 488 - * This is controlled through suspend/resume the port. 489 488 * In host mode, controller will automatically send SOF. 490 489 * Suspend will block the data on the port. 490 + * 491 + * This is controlled through usbcore by usb autosuspend, 492 + * so the usb device class driver need support autosuspend, 493 + * otherwise the bus suspend will not happen. 491 494 */ 492 495 static void ci_otg_loc_sof(struct otg_fsm *fsm, int on) 493 496 { 494 - struct ci_hdrc *ci = container_of(fsm, struct ci_hdrc, fsm); 497 + struct usb_device *udev; 495 498 496 - if (on) 497 - hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_FPR, 498 - PORTSC_FPR); 499 - else 500 - hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_SUSP, 501 - PORTSC_SUSP); 499 + if (!fsm->otg->host) 500 + return; 501 + 502 + udev = usb_hub_find_child(fsm->otg->host->root_hub, 1); 503 + if (!udev) 504 + return; 505 + 506 + if (on) { 507 + usb_disable_autosuspend(udev); 508 + } else { 509 + pm_runtime_set_autosuspend_delay(&udev->dev, 0); 510 + usb_enable_autosuspend(udev); 511 + } 502 512 } 503 513 504 514 /*
+21 -10
drivers/usb/chipidea/udc.c
··· 26 26 #include "ci.h" 27 27 #include "udc.h" 28 28 #include "bits.h" 29 - #include "debug.h" 30 29 #include "otg.h" 31 30 #include "otg_fsm.h" 32 31 ··· 348 349 if (node == NULL) 349 350 return -ENOMEM; 350 351 351 - node->ptr = dma_pool_alloc(hwep->td_pool, GFP_ATOMIC, 352 + node->ptr = dma_pool_zalloc(hwep->td_pool, GFP_ATOMIC, 352 353 &node->dma); 353 354 if (node->ptr == NULL) { 354 355 kfree(node); 355 356 return -ENOMEM; 356 357 } 357 358 358 - memset(node->ptr, 0, sizeof(struct ci_hw_td)); 359 359 node->ptr->token = cpu_to_le32(length << __ffs(TD_TOTAL_BYTES)); 360 360 node->ptr->token &= cpu_to_le32(TD_TOTAL_BYTES); 361 361 node->ptr->token |= cpu_to_le32(TD_STATUS_ACTIVE); ··· 402 404 } 403 405 404 406 /** 405 - * _hardware_queue: configures a request at hardware level 406 - * @gadget: gadget 407 + * _hardware_enqueue: configures a request at hardware level 407 408 * @hwep: endpoint 409 + * @hwreq: request 408 410 * 409 411 * This function returns an error code 410 412 */ ··· 433 435 if (hwreq->req.dma % PAGE_SIZE) 434 436 pages--; 435 437 436 - if (rest == 0) 437 - add_td_to_list(hwep, hwreq, 0); 438 + if (rest == 0) { 439 + ret = add_td_to_list(hwep, hwreq, 0); 440 + if (ret < 0) 441 + goto done; 442 + } 438 443 439 444 while (rest > 0) { 440 445 unsigned count = min(hwreq->req.length - hwreq->req.actual, 441 446 (unsigned)(pages * CI_HDRC_PAGE_SIZE)); 442 - add_td_to_list(hwep, hwreq, count); 447 + ret = add_td_to_list(hwep, hwreq, count); 448 + if (ret < 0) 449 + goto done; 450 + 443 451 rest -= count; 444 452 } 445 453 446 454 if (hwreq->req.zero && hwreq->req.length && hwep->dir == TX 447 - && (hwreq->req.length % hwep->ep.maxpacket == 0)) 448 - add_td_to_list(hwep, hwreq, 0); 455 + && (hwreq->req.length % hwep->ep.maxpacket == 0)) { 456 + ret = add_td_to_list(hwep, hwreq, 0); 457 + if (ret < 0) 458 + goto done; 459 + } 449 460 450 461 firstnode = list_first_entry(&hwreq->tds, struct td_node, td); 451 462 ··· 795 788 796 789 /** 797 790 * _ep_queue: queues (submits) an I/O request to an endpoint 791 + * @ep: endpoint 792 + * @req: request 793 + * @gfp_flags: GFP flags (not used) 798 794 * 799 795 * Caller must hold lock 796 + * This function returns an error code 800 797 */ 801 798 static int _ep_queue(struct usb_ep *ep, struct usb_request *req, 802 799 gfp_t __maybe_unused gfp_flags)
+54 -6
drivers/usb/common/common.c
··· 17 17 #include <linux/usb/ch9.h> 18 18 #include <linux/usb/of.h> 19 19 #include <linux/usb/otg.h> 20 + #include <linux/of_platform.h> 20 21 21 22 const char *usb_otg_state_string(enum usb_otg_state state) 22 23 { ··· 107 106 [USB_DR_MODE_OTG] = "otg", 108 107 }; 109 108 109 + static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str) 110 + { 111 + int i; 112 + 113 + for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++) 114 + if (!strcmp(usb_dr_modes[i], str)) 115 + return i; 116 + 117 + return USB_DR_MODE_UNKNOWN; 118 + } 119 + 110 120 enum usb_dr_mode usb_get_dr_mode(struct device *dev) 111 121 { 112 122 const char *dr_mode; 113 - int err, i; 123 + int err; 114 124 115 125 err = device_property_read_string(dev, "dr_mode", &dr_mode); 116 126 if (err < 0) 117 127 return USB_DR_MODE_UNKNOWN; 118 128 119 - for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++) 120 - if (!strcmp(dr_mode, usb_dr_modes[i])) 121 - return i; 122 - 123 - return USB_DR_MODE_UNKNOWN; 129 + return usb_get_dr_mode_from_string(dr_mode); 124 130 } 125 131 EXPORT_SYMBOL_GPL(usb_get_dr_mode); 126 132 127 133 #ifdef CONFIG_OF 134 + /** 135 + * of_usb_get_dr_mode_by_phy - Get dual role mode for the controller device 136 + * which is associated with the given phy device_node 137 + * @np: Pointer to the given phy device_node 138 + * 139 + * In dts a usb controller associates with phy devices. The function gets 140 + * the string from property 'dr_mode' of the controller associated with the 141 + * given phy device node, and returns the correspondig enum usb_dr_mode. 142 + */ 143 + enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np) 144 + { 145 + struct device_node *controller = NULL; 146 + struct device_node *phy; 147 + const char *dr_mode; 148 + int index; 149 + int err; 150 + 151 + do { 152 + controller = of_find_node_with_property(controller, "phys"); 153 + index = 0; 154 + do { 155 + phy = of_parse_phandle(controller, "phys", index); 156 + of_node_put(phy); 157 + if (phy == phy_np) 158 + goto finish; 159 + index++; 160 + } while (phy); 161 + } while (controller); 162 + 163 + finish: 164 + err = of_property_read_string(controller, "dr_mode", &dr_mode); 165 + of_node_put(controller); 166 + 167 + if (err < 0) 168 + return USB_DR_MODE_UNKNOWN; 169 + 170 + return usb_get_dr_mode_from_string(dr_mode); 171 + } 172 + EXPORT_SYMBOL_GPL(of_usb_get_dr_mode_by_phy); 173 + 128 174 /** 129 175 * of_usb_host_tpl_support - to get if Targeted Peripheral List is supported 130 176 * for given targeted hosts (non-PC hosts)
+21 -4
drivers/usb/core/devio.c
··· 100 100 module_param(usbfs_snoop, bool, S_IRUGO | S_IWUSR); 101 101 MODULE_PARM_DESC(usbfs_snoop, "true to log all usbfs traffic"); 102 102 103 + static unsigned usbfs_snoop_max = 65536; 104 + module_param(usbfs_snoop_max, uint, S_IRUGO | S_IWUSR); 105 + MODULE_PARM_DESC(usbfs_snoop_max, 106 + "maximum number of bytes to print while snooping"); 107 + 103 108 #define snoop(dev, format, arg...) \ 104 109 do { \ 105 110 if (usbfs_snoop) \ ··· 373 368 ep, t, d, length, timeout_or_status); 374 369 } 375 370 371 + data_len = min(data_len, usbfs_snoop_max); 376 372 if (data && data_len > 0) { 377 373 print_hex_dump(KERN_DEBUG, "data: ", DUMP_PREFIX_NONE, 32, 1, 378 374 data, data_len, 1); ··· 384 378 { 385 379 int i, size; 386 380 387 - if (!usbfs_snoop) 381 + len = min(len, usbfs_snoop_max); 382 + if (!usbfs_snoop || len == 0) 388 383 return; 389 384 390 385 if (urb->num_sgs == 0) { ··· 1692 1685 static int proc_reapurb(struct usb_dev_state *ps, void __user *arg) 1693 1686 { 1694 1687 struct async *as = reap_as(ps); 1688 + 1695 1689 if (as) { 1696 - int retval = processcompl(as, (void __user * __user *)arg); 1690 + int retval; 1691 + 1692 + snoop(&ps->dev->dev, "reap %p\n", as->userurb); 1693 + retval = processcompl(as, (void __user * __user *)arg); 1697 1694 free_async(as); 1698 1695 return retval; 1699 1696 } ··· 1713 1702 1714 1703 as = async_getcompleted(ps); 1715 1704 if (as) { 1705 + snoop(&ps->dev->dev, "reap %p\n", as->userurb); 1716 1706 retval = processcompl(as, (void __user * __user *)arg); 1717 1707 free_async(as); 1718 1708 } else { ··· 1840 1828 static int proc_reapurb_compat(struct usb_dev_state *ps, void __user *arg) 1841 1829 { 1842 1830 struct async *as = reap_as(ps); 1831 + 1843 1832 if (as) { 1844 - int retval = processcompl_compat(as, (void __user * __user *)arg); 1833 + int retval; 1834 + 1835 + snoop(&ps->dev->dev, "reap %p\n", as->userurb); 1836 + retval = processcompl_compat(as, (void __user * __user *)arg); 1845 1837 free_async(as); 1846 1838 return retval; 1847 1839 } ··· 1861 1845 1862 1846 as = async_getcompleted(ps); 1863 1847 if (as) { 1848 + snoop(&ps->dev->dev, "reap %p\n", as->userurb); 1864 1849 retval = processcompl_compat(as, (void __user * __user *)arg); 1865 1850 free_async(as); 1866 1851 } else { ··· 2266 2249 #endif 2267 2250 2268 2251 case USBDEVFS_DISCARDURB: 2269 - snoop(&dev->dev, "%s: DISCARDURB\n", __func__); 2252 + snoop(&dev->dev, "%s: DISCARDURB %p\n", __func__, p); 2270 2253 ret = proc_unlinkurb(ps, p); 2271 2254 break; 2272 2255
+2 -2
drivers/usb/core/hcd.c
··· 3000 3000 3001 3001 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE) 3002 3002 3003 - struct usb_mon_operations *mon_ops; 3003 + const struct usb_mon_operations *mon_ops; 3004 3004 3005 3005 /* 3006 3006 * The registration is unlocked. ··· 3010 3010 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first. 3011 3011 */ 3012 3012 3013 - int usb_mon_register (struct usb_mon_operations *ops) 3013 + int usb_mon_register(const struct usb_mon_operations *ops) 3014 3014 { 3015 3015 3016 3016 if (mon_ops)
+52 -16
drivers/usb/core/hub.c
··· 3324 3324 /* 3325 3325 * There are some SS USB devices which take longer time for link training. 3326 3326 * XHCI specs 4.19.4 says that when Link training is successful, port 3327 - * sets CSC bit to 1. So if SW reads port status before successful link 3327 + * sets CCS bit to 1. So if SW reads port status before successful link 3328 3328 * training, then it will not find device to be present. 3329 3329 * USB Analyzer log with such buggy devices show that in some cases 3330 3330 * device switch on the RX termination after long delay of host enabling ··· 3335 3335 * routine implements a 2000 ms timeout for link training. If in a case 3336 3336 * link trains before timeout, loop will exit earlier. 3337 3337 * 3338 + * There are also some 2.0 hard drive based devices and 3.0 thumb 3339 + * drives that, when plugged into a 2.0 only port, take a long 3340 + * time to set CCS after VBUS enable. 3341 + * 3338 3342 * FIXME: If a device was connected before suspend, but was removed 3339 3343 * while system was asleep, then the loop in the following routine will 3340 3344 * only exit at timeout. 3341 3345 * 3342 - * This routine should only be called when persist is enabled for a SS 3343 - * device. 3346 + * This routine should only be called when persist is enabled. 3344 3347 */ 3345 - static int wait_for_ss_port_enable(struct usb_device *udev, 3348 + static int wait_for_connected(struct usb_device *udev, 3346 3349 struct usb_hub *hub, int *port1, 3347 3350 u16 *portchange, u16 *portstatus) 3348 3351 { ··· 3358 3355 delay_ms += 20; 3359 3356 status = hub_port_status(hub, *port1, portstatus, portchange); 3360 3357 } 3358 + dev_dbg(&udev->dev, "Waited %dms for CONNECT\n", delay_ms); 3361 3359 return status; 3362 3360 } 3363 3361 ··· 3458 3454 } 3459 3455 } 3460 3456 3461 - if (udev->persist_enabled && hub_is_superspeed(hub->hdev)) 3462 - status = wait_for_ss_port_enable(udev, hub, &port1, &portchange, 3457 + if (udev->persist_enabled) 3458 + status = wait_for_connected(udev, hub, &port1, &portchange, 3463 3459 &portstatus); 3464 3460 3465 3461 status = check_port_resume_type(udev, ··· 3899 3895 return; 3900 3896 } 3901 3897 3902 - if (usb_set_lpm_timeout(udev, state, timeout)) 3898 + if (usb_set_lpm_timeout(udev, state, timeout)) { 3903 3899 /* If we can't set the parent hub U1/U2 timeout, 3904 3900 * device-initiated LPM won't be allowed either, so let the xHCI 3905 3901 * host know that this link state won't be enabled. 3906 3902 */ 3907 3903 hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); 3904 + } else { 3905 + /* Only a configured device will accept the Set Feature 3906 + * U1/U2_ENABLE 3907 + */ 3908 + if (udev->actconfig) 3909 + usb_set_device_initiated_lpm(udev, state, true); 3908 3910 3909 - /* Only a configured device will accept the Set Feature U1/U2_ENABLE */ 3910 - else if (udev->actconfig) 3911 - usb_set_device_initiated_lpm(udev, state, true); 3912 - 3911 + /* As soon as usb_set_lpm_timeout(timeout) returns 0, the 3912 + * hub-initiated LPM is enabled. Thus, LPM is enabled no 3913 + * matter the result of usb_set_device_initiated_lpm(). 3914 + * The only difference is whether device is able to initiate 3915 + * LPM. 3916 + */ 3917 + if (state == USB3_LPM_U1) 3918 + udev->usb3_lpm_u1_enabled = 1; 3919 + else if (state == USB3_LPM_U2) 3920 + udev->usb3_lpm_u2_enabled = 1; 3921 + } 3913 3922 } 3914 3923 3915 3924 /* ··· 3962 3945 dev_warn(&udev->dev, "Could not disable xHCI %s timeout, " 3963 3946 "bus schedule bandwidth may be impacted.\n", 3964 3947 usb3_lpm_names[state]); 3948 + 3949 + /* As soon as usb_set_lpm_timeout(0) return 0, hub initiated LPM 3950 + * is disabled. Hub will disallows link to enter U1/U2 as well, 3951 + * even device is initiating LPM. Hence LPM is disabled if hub LPM 3952 + * timeout set to 0, no matter device-initiated LPM is disabled or 3953 + * not. 3954 + */ 3955 + if (state == USB3_LPM_U1) 3956 + udev->usb3_lpm_u1_enabled = 0; 3957 + else if (state == USB3_LPM_U2) 3958 + udev->usb3_lpm_u2_enabled = 0; 3959 + 3965 3960 return 0; 3966 3961 } 3967 3962 ··· 4007 3978 goto enable_lpm; 4008 3979 if (usb_disable_link_state(hcd, udev, USB3_LPM_U2)) 4009 3980 goto enable_lpm; 4010 - 4011 - udev->usb3_lpm_enabled = 0; 4012 3981 4013 3982 return 0; 4014 3983 ··· 4044 4017 void usb_enable_lpm(struct usb_device *udev) 4045 4018 { 4046 4019 struct usb_hcd *hcd; 4020 + struct usb_hub *hub; 4021 + struct usb_port *port_dev; 4047 4022 4048 4023 if (!udev || !udev->parent || 4049 4024 udev->speed != USB_SPEED_SUPER || ··· 4065 4036 if (udev->lpm_disable_count > 0) 4066 4037 return; 4067 4038 4068 - usb_enable_link_state(hcd, udev, USB3_LPM_U1); 4069 - usb_enable_link_state(hcd, udev, USB3_LPM_U2); 4039 + hub = usb_hub_to_struct_hub(udev->parent); 4040 + if (!hub) 4041 + return; 4070 4042 4071 - udev->usb3_lpm_enabled = 1; 4043 + port_dev = hub->ports[udev->portnum - 1]; 4044 + 4045 + if (port_dev->usb3_lpm_u1_permit) 4046 + usb_enable_link_state(hcd, udev, USB3_LPM_U1); 4047 + 4048 + if (port_dev->usb3_lpm_u2_permit) 4049 + usb_enable_link_state(hcd, udev, USB3_LPM_U2); 4072 4050 } 4073 4051 EXPORT_SYMBOL_GPL(usb_enable_lpm); 4074 4052
+4 -1
drivers/usb/core/hub.h
··· 92 92 * @status_lock: synchronize port_event() vs usb_port_{suspend|resume} 93 93 * @portnum: port index num based one 94 94 * @is_superspeed cache super-speed status 95 + * @usb3_lpm_u1_permit: whether USB3 U1 LPM is permitted. 96 + * @usb3_lpm_u2_permit: whether USB3 U2 LPM is permitted. 95 97 */ 96 98 struct usb_port { 97 99 struct usb_device *child; ··· 106 104 struct mutex status_lock; 107 105 u8 portnum; 108 106 unsigned int is_superspeed:1; 107 + unsigned int usb3_lpm_u1_permit:1; 108 + unsigned int usb3_lpm_u2_permit:1; 109 109 }; 110 110 111 111 #define to_usb_port(_dev) \ ··· 159 155 { 160 156 return hub_port_debounce(hub, port1, false); 161 157 } 162 -
+88 -1
drivers/usb/core/port.c
··· 50 50 } 51 51 static DEVICE_ATTR_RO(connect_type); 52 52 53 + static ssize_t usb3_lpm_permit_show(struct device *dev, 54 + struct device_attribute *attr, char *buf) 55 + { 56 + struct usb_port *port_dev = to_usb_port(dev); 57 + const char *p; 58 + 59 + if (port_dev->usb3_lpm_u1_permit) { 60 + if (port_dev->usb3_lpm_u2_permit) 61 + p = "u1_u2"; 62 + else 63 + p = "u1"; 64 + } else { 65 + if (port_dev->usb3_lpm_u2_permit) 66 + p = "u2"; 67 + else 68 + p = "0"; 69 + } 70 + 71 + return sprintf(buf, "%s\n", p); 72 + } 73 + 74 + static ssize_t usb3_lpm_permit_store(struct device *dev, 75 + struct device_attribute *attr, 76 + const char *buf, size_t count) 77 + { 78 + struct usb_port *port_dev = to_usb_port(dev); 79 + struct usb_device *udev = port_dev->child; 80 + struct usb_hcd *hcd; 81 + 82 + if (!strncmp(buf, "u1_u2", 5)) { 83 + port_dev->usb3_lpm_u1_permit = 1; 84 + port_dev->usb3_lpm_u2_permit = 1; 85 + 86 + } else if (!strncmp(buf, "u1", 2)) { 87 + port_dev->usb3_lpm_u1_permit = 1; 88 + port_dev->usb3_lpm_u2_permit = 0; 89 + 90 + } else if (!strncmp(buf, "u2", 2)) { 91 + port_dev->usb3_lpm_u1_permit = 0; 92 + port_dev->usb3_lpm_u2_permit = 1; 93 + 94 + } else if (!strncmp(buf, "0", 1)) { 95 + port_dev->usb3_lpm_u1_permit = 0; 96 + port_dev->usb3_lpm_u2_permit = 0; 97 + } else 98 + return -EINVAL; 99 + 100 + /* If device is connected to the port, disable or enable lpm 101 + * to make new u1 u2 setting take effect immediately. 102 + */ 103 + if (udev) { 104 + hcd = bus_to_hcd(udev->bus); 105 + if (!hcd) 106 + return -EINVAL; 107 + usb_lock_device(udev); 108 + mutex_lock(hcd->bandwidth_mutex); 109 + if (!usb_disable_lpm(udev)) 110 + usb_enable_lpm(udev); 111 + mutex_unlock(hcd->bandwidth_mutex); 112 + usb_unlock_device(udev); 113 + } 114 + 115 + return count; 116 + } 117 + static DEVICE_ATTR_RW(usb3_lpm_permit); 118 + 53 119 static struct attribute *port_dev_attrs[] = { 54 120 &dev_attr_connect_type.attr, 55 121 NULL, ··· 127 61 128 62 static const struct attribute_group *port_dev_group[] = { 129 63 &port_dev_attr_grp, 64 + NULL, 65 + }; 66 + 67 + static struct attribute *port_dev_usb3_attrs[] = { 68 + &dev_attr_usb3_lpm_permit.attr, 69 + NULL, 70 + }; 71 + 72 + static struct attribute_group port_dev_usb3_attr_grp = { 73 + .attrs = port_dev_usb3_attrs, 74 + }; 75 + 76 + static const struct attribute_group *port_dev_usb3_group[] = { 77 + &port_dev_attr_grp, 78 + &port_dev_usb3_attr_grp, 130 79 NULL, 131 80 }; 132 81 ··· 482 401 int usb_hub_create_port_device(struct usb_hub *hub, int port1) 483 402 { 484 403 struct usb_port *port_dev; 404 + struct usb_device *hdev = hub->hdev; 485 405 int retval; 486 406 487 407 port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL); ··· 499 417 port_dev->portnum = port1; 500 418 set_bit(port1, hub->power_bits); 501 419 port_dev->dev.parent = hub->intfdev; 502 - port_dev->dev.groups = port_dev_group; 420 + if (hub_is_superspeed(hdev)) { 421 + port_dev->usb3_lpm_u1_permit = 1; 422 + port_dev->usb3_lpm_u2_permit = 1; 423 + port_dev->dev.groups = port_dev_usb3_group; 424 + } else 425 + port_dev->dev.groups = port_dev_group; 503 426 port_dev->dev.type = &usb_port_device_type; 504 427 port_dev->dev.driver = &usb_port_driver; 505 428 if (hub_is_superspeed(hub->hdev))
+26 -5
drivers/usb/core/sysfs.c
··· 531 531 } 532 532 static DEVICE_ATTR_RW(usb2_lpm_besl); 533 533 534 - static ssize_t usb3_hardware_lpm_show(struct device *dev, 534 + static ssize_t usb3_hardware_lpm_u1_show(struct device *dev, 535 535 struct device_attribute *attr, char *buf) 536 536 { 537 537 struct usb_device *udev = to_usb_device(dev); ··· 539 539 540 540 usb_lock_device(udev); 541 541 542 - if (udev->usb3_lpm_enabled) 542 + if (udev->usb3_lpm_u1_enabled) 543 543 p = "enabled"; 544 544 else 545 545 p = "disabled"; ··· 548 548 549 549 return sprintf(buf, "%s\n", p); 550 550 } 551 - static DEVICE_ATTR_RO(usb3_hardware_lpm); 551 + static DEVICE_ATTR_RO(usb3_hardware_lpm_u1); 552 + 553 + static ssize_t usb3_hardware_lpm_u2_show(struct device *dev, 554 + struct device_attribute *attr, char *buf) 555 + { 556 + struct usb_device *udev = to_usb_device(dev); 557 + const char *p; 558 + 559 + usb_lock_device(udev); 560 + 561 + if (udev->usb3_lpm_u2_enabled) 562 + p = "enabled"; 563 + else 564 + p = "disabled"; 565 + 566 + usb_unlock_device(udev); 567 + 568 + return sprintf(buf, "%s\n", p); 569 + } 570 + static DEVICE_ATTR_RO(usb3_hardware_lpm_u2); 552 571 553 572 static struct attribute *usb2_hardware_lpm_attr[] = { 554 573 &dev_attr_usb2_hardware_lpm.attr, ··· 581 562 }; 582 563 583 564 static struct attribute *usb3_hardware_lpm_attr[] = { 584 - &dev_attr_usb3_hardware_lpm.attr, 565 + &dev_attr_usb3_hardware_lpm_u1.attr, 566 + &dev_attr_usb3_hardware_lpm_u2.attr, 585 567 NULL, 586 568 }; 587 569 static struct attribute_group usb3_hardware_lpm_attr_group = { ··· 612 592 if (udev->usb2_hw_lpm_capable == 1) 613 593 rc = sysfs_merge_group(&dev->kobj, 614 594 &usb2_hardware_lpm_attr_group); 615 - if (udev->lpm_capable == 1) 595 + if (udev->speed == USB_SPEED_SUPER && 596 + udev->lpm_capable == 1) 616 597 rc = sysfs_merge_group(&dev->kobj, 617 598 &usb3_hardware_lpm_attr_group); 618 599 }
-5
drivers/usb/core/usb.c
··· 49 49 50 50 static bool nousb; /* Disable USB when built into kernel image */ 51 51 52 - /* To disable USB, kernel command line is 'nousb' not 'usbcore.nousb' */ 53 - #ifdef MODULE 54 52 module_param(nousb, bool, 0444); 55 - #else 56 - core_param(nousb, nousb, bool, 0444); 57 - #endif 58 53 59 54 /* 60 55 * for external read access to <nousb>
+349 -90
drivers/usb/dwc2/core.c
··· 481 481 * Do core a soft reset of the core. Be careful with this because it 482 482 * resets all the internal state machines of the core. 483 483 */ 484 - static int dwc2_core_reset(struct dwc2_hsotg *hsotg) 484 + int dwc2_core_reset(struct dwc2_hsotg *hsotg) 485 485 { 486 486 u32 greset; 487 487 int count = 0; 488 - u32 gusbcfg; 489 488 490 489 dev_vdbg(hsotg->dev, "%s()\n", __func__); 491 490 492 - /* Wait for AHB master IDLE state */ 493 - do { 494 - usleep_range(20000, 40000); 495 - greset = dwc2_readl(hsotg->regs + GRSTCTL); 496 - if (++count > 50) { 497 - dev_warn(hsotg->dev, 498 - "%s() HANG! AHB Idle GRSTCTL=%0x\n", 499 - __func__, greset); 500 - return -EBUSY; 501 - } 502 - } while (!(greset & GRSTCTL_AHBIDLE)); 503 - 504 491 /* Core Soft Reset */ 505 - count = 0; 492 + greset = dwc2_readl(hsotg->regs + GRSTCTL); 506 493 greset |= GRSTCTL_CSFTRST; 507 494 dwc2_writel(greset, hsotg->regs + GRSTCTL); 508 495 do { 509 - usleep_range(20000, 40000); 496 + udelay(1); 510 497 greset = dwc2_readl(hsotg->regs + GRSTCTL); 511 498 if (++count > 50) { 512 499 dev_warn(hsotg->dev, ··· 503 516 } 504 517 } while (greset & GRSTCTL_CSFTRST); 505 518 506 - if (hsotg->dr_mode == USB_DR_MODE_HOST) { 507 - gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 508 - gusbcfg &= ~GUSBCFG_FORCEDEVMODE; 509 - gusbcfg |= GUSBCFG_FORCEHOSTMODE; 510 - dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 511 - } else if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) { 512 - gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 513 - gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; 514 - gusbcfg |= GUSBCFG_FORCEDEVMODE; 515 - dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 516 - } else if (hsotg->dr_mode == USB_DR_MODE_OTG) { 517 - gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 518 - gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; 519 - gusbcfg &= ~GUSBCFG_FORCEDEVMODE; 520 - dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 521 - } 519 + /* Wait for AHB master IDLE state */ 520 + count = 0; 521 + do { 522 + udelay(1); 523 + greset = dwc2_readl(hsotg->regs + GRSTCTL); 524 + if (++count > 50) { 525 + dev_warn(hsotg->dev, 526 + "%s() HANG! AHB Idle GRSTCTL=%0x\n", 527 + __func__, greset); 528 + return -EBUSY; 529 + } 530 + } while (!(greset & GRSTCTL_AHBIDLE)); 531 + 532 + return 0; 533 + } 534 + 535 + /* 536 + * Force the mode of the controller. 537 + * 538 + * Forcing the mode is needed for two cases: 539 + * 540 + * 1) If the dr_mode is set to either HOST or PERIPHERAL we force the 541 + * controller to stay in a particular mode regardless of ID pin 542 + * changes. We do this usually after a core reset. 543 + * 544 + * 2) During probe we want to read reset values of the hw 545 + * configuration registers that are only available in either host or 546 + * device mode. We may need to force the mode if the current mode does 547 + * not allow us to access the register in the mode that we want. 548 + * 549 + * In either case it only makes sense to force the mode if the 550 + * controller hardware is OTG capable. 551 + * 552 + * Checks are done in this function to determine whether doing a force 553 + * would be valid or not. 554 + * 555 + * If a force is done, it requires a 25ms delay to take effect. 556 + * 557 + * Returns true if the mode was forced. 558 + */ 559 + static bool dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host) 560 + { 561 + u32 gusbcfg; 562 + u32 set; 563 + u32 clear; 564 + 565 + dev_dbg(hsotg->dev, "Forcing mode to %s\n", host ? "host" : "device"); 566 + 567 + /* 568 + * Force mode has no effect if the hardware is not OTG. 569 + */ 570 + if (!dwc2_hw_is_otg(hsotg)) 571 + return false; 572 + 573 + /* 574 + * If dr_mode is either peripheral or host only, there is no 575 + * need to ever force the mode to the opposite mode. 576 + */ 577 + if (WARN_ON(host && hsotg->dr_mode == USB_DR_MODE_PERIPHERAL)) 578 + return false; 579 + 580 + if (WARN_ON(!host && hsotg->dr_mode == USB_DR_MODE_HOST)) 581 + return false; 582 + 583 + gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 584 + 585 + set = host ? GUSBCFG_FORCEHOSTMODE : GUSBCFG_FORCEDEVMODE; 586 + clear = host ? GUSBCFG_FORCEDEVMODE : GUSBCFG_FORCEHOSTMODE; 587 + 588 + /* 589 + * If the force mode bit is already set, don't set it. 590 + */ 591 + if ((gusbcfg & set) && !(gusbcfg & clear)) 592 + return false; 593 + 594 + gusbcfg &= ~clear; 595 + gusbcfg |= set; 596 + dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 597 + 598 + msleep(25); 599 + return true; 600 + } 601 + 602 + /* 603 + * Clears the force mode bits. 604 + */ 605 + static void dwc2_clear_force_mode(struct dwc2_hsotg *hsotg) 606 + { 607 + u32 gusbcfg; 608 + 609 + gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 610 + gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; 611 + gusbcfg &= ~GUSBCFG_FORCEDEVMODE; 612 + dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 522 613 523 614 /* 524 615 * NOTE: This long sleep is _very_ important, otherwise the core will 525 616 * not stay in host mode after a connector ID change! 526 617 */ 527 - usleep_range(150000, 200000); 618 + msleep(25); 619 + } 528 620 621 + /* 622 + * Sets or clears force mode based on the dr_mode parameter. 623 + */ 624 + void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg) 625 + { 626 + switch (hsotg->dr_mode) { 627 + case USB_DR_MODE_HOST: 628 + dwc2_force_mode(hsotg, true); 629 + break; 630 + case USB_DR_MODE_PERIPHERAL: 631 + dwc2_force_mode(hsotg, false); 632 + break; 633 + case USB_DR_MODE_OTG: 634 + dwc2_clear_force_mode(hsotg); 635 + break; 636 + default: 637 + dev_warn(hsotg->dev, "%s() Invalid dr_mode=%d\n", 638 + __func__, hsotg->dr_mode); 639 + break; 640 + } 641 + } 642 + 643 + /* 644 + * Do core a soft reset of the core. Be careful with this because it 645 + * resets all the internal state machines of the core. 646 + * 647 + * Additionally this will apply force mode as per the hsotg->dr_mode 648 + * parameter. 649 + */ 650 + int dwc2_core_reset_and_force_dr_mode(struct dwc2_hsotg *hsotg) 651 + { 652 + int retval; 653 + 654 + retval = dwc2_core_reset(hsotg); 655 + if (retval) 656 + return retval; 657 + 658 + dwc2_force_dr_mode(hsotg); 529 659 return 0; 530 660 } 531 661 ··· 657 553 */ 658 554 if (select_phy) { 659 555 dev_dbg(hsotg->dev, "FS PHY selected\n"); 660 - usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 661 - usbcfg |= GUSBCFG_PHYSEL; 662 - dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 663 556 664 - /* Reset after a PHY select */ 665 - retval = dwc2_core_reset(hsotg); 666 - if (retval) { 667 - dev_err(hsotg->dev, "%s() Reset failed, aborting", 668 - __func__); 669 - return retval; 557 + usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 558 + if (!(usbcfg & GUSBCFG_PHYSEL)) { 559 + usbcfg |= GUSBCFG_PHYSEL; 560 + dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 561 + 562 + /* Reset after a PHY select */ 563 + retval = dwc2_core_reset_and_force_dr_mode(hsotg); 564 + 565 + if (retval) { 566 + dev_err(hsotg->dev, 567 + "%s: Reset failed, aborting", __func__); 568 + return retval; 569 + } 670 570 } 671 571 } 672 572 ··· 705 597 706 598 static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) 707 599 { 708 - u32 usbcfg; 600 + u32 usbcfg, usbcfg_old; 709 601 int retval = 0; 710 602 711 603 if (!select_phy) 712 604 return 0; 713 605 714 - usbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 606 + usbcfg = usbcfg_old = dwc2_readl(hsotg->regs + GUSBCFG); 715 607 716 608 /* 717 609 * HS PHY parameters. These parameters are preserved during soft reset ··· 739 631 break; 740 632 } 741 633 742 - dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 634 + if (usbcfg != usbcfg_old) { 635 + dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 743 636 744 - /* Reset after setting the PHY parameters */ 745 - retval = dwc2_core_reset(hsotg); 746 - if (retval) { 747 - dev_err(hsotg->dev, "%s() Reset failed, aborting", 748 - __func__); 749 - return retval; 637 + /* Reset after setting the PHY parameters */ 638 + retval = dwc2_core_reset_and_force_dr_mode(hsotg); 639 + if (retval) { 640 + dev_err(hsotg->dev, 641 + "%s: Reset failed, aborting", __func__); 642 + return retval; 643 + } 750 644 } 751 645 752 646 return retval; ··· 875 765 * dwc2_core_init() - Initializes the DWC_otg controller registers and 876 766 * prepares the core for device mode or host mode operation 877 767 * 878 - * @hsotg: Programming view of the DWC_otg controller 879 - * @select_phy: If true then also set the Phy type 880 - * @irq: If >= 0, the irq to register 768 + * @hsotg: Programming view of the DWC_otg controller 769 + * @initial_setup: If true then this is the first init for this instance. 881 770 */ 882 - int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq) 771 + int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup) 883 772 { 884 773 u32 usbcfg, otgctl; 885 774 int retval; ··· 900 791 901 792 dwc2_writel(usbcfg, hsotg->regs + GUSBCFG); 902 793 903 - /* Reset the Controller */ 904 - retval = dwc2_core_reset(hsotg); 905 - if (retval) { 906 - dev_err(hsotg->dev, "%s(): Reset failed, aborting\n", 907 - __func__); 908 - return retval; 794 + /* 795 + * Reset the Controller 796 + * 797 + * We only need to reset the controller if this is a re-init. 798 + * For the first init we know for sure that earlier code reset us (it 799 + * needed to in order to properly detect various parameters). 800 + */ 801 + if (!initial_setup) { 802 + retval = dwc2_core_reset_and_force_dr_mode(hsotg); 803 + if (retval) { 804 + dev_err(hsotg->dev, "%s(): Reset failed, aborting\n", 805 + __func__); 806 + return retval; 807 + } 909 808 } 910 809 911 810 /* 912 811 * This needs to happen in FS mode before any other programming occurs 913 812 */ 914 - retval = dwc2_phy_init(hsotg, select_phy); 813 + retval = dwc2_phy_init(hsotg, initial_setup); 915 814 if (retval) 916 815 return retval; 917 816 ··· 1824 1707 u32 hcchar; 1825 1708 u32 hctsiz = 0; 1826 1709 u16 num_packets; 1710 + u32 ec_mc; 1827 1711 1828 1712 if (dbg_hc(chan)) 1829 1713 dev_vdbg(hsotg->dev, "%s()\n", __func__); ··· 1861 1743 1862 1744 hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT & 1863 1745 TSIZ_XFERSIZE_MASK; 1746 + 1747 + /* For split set ec_mc for immediate retries */ 1748 + if (chan->ep_type == USB_ENDPOINT_XFER_INT || 1749 + chan->ep_type == USB_ENDPOINT_XFER_ISOC) 1750 + ec_mc = 3; 1751 + else 1752 + ec_mc = 1; 1864 1753 } else { 1865 1754 if (dbg_hc(chan)) 1866 1755 dev_vdbg(hsotg->dev, "no split\n"); ··· 1930 1805 1931 1806 hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT & 1932 1807 TSIZ_XFERSIZE_MASK; 1808 + 1809 + /* The ec_mc gets the multi_count for non-split */ 1810 + ec_mc = chan->multi_count; 1933 1811 } 1934 1812 1935 1813 chan->start_pkt_count = num_packets; ··· 1983 1855 1984 1856 hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); 1985 1857 hcchar &= ~HCCHAR_MULTICNT_MASK; 1986 - hcchar |= chan->multi_count << HCCHAR_MULTICNT_SHIFT & 1987 - HCCHAR_MULTICNT_MASK; 1858 + hcchar |= (ec_mc << HCCHAR_MULTICNT_SHIFT) & HCCHAR_MULTICNT_MASK; 1988 1859 dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar); 1989 1860 1990 1861 if (hcchar & HCCHAR_CHDIS) ··· 2032 1905 struct dwc2_host_chan *chan) 2033 1906 { 2034 1907 u32 hcchar; 2035 - u32 hc_dma; 2036 1908 u32 hctsiz = 0; 2037 1909 2038 1910 if (chan->do_ping) ··· 2060 1934 2061 1935 dwc2_writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num)); 2062 1936 2063 - hc_dma = (u32)chan->desc_list_addr & HCDMA_DMA_ADDR_MASK; 1937 + dma_sync_single_for_device(hsotg->dev, chan->desc_list_addr, 1938 + chan->desc_list_sz, DMA_TO_DEVICE); 2064 1939 2065 - /* Always start from first descriptor */ 2066 - hc_dma &= ~HCDMA_CTD_MASK; 2067 - dwc2_writel(hc_dma, hsotg->regs + HCDMA(chan->hc_num)); 1940 + dwc2_writel(chan->desc_list_addr, hsotg->regs + HCDMA(chan->hc_num)); 1941 + 2068 1942 if (dbg_hc(chan)) 2069 - dev_vdbg(hsotg->dev, "Wrote %08x to HCDMA(%d)\n", 2070 - hc_dma, chan->hc_num); 1943 + dev_vdbg(hsotg->dev, "Wrote %pad to HCDMA(%d)\n", 1944 + &chan->desc_list_addr, chan->hc_num); 2071 1945 2072 1946 hcchar = dwc2_readl(hsotg->regs + HCCHAR(chan->hc_num)); 2073 1947 hcchar &= ~HCCHAR_MULTICNT_MASK; ··· 2611 2485 hsotg->core_params->dma_desc_enable = val; 2612 2486 } 2613 2487 2488 + void dwc2_set_param_dma_desc_fs_enable(struct dwc2_hsotg *hsotg, int val) 2489 + { 2490 + int valid = 1; 2491 + 2492 + if (val > 0 && (hsotg->core_params->dma_enable <= 0 || 2493 + !hsotg->hw_params.dma_desc_enable)) 2494 + valid = 0; 2495 + if (val < 0) 2496 + valid = 0; 2497 + 2498 + if (!valid) { 2499 + if (val >= 0) 2500 + dev_err(hsotg->dev, 2501 + "%d invalid for dma_desc_fs_enable parameter. Check HW configuration.\n", 2502 + val); 2503 + val = (hsotg->core_params->dma_enable > 0 && 2504 + hsotg->hw_params.dma_desc_enable); 2505 + } 2506 + 2507 + hsotg->core_params->dma_desc_fs_enable = val; 2508 + dev_dbg(hsotg->dev, "Setting dma_desc_fs_enable to %d\n", val); 2509 + } 2510 + 2614 2511 void dwc2_set_param_host_support_fs_ls_low_power(struct dwc2_hsotg *hsotg, 2615 2512 int val) 2616 2513 { ··· 3165 3016 dwc2_set_param_otg_cap(hsotg, params->otg_cap); 3166 3017 dwc2_set_param_dma_enable(hsotg, params->dma_enable); 3167 3018 dwc2_set_param_dma_desc_enable(hsotg, params->dma_desc_enable); 3019 + dwc2_set_param_dma_desc_fs_enable(hsotg, params->dma_desc_fs_enable); 3168 3020 dwc2_set_param_host_support_fs_ls_low_power(hsotg, 3169 3021 params->host_support_fs_ls_low_power); 3170 3022 dwc2_set_param_enable_dynamic_fifo(hsotg, ··· 3202 3052 dwc2_set_param_hibernation(hsotg, params->hibernation); 3203 3053 } 3204 3054 3055 + /* 3056 + * Forces either host or device mode if the controller is not 3057 + * currently in that mode. 3058 + * 3059 + * Returns true if the mode was forced. 3060 + */ 3061 + static bool dwc2_force_mode_if_needed(struct dwc2_hsotg *hsotg, bool host) 3062 + { 3063 + if (host && dwc2_is_host_mode(hsotg)) 3064 + return false; 3065 + else if (!host && dwc2_is_device_mode(hsotg)) 3066 + return false; 3067 + 3068 + return dwc2_force_mode(hsotg, host); 3069 + } 3070 + 3071 + /* 3072 + * Gets host hardware parameters. Forces host mode if not currently in 3073 + * host mode. Should be called immediately after a core soft reset in 3074 + * order to get the reset values. 3075 + */ 3076 + static void dwc2_get_host_hwparams(struct dwc2_hsotg *hsotg) 3077 + { 3078 + struct dwc2_hw_params *hw = &hsotg->hw_params; 3079 + u32 gnptxfsiz; 3080 + u32 hptxfsiz; 3081 + bool forced; 3082 + 3083 + if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) 3084 + return; 3085 + 3086 + forced = dwc2_force_mode_if_needed(hsotg, true); 3087 + 3088 + gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); 3089 + hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ); 3090 + dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); 3091 + dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hptxfsiz); 3092 + 3093 + if (forced) 3094 + dwc2_clear_force_mode(hsotg); 3095 + 3096 + hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> 3097 + FIFOSIZE_DEPTH_SHIFT; 3098 + hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >> 3099 + FIFOSIZE_DEPTH_SHIFT; 3100 + } 3101 + 3102 + /* 3103 + * Gets device hardware parameters. Forces device mode if not 3104 + * currently in device mode. Should be called immediately after a core 3105 + * soft reset in order to get the reset values. 3106 + */ 3107 + static void dwc2_get_dev_hwparams(struct dwc2_hsotg *hsotg) 3108 + { 3109 + struct dwc2_hw_params *hw = &hsotg->hw_params; 3110 + bool forced; 3111 + u32 gnptxfsiz; 3112 + 3113 + if (hsotg->dr_mode == USB_DR_MODE_HOST) 3114 + return; 3115 + 3116 + forced = dwc2_force_mode_if_needed(hsotg, false); 3117 + 3118 + gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); 3119 + dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); 3120 + 3121 + if (forced) 3122 + dwc2_clear_force_mode(hsotg); 3123 + 3124 + hw->dev_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> 3125 + FIFOSIZE_DEPTH_SHIFT; 3126 + } 3127 + 3205 3128 /** 3206 3129 * During device initialization, read various hardware configuration 3207 3130 * registers and interpret the contents. 3131 + * 3132 + * This should be called during driver probe. It will perform a core 3133 + * soft reset in order to get the reset values of the parameters. 3208 3134 */ 3209 3135 int dwc2_get_hwparams(struct dwc2_hsotg *hsotg) 3210 3136 { 3211 3137 struct dwc2_hw_params *hw = &hsotg->hw_params; 3212 3138 unsigned width; 3213 3139 u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4; 3214 - u32 hptxfsiz, grxfsiz, gnptxfsiz; 3215 - u32 gusbcfg; 3140 + u32 grxfsiz; 3141 + int retval; 3216 3142 3217 3143 /* 3218 3144 * Attempt to ensure this device is really a DWC_otg Controller. ··· 3308 3082 hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf, 3309 3083 hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid); 3310 3084 3085 + retval = dwc2_core_reset(hsotg); 3086 + if (retval) 3087 + return retval; 3088 + 3311 3089 hwcfg1 = dwc2_readl(hsotg->regs + GHWCFG1); 3312 3090 hwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2); 3313 3091 hwcfg3 = dwc2_readl(hsotg->regs + GHWCFG3); ··· 3324 3094 dev_dbg(hsotg->dev, "hwcfg4=%08x\n", hwcfg4); 3325 3095 dev_dbg(hsotg->dev, "grxfsiz=%08x\n", grxfsiz); 3326 3096 3327 - /* Force host mode to get HPTXFSIZ / GNPTXFSIZ exact power on value */ 3328 - gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 3329 - gusbcfg |= GUSBCFG_FORCEHOSTMODE; 3330 - dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 3331 - usleep_range(100000, 150000); 3097 + /* 3098 + * Host specific hardware parameters. Reading these parameters 3099 + * requires the controller to be in host mode. The mode will 3100 + * be forced, if necessary, to read these values. 3101 + */ 3102 + dwc2_get_host_hwparams(hsotg); 3103 + dwc2_get_dev_hwparams(hsotg); 3332 3104 3333 - gnptxfsiz = dwc2_readl(hsotg->regs + GNPTXFSIZ); 3334 - hptxfsiz = dwc2_readl(hsotg->regs + HPTXFSIZ); 3335 - dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); 3336 - dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hptxfsiz); 3337 - gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG); 3338 - gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; 3339 - dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG); 3340 - usleep_range(100000, 150000); 3105 + /* hwcfg1 */ 3106 + hw->dev_ep_dirs = hwcfg1; 3341 3107 3342 3108 /* hwcfg2 */ 3343 3109 hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >> ··· 3389 3163 /* fifo sizes */ 3390 3164 hw->host_rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >> 3391 3165 GRXFSIZ_DEPTH_SHIFT; 3392 - hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> 3393 - FIFOSIZE_DEPTH_SHIFT; 3394 - hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >> 3395 - FIFOSIZE_DEPTH_SHIFT; 3396 3166 3397 3167 dev_dbg(hsotg->dev, "Detected values from hardware:\n"); 3398 3168 dev_dbg(hsotg->dev, " op_mode=%d\n", ··· 3495 3273 3496 3274 ahbcfg &= ~GAHBCFG_GLBL_INTR_EN; 3497 3275 dwc2_writel(ahbcfg, hsotg->regs + GAHBCFG); 3276 + } 3277 + 3278 + /* Returns the controller's GHWCFG2.OTG_MODE. */ 3279 + unsigned dwc2_op_mode(struct dwc2_hsotg *hsotg) 3280 + { 3281 + u32 ghwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2); 3282 + 3283 + return (ghwcfg2 & GHWCFG2_OP_MODE_MASK) >> 3284 + GHWCFG2_OP_MODE_SHIFT; 3285 + } 3286 + 3287 + /* Returns true if the controller is capable of DRD. */ 3288 + bool dwc2_hw_is_otg(struct dwc2_hsotg *hsotg) 3289 + { 3290 + unsigned op_mode = dwc2_op_mode(hsotg); 3291 + 3292 + return (op_mode == GHWCFG2_OP_MODE_HNP_SRP_CAPABLE) || 3293 + (op_mode == GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE) || 3294 + (op_mode == GHWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE); 3295 + } 3296 + 3297 + /* Returns true if the controller is host-only. */ 3298 + bool dwc2_hw_is_host(struct dwc2_hsotg *hsotg) 3299 + { 3300 + unsigned op_mode = dwc2_op_mode(hsotg); 3301 + 3302 + return (op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_HOST) || 3303 + (op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST); 3304 + } 3305 + 3306 + /* Returns true if the controller is device-only. */ 3307 + bool dwc2_hw_is_device(struct dwc2_hsotg *hsotg) 3308 + { 3309 + unsigned op_mode = dwc2_op_mode(hsotg); 3310 + 3311 + return (op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) || 3312 + (op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE); 3498 3313 } 3499 3314 3500 3315 MODULE_DESCRIPTION("DESIGNWARE HS OTG Core");
+63 -3
drivers/usb/dwc2/core.h
··· 246 246 * value for this if none is specified. 247 247 * 0 - Address DMA 248 248 * 1 - Descriptor DMA (default, if available) 249 + * @dma_desc_fs_enable: When DMA mode is enabled, specifies whether to use 250 + * address DMA mode or descriptor DMA mode for accessing 251 + * the data FIFOs in Full Speed mode only. The driver 252 + * will automatically detect the value for this if none is 253 + * specified. 254 + * 0 - Address DMA 255 + * 1 - Descriptor DMA in FS (default, if available) 249 256 * @speed: Specifies the maximum speed of operation in host and 250 257 * device mode. The actual speed depends on the speed of 251 258 * the attached device and the value of phy_type. ··· 382 375 int otg_ver; 383 376 int dma_enable; 384 377 int dma_desc_enable; 378 + int dma_desc_fs_enable; 385 379 int speed; 386 380 int enable_dynamic_fifo; 387 381 int en_multiple_tx_fifo; ··· 459 451 * 1 - 16 bits 460 452 * 2 - 8 or 16 bits 461 453 * @snpsid: Value from SNPSID register 454 + * @dev_ep_dirs: Direction of device endpoints (GHWCFG1) 462 455 */ 463 456 struct dwc2_hw_params { 464 457 unsigned op_mode:3; 465 458 unsigned arch:2; 466 459 unsigned dma_desc_enable:1; 460 + unsigned dma_desc_fs_enable:1; 467 461 unsigned enable_dynamic_fifo:1; 468 462 unsigned en_multiple_tx_fifo:1; 469 463 unsigned host_rx_fifo_size:16; 470 464 unsigned host_nperio_tx_fifo_size:16; 465 + unsigned dev_nperio_tx_fifo_size:16; 471 466 unsigned host_perio_tx_fifo_size:16; 472 467 unsigned nperio_tx_q_depth:3; 473 468 unsigned host_perio_tx_q_depth:3; ··· 487 476 unsigned power_optimized:1; 488 477 unsigned utmi_phy_data_width:2; 489 478 u32 snpsid; 479 + u32 dev_ep_dirs; 490 480 }; 491 481 492 482 /* Size of control and EP0 buffers */ ··· 688 676 * @otg_port: OTG port number 689 677 * @frame_list: Frame list 690 678 * @frame_list_dma: Frame list DMA address 679 + * @frame_list_sz: Frame list size 680 + * @desc_gen_cache: Kmem cache for generic descriptors 681 + * @desc_hsisoc_cache: Kmem cache for hs isochronous descriptors 691 682 * 692 683 * These are for peripheral mode: 693 684 * ··· 785 770 u16 frame_number; 786 771 u16 periodic_qh_count; 787 772 bool bus_suspended; 773 + bool new_connection; 788 774 789 775 #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS 790 776 #define FRAME_NUM_ARRAY_SIZE 1000 ··· 810 794 u8 otg_port; 811 795 u32 *frame_list; 812 796 dma_addr_t frame_list_dma; 797 + u32 frame_list_sz; 798 + struct kmem_cache *desc_gen_cache; 799 + struct kmem_cache *desc_hsisoc_cache; 813 800 814 801 #ifdef DEBUG 815 802 u32 frrem_samples; ··· 883 864 * The following functions support initialization of the core driver component 884 865 * and the DWC_otg controller 885 866 */ 867 + extern int dwc2_core_reset(struct dwc2_hsotg *hsotg); 868 + extern int dwc2_core_reset_and_force_dr_mode(struct dwc2_hsotg *hsotg); 886 869 extern void dwc2_core_host_init(struct dwc2_hsotg *hsotg); 887 870 extern int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg); 888 871 extern int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore); 872 + 873 + void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg); 889 874 890 875 /* 891 876 * Host core Functions. ··· 924 901 extern void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num); 925 902 extern void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg); 926 903 927 - extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq); 904 + extern int dwc2_core_init(struct dwc2_hsotg *hsotg, bool initial_setup); 928 905 extern void dwc2_enable_global_interrupts(struct dwc2_hsotg *hcd); 929 906 extern void dwc2_disable_global_interrupts(struct dwc2_hsotg *hcd); 930 907 ··· 963 940 * 1 - DMA Descriptor(default, if available) 964 941 */ 965 942 extern void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val); 943 + 944 + /* 945 + * When DMA mode is enabled specifies whether to use 946 + * address DMA or DMA Descritor mode with full speed devices 947 + * for accessing the data FIFOs in host mode. 948 + * 0 - address DMA 949 + * 1 - FS DMA Descriptor(default, if available) 950 + */ 951 + extern void dwc2_set_param_dma_desc_fs_enable(struct dwc2_hsotg *hsotg, 952 + int val); 966 953 967 954 /* 968 955 * Specifies the maximum speed of operation in host and device mode. ··· 1143 1110 extern int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg); 1144 1111 1145 1112 /* 1113 + * The following functions check the controller's OTG operation mode 1114 + * capability (GHWCFG2.OTG_MODE). 1115 + * 1116 + * These functions can be used before the internal hsotg->hw_params 1117 + * are read in and cached so they always read directly from the 1118 + * GHWCFG2 register. 1119 + */ 1120 + unsigned dwc2_op_mode(struct dwc2_hsotg *hsotg); 1121 + bool dwc2_hw_is_otg(struct dwc2_hsotg *hsotg); 1122 + bool dwc2_hw_is_host(struct dwc2_hsotg *hsotg); 1123 + bool dwc2_hw_is_device(struct dwc2_hsotg *hsotg); 1124 + 1125 + /* 1126 + * Returns the mode of operation, host or device 1127 + */ 1128 + static inline int dwc2_is_host_mode(struct dwc2_hsotg *hsotg) 1129 + { 1130 + return (dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) != 0; 1131 + } 1132 + static inline int dwc2_is_device_mode(struct dwc2_hsotg *hsotg) 1133 + { 1134 + return (dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) == 0; 1135 + } 1136 + 1137 + /* 1146 1138 * Dump core registers and SPRAM 1147 1139 */ 1148 1140 extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg); ··· 1212 1154 1213 1155 #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) 1214 1156 extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg); 1215 - extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg); 1157 + extern void dwc2_hcd_connect(struct dwc2_hsotg *hsotg); 1158 + extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force); 1216 1159 extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg); 1217 1160 #else 1218 1161 static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg) 1219 1162 { return 0; } 1220 - static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg) {} 1163 + static inline void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) {} 1164 + static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) {} 1221 1165 static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {} 1222 1166 static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {} 1223 1167 static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq)
+25 -28
drivers/usb/dwc2/core_intr.c
··· 86 86 hprt0 &= ~HPRT0_ENA; 87 87 dwc2_writel(hprt0, hsotg->regs + HPRT0); 88 88 } 89 - 90 - /* Clear interrupt */ 91 - dwc2_writel(GINTSTS_PRTINT, hsotg->regs + GINTSTS); 92 89 } 93 90 94 91 /** ··· 95 98 */ 96 99 static void dwc2_handle_mode_mismatch_intr(struct dwc2_hsotg *hsotg) 97 100 { 98 - dev_warn(hsotg->dev, "Mode Mismatch Interrupt: currently in %s mode\n", 99 - dwc2_is_host_mode(hsotg) ? "Host" : "Device"); 100 - 101 101 /* Clear interrupt */ 102 102 dwc2_writel(GINTSTS_MODEMIS, hsotg->regs + GINTSTS); 103 + 104 + dev_warn(hsotg->dev, "Mode Mismatch Interrupt: currently in %s mode\n", 105 + dwc2_is_host_mode(hsotg) ? "Host" : "Device"); 103 106 } 104 107 105 108 /** ··· 236 239 dev_dbg(hsotg->dev, "a_suspend->a_peripheral (%d)\n", 237 240 hsotg->op_state); 238 241 spin_unlock(&hsotg->lock); 239 - dwc2_hcd_disconnect(hsotg); 242 + dwc2_hcd_disconnect(hsotg, false); 240 243 spin_lock(&hsotg->lock); 241 244 hsotg->op_state = OTG_STATE_A_PERIPHERAL; 242 245 } else { ··· 273 276 */ 274 277 static void dwc2_handle_conn_id_status_change_intr(struct dwc2_hsotg *hsotg) 275 278 { 276 - u32 gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 279 + u32 gintmsk; 280 + 281 + /* Clear interrupt */ 282 + dwc2_writel(GINTSTS_CONIDSTSCHNG, hsotg->regs + GINTSTS); 277 283 278 284 /* Need to disable SOF interrupt immediately */ 285 + gintmsk = dwc2_readl(hsotg->regs + GINTMSK); 279 286 gintmsk &= ~GINTSTS_SOF; 280 287 dwc2_writel(gintmsk, hsotg->regs + GINTMSK); 281 288 ··· 296 295 queue_work(hsotg->wq_otg, &hsotg->wf_otg); 297 296 spin_lock(&hsotg->lock); 298 297 } 299 - 300 - /* Clear interrupt */ 301 - dwc2_writel(GINTSTS_CONIDSTSCHNG, hsotg->regs + GINTSTS); 302 298 } 303 299 304 300 /** ··· 313 315 { 314 316 int ret; 315 317 316 - dev_dbg(hsotg->dev, "Session request interrupt - lx_state=%d\n", 317 - hsotg->lx_state); 318 - 319 318 /* Clear interrupt */ 320 319 dwc2_writel(GINTSTS_SESSREQINT, hsotg->regs + GINTSTS); 320 + 321 + dev_dbg(hsotg->dev, "Session request interrupt - lx_state=%d\n", 322 + hsotg->lx_state); 321 323 322 324 if (dwc2_is_device_mode(hsotg)) { 323 325 if (hsotg->lx_state == DWC2_L2) { ··· 345 347 static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg) 346 348 { 347 349 int ret; 350 + 351 + /* Clear interrupt */ 352 + dwc2_writel(GINTSTS_WKUPINT, hsotg->regs + GINTSTS); 353 + 348 354 dev_dbg(hsotg->dev, "++Resume or Remote Wakeup Detected Interrupt++\n"); 349 355 dev_dbg(hsotg->dev, "%s lxstate = %d\n", __func__, hsotg->lx_state); 350 356 ··· 370 368 /* Change to L0 state */ 371 369 hsotg->lx_state = DWC2_L0; 372 370 } else { 373 - if (hsotg->core_params->hibernation) { 374 - dwc2_writel(GINTSTS_WKUPINT, hsotg->regs + GINTSTS); 371 + if (hsotg->core_params->hibernation) 375 372 return; 376 - } 373 + 377 374 if (hsotg->lx_state != DWC2_L1) { 378 375 u32 pcgcctl = dwc2_readl(hsotg->regs + PCGCTL); 379 376 ··· 386 385 hsotg->lx_state = DWC2_L0; 387 386 } 388 387 } 389 - 390 - /* Clear interrupt */ 391 - dwc2_writel(GINTSTS_WKUPINT, hsotg->regs + GINTSTS); 392 388 } 393 389 394 390 /* ··· 394 396 */ 395 397 static void dwc2_handle_disconnect_intr(struct dwc2_hsotg *hsotg) 396 398 { 399 + dwc2_writel(GINTSTS_DISCONNINT, hsotg->regs + GINTSTS); 400 + 397 401 dev_dbg(hsotg->dev, "++Disconnect Detected Interrupt++ (%s) %s\n", 398 402 dwc2_is_host_mode(hsotg) ? "Host" : "Device", 399 403 dwc2_op_state_str(hsotg)); 400 404 401 405 if (hsotg->op_state == OTG_STATE_A_HOST) 402 - dwc2_hcd_disconnect(hsotg); 403 - 404 - dwc2_writel(GINTSTS_DISCONNINT, hsotg->regs + GINTSTS); 406 + dwc2_hcd_disconnect(hsotg, false); 405 407 } 406 408 407 409 /* ··· 416 418 { 417 419 u32 dsts; 418 420 int ret; 421 + 422 + /* Clear interrupt */ 423 + dwc2_writel(GINTSTS_USBSUSP, hsotg->regs + GINTSTS); 419 424 420 425 dev_dbg(hsotg->dev, "USB SUSPEND\n"); 421 426 ··· 438 437 if (!dwc2_is_device_connected(hsotg)) { 439 438 dev_dbg(hsotg->dev, 440 439 "ignore suspend request before enumeration\n"); 441 - goto clear_int; 440 + return; 442 441 } 443 442 444 443 ret = dwc2_enter_hibernation(hsotg); ··· 477 476 hsotg->op_state = OTG_STATE_A_HOST; 478 477 } 479 478 } 480 - 481 - clear_int: 482 - /* Clear interrupt */ 483 - dwc2_writel(GINTSTS_USBSUSP, hsotg->regs + GINTSTS); 484 479 } 485 480 486 481 #define GINTMSK_COMMON (GINTSTS_WKUPINT | GINTSTS_SESSREQINT | \
+25 -84
drivers/usb/dwc2/gadget.c
··· 2095 2095 */ 2096 2096 2097 2097 /* catch both EnumSpd_FS and EnumSpd_FS48 */ 2098 - switch (dsts & DSTS_ENUMSPD_MASK) { 2098 + switch ((dsts & DSTS_ENUMSPD_MASK) >> DSTS_ENUMSPD_SHIFT) { 2099 2099 case DSTS_ENUMSPD_FS: 2100 2100 case DSTS_ENUMSPD_FS48: 2101 2101 hsotg->gadget.speed = USB_SPEED_FULL; ··· 2244 2244 GINTSTS_RXFLVL) 2245 2245 2246 2246 /** 2247 - * dwc2_hsotg_corereset - issue softreset to the core 2248 - * @hsotg: The device state 2249 - * 2250 - * Issue a soft reset to the core, and await the core finishing it. 2251 - */ 2252 - static int dwc2_hsotg_corereset(struct dwc2_hsotg *hsotg) 2253 - { 2254 - int timeout; 2255 - u32 grstctl; 2256 - 2257 - dev_dbg(hsotg->dev, "resetting core\n"); 2258 - 2259 - /* issue soft reset */ 2260 - dwc2_writel(GRSTCTL_CSFTRST, hsotg->regs + GRSTCTL); 2261 - 2262 - timeout = 10000; 2263 - do { 2264 - grstctl = dwc2_readl(hsotg->regs + GRSTCTL); 2265 - } while ((grstctl & GRSTCTL_CSFTRST) && timeout-- > 0); 2266 - 2267 - if (grstctl & GRSTCTL_CSFTRST) { 2268 - dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); 2269 - return -EINVAL; 2270 - } 2271 - 2272 - timeout = 10000; 2273 - 2274 - while (1) { 2275 - u32 grstctl = dwc2_readl(hsotg->regs + GRSTCTL); 2276 - 2277 - if (timeout-- < 0) { 2278 - dev_info(hsotg->dev, 2279 - "%s: reset failed, GRSTCTL=%08x\n", 2280 - __func__, grstctl); 2281 - return -ETIMEDOUT; 2282 - } 2283 - 2284 - if (!(grstctl & GRSTCTL_AHBIDLE)) 2285 - continue; 2286 - 2287 - break; /* reset done */ 2288 - } 2289 - 2290 - dev_dbg(hsotg->dev, "reset successful\n"); 2291 - return 0; 2292 - } 2293 - 2294 - /** 2295 2247 * dwc2_hsotg_core_init - issue softreset to the core 2296 2248 * @hsotg: The device state 2297 2249 * ··· 2259 2307 kill_all_requests(hsotg, hsotg->eps_out[0], -ECONNRESET); 2260 2308 2261 2309 if (!is_usb_reset) 2262 - if (dwc2_hsotg_corereset(hsotg)) 2310 + if (dwc2_core_reset(hsotg)) 2263 2311 return; 2264 2312 2265 2313 /* ··· 2537 2585 if (gintsts & GINTSTS_GOUTNAKEFF) { 2538 2586 dev_info(hsotg->dev, "GOUTNakEff triggered\n"); 2539 2587 2540 - dwc2_writel(DCTL_CGOUTNAK, hsotg->regs + DCTL); 2588 + __orr32(hsotg->regs + DCTL, DCTL_CGOUTNAK); 2541 2589 2542 2590 dwc2_hsotg_dump(hsotg); 2543 2591 } ··· 2545 2593 if (gintsts & GINTSTS_GINNAKEFF) { 2546 2594 dev_info(hsotg->dev, "GINNakEff triggered\n"); 2547 2595 2548 - dwc2_writel(DCTL_CGNPINNAK, hsotg->regs + DCTL); 2596 + __orr32(hsotg->regs + DCTL, DCTL_CGNPINNAK); 2549 2597 2550 2598 dwc2_hsotg_dump(hsotg); 2551 2599 } ··· 2863 2911 "%s: timeout DIEPINT.NAKEFF\n", __func__); 2864 2912 } else { 2865 2913 /* Clear any pending nak effect interrupt */ 2866 - dwc2_writel(GINTSTS_GINNAKEFF, hsotg->regs + GINTSTS); 2914 + dwc2_writel(GINTSTS_GOUTNAKEFF, hsotg->regs + GINTSTS); 2867 2915 2868 - __orr32(hsotg->regs + DCTL, DCTL_SGNPINNAK); 2916 + __orr32(hsotg->regs + DCTL, DCTL_SGOUTNAK); 2869 2917 2870 2918 /* Wait for global nak to take effect */ 2871 2919 if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS, 2872 - GINTSTS_GINNAKEFF, 100)) 2920 + GINTSTS_GOUTNAKEFF, 100)) 2873 2921 dev_warn(hsotg->dev, 2874 - "%s: timeout GINTSTS.GINNAKEFF\n", __func__); 2922 + "%s: timeout GINTSTS.GOUTNAKEFF\n", __func__); 2875 2923 } 2876 2924 2877 2925 /* Disable ep */ ··· 2896 2944 /* TODO: Flush shared tx fifo */ 2897 2945 } else { 2898 2946 /* Remove global NAKs */ 2899 - __bic32(hsotg->regs + DCTL, DCTL_SGNPINNAK); 2947 + __bic32(hsotg->regs + DCTL, DCTL_SGOUTNAK); 2900 2948 } 2901 2949 } 2902 2950 ··· 3355 3403 3356 3404 /* check hardware configuration */ 3357 3405 3358 - cfg = dwc2_readl(hsotg->regs + GHWCFG2); 3359 - hsotg->num_of_eps = (cfg >> GHWCFG2_NUM_DEV_EP_SHIFT) & 0xF; 3406 + hsotg->num_of_eps = hsotg->hw_params.num_dev_ep; 3407 + 3360 3408 /* Add ep0 */ 3361 3409 hsotg->num_of_eps++; 3362 3410 ··· 3367 3415 /* Same dwc2_hsotg_ep is used in both directions for ep0 */ 3368 3416 hsotg->eps_out[0] = hsotg->eps_in[0]; 3369 3417 3370 - cfg = dwc2_readl(hsotg->regs + GHWCFG1); 3418 + cfg = hsotg->hw_params.dev_ep_dirs; 3371 3419 for (i = 1, cfg >>= 2; i < hsotg->num_of_eps; i++, cfg >>= 2) { 3372 3420 ep_type = cfg & 3; 3373 3421 /* Direction in or both */ ··· 3386 3434 } 3387 3435 } 3388 3436 3389 - cfg = dwc2_readl(hsotg->regs + GHWCFG3); 3390 - hsotg->fifo_mem = (cfg >> GHWCFG3_DFIFO_DEPTH_SHIFT); 3391 - 3392 - cfg = dwc2_readl(hsotg->regs + GHWCFG4); 3393 - hsotg->dedicated_fifos = (cfg >> GHWCFG4_DED_FIFO_SHIFT) & 1; 3437 + hsotg->fifo_mem = hsotg->hw_params.total_fifo_size; 3438 + hsotg->dedicated_fifos = hsotg->hw_params.en_multiple_tx_fifo; 3394 3439 3395 3440 dev_info(hsotg->dev, "EPs: %d, %s fifos, %d entries in SPRAM\n", 3396 3441 hsotg->num_of_eps, ··· 3512 3563 memcpy(&hsotg->g_tx_fifo_sz[1], p_tx_fifo, sizeof(p_tx_fifo)); 3513 3564 /* Device tree specific probe */ 3514 3565 dwc2_hsotg_of_probe(hsotg); 3566 + 3567 + /* Check against largest possible value. */ 3568 + if (hsotg->g_np_g_tx_fifo_sz > 3569 + hsotg->hw_params.dev_nperio_tx_fifo_size) { 3570 + dev_warn(dev, "Specified GNPTXFDEP=%d > %d\n", 3571 + hsotg->g_np_g_tx_fifo_sz, 3572 + hsotg->hw_params.dev_nperio_tx_fifo_size); 3573 + hsotg->g_np_g_tx_fifo_sz = 3574 + hsotg->hw_params.dev_nperio_tx_fifo_size; 3575 + } 3576 + 3515 3577 /* Dump fifo information */ 3516 3578 dev_dbg(dev, "NonPeriodic TXFIFO size: %d\n", 3517 3579 hsotg->g_np_g_tx_fifo_sz); ··· 3539 3579 else if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) 3540 3580 hsotg->op_state = OTG_STATE_B_PERIPHERAL; 3541 3581 3542 - /* 3543 - * Force Device mode before initialization. 3544 - * This allows correctly configuring fifo for device mode. 3545 - */ 3546 - __bic32(hsotg->regs + GUSBCFG, GUSBCFG_FORCEHOSTMODE); 3547 - __orr32(hsotg->regs + GUSBCFG, GUSBCFG_FORCEDEVMODE); 3548 - 3549 - /* 3550 - * According to Synopsys databook, this sleep is needed for the force 3551 - * device mode to take effect. 3552 - */ 3553 - msleep(25); 3554 - 3555 - dwc2_hsotg_corereset(hsotg); 3556 3582 ret = dwc2_hsotg_hw_cfg(hsotg); 3557 3583 if (ret) { 3558 3584 dev_err(hsotg->dev, "Hardware configuration failed: %d\n", ret); 3559 3585 return ret; 3560 3586 } 3561 - 3562 - dwc2_hsotg_init(hsotg); 3563 - 3564 - /* Switch back to default configuration */ 3565 - __bic32(hsotg->regs + GUSBCFG, GUSBCFG_FORCEDEVMODE); 3566 3587 3567 3588 hsotg->ctrl_buff = devm_kzalloc(hsotg->dev, 3568 3589 DWC2_CTRL_BUFF_SIZE, GFP_KERNEL);
+122 -8
drivers/usb/dwc2/hcd.c
··· 268 268 } 269 269 270 270 /** 271 - * dwc2_hcd_disconnect() - Handles disconnect of the HCD 271 + * dwc2_hcd_connect() - Handles connect of the HCD 272 272 * 273 273 * @hsotg: Pointer to struct dwc2_hsotg 274 274 * 275 275 * Must be called with interrupt disabled and spinlock held 276 276 */ 277 - void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg) 277 + void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) 278 + { 279 + if (hsotg->lx_state != DWC2_L0) 280 + usb_hcd_resume_root_hub(hsotg->priv); 281 + 282 + hsotg->flags.b.port_connect_status_change = 1; 283 + hsotg->flags.b.port_connect_status = 1; 284 + } 285 + 286 + /** 287 + * dwc2_hcd_disconnect() - Handles disconnect of the HCD 288 + * 289 + * @hsotg: Pointer to struct dwc2_hsotg 290 + * @force: If true, we won't try to reconnect even if we see device connected. 291 + * 292 + * Must be called with interrupt disabled and spinlock held 293 + */ 294 + void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) 278 295 { 279 296 u32 intr; 297 + u32 hprt0; 280 298 281 299 /* Set status flags for the hub driver */ 282 300 hsotg->flags.b.port_connect_status_change = 1; ··· 333 315 dwc2_hcd_cleanup_channels(hsotg); 334 316 335 317 dwc2_host_disconnect(hsotg); 318 + 319 + /* 320 + * Add an extra check here to see if we're actually connected but 321 + * we don't have a detection interrupt pending. This can happen if: 322 + * 1. hardware sees connect 323 + * 2. hardware sees disconnect 324 + * 3. hardware sees connect 325 + * 4. dwc2_port_intr() - clears connect interrupt 326 + * 5. dwc2_handle_common_intr() - calls here 327 + * 328 + * Without the extra check here we will end calling disconnect 329 + * and won't get any future interrupts to handle the connect. 330 + */ 331 + if (!force) { 332 + hprt0 = dwc2_readl(hsotg->regs + HPRT0); 333 + if (!(hprt0 & HPRT0_CONNDET) && (hprt0 & HPRT0_CONNSTS)) 334 + dwc2_hcd_connect(hsotg); 335 + } 336 336 } 337 337 338 338 /** ··· 917 881 */ 918 882 chan->multi_count = dwc2_hb_mult(qh->maxp); 919 883 920 - if (hsotg->core_params->dma_desc_enable > 0) 884 + if (hsotg->core_params->dma_desc_enable > 0) { 921 885 chan->desc_list_addr = qh->desc_list_dma; 886 + chan->desc_list_sz = qh->desc_list_sz; 887 + } 922 888 923 889 dwc2_hc_init(hsotg, chan); 924 890 chan->qh = qh; ··· 1420 1382 dev_err(hsotg->dev, 1421 1383 "Connection id status change timed out\n"); 1422 1384 hsotg->op_state = OTG_STATE_B_PERIPHERAL; 1423 - dwc2_core_init(hsotg, false, -1); 1385 + dwc2_core_init(hsotg, false); 1424 1386 dwc2_enable_global_interrupts(hsotg); 1425 1387 spin_lock_irqsave(&hsotg->lock, flags); 1426 1388 dwc2_hsotg_core_init_disconnected(hsotg, false); ··· 1443 1405 hsotg->op_state = OTG_STATE_A_HOST; 1444 1406 1445 1407 /* Initialize the Core for Host mode */ 1446 - dwc2_core_init(hsotg, false, -1); 1408 + dwc2_core_init(hsotg, false); 1447 1409 dwc2_enable_global_interrupts(hsotg); 1448 1410 dwc2_hcd_start(hsotg); 1449 1411 } ··· 1771 1733 if (hprt0 & HPRT0_TSTCTL_MASK) 1772 1734 port_status |= USB_PORT_STAT_TEST; 1773 1735 /* USB_PORT_FEAT_INDICATOR unsupported always 0 */ 1736 + 1737 + if (hsotg->core_params->dma_desc_fs_enable) { 1738 + /* 1739 + * Enable descriptor DMA only if a full speed 1740 + * device is connected. 1741 + */ 1742 + if (hsotg->new_connection && 1743 + ((port_status & 1744 + (USB_PORT_STAT_CONNECTION | 1745 + USB_PORT_STAT_HIGH_SPEED | 1746 + USB_PORT_STAT_LOW_SPEED)) == 1747 + USB_PORT_STAT_CONNECTION)) { 1748 + u32 hcfg; 1749 + 1750 + dev_info(hsotg->dev, "Enabling descriptor DMA mode\n"); 1751 + hsotg->core_params->dma_desc_enable = 1; 1752 + hcfg = dwc2_readl(hsotg->regs + HCFG); 1753 + hcfg |= HCFG_DESCDMA; 1754 + dwc2_writel(hcfg, hsotg->regs + HCFG); 1755 + hsotg->new_connection = false; 1756 + } 1757 + } 1774 1758 1775 1759 dev_vdbg(hsotg->dev, "port_status=%08x\n", port_status); 1776 1760 *(__le32 *)buf = cpu_to_le32(port_status); ··· 2358 2298 { 2359 2299 struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg, 2360 2300 reset_work.work); 2301 + unsigned long flags; 2361 2302 u32 hprt0; 2362 2303 2363 2304 dev_dbg(hsotg->dev, "USB RESET function called\n"); 2305 + 2306 + spin_lock_irqsave(&hsotg->lock, flags); 2307 + 2364 2308 hprt0 = dwc2_read_hprt0(hsotg); 2365 2309 hprt0 &= ~HPRT0_RST; 2366 2310 dwc2_writel(hprt0, hsotg->regs + HPRT0); 2367 2311 hsotg->flags.b.port_reset_change = 1; 2312 + 2313 + spin_unlock_irqrestore(&hsotg->lock, flags); 2368 2314 } 2369 2315 2370 2316 /* ··· 2432 2366 2433 2367 spin_lock_irqsave(&hsotg->lock, flags); 2434 2368 /* Ensure hcd is disconnected */ 2435 - dwc2_hcd_disconnect(hsotg); 2369 + dwc2_hcd_disconnect(hsotg, true); 2436 2370 dwc2_hcd_stop(hsotg); 2437 2371 hsotg->lx_state = DWC2_L3; 2438 2372 hcd->state = HC_STATE_HALT; ··· 3120 3054 dwc2_disable_global_interrupts(hsotg); 3121 3055 3122 3056 /* Initialize the DWC_otg core, and select the Phy type */ 3123 - retval = dwc2_core_init(hsotg, true, irq); 3057 + retval = dwc2_core_init(hsotg, true); 3124 3058 if (retval) 3125 3059 goto error2; 3126 3060 ··· 3188 3122 if (!hsotg->status_buf) 3189 3123 goto error3; 3190 3124 3125 + /* 3126 + * Create kmem caches to handle descriptor buffers in descriptor 3127 + * DMA mode. 3128 + * Alignment must be set to 512 bytes. 3129 + */ 3130 + if (hsotg->core_params->dma_desc_enable || 3131 + hsotg->core_params->dma_desc_fs_enable) { 3132 + hsotg->desc_gen_cache = kmem_cache_create("dwc2-gen-desc", 3133 + sizeof(struct dwc2_hcd_dma_desc) * 3134 + MAX_DMA_DESC_NUM_GENERIC, 512, SLAB_CACHE_DMA, 3135 + NULL); 3136 + if (!hsotg->desc_gen_cache) { 3137 + dev_err(hsotg->dev, 3138 + "unable to create dwc2 generic desc cache\n"); 3139 + 3140 + /* 3141 + * Disable descriptor dma mode since it will not be 3142 + * usable. 3143 + */ 3144 + hsotg->core_params->dma_desc_enable = 0; 3145 + hsotg->core_params->dma_desc_fs_enable = 0; 3146 + } 3147 + 3148 + hsotg->desc_hsisoc_cache = kmem_cache_create("dwc2-hsisoc-desc", 3149 + sizeof(struct dwc2_hcd_dma_desc) * 3150 + MAX_DMA_DESC_NUM_HS_ISOC, 512, 0, NULL); 3151 + if (!hsotg->desc_hsisoc_cache) { 3152 + dev_err(hsotg->dev, 3153 + "unable to create dwc2 hs isoc desc cache\n"); 3154 + 3155 + kmem_cache_destroy(hsotg->desc_gen_cache); 3156 + 3157 + /* 3158 + * Disable descriptor dma mode since it will not be 3159 + * usable. 3160 + */ 3161 + hsotg->core_params->dma_desc_enable = 0; 3162 + hsotg->core_params->dma_desc_fs_enable = 0; 3163 + } 3164 + } 3165 + 3191 3166 hsotg->otg_port = 1; 3192 3167 hsotg->frame_list = NULL; 3193 3168 hsotg->frame_list_dma = 0; ··· 3252 3145 */ 3253 3146 retval = usb_add_hcd(hcd, irq, IRQF_SHARED); 3254 3147 if (retval < 0) 3255 - goto error3; 3148 + goto error4; 3256 3149 3257 3150 device_wakeup_enable(hcd->self.controller); 3258 3151 ··· 3262 3155 3263 3156 return 0; 3264 3157 3158 + error4: 3159 + kmem_cache_destroy(hsotg->desc_gen_cache); 3160 + kmem_cache_destroy(hsotg->desc_hsisoc_cache); 3265 3161 error3: 3266 3162 dwc2_hcd_release(hsotg); 3267 3163 error2: ··· 3305 3195 3306 3196 usb_remove_hcd(hcd); 3307 3197 hsotg->priv = NULL; 3198 + 3199 + kmem_cache_destroy(hsotg->desc_gen_cache); 3200 + kmem_cache_destroy(hsotg->desc_hsisoc_cache); 3201 + 3308 3202 dwc2_hcd_release(hsotg); 3309 3203 usb_put_hcd(hcd); 3310 3204
+19 -12
drivers/usb/dwc2/hcd.h
··· 107 107 * @qh: QH for the transfer being processed by this channel 108 108 * @hc_list_entry: For linking to list of host channels 109 109 * @desc_list_addr: Current QH's descriptor list DMA address 110 + * @desc_list_sz: Current QH's descriptor list size 110 111 * 111 112 * This structure represents the state of a single host channel when acting in 112 113 * host mode. It contains the data items needed to transfer packets to an ··· 160 159 struct dwc2_qh *qh; 161 160 struct list_head hc_list_entry; 162 161 dma_addr_t desc_list_addr; 162 + u32 desc_list_sz; 163 163 }; 164 164 165 165 struct dwc2_hcd_pipe_info { ··· 253 251 * schedule 254 252 * @desc_list: List of transfer descriptors 255 253 * @desc_list_dma: Physical address of desc_list 254 + * @desc_list_sz: Size of descriptors list 256 255 * @n_bytes: Xfer Bytes array. Each element corresponds to a transfer 257 256 * descriptor and indicates original XferSize value for the 258 257 * descriptor ··· 287 284 struct list_head qh_list_entry; 288 285 struct dwc2_hcd_dma_desc *desc_list; 289 286 dma_addr_t desc_list_dma; 287 + u32 desc_list_sz; 290 288 u32 *n_bytes; 291 289 unsigned tt_buffer_dirty:1; 292 290 }; ··· 344 340 u8 isoc_split_pos; 345 341 u16 isoc_frame_index; 346 342 u16 isoc_split_offset; 343 + u16 isoc_td_last; 344 + u16 isoc_td_first; 347 345 u32 ssplit_out_xfer_count; 348 346 u8 error_count; 349 347 u8 n_desc; ··· 381 375 382 376 mask &= ~intr; 383 377 dwc2_writel(mask, hsotg->regs + HCINTMSK(chnum)); 384 - } 385 - 386 - /* 387 - * Returns the mode of operation, host or device 388 - */ 389 - static inline int dwc2_is_host_mode(struct dwc2_hsotg *hsotg) 390 - { 391 - return (dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) != 0; 392 - } 393 - static inline int dwc2_is_device_mode(struct dwc2_hsotg *hsotg) 394 - { 395 - return (dwc2_readl(hsotg->regs + GINTSTS) & GINTSTS_CURMODE_HOST) == 0; 396 378 } 397 379 398 380 /* ··· 527 533 528 534 /* Packet size for any kind of endpoint descriptor */ 529 535 #define dwc2_max_packet(wmaxpacketsize) ((wmaxpacketsize) & 0x07ff) 536 + 537 + /* 538 + * Returns true if frame1 index is greater than frame2 index. The comparison 539 + * is done modulo FRLISTEN_64_SIZE. This accounts for the rollover of the 540 + * frame number when the max index frame number is reached. 541 + */ 542 + static inline bool dwc2_frame_idx_num_gt(u16 fr_idx1, u16 fr_idx2) 543 + { 544 + u16 diff = fr_idx1 - fr_idx2; 545 + u16 sign = diff & (FRLISTEN_64_SIZE >> 1); 546 + 547 + return diff && !sign; 548 + } 530 549 531 550 /* 532 551 * Returns true if frame1 is less than or equal to frame2. The comparison is
+200 -40
drivers/usb/dwc2/hcd_ddma.c
··· 87 87 static int dwc2_desc_list_alloc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, 88 88 gfp_t flags) 89 89 { 90 - qh->desc_list = dma_alloc_coherent(hsotg->dev, 91 - sizeof(struct dwc2_hcd_dma_desc) * 92 - dwc2_max_desc_num(qh), &qh->desc_list_dma, 93 - flags); 90 + struct kmem_cache *desc_cache; 94 91 92 + if (qh->ep_type == USB_ENDPOINT_XFER_ISOC 93 + && qh->dev_speed == USB_SPEED_HIGH) 94 + desc_cache = hsotg->desc_hsisoc_cache; 95 + else 96 + desc_cache = hsotg->desc_gen_cache; 97 + 98 + qh->desc_list_sz = sizeof(struct dwc2_hcd_dma_desc) * 99 + dwc2_max_desc_num(qh); 100 + 101 + qh->desc_list = kmem_cache_zalloc(desc_cache, flags | GFP_DMA); 95 102 if (!qh->desc_list) 96 103 return -ENOMEM; 97 104 98 - memset(qh->desc_list, 0, 99 - sizeof(struct dwc2_hcd_dma_desc) * dwc2_max_desc_num(qh)); 105 + qh->desc_list_dma = dma_map_single(hsotg->dev, qh->desc_list, 106 + qh->desc_list_sz, 107 + DMA_TO_DEVICE); 100 108 101 109 qh->n_bytes = kzalloc(sizeof(u32) * dwc2_max_desc_num(qh), flags); 102 110 if (!qh->n_bytes) { 103 - dma_free_coherent(hsotg->dev, sizeof(struct dwc2_hcd_dma_desc) 104 - * dwc2_max_desc_num(qh), qh->desc_list, 105 - qh->desc_list_dma); 111 + dma_unmap_single(hsotg->dev, qh->desc_list_dma, 112 + qh->desc_list_sz, 113 + DMA_FROM_DEVICE); 114 + kfree(qh->desc_list); 106 115 qh->desc_list = NULL; 107 116 return -ENOMEM; 108 117 } ··· 121 112 122 113 static void dwc2_desc_list_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) 123 114 { 115 + struct kmem_cache *desc_cache; 116 + 117 + if (qh->ep_type == USB_ENDPOINT_XFER_ISOC 118 + && qh->dev_speed == USB_SPEED_HIGH) 119 + desc_cache = hsotg->desc_hsisoc_cache; 120 + else 121 + desc_cache = hsotg->desc_gen_cache; 122 + 124 123 if (qh->desc_list) { 125 - dma_free_coherent(hsotg->dev, sizeof(struct dwc2_hcd_dma_desc) 126 - * dwc2_max_desc_num(qh), qh->desc_list, 127 - qh->desc_list_dma); 124 + dma_unmap_single(hsotg->dev, qh->desc_list_dma, 125 + qh->desc_list_sz, DMA_FROM_DEVICE); 126 + kmem_cache_free(desc_cache, qh->desc_list); 128 127 qh->desc_list = NULL; 129 128 } 130 129 ··· 145 128 if (hsotg->frame_list) 146 129 return 0; 147 130 148 - hsotg->frame_list = dma_alloc_coherent(hsotg->dev, 149 - 4 * FRLISTEN_64_SIZE, 150 - &hsotg->frame_list_dma, 151 - mem_flags); 131 + hsotg->frame_list_sz = 4 * FRLISTEN_64_SIZE; 132 + hsotg->frame_list = kzalloc(hsotg->frame_list_sz, GFP_ATOMIC | GFP_DMA); 152 133 if (!hsotg->frame_list) 153 134 return -ENOMEM; 154 135 155 - memset(hsotg->frame_list, 0, 4 * FRLISTEN_64_SIZE); 136 + hsotg->frame_list_dma = dma_map_single(hsotg->dev, hsotg->frame_list, 137 + hsotg->frame_list_sz, 138 + DMA_TO_DEVICE); 139 + 156 140 return 0; 157 141 } 158 142 159 143 static void dwc2_frame_list_free(struct dwc2_hsotg *hsotg) 160 144 { 161 - u32 *frame_list; 162 - dma_addr_t frame_list_dma; 163 145 unsigned long flags; 164 146 165 147 spin_lock_irqsave(&hsotg->lock, flags); ··· 168 152 return; 169 153 } 170 154 171 - frame_list = hsotg->frame_list; 172 - frame_list_dma = hsotg->frame_list_dma; 155 + dma_unmap_single(hsotg->dev, hsotg->frame_list_dma, 156 + hsotg->frame_list_sz, DMA_FROM_DEVICE); 157 + 158 + kfree(hsotg->frame_list); 173 159 hsotg->frame_list = NULL; 174 160 175 161 spin_unlock_irqrestore(&hsotg->lock, flags); 176 162 177 - dma_free_coherent(hsotg->dev, 4 * FRLISTEN_64_SIZE, frame_list, 178 - frame_list_dma); 179 163 } 180 164 181 165 static void dwc2_per_sched_enable(struct dwc2_hsotg *hsotg, u32 fr_list_en) ··· 265 249 j = (j + inc) & (FRLISTEN_64_SIZE - 1); 266 250 } while (j != i); 267 251 252 + /* 253 + * Sync frame list since controller will access it if periodic 254 + * channel is currently enabled. 255 + */ 256 + dma_sync_single_for_device(hsotg->dev, 257 + hsotg->frame_list_dma, 258 + hsotg->frame_list_sz, 259 + DMA_TO_DEVICE); 260 + 268 261 if (!enable) 269 262 return; 270 263 ··· 303 278 hsotg->non_periodic_channels--; 304 279 } else { 305 280 dwc2_update_frame_list(hsotg, qh, 0); 281 + hsotg->available_host_channels++; 306 282 } 307 283 308 284 /* ··· 386 360 */ 387 361 void dwc2_hcd_qh_free_ddma(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) 388 362 { 363 + unsigned long flags; 364 + 389 365 dwc2_desc_list_free(hsotg, qh); 390 366 391 367 /* ··· 397 369 * when it comes here from endpoint disable routine 398 370 * channel remains assigned. 399 371 */ 372 + spin_lock_irqsave(&hsotg->lock, flags); 400 373 if (qh->channel) 401 374 dwc2_release_channel_ddma(hsotg, qh); 375 + spin_unlock_irqrestore(&hsotg->lock, flags); 402 376 403 377 if ((qh->ep_type == USB_ENDPOINT_XFER_ISOC || 404 378 qh->ep_type == USB_ENDPOINT_XFER_INT) && ··· 554 524 dma_desc->status = qh->n_bytes[idx] << HOST_DMA_ISOC_NBYTES_SHIFT & 555 525 HOST_DMA_ISOC_NBYTES_MASK; 556 526 527 + /* Set active bit */ 528 + dma_desc->status |= HOST_DMA_A; 529 + 530 + qh->ntd++; 531 + qtd->isoc_frame_index_last++; 532 + 557 533 #ifdef ISOC_URB_GIVEBACK_ASAP 558 534 /* Set IOC for each descriptor corresponding to last frame of URB */ 559 535 if (qtd->isoc_frame_index_last == qtd->urb->packet_count) 560 536 dma_desc->status |= HOST_DMA_IOC; 561 537 #endif 562 538 563 - qh->ntd++; 564 - qtd->isoc_frame_index_last++; 539 + dma_sync_single_for_device(hsotg->dev, 540 + qh->desc_list_dma + 541 + (idx * sizeof(struct dwc2_hcd_dma_desc)), 542 + sizeof(struct dwc2_hcd_dma_desc), 543 + DMA_TO_DEVICE); 565 544 } 566 545 567 546 static void dwc2_init_isoc_dma_desc(struct dwc2_hsotg *hsotg, ··· 578 539 { 579 540 struct dwc2_qtd *qtd; 580 541 u32 max_xfer_size; 581 - u16 idx, inc, n_desc, ntd_max = 0; 542 + u16 idx, inc, n_desc = 0, ntd_max = 0; 543 + u16 cur_idx; 544 + u16 next_idx; 582 545 583 546 idx = qh->td_last; 584 547 inc = qh->interval; 585 - n_desc = 0; 548 + hsotg->frame_number = dwc2_hcd_get_frame_number(hsotg); 549 + cur_idx = dwc2_frame_list_idx(hsotg->frame_number); 550 + next_idx = dwc2_desclist_idx_inc(qh->td_last, inc, qh->dev_speed); 551 + 552 + /* 553 + * Ensure current frame number didn't overstep last scheduled 554 + * descriptor. If it happens, the only way to recover is to move 555 + * qh->td_last to current frame number + 1. 556 + * So that next isoc descriptor will be scheduled on frame number + 1 557 + * and not on a past frame. 558 + */ 559 + if (dwc2_frame_idx_num_gt(cur_idx, next_idx) || (cur_idx == next_idx)) { 560 + if (inc < 32) { 561 + dev_vdbg(hsotg->dev, 562 + "current frame number overstep last descriptor\n"); 563 + qh->td_last = dwc2_desclist_idx_inc(cur_idx, inc, 564 + qh->dev_speed); 565 + idx = qh->td_last; 566 + } 567 + } 586 568 587 569 if (qh->interval) { 588 570 ntd_max = (dwc2_max_desc_num(qh) + qh->interval - 1) / ··· 616 556 MAX_ISOC_XFER_SIZE_HS : MAX_ISOC_XFER_SIZE_FS; 617 557 618 558 list_for_each_entry(qtd, &qh->qtd_list, qtd_list_entry) { 559 + if (qtd->in_process && 560 + qtd->isoc_frame_index_last == 561 + qtd->urb->packet_count) 562 + continue; 563 + 564 + qtd->isoc_td_first = idx; 619 565 while (qh->ntd < ntd_max && qtd->isoc_frame_index_last < 620 566 qtd->urb->packet_count) { 621 - if (n_desc > 1) 622 - qh->desc_list[n_desc - 1].status |= HOST_DMA_A; 623 567 dwc2_fill_host_isoc_dma_desc(hsotg, qtd, qh, 624 568 max_xfer_size, idx); 625 569 idx = dwc2_desclist_idx_inc(idx, inc, qh->dev_speed); 626 570 n_desc++; 627 571 } 572 + qtd->isoc_td_last = idx; 628 573 qtd->in_process = 1; 629 574 } 630 575 ··· 640 575 if (qh->ntd == ntd_max) { 641 576 idx = dwc2_desclist_idx_dec(qh->td_last, inc, qh->dev_speed); 642 577 qh->desc_list[idx].status |= HOST_DMA_IOC; 578 + dma_sync_single_for_device(hsotg->dev, 579 + qh->desc_list_dma + (idx * 580 + sizeof(struct dwc2_hcd_dma_desc)), 581 + sizeof(struct dwc2_hcd_dma_desc), 582 + DMA_TO_DEVICE); 643 583 } 644 584 #else 645 585 /* ··· 674 604 idx = dwc2_desclist_idx_dec(qh->td_last, inc, qh->dev_speed); 675 605 676 606 qh->desc_list[idx].status |= HOST_DMA_IOC; 607 + dma_sync_single_for_device(hsotg->dev, 608 + qh->desc_list_dma + 609 + (idx * sizeof(struct dwc2_hcd_dma_desc)), 610 + sizeof(struct dwc2_hcd_dma_desc), 611 + DMA_TO_DEVICE); 677 612 #endif 678 - 679 - if (n_desc) { 680 - qh->desc_list[n_desc - 1].status |= HOST_DMA_A; 681 - if (n_desc > 1) 682 - qh->desc_list[0].status |= HOST_DMA_A; 683 - } 684 613 } 685 614 686 615 static void dwc2_fill_host_dma_desc(struct dwc2_hsotg *hsotg, ··· 715 646 dma_desc->status |= HOST_DMA_SUP; 716 647 717 648 dma_desc->buf = (u32)chan->xfer_dma; 649 + 650 + dma_sync_single_for_device(hsotg->dev, 651 + qh->desc_list_dma + 652 + (n_desc * sizeof(struct dwc2_hcd_dma_desc)), 653 + sizeof(struct dwc2_hcd_dma_desc), 654 + DMA_TO_DEVICE); 718 655 719 656 /* 720 657 * Last (or only) descriptor of IN transfer with actual size less ··· 772 697 "set A bit in desc %d (%p)\n", 773 698 n_desc - 1, 774 699 &qh->desc_list[n_desc - 1]); 700 + dma_sync_single_for_device(hsotg->dev, 701 + qh->desc_list_dma + 702 + ((n_desc - 1) * 703 + sizeof(struct dwc2_hcd_dma_desc)), 704 + sizeof(struct dwc2_hcd_dma_desc), 705 + DMA_TO_DEVICE); 775 706 } 776 707 dwc2_fill_host_dma_desc(hsotg, chan, qtd, qh, n_desc); 777 708 dev_vdbg(hsotg->dev, ··· 803 722 HOST_DMA_IOC | HOST_DMA_EOL | HOST_DMA_A; 804 723 dev_vdbg(hsotg->dev, "set IOC/EOL/A bits in desc %d (%p)\n", 805 724 n_desc - 1, &qh->desc_list[n_desc - 1]); 725 + dma_sync_single_for_device(hsotg->dev, 726 + qh->desc_list_dma + (n_desc - 1) * 727 + sizeof(struct dwc2_hcd_dma_desc), 728 + sizeof(struct dwc2_hcd_dma_desc), 729 + DMA_TO_DEVICE); 806 730 if (n_desc > 1) { 807 731 qh->desc_list[0].status |= HOST_DMA_A; 808 732 dev_vdbg(hsotg->dev, "set A bit in desc 0 (%p)\n", 809 733 &qh->desc_list[0]); 734 + dma_sync_single_for_device(hsotg->dev, 735 + qh->desc_list_dma, 736 + sizeof(struct dwc2_hcd_dma_desc), 737 + DMA_TO_DEVICE); 810 738 } 811 739 chan->ntd = n_desc; 812 740 } ··· 890 800 struct dwc2_qtd *qtd, 891 801 struct dwc2_qh *qh, u16 idx) 892 802 { 893 - struct dwc2_hcd_dma_desc *dma_desc = &qh->desc_list[idx]; 803 + struct dwc2_hcd_dma_desc *dma_desc; 894 804 struct dwc2_hcd_iso_packet_desc *frame_desc; 895 805 u16 remain = 0; 896 806 int rc = 0; 897 807 898 808 if (!qtd->urb) 899 809 return -EINVAL; 810 + 811 + dma_sync_single_for_cpu(hsotg->dev, qh->desc_list_dma + (idx * 812 + sizeof(struct dwc2_hcd_dma_desc)), 813 + sizeof(struct dwc2_hcd_dma_desc), 814 + DMA_FROM_DEVICE); 815 + 816 + dma_desc = &qh->desc_list[idx]; 900 817 901 818 frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last]; 902 819 dma_desc->buf = (u32)(qtd->urb->dma + frame_desc->offset); ··· 1008 911 list_for_each_entry_safe(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) { 1009 912 if (!qtd->in_process) 1010 913 break; 914 + 915 + /* 916 + * Ensure idx corresponds to descriptor where first urb of this 917 + * qtd was added. In fact, during isoc desc init, dwc2 may skip 918 + * an index if current frame number is already over this index. 919 + */ 920 + if (idx != qtd->isoc_td_first) { 921 + dev_vdbg(hsotg->dev, 922 + "try to complete %d instead of %d\n", 923 + idx, qtd->isoc_td_first); 924 + idx = qtd->isoc_td_first; 925 + } 926 + 1011 927 do { 928 + struct dwc2_qtd *qtd_next; 929 + u16 cur_idx; 930 + 1012 931 rc = dwc2_cmpl_host_isoc_dma_desc(hsotg, chan, qtd, qh, 1013 932 idx); 1014 933 if (rc < 0) 1015 934 return; 1016 935 idx = dwc2_desclist_idx_inc(idx, qh->interval, 1017 936 chan->speed); 1018 - if (rc == DWC2_CMPL_STOP) 1019 - goto stop_scan; 937 + if (!rc) 938 + continue; 939 + 1020 940 if (rc == DWC2_CMPL_DONE) 1021 941 break; 942 + 943 + /* rc == DWC2_CMPL_STOP */ 944 + 945 + if (qh->interval >= 32) 946 + goto stop_scan; 947 + 948 + qh->td_first = idx; 949 + cur_idx = dwc2_frame_list_idx(hsotg->frame_number); 950 + qtd_next = list_first_entry(&qh->qtd_list, 951 + struct dwc2_qtd, 952 + qtd_list_entry); 953 + if (dwc2_frame_idx_num_gt(cur_idx, 954 + qtd_next->isoc_td_last)) 955 + break; 956 + 957 + goto stop_scan; 958 + 1022 959 } while (idx != qh->td_first); 1023 960 } 1024 961 ··· 1160 1029 if (!urb) 1161 1030 return -EINVAL; 1162 1031 1032 + dma_sync_single_for_cpu(hsotg->dev, 1033 + qh->desc_list_dma + (desc_num * 1034 + sizeof(struct dwc2_hcd_dma_desc)), 1035 + sizeof(struct dwc2_hcd_dma_desc), 1036 + DMA_FROM_DEVICE); 1037 + 1163 1038 dma_desc = &qh->desc_list[desc_num]; 1164 1039 n_bytes = qh->n_bytes[desc_num]; 1165 1040 dev_vdbg(hsotg->dev, ··· 1174 1037 failed = dwc2_update_non_isoc_urb_state_ddma(hsotg, chan, qtd, dma_desc, 1175 1038 halt_status, n_bytes, 1176 1039 xfer_done); 1177 - if (failed || (*xfer_done && urb->status != -EINPROGRESS)) { 1040 + if (*xfer_done && urb->status != -EINPROGRESS) 1041 + failed = 1; 1042 + 1043 + if (failed) { 1178 1044 dwc2_host_complete(hsotg, qtd, urb->status); 1179 1045 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd, qh); 1180 1046 dev_vdbg(hsotg->dev, "failed=%1x xfer_done=%1x status=%08x\n", ··· 1305 1165 /* Release the channel if halted or session completed */ 1306 1166 if (halt_status != DWC2_HC_XFER_COMPLETE || 1307 1167 list_empty(&qh->qtd_list)) { 1168 + struct dwc2_qtd *qtd, *qtd_tmp; 1169 + 1170 + /* 1171 + * Kill all remainings QTDs since channel has been 1172 + * halted. 1173 + */ 1174 + list_for_each_entry_safe(qtd, qtd_tmp, 1175 + &qh->qtd_list, 1176 + qtd_list_entry) { 1177 + dwc2_host_complete(hsotg, qtd, 1178 + -ECONNRESET); 1179 + dwc2_hcd_qtd_unlink_and_free(hsotg, 1180 + qtd, qh); 1181 + } 1182 + 1308 1183 /* Halt the channel if session completed */ 1309 1184 if (halt_status == DWC2_HC_XFER_COMPLETE) 1310 1185 dwc2_hc_halt(hsotg, chan, halt_status); ··· 1329 1174 /* Keep in assigned schedule to continue transfer */ 1330 1175 list_move(&qh->qh_list_entry, 1331 1176 &hsotg->periodic_sched_assigned); 1332 - continue_isoc_xfer = 1; 1177 + /* 1178 + * If channel has been halted during giveback of urb 1179 + * then prevent any new scheduling. 1180 + */ 1181 + if (!chan->halt_status) 1182 + continue_isoc_xfer = 1; 1333 1183 } 1334 1184 /* 1335 1185 * Todo: Consider the case when period exceeds FrameList size.
+23 -16
drivers/usb/dwc2/hcd_intr.c
··· 122 122 struct dwc2_qh *qh; 123 123 enum dwc2_transaction_type tr_type; 124 124 125 + /* Clear interrupt */ 126 + dwc2_writel(GINTSTS_SOF, hsotg->regs + GINTSTS); 127 + 125 128 #ifdef DEBUG_SOF 126 129 dev_vdbg(hsotg->dev, "--Start of Frame Interrupt--\n"); 127 130 #endif ··· 149 146 tr_type = dwc2_hcd_select_transactions(hsotg); 150 147 if (tr_type != DWC2_TRANSACTION_NONE) 151 148 dwc2_hcd_queue_transactions(hsotg, tr_type); 152 - 153 - /* Clear interrupt */ 154 - dwc2_writel(GINTSTS_SOF, hsotg->regs + GINTSTS); 155 149 } 156 150 157 151 /* ··· 312 312 313 313 if (do_reset) { 314 314 *hprt0_modify |= HPRT0_RST; 315 + dwc2_writel(*hprt0_modify, hsotg->regs + HPRT0); 315 316 queue_delayed_work(hsotg->wq_otg, &hsotg->reset_work, 316 317 msecs_to_jiffies(60)); 317 318 } else { ··· 348 347 * Set flag and clear if detected 349 348 */ 350 349 if (hprt0 & HPRT0_CONNDET) { 350 + dwc2_writel(hprt0_modify | HPRT0_CONNDET, hsotg->regs + HPRT0); 351 + 351 352 dev_vdbg(hsotg->dev, 352 353 "--Port Interrupt HPRT0=0x%08x Port Connect Detected--\n", 353 354 hprt0); 354 - if (hsotg->lx_state != DWC2_L0) 355 - usb_hcd_resume_root_hub(hsotg->priv); 356 - 357 - hsotg->flags.b.port_connect_status_change = 1; 358 - hsotg->flags.b.port_connect_status = 1; 359 - hprt0_modify |= HPRT0_CONNDET; 355 + dwc2_hcd_connect(hsotg); 360 356 361 357 /* 362 358 * The Hub driver asserts a reset when it sees port connect ··· 366 368 * Clear if detected - Set internal flag if disabled 367 369 */ 368 370 if (hprt0 & HPRT0_ENACHG) { 371 + dwc2_writel(hprt0_modify | HPRT0_ENACHG, hsotg->regs + HPRT0); 369 372 dev_vdbg(hsotg->dev, 370 373 " --Port Interrupt HPRT0=0x%08x Port Enable Changed (now %d)--\n", 371 374 hprt0, !!(hprt0 & HPRT0_ENA)); 372 - hprt0_modify |= HPRT0_ENACHG; 373 - if (hprt0 & HPRT0_ENA) 375 + if (hprt0 & HPRT0_ENA) { 376 + hsotg->new_connection = true; 374 377 dwc2_hprt0_enable(hsotg, hprt0, &hprt0_modify); 375 - else 378 + } else { 376 379 hsotg->flags.b.port_enable_change = 1; 380 + if (hsotg->core_params->dma_desc_fs_enable) { 381 + u32 hcfg; 382 + 383 + hsotg->core_params->dma_desc_enable = 0; 384 + hsotg->new_connection = false; 385 + hcfg = dwc2_readl(hsotg->regs + HCFG); 386 + hcfg &= ~HCFG_DESCDMA; 387 + dwc2_writel(hcfg, hsotg->regs + HCFG); 388 + } 389 + } 377 390 } 378 391 379 392 /* Overcurrent Change Interrupt */ 380 393 if (hprt0 & HPRT0_OVRCURRCHG) { 394 + dwc2_writel(hprt0_modify | HPRT0_OVRCURRCHG, 395 + hsotg->regs + HPRT0); 381 396 dev_vdbg(hsotg->dev, 382 397 " --Port Interrupt HPRT0=0x%08x Port Overcurrent Changed--\n", 383 398 hprt0); 384 399 hsotg->flags.b.port_over_current_change = 1; 385 - hprt0_modify |= HPRT0_OVRCURRCHG; 386 400 } 387 - 388 - /* Clear Port Interrupts */ 389 - dwc2_writel(hprt0_modify, hsotg->regs + HPRT0); 390 401 } 391 402 392 403 /*
+1 -1
drivers/usb/dwc2/hcd_queue.c
··· 232 232 */ 233 233 void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) 234 234 { 235 - if (hsotg->core_params->dma_desc_enable > 0) { 235 + if (qh->desc_list) { 236 236 dwc2_hcd_qh_free_ddma(hsotg, qh); 237 237 } else { 238 238 /* kfree(NULL) is safe */
-4
drivers/usb/dwc2/hw.h
··· 769 769 #define TSIZ_XFERSIZE_SHIFT 0 770 770 771 771 #define HCDMA(_ch) HSOTG_REG(0x0514 + 0x20 * (_ch)) 772 - #define HCDMA_DMA_ADDR_MASK (0x1fffff << 11) 773 - #define HCDMA_DMA_ADDR_SHIFT 11 774 - #define HCDMA_CTD_MASK (0xff << 3) 775 - #define HCDMA_CTD_SHIFT 3 776 772 777 773 #define HCDMAB(_ch) HSOTG_REG(0x051c + 0x20 * (_ch)) 778 774
+136 -22
drivers/usb/dwc2/platform.c
··· 54 54 55 55 static const char dwc2_driver_name[] = "dwc2"; 56 56 57 + static const struct dwc2_core_params params_hi6220 = { 58 + .otg_cap = 2, /* No HNP/SRP capable */ 59 + .otg_ver = 0, /* 1.3 */ 60 + .dma_enable = 1, 61 + .dma_desc_enable = 0, 62 + .dma_desc_fs_enable = 0, 63 + .speed = 0, /* High Speed */ 64 + .enable_dynamic_fifo = 1, 65 + .en_multiple_tx_fifo = 1, 66 + .host_rx_fifo_size = 512, 67 + .host_nperio_tx_fifo_size = 512, 68 + .host_perio_tx_fifo_size = 512, 69 + .max_transfer_size = 65535, 70 + .max_packet_count = 511, 71 + .host_channels = 16, 72 + .phy_type = 1, /* UTMI */ 73 + .phy_utmi_width = 8, 74 + .phy_ulpi_ddr = 0, /* Single */ 75 + .phy_ulpi_ext_vbus = 0, 76 + .i2c_enable = 0, 77 + .ulpi_fs_ls = 0, 78 + .host_support_fs_ls_low_power = 0, 79 + .host_ls_low_power_phy_clk = 0, /* 48 MHz */ 80 + .ts_dline = 0, 81 + .reload_ctl = 0, 82 + .ahbcfg = GAHBCFG_HBSTLEN_INCR16 << 83 + GAHBCFG_HBSTLEN_SHIFT, 84 + .uframe_sched = 0, 85 + .external_id_pin_ctl = -1, 86 + .hibernation = -1, 87 + }; 88 + 57 89 static const struct dwc2_core_params params_bcm2835 = { 58 90 .otg_cap = 0, /* HNP/SRP capable */ 59 91 .otg_ver = 0, /* 1.3 */ 60 92 .dma_enable = 1, 61 93 .dma_desc_enable = 0, 94 + .dma_desc_fs_enable = 0, 62 95 .speed = 0, /* High Speed */ 63 96 .enable_dynamic_fifo = 1, 64 97 .en_multiple_tx_fifo = 1, ··· 122 89 .otg_ver = -1, 123 90 .dma_enable = -1, 124 91 .dma_desc_enable = 0, 92 + .dma_desc_fs_enable = 0, 125 93 .speed = -1, 126 94 .enable_dynamic_fifo = 1, 127 95 .en_multiple_tx_fifo = -1, ··· 148 114 .external_id_pin_ctl = -1, 149 115 .hibernation = -1, 150 116 }; 117 + 118 + /* 119 + * Check the dr_mode against the module configuration and hardware 120 + * capabilities. 121 + * 122 + * The hardware, module, and dr_mode, can each be set to host, device, 123 + * or otg. Check that all these values are compatible and adjust the 124 + * value of dr_mode if possible. 125 + * 126 + * actual 127 + * HW MOD dr_mode dr_mode 128 + * ------------------------------ 129 + * HST HST any : HST 130 + * HST DEV any : --- 131 + * HST OTG any : HST 132 + * 133 + * DEV HST any : --- 134 + * DEV DEV any : DEV 135 + * DEV OTG any : DEV 136 + * 137 + * OTG HST any : HST 138 + * OTG DEV any : DEV 139 + * OTG OTG any : dr_mode 140 + */ 141 + static int dwc2_get_dr_mode(struct dwc2_hsotg *hsotg) 142 + { 143 + enum usb_dr_mode mode; 144 + 145 + hsotg->dr_mode = usb_get_dr_mode(hsotg->dev); 146 + if (hsotg->dr_mode == USB_DR_MODE_UNKNOWN) 147 + hsotg->dr_mode = USB_DR_MODE_OTG; 148 + 149 + mode = hsotg->dr_mode; 150 + 151 + if (dwc2_hw_is_device(hsotg)) { 152 + if (IS_ENABLED(CONFIG_USB_DWC2_HOST)) { 153 + dev_err(hsotg->dev, 154 + "Controller does not support host mode.\n"); 155 + return -EINVAL; 156 + } 157 + mode = USB_DR_MODE_PERIPHERAL; 158 + } else if (dwc2_hw_is_host(hsotg)) { 159 + if (IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL)) { 160 + dev_err(hsotg->dev, 161 + "Controller does not support device mode.\n"); 162 + return -EINVAL; 163 + } 164 + mode = USB_DR_MODE_HOST; 165 + } else { 166 + if (IS_ENABLED(CONFIG_USB_DWC2_HOST)) 167 + mode = USB_DR_MODE_HOST; 168 + else if (IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL)) 169 + mode = USB_DR_MODE_PERIPHERAL; 170 + } 171 + 172 + if (mode != hsotg->dr_mode) { 173 + dev_warn(hsotg->dev, 174 + "Configuration mismatch. dr_mode forced to %s\n", 175 + mode == USB_DR_MODE_HOST ? "host" : "device"); 176 + 177 + hsotg->dr_mode = mode; 178 + } 179 + 180 + return 0; 181 + } 151 182 152 183 static int __dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg) 153 184 { ··· 405 306 return 0; 406 307 } 407 308 309 + /** 310 + * dwc2_driver_shutdown() - Called on device shutdown 311 + * 312 + * @dev: Platform device 313 + * 314 + * In specific conditions (involving usb hubs) dwc2 devices can create a 315 + * lot of interrupts, even to the point of overwhelming devices running 316 + * at low frequencies. Some devices need to do special clock handling 317 + * at shutdown-time which may bring the system clock below the threshold 318 + * of being able to handle the dwc2 interrupts. Disabling dwc2-irqs 319 + * prevents reboots/poweroffs from getting stuck in such cases. 320 + */ 321 + static void dwc2_driver_shutdown(struct platform_device *dev) 322 + { 323 + struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); 324 + 325 + disable_irq(hsotg->irq); 326 + } 327 + 408 328 static const struct of_device_id dwc2_of_match_table[] = { 409 329 { .compatible = "brcm,bcm2835-usb", .data = &params_bcm2835 }, 330 + { .compatible = "hisilicon,hi6220-usb", .data = &params_hi6220 }, 410 331 { .compatible = "rockchip,rk3066-usb", .data = &params_rk3066 }, 411 332 { .compatible = "snps,dwc2", .data = NULL }, 412 333 { .compatible = "samsung,s3c6400-hsotg", .data = NULL}, ··· 454 335 struct dwc2_hsotg *hsotg; 455 336 struct resource *res; 456 337 int retval; 457 - int irq; 458 338 459 339 match = of_match_device(dwc2_of_match_table, &dev->dev); 460 340 if (match && match->data) { ··· 466 348 /* 467 349 * Disable descriptor dma mode by default as the HW can support 468 350 * it, but does not support it for SPLIT transactions. 351 + * Disable it for FS devices as well. 469 352 */ 470 353 defparams.dma_desc_enable = 0; 354 + defparams.dma_desc_fs_enable = 0; 471 355 } 472 356 473 357 hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL); ··· 495 375 dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n", 496 376 (unsigned long)res->start, hsotg->regs); 497 377 498 - hsotg->dr_mode = usb_get_dr_mode(&dev->dev); 499 - if (IS_ENABLED(CONFIG_USB_DWC2_HOST) && 500 - hsotg->dr_mode != USB_DR_MODE_HOST) { 501 - hsotg->dr_mode = USB_DR_MODE_HOST; 502 - dev_warn(hsotg->dev, 503 - "Configuration mismatch. Forcing host mode\n"); 504 - } else if (IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) && 505 - hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) { 506 - hsotg->dr_mode = USB_DR_MODE_PERIPHERAL; 507 - dev_warn(hsotg->dev, 508 - "Configuration mismatch. Forcing peripheral mode\n"); 509 - } 510 - 511 378 retval = dwc2_lowlevel_hw_init(hsotg); 512 379 if (retval) 513 380 return retval; ··· 508 401 509 402 dwc2_set_all_params(hsotg->core_params, -1); 510 403 511 - irq = platform_get_irq(dev, 0); 512 - if (irq < 0) { 404 + hsotg->irq = platform_get_irq(dev, 0); 405 + if (hsotg->irq < 0) { 513 406 dev_err(&dev->dev, "missing IRQ resource\n"); 514 - return irq; 407 + return hsotg->irq; 515 408 } 516 409 517 410 dev_dbg(hsotg->dev, "registering common handler for irq%d\n", 518 - irq); 519 - retval = devm_request_irq(hsotg->dev, irq, 411 + hsotg->irq); 412 + retval = devm_request_irq(hsotg->dev, hsotg->irq, 520 413 dwc2_handle_common_intr, IRQF_SHARED, 521 414 dev_name(hsotg->dev), hsotg); 522 415 if (retval) ··· 526 419 if (retval) 527 420 return retval; 528 421 529 - /* Detect config values from hardware */ 422 + retval = dwc2_get_dr_mode(hsotg); 423 + if (retval) 424 + return retval; 425 + 426 + /* Reset the controller and detect hardware config values */ 530 427 retval = dwc2_get_hwparams(hsotg); 531 428 if (retval) 532 429 goto error; ··· 538 427 /* Validate parameter values */ 539 428 dwc2_set_parameters(hsotg, params); 540 429 430 + dwc2_force_dr_mode(hsotg); 431 + 541 432 if (hsotg->dr_mode != USB_DR_MODE_HOST) { 542 - retval = dwc2_gadget_init(hsotg, irq); 433 + retval = dwc2_gadget_init(hsotg, hsotg->irq); 543 434 if (retval) 544 435 goto error; 545 436 hsotg->gadget_enabled = 1; 546 437 } 547 438 548 439 if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) { 549 - retval = dwc2_hcd_init(hsotg, irq); 440 + retval = dwc2_hcd_init(hsotg, hsotg->irq); 550 441 if (retval) { 551 442 if (hsotg->gadget_enabled) 552 443 dwc2_hsotg_remove(hsotg); ··· 615 502 }, 616 503 .probe = dwc2_driver_probe, 617 504 .remove = dwc2_driver_remove, 505 + .shutdown = dwc2_driver_shutdown, 618 506 }; 619 507 620 508 module_platform_driver(dwc2_platform_driver);
+9 -8
drivers/usb/dwc3/Kconfig
··· 87 87 Support of USB2/3 functionality in TI Keystone2 platforms. 88 88 Say 'Y' or 'M' here if you have one such device 89 89 90 + config USB_DWC3_OF_SIMPLE 91 + tristate "Generic OF Simple Glue Layer" 92 + depends on OF && COMMON_CLK 93 + default USB_DWC3 94 + help 95 + Support USB2/3 functionality in simple SoC integrations. 96 + Currently supports Xilinx and Qualcomm DWC USB3 IP. 97 + Say 'Y' or 'M' if you have one such device. 98 + 90 99 config USB_DWC3_ST 91 100 tristate "STMicroelectronics Platforms" 92 101 depends on ARCH_STI && OF ··· 104 95 STMicroelectronics SoCs with one DesignWare Core USB3 IP 105 96 inside (i.e. STiH407). 106 97 Say 'Y' or 'M' if you have one such device. 107 - 108 - config USB_DWC3_QCOM 109 - tristate "Qualcomm Platforms" 110 - depends on ARCH_QCOM || COMPILE_TEST 111 - default USB_DWC3 112 - help 113 - Recent Qualcomm SoCs ship with one DesignWare Core USB3 IP inside, 114 - say 'Y' or 'M' if you have one such device. 115 98 116 99 endif
+1 -1
drivers/usb/dwc3/Makefile
··· 37 37 obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o 38 38 obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o 39 39 obj-$(CONFIG_USB_DWC3_KEYSTONE) += dwc3-keystone.o 40 - obj-$(CONFIG_USB_DWC3_QCOM) += dwc3-qcom.o 40 + obj-$(CONFIG_USB_DWC3_OF_SIMPLE) += dwc3-of-simple.o 41 41 obj-$(CONFIG_USB_DWC3_ST) += dwc3-st.o
+5 -3
drivers/usb/dwc3/core.c
··· 272 272 273 273 for (n = 0; n < dwc->num_event_buffers; n++) { 274 274 evt = dwc->ev_buffs[n]; 275 - dev_dbg(dwc->dev, "Event buf %p dma %08llx length %d\n", 275 + dwc3_trace(trace_dwc3_core, 276 + "Event buf %p dma %08llx length %d\n", 276 277 evt->buf, (unsigned long long) evt->dma, 277 278 evt->length); 278 279 ··· 609 608 reg |= DWC3_GCTL_GBLHIBERNATIONEN; 610 609 break; 611 610 default: 612 - dev_dbg(dwc->dev, "No power optimization available\n"); 611 + dwc3_trace(trace_dwc3_core, "No power optimization available\n"); 613 612 } 614 613 615 614 /* check if current dwc3 is on simulation board */ 616 615 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) { 617 - dev_dbg(dwc->dev, "it is on FPGA board\n"); 616 + dwc3_trace(trace_dwc3_core, 617 + "running on FPGA platform\n"); 618 618 dwc->is_fpga = true; 619 619 } 620 620
+3
drivers/usb/dwc3/core.h
··· 37 37 #define DWC3_MSG_MAX 500 38 38 39 39 /* Global constants */ 40 + #define DWC3_ZLP_BUF_SIZE 1024 /* size of a superspeed bulk */ 40 41 #define DWC3_EP0_BOUNCE_SIZE 512 41 42 #define DWC3_ENDPOINTS_NUM 32 42 43 #define DWC3_XHCI_RESOURCES_NUM 2 ··· 648 647 * @ctrl_req: usb control request which is used for ep0 649 648 * @ep0_trb: trb which is used for the ctrl_req 650 649 * @ep0_bounce: bounce buffer for ep0 650 + * @zlp_buf: used when request->zero is set 651 651 * @setup_buf: used while precessing STD USB requests 652 652 * @ctrl_req_addr: dma address of ctrl_req 653 653 * @ep0_trb: dma address of ep0_trb ··· 736 734 struct usb_ctrlrequest *ctrl_req; 737 735 struct dwc3_trb *ep0_trb; 738 736 void *ep0_bounce; 737 + void *zlp_buf; 739 738 void *scratchbuf; 740 739 u8 *setup_buf; 741 740 dma_addr_t ctrl_req_addr;
+180
drivers/usb/dwc3/dwc3-of-simple.c
··· 1 + /** 2 + * dwc3-of-simple.c - OF glue layer for simple integrations 3 + * 4 + * Copyright (c) 2015 Texas Instruments Incorporated - http://www.ti.com 5 + * 6 + * Author: Felipe Balbi <balbi@ti.com> 7 + * 8 + * This program is free software: you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License version 2 of 10 + * the License as published by the Free Software Foundation. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + * 17 + * This is a combination of the old dwc3-qcom.c by Ivan T. Ivanov 18 + * <iivanov@mm-sol.com> and the original patch adding support for Xilinx' SoC 19 + * by Subbaraya Sundeep Bhatta <subbaraya.sundeep.bhatta@xilinx.com> 20 + */ 21 + 22 + #include <linux/module.h> 23 + #include <linux/kernel.h> 24 + #include <linux/slab.h> 25 + #include <linux/platform_device.h> 26 + #include <linux/dma-mapping.h> 27 + #include <linux/clk.h> 28 + #include <linux/clk-provider.h> 29 + #include <linux/of.h> 30 + #include <linux/of_platform.h> 31 + #include <linux/pm_runtime.h> 32 + 33 + struct dwc3_of_simple { 34 + struct device *dev; 35 + struct clk **clks; 36 + int num_clocks; 37 + }; 38 + 39 + static int dwc3_of_simple_probe(struct platform_device *pdev) 40 + { 41 + struct dwc3_of_simple *simple; 42 + struct device *dev = &pdev->dev; 43 + struct device_node *np = dev->of_node; 44 + 45 + int ret; 46 + int i; 47 + 48 + simple = devm_kzalloc(dev, sizeof(*simple), GFP_KERNEL); 49 + if (!simple) 50 + return -ENOMEM; 51 + 52 + ret = of_clk_get_parent_count(np); 53 + if (ret < 0) 54 + return ret; 55 + 56 + simple->num_clocks = ret; 57 + 58 + simple->clks = devm_kcalloc(dev, simple->num_clocks, 59 + sizeof(struct clk *), GFP_KERNEL); 60 + if (!simple->clks) 61 + return -ENOMEM; 62 + 63 + simple->dev = dev; 64 + 65 + for (i = 0; i < simple->num_clocks; i++) { 66 + struct clk *clk; 67 + 68 + clk = of_clk_get(np, i); 69 + if (IS_ERR(clk)) { 70 + while (--i >= 0) 71 + clk_put(simple->clks[i]); 72 + return PTR_ERR(clk); 73 + } 74 + 75 + ret = clk_prepare_enable(clk); 76 + if (ret < 0) { 77 + while (--i >= 0) { 78 + clk_disable_unprepare(simple->clks[i]); 79 + clk_put(simple->clks[i]); 80 + } 81 + clk_put(clk); 82 + 83 + return ret; 84 + } 85 + 86 + simple->clks[i] = clk; 87 + } 88 + 89 + ret = of_platform_populate(np, NULL, NULL, dev); 90 + if (ret) { 91 + for (i = 0; i < simple->num_clocks; i++) { 92 + clk_disable_unprepare(simple->clks[i]); 93 + clk_put(simple->clks[i]); 94 + } 95 + 96 + return ret; 97 + } 98 + 99 + pm_runtime_set_active(dev); 100 + pm_runtime_enable(dev); 101 + pm_runtime_get_sync(dev); 102 + 103 + return 0; 104 + } 105 + 106 + static int dwc3_of_simple_remove(struct platform_device *pdev) 107 + { 108 + struct dwc3_of_simple *simple = platform_get_drvdata(pdev); 109 + struct device *dev = &pdev->dev; 110 + int i; 111 + 112 + for (i = 0; i < simple->num_clocks; i++) { 113 + clk_unprepare(simple->clks[i]); 114 + clk_put(simple->clks[i]); 115 + } 116 + 117 + of_platform_depopulate(dev); 118 + 119 + pm_runtime_put_sync(dev); 120 + pm_runtime_disable(dev); 121 + 122 + return 0; 123 + } 124 + 125 + #ifdef CONFIG_PM 126 + static int dwc3_of_simple_runtime_suspend(struct device *dev) 127 + { 128 + struct dwc3_of_simple *simple = dev_get_drvdata(dev); 129 + int i; 130 + 131 + for (i = 0; i < simple->num_clocks; i++) 132 + clk_disable(simple->clks[i]); 133 + 134 + return 0; 135 + } 136 + 137 + static int dwc3_of_simple_runtime_resume(struct device *dev) 138 + { 139 + struct dwc3_of_simple *simple = dev_get_drvdata(dev); 140 + int ret; 141 + int i; 142 + 143 + for (i = 0; i < simple->num_clocks; i++) { 144 + ret = clk_enable(simple->clks[i]); 145 + if (ret < 0) { 146 + while (--i >= 0) 147 + clk_disable(simple->clks[i]); 148 + return ret; 149 + } 150 + } 151 + 152 + return 0; 153 + } 154 + #endif 155 + 156 + static const struct dev_pm_ops dwc3_of_simple_dev_pm_ops = { 157 + SET_RUNTIME_PM_OPS(dwc3_of_simple_runtime_suspend, 158 + dwc3_of_simple_runtime_resume, NULL) 159 + }; 160 + 161 + static const struct of_device_id of_dwc3_simple_match[] = { 162 + { .compatible = "qcom,dwc3" }, 163 + { .compatible = "xlnx,zynqmp-dwc3" }, 164 + { /* Sentinel */ } 165 + }; 166 + MODULE_DEVICE_TABLE(of, of_dwc3_simple_match); 167 + 168 + static struct platform_driver dwc3_of_simple_driver = { 169 + .probe = dwc3_of_simple_probe, 170 + .remove = dwc3_of_simple_remove, 171 + .driver = { 172 + .name = "dwc3-of-simple", 173 + .of_match_table = of_dwc3_simple_match, 174 + }, 175 + }; 176 + 177 + module_platform_driver(dwc3_of_simple_driver); 178 + MODULE_LICENSE("GPL v2"); 179 + MODULE_DESCRIPTION("DesignWare USB3 OF Simple Glue Layer"); 180 + MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
-130
drivers/usb/dwc3/dwc3-qcom.c
··· 1 - /* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. 2 - * 3 - * This program is free software; you can redistribute it and/or modify 4 - * it under the terms of the GNU General Public License version 2 and 5 - * only version 2 as published by the Free Software Foundation. 6 - * 7 - * This program is distributed in the hope that it will be useful, 8 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 - * GNU General Public License for more details. 11 - */ 12 - 13 - #include <linux/clk.h> 14 - #include <linux/err.h> 15 - #include <linux/io.h> 16 - #include <linux/module.h> 17 - #include <linux/of.h> 18 - #include <linux/of_platform.h> 19 - #include <linux/platform_device.h> 20 - 21 - struct dwc3_qcom { 22 - struct device *dev; 23 - 24 - struct clk *core_clk; 25 - struct clk *iface_clk; 26 - struct clk *sleep_clk; 27 - }; 28 - 29 - static int dwc3_qcom_probe(struct platform_device *pdev) 30 - { 31 - struct device_node *node = pdev->dev.of_node; 32 - struct dwc3_qcom *qdwc; 33 - int ret; 34 - 35 - qdwc = devm_kzalloc(&pdev->dev, sizeof(*qdwc), GFP_KERNEL); 36 - if (!qdwc) 37 - return -ENOMEM; 38 - 39 - platform_set_drvdata(pdev, qdwc); 40 - 41 - qdwc->dev = &pdev->dev; 42 - 43 - qdwc->core_clk = devm_clk_get(qdwc->dev, "core"); 44 - if (IS_ERR(qdwc->core_clk)) { 45 - dev_err(qdwc->dev, "failed to get core clock\n"); 46 - return PTR_ERR(qdwc->core_clk); 47 - } 48 - 49 - qdwc->iface_clk = devm_clk_get(qdwc->dev, "iface"); 50 - if (IS_ERR(qdwc->iface_clk)) { 51 - dev_info(qdwc->dev, "failed to get optional iface clock\n"); 52 - qdwc->iface_clk = NULL; 53 - } 54 - 55 - qdwc->sleep_clk = devm_clk_get(qdwc->dev, "sleep"); 56 - if (IS_ERR(qdwc->sleep_clk)) { 57 - dev_info(qdwc->dev, "failed to get optional sleep clock\n"); 58 - qdwc->sleep_clk = NULL; 59 - } 60 - 61 - ret = clk_prepare_enable(qdwc->core_clk); 62 - if (ret) { 63 - dev_err(qdwc->dev, "failed to enable core clock\n"); 64 - goto err_core; 65 - } 66 - 67 - ret = clk_prepare_enable(qdwc->iface_clk); 68 - if (ret) { 69 - dev_err(qdwc->dev, "failed to enable optional iface clock\n"); 70 - goto err_iface; 71 - } 72 - 73 - ret = clk_prepare_enable(qdwc->sleep_clk); 74 - if (ret) { 75 - dev_err(qdwc->dev, "failed to enable optional sleep clock\n"); 76 - goto err_sleep; 77 - } 78 - 79 - ret = of_platform_populate(node, NULL, NULL, qdwc->dev); 80 - if (ret) { 81 - dev_err(qdwc->dev, "failed to register core - %d\n", ret); 82 - goto err_clks; 83 - } 84 - 85 - return 0; 86 - 87 - err_clks: 88 - clk_disable_unprepare(qdwc->sleep_clk); 89 - err_sleep: 90 - clk_disable_unprepare(qdwc->iface_clk); 91 - err_iface: 92 - clk_disable_unprepare(qdwc->core_clk); 93 - err_core: 94 - return ret; 95 - } 96 - 97 - static int dwc3_qcom_remove(struct platform_device *pdev) 98 - { 99 - struct dwc3_qcom *qdwc = platform_get_drvdata(pdev); 100 - 101 - of_platform_depopulate(&pdev->dev); 102 - 103 - clk_disable_unprepare(qdwc->sleep_clk); 104 - clk_disable_unprepare(qdwc->iface_clk); 105 - clk_disable_unprepare(qdwc->core_clk); 106 - 107 - return 0; 108 - } 109 - 110 - static const struct of_device_id of_dwc3_match[] = { 111 - { .compatible = "qcom,dwc3" }, 112 - { /* Sentinel */ } 113 - }; 114 - MODULE_DEVICE_TABLE(of, of_dwc3_match); 115 - 116 - static struct platform_driver dwc3_qcom_driver = { 117 - .probe = dwc3_qcom_probe, 118 - .remove = dwc3_qcom_remove, 119 - .driver = { 120 - .name = "qcom-dwc3", 121 - .of_match_table = of_dwc3_match, 122 - }, 123 - }; 124 - 125 - module_platform_driver(dwc3_qcom_driver); 126 - 127 - MODULE_ALIAS("platform:qcom-dwc3"); 128 - MODULE_LICENSE("GPL v2"); 129 - MODULE_DESCRIPTION("DesignWare USB3 QCOM Glue Layer"); 130 - MODULE_AUTHOR("Ivan T. Ivanov <iivanov@mm-sol.com>");
+7 -5
drivers/usb/dwc3/ep0.c
··· 817 817 818 818 status = DWC3_TRB_SIZE_TRBSTS(trb->size); 819 819 if (status == DWC3_TRBSTS_SETUP_PENDING) { 820 + dwc->setup_packet_pending = true; 821 + 820 822 dwc3_trace(trace_dwc3_ep0, "Setup Pending received"); 821 823 822 824 if (r) ··· 918 916 } 919 917 920 918 status = DWC3_TRB_SIZE_TRBSTS(trb->size); 921 - if (status == DWC3_TRBSTS_SETUP_PENDING) 919 + if (status == DWC3_TRBSTS_SETUP_PENDING) { 920 + dwc->setup_packet_pending = true; 922 921 dwc3_trace(trace_dwc3_ep0, "Setup Pending received"); 922 + } 923 923 924 924 dwc->ep0state = EP0_SETUP_PHASE; 925 925 dwc3_ep0_out_start(dwc); ··· 975 971 ret = usb_gadget_map_request(&dwc->gadget, &req->request, 976 972 dep->number); 977 973 if (ret) { 978 - dev_dbg(dwc->dev, "failed to map request\n"); 974 + dwc3_trace(trace_dwc3_ep0, "failed to map request\n"); 979 975 return; 980 976 } 981 977 ··· 1003 999 ret = usb_gadget_map_request(&dwc->gadget, &req->request, 1004 1000 dep->number); 1005 1001 if (ret) { 1006 - dev_dbg(dwc->dev, "failed to map request\n"); 1002 + dwc3_trace(trace_dwc3_ep0, "failed to map request\n"); 1007 1003 return; 1008 1004 } 1009 1005 ··· 1067 1063 static void dwc3_ep0_xfernotready(struct dwc3 *dwc, 1068 1064 const struct dwc3_event_depevt *event) 1069 1065 { 1070 - dwc->setup_packet_pending = true; 1071 - 1072 1066 switch (event->status) { 1073 1067 case DEPEVT_STATUS_CONTROL_DATA: 1074 1068 dwc3_trace(trace_dwc3_ep0, "Control Data");
+89 -44
drivers/usb/dwc3/gadget.c
··· 265 265 usb_gadget_unmap_request(&dwc->gadget, &req->request, 266 266 req->direction); 267 267 268 - dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n", 269 - req, dep->name, req->request.actual, 270 - req->request.length, status); 271 268 trace_dwc3_gadget_giveback(req); 272 269 273 270 spin_unlock(&dwc->lock); ··· 661 664 dep = to_dwc3_ep(ep); 662 665 dwc = dep->dwc; 663 666 664 - if (dep->flags & DWC3_EP_ENABLED) { 665 - dev_WARN_ONCE(dwc->dev, true, "%s is already enabled\n", 666 - dep->name); 667 + if (dev_WARN_ONCE(dwc->dev, dep->flags & DWC3_EP_ENABLED, 668 + "%s is already enabled\n", 669 + dep->name)) 667 670 return 0; 668 - } 669 671 670 672 spin_lock_irqsave(&dwc->lock, flags); 671 673 ret = __dwc3_gadget_ep_enable(dep, desc, ep->comp_desc, false, false); ··· 688 692 dep = to_dwc3_ep(ep); 689 693 dwc = dep->dwc; 690 694 691 - if (!(dep->flags & DWC3_EP_ENABLED)) { 692 - dev_WARN_ONCE(dwc->dev, true, "%s is already disabled\n", 693 - dep->name); 695 + if (dev_WARN_ONCE(dwc->dev, !(dep->flags & DWC3_EP_ENABLED), 696 + "%s is already disabled\n", 697 + dep->name)) 694 698 return 0; 695 - } 696 699 697 700 spin_lock_irqsave(&dwc->lock, flags); 698 701 ret = __dwc3_gadget_ep_disable(dep); ··· 980 985 cmd |= DWC3_DEPCMD_PARAM(cmd_param); 981 986 ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params); 982 987 if (ret < 0) { 983 - dev_dbg(dwc->dev, "failed to send STARTTRANSFER command\n"); 984 - 985 988 /* 986 989 * FIXME we need to iterate over the list of requests 987 990 * here and stop, unmap, free and del each of the linked ··· 1036 1043 { 1037 1044 struct dwc3 *dwc = dep->dwc; 1038 1045 int ret; 1046 + 1047 + if (!dep->endpoint.desc) { 1048 + dwc3_trace(trace_dwc3_gadget, 1049 + "trying to queue request %p to disabled %s\n", 1050 + &req->request, dep->endpoint.name); 1051 + return -ESHUTDOWN; 1052 + } 1053 + 1054 + if (WARN(req->dep != dep, "request %p belongs to '%s'\n", 1055 + &req->request, req->dep->name)) { 1056 + dwc3_trace(trace_dwc3_gadget, "request %p belongs to '%s'\n", 1057 + &req->request, req->dep->name); 1058 + return -EINVAL; 1059 + } 1039 1060 1040 1061 req->request.actual = 0; 1041 1062 req->request.status = -EINPROGRESS; ··· 1148 1141 1149 1142 out: 1150 1143 if (ret && ret != -EBUSY) 1151 - dev_dbg(dwc->dev, "%s: failed to kick transfers\n", 1144 + dwc3_trace(trace_dwc3_gadget, 1145 + "%s: failed to kick transfers\n", 1152 1146 dep->name); 1153 1147 if (ret == -EBUSY) 1154 1148 ret = 0; 1155 1149 1156 1150 return ret; 1151 + } 1152 + 1153 + static void __dwc3_gadget_ep_zlp_complete(struct usb_ep *ep, 1154 + struct usb_request *request) 1155 + { 1156 + dwc3_gadget_ep_free_request(ep, request); 1157 + } 1158 + 1159 + static int __dwc3_gadget_ep_queue_zlp(struct dwc3 *dwc, struct dwc3_ep *dep) 1160 + { 1161 + struct dwc3_request *req; 1162 + struct usb_request *request; 1163 + struct usb_ep *ep = &dep->endpoint; 1164 + 1165 + dwc3_trace(trace_dwc3_gadget, "queueing ZLP\n"); 1166 + request = dwc3_gadget_ep_alloc_request(ep, GFP_ATOMIC); 1167 + if (!request) 1168 + return -ENOMEM; 1169 + 1170 + request->length = 0; 1171 + request->buf = dwc->zlp_buf; 1172 + request->complete = __dwc3_gadget_ep_zlp_complete; 1173 + 1174 + req = to_dwc3_request(request); 1175 + 1176 + return __dwc3_gadget_ep_queue(dep, req); 1157 1177 } 1158 1178 1159 1179 static int dwc3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request, ··· 1195 1161 int ret; 1196 1162 1197 1163 spin_lock_irqsave(&dwc->lock, flags); 1198 - if (!dep->endpoint.desc) { 1199 - dev_dbg(dwc->dev, "trying to queue request %p to disabled %s\n", 1200 - request, ep->name); 1201 - ret = -ESHUTDOWN; 1202 - goto out; 1203 - } 1204 - 1205 - if (WARN(req->dep != dep, "request %p belongs to '%s'\n", 1206 - request, req->dep->name)) { 1207 - ret = -EINVAL; 1208 - goto out; 1209 - } 1210 - 1211 1164 ret = __dwc3_gadget_ep_queue(dep, req); 1212 1165 1213 - out: 1166 + /* 1167 + * Okay, here's the thing, if gadget driver has requested for a ZLP by 1168 + * setting request->zero, instead of doing magic, we will just queue an 1169 + * extra usb_request ourselves so that it gets handled the same way as 1170 + * any other request. 1171 + */ 1172 + if (ret == 0 && request->zero && request->length && 1173 + (request->length % ep->maxpacket == 0)) 1174 + ret = __dwc3_gadget_ep_queue_zlp(dwc, dep); 1175 + 1214 1176 spin_unlock_irqrestore(&dwc->lock, flags); 1215 1177 1216 1178 return ret; ··· 1276 1246 if (!protocol && ((dep->direction && dep->flags & DWC3_EP_BUSY) || 1277 1247 (!list_empty(&dep->req_queued) || 1278 1248 !list_empty(&dep->request_list)))) { 1279 - dev_dbg(dwc->dev, "%s: pending request, cannot halt\n", 1249 + dwc3_trace(trace_dwc3_gadget, 1250 + "%s: pending request, cannot halt\n", 1280 1251 dep->name); 1281 1252 return -EAGAIN; 1282 1253 } ··· 1404 1373 1405 1374 speed = reg & DWC3_DSTS_CONNECTSPD; 1406 1375 if (speed == DWC3_DSTS_SUPERSPEED) { 1407 - dev_dbg(dwc->dev, "no wakeup on SuperSpeed\n"); 1376 + dwc3_trace(trace_dwc3_gadget, "no wakeup on SuperSpeed\n"); 1408 1377 ret = -EINVAL; 1409 1378 goto out; 1410 1379 } ··· 1416 1385 case DWC3_LINK_STATE_U3: /* in HS, means SUSPEND */ 1417 1386 break; 1418 1387 default: 1419 - dev_dbg(dwc->dev, "can't wakeup from link state %d\n", 1420 - link_state); 1388 + dwc3_trace(trace_dwc3_gadget, 1389 + "can't wakeup from '%s'\n", 1390 + dwc3_gadget_link_string(link_state)); 1421 1391 ret = -EINVAL; 1422 1392 goto out; 1423 1393 } ··· 1857 1825 if (count) { 1858 1826 trb_status = DWC3_TRB_SIZE_TRBSTS(trb->size); 1859 1827 if (trb_status == DWC3_TRBSTS_MISSED_ISOC) { 1860 - dev_dbg(dwc->dev, "incomplete IN transfer %s\n", 1828 + dwc3_trace(trace_dwc3_gadget, 1829 + "%s: incomplete IN transfer\n", 1861 1830 dep->name); 1862 1831 /* 1863 1832 * If missed isoc occurred and there is ··· 1920 1887 1921 1888 do { 1922 1889 req = next_request(&dep->req_queued); 1923 - if (!req) { 1924 - WARN_ON_ONCE(1); 1890 + if (WARN_ON_ONCE(!req)) 1925 1891 return 1; 1926 - } 1892 + 1927 1893 i = 0; 1928 1894 do { 1929 1895 slot = req->start_slot + i; ··· 2036 2004 dep->resource_index = 0; 2037 2005 2038 2006 if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) { 2039 - dev_dbg(dwc->dev, "%s is an Isochronous endpoint\n", 2007 + dwc3_trace(trace_dwc3_gadget, 2008 + "%s is an Isochronous endpoint\n", 2040 2009 dep->name); 2041 2010 return; 2042 2011 } ··· 2064 2031 if (!ret || ret == -EBUSY) 2065 2032 return; 2066 2033 2067 - dev_dbg(dwc->dev, "%s: failed to kick transfers\n", 2034 + dwc3_trace(trace_dwc3_gadget, 2035 + "%s: failed to kick transfers\n", 2068 2036 dep->name); 2069 2037 } 2070 2038 ··· 2087 2053 case DEPEVT_STREAMEVT_NOTFOUND: 2088 2054 /* FALLTHROUGH */ 2089 2055 default: 2090 - dev_dbg(dwc->dev, "Couldn't find suitable stream\n"); 2056 + dwc3_trace(trace_dwc3_gadget, 2057 + "unable to find suitable stream\n"); 2091 2058 } 2092 2059 break; 2093 2060 case DWC3_DEPEVT_RXTXFIFOEVT: 2094 - dev_dbg(dwc->dev, "%s FIFO Overrun\n", dep->name); 2061 + dwc3_trace(trace_dwc3_gadget, "%s FIFO Overrun\n", dep->name); 2095 2062 break; 2096 2063 case DWC3_DEPEVT_EPCMDCMPLT: 2097 2064 dwc3_trace(trace_dwc3_gadget, "Endpoint Command Complete"); ··· 2265 2230 * 2266 2231 * Our suggested workaround is to follow the Disconnect 2267 2232 * Event steps here, instead, based on a setup_packet_pending 2268 - * flag. Such flag gets set whenever we have a XferNotReady 2269 - * event on EP0 and gets cleared on XferComplete for the 2233 + * flag. Such flag gets set whenever we have a SETUP_PENDING 2234 + * status for EP0 TRBs and gets cleared on XferComplete for the 2270 2235 * same endpoint. 2271 2236 * 2272 2237 * Refers to: ··· 2779 2744 goto err3; 2780 2745 } 2781 2746 2747 + dwc->zlp_buf = kzalloc(DWC3_ZLP_BUF_SIZE, GFP_KERNEL); 2748 + if (!dwc->zlp_buf) { 2749 + ret = -ENOMEM; 2750 + goto err4; 2751 + } 2752 + 2782 2753 dwc->gadget.ops = &dwc3_gadget_ops; 2783 2754 dwc->gadget.speed = USB_SPEED_UNKNOWN; 2784 2755 dwc->gadget.sg_supported = true; ··· 2826 2785 2827 2786 ret = dwc3_gadget_init_endpoints(dwc); 2828 2787 if (ret) 2829 - goto err4; 2788 + goto err5; 2830 2789 2831 2790 ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget); 2832 2791 if (ret) { 2833 2792 dev_err(dwc->dev, "failed to register udc\n"); 2834 - goto err4; 2793 + goto err5; 2835 2794 } 2836 2795 2837 2796 return 0; 2797 + 2798 + err5: 2799 + kfree(dwc->zlp_buf); 2838 2800 2839 2801 err4: 2840 2802 dwc3_gadget_free_endpoints(dwc); ··· 2871 2827 dwc->ep0_bounce, dwc->ep0_bounce_addr); 2872 2828 2873 2829 kfree(dwc->setup_buf); 2830 + kfree(dwc->zlp_buf); 2874 2831 2875 2832 dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb), 2876 2833 dwc->ep0_trb, dwc->ep0_trb_addr);
+10 -1
drivers/usb/dwc3/trace.h
··· 117 117 __field(unsigned, actual) 118 118 __field(unsigned, length) 119 119 __field(int, status) 120 + __field(int, zero) 121 + __field(int, short_not_ok) 122 + __field(int, no_interrupt) 120 123 ), 121 124 TP_fast_assign( 122 125 snprintf(__get_str(name), DWC3_MSG_MAX, "%s", req->dep->name); ··· 127 124 __entry->actual = req->request.actual; 128 125 __entry->length = req->request.length; 129 126 __entry->status = req->request.status; 127 + __entry->zero = req->request.zero; 128 + __entry->short_not_ok = req->request.short_not_ok; 129 + __entry->no_interrupt = req->request.no_interrupt; 130 130 ), 131 - TP_printk("%s: req %p length %u/%u ==> %d", 131 + TP_printk("%s: req %p length %u/%u %s%s%s ==> %d", 132 132 __get_str(name), __entry->req, __entry->actual, __entry->length, 133 + __entry->zero ? "Z" : "z", 134 + __entry->short_not_ok ? "S" : "s", 135 + __entry->no_interrupt ? "i" : "I", 133 136 __entry->status 134 137 ) 135 138 );
+6
drivers/usb/gadget/Kconfig
··· 127 127 a module parameter as well. 128 128 If unsure, say 2. 129 129 130 + config U_SERIAL_CONSOLE 131 + bool "Serial gadget console support" 132 + depends on USB_G_SERIAL 133 + help 134 + It supports the serial gadget can be used as a console. 135 + 130 136 source "drivers/usb/gadget/udc/Kconfig" 131 137 132 138 #
+16 -13
drivers/usb/gadget/configfs.c
··· 56 56 struct list_head string_list; 57 57 struct list_head available_func; 58 58 59 - const char *udc_name; 60 59 struct usb_composite_driver composite; 61 60 struct usb_composite_dev cdev; 62 61 bool use_os_desc; ··· 232 233 233 234 static ssize_t gadget_dev_desc_UDC_show(struct config_item *item, char *page) 234 235 { 235 - return sprintf(page, "%s\n", to_gadget_info(item)->udc_name ?: ""); 236 + char *udc_name = to_gadget_info(item)->composite.gadget_driver.udc_name; 237 + 238 + return sprintf(page, "%s\n", udc_name ?: ""); 236 239 } 237 240 238 241 static int unregister_gadget(struct gadget_info *gi) 239 242 { 240 243 int ret; 241 244 242 - if (!gi->udc_name) 245 + if (!gi->composite.gadget_driver.udc_name) 243 246 return -ENODEV; 244 247 245 248 ret = usb_gadget_unregister_driver(&gi->composite.gadget_driver); 246 249 if (ret) 247 250 return ret; 248 - kfree(gi->udc_name); 249 - gi->udc_name = NULL; 251 + kfree(gi->composite.gadget_driver.udc_name); 252 + gi->composite.gadget_driver.udc_name = NULL; 250 253 return 0; 251 254 } 252 255 ··· 272 271 if (ret) 273 272 goto err; 274 273 } else { 275 - if (gi->udc_name) { 274 + if (gi->composite.gadget_driver.udc_name) { 276 275 ret = -EBUSY; 277 276 goto err; 278 277 } 279 - ret = usb_udc_attach_driver(name, &gi->composite.gadget_driver); 280 - if (ret) 278 + gi->composite.gadget_driver.udc_name = name; 279 + ret = usb_gadget_probe_driver(&gi->composite.gadget_driver); 280 + if (ret) { 281 + gi->composite.gadget_driver.udc_name = NULL; 281 282 goto err; 282 - gi->udc_name = name; 283 + } 283 284 } 284 285 mutex_unlock(&gi->lock); 285 286 return len; ··· 430 427 * remove the function. 431 428 */ 432 429 mutex_lock(&gi->lock); 433 - if (gi->udc_name) 430 + if (gi->composite.gadget_driver.udc_name) 434 431 unregister_gadget(gi); 435 - WARN_ON(gi->udc_name); 432 + WARN_ON(gi->composite.gadget_driver.udc_name); 436 433 437 434 list_for_each_entry(f, &cfg->func_list, list) { 438 435 if (f->fi == fi) { ··· 876 873 struct usb_composite_dev *cdev = &gi->cdev; 877 874 878 875 mutex_lock(&gi->lock); 879 - if (gi->udc_name) 876 + if (gi->composite.gadget_driver.udc_name) 880 877 unregister_gadget(gi); 881 878 cdev->os_desc_config = NULL; 882 - WARN_ON(gi->udc_name); 879 + WARN_ON(gi->composite.gadget_driver.udc_name); 883 880 mutex_unlock(&gi->lock); 884 881 return 0; 885 882 }
+131 -63
drivers/usb/gadget/function/f_midi.c
··· 23 23 #include <linux/module.h> 24 24 #include <linux/slab.h> 25 25 #include <linux/device.h> 26 + #include <linux/kfifo.h> 26 27 27 28 #include <sound/core.h> 28 29 #include <sound/initval.h> ··· 76 75 struct usb_ep *in_ep, *out_ep; 77 76 struct snd_card *card; 78 77 struct snd_rawmidi *rmidi; 78 + u8 ms_id; 79 79 80 80 struct snd_rawmidi_substream *in_substream[MAX_PORTS]; 81 81 struct snd_rawmidi_substream *out_substream[MAX_PORTS]; ··· 89 87 int index; 90 88 char *id; 91 89 unsigned int buflen, qlen; 90 + /* This fifo is used as a buffer ring for pre-allocated IN usb_requests */ 91 + DECLARE_KFIFO_PTR(in_req_fifo, struct usb_request *); 92 + unsigned int in_last_port; 92 93 }; 93 94 94 95 static inline struct f_midi *func_to_midi(struct usb_function *f) ··· 99 94 return container_of(f, struct f_midi, func); 100 95 } 101 96 102 - static void f_midi_transmit(struct f_midi *midi, struct usb_request *req); 97 + static void f_midi_transmit(struct f_midi *midi); 103 98 104 99 DECLARE_UAC_AC_HEADER_DESCRIPTOR(1); 105 100 DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1); ··· 206 201 return alloc_ep_req(ep, length, length); 207 202 } 208 203 209 - static void free_ep_req(struct usb_ep *ep, struct usb_request *req) 210 - { 211 - kfree(req->buf); 212 - usb_ep_free_request(ep, req); 213 - } 214 - 215 204 static const uint8_t f_midi_cin_length[] = { 216 205 0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1 217 206 }; ··· 257 258 } else if (ep == midi->in_ep) { 258 259 /* Our transmit completed. See if there's more to go. 259 260 * f_midi_transmit eats req, don't queue it again. */ 260 - f_midi_transmit(midi, req); 261 + req->length = 0; 262 + f_midi_transmit(midi); 261 263 return; 262 264 } 263 265 break; ··· 269 269 case -ESHUTDOWN: /* disconnect from host */ 270 270 VDBG(cdev, "%s gone (%d), %d/%d\n", ep->name, status, 271 271 req->actual, req->length); 272 - if (ep == midi->out_ep) 272 + if (ep == midi->out_ep) { 273 273 f_midi_handle_out_data(ep, req); 274 - 275 - free_ep_req(ep, req); 274 + /* We don't need to free IN requests because it's handled 275 + * by the midi->in_req_fifo. */ 276 + free_ep_req(ep, req); 277 + } 276 278 return; 277 279 278 280 case -EOVERFLOW: /* buffer overrun on read means that ··· 326 324 static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt) 327 325 { 328 326 struct f_midi *midi = func_to_midi(f); 329 - struct usb_composite_dev *cdev = f->config->cdev; 330 327 unsigned i; 331 328 int err; 332 329 333 - /* For Control Device interface we do nothing */ 334 - if (intf == 0) 330 + /* we only set alt for MIDIStreaming interface */ 331 + if (intf != midi->ms_id) 335 332 return 0; 336 333 337 334 err = f_midi_start_ep(midi, f, midi->in_ep); ··· 341 340 if (err) 342 341 return err; 343 342 344 - usb_ep_disable(midi->out_ep); 343 + /* pre-allocate write usb requests to use on f_midi_transmit. */ 344 + while (kfifo_avail(&midi->in_req_fifo)) { 345 + struct usb_request *req = 346 + midi_alloc_ep_req(midi->in_ep, midi->buflen); 345 347 346 - err = config_ep_by_speed(midi->gadget, f, midi->out_ep); 347 - if (err) { 348 - ERROR(cdev, "can't configure %s: %d\n", 349 - midi->out_ep->name, err); 350 - return err; 348 + if (req == NULL) 349 + return -ENOMEM; 350 + 351 + req->length = 0; 352 + req->complete = f_midi_complete; 353 + 354 + kfifo_put(&midi->in_req_fifo, req); 351 355 } 352 - 353 - err = usb_ep_enable(midi->out_ep); 354 - if (err) { 355 - ERROR(cdev, "can't start %s: %d\n", 356 - midi->out_ep->name, err); 357 - return err; 358 - } 359 - 360 - midi->out_ep->driver_data = midi; 361 356 362 357 /* allocate a bunch of read buffers and queue them all at once. */ 363 358 for (i = 0; i < midi->qlen && err == 0; i++) { ··· 365 368 req->complete = f_midi_complete; 366 369 err = usb_ep_queue(midi->out_ep, req, GFP_ATOMIC); 367 370 if (err) { 368 - ERROR(midi, "%s queue req: %d\n", 371 + ERROR(midi, "%s: couldn't enqueue request: %d\n", 369 372 midi->out_ep->name, err); 370 373 free_ep_req(midi->out_ep, req); 374 + return err; 371 375 } 372 376 } 373 377 ··· 379 381 { 380 382 struct f_midi *midi = func_to_midi(f); 381 383 struct usb_composite_dev *cdev = f->config->cdev; 384 + struct usb_request *req = NULL; 382 385 383 386 DBG(cdev, "disable\n"); 384 387 ··· 389 390 */ 390 391 usb_ep_disable(midi->in_ep); 391 392 usb_ep_disable(midi->out_ep); 393 + 394 + /* release IN requests */ 395 + while (kfifo_get(&midi->in_req_fifo, &req)) 396 + free_ep_req(midi->in_ep, req); 392 397 } 393 398 394 399 static int f_midi_snd_free(struct snd_device *device) ··· 514 511 } 515 512 } 516 513 517 - static void f_midi_transmit(struct f_midi *midi, struct usb_request *req) 514 + static void f_midi_drop_out_substreams(struct f_midi *midi) 518 515 { 519 - struct usb_ep *ep = midi->in_ep; 520 - int i; 521 - 522 - if (!ep) 523 - return; 524 - 525 - if (!req) 526 - req = midi_alloc_ep_req(ep, midi->buflen); 527 - 528 - if (!req) { 529 - ERROR(midi, "%s: alloc_ep_request failed\n", __func__); 530 - return; 531 - } 532 - req->length = 0; 533 - req->complete = f_midi_complete; 516 + unsigned int i; 534 517 535 518 for (i = 0; i < MAX_PORTS; i++) { 536 519 struct gmidi_in_port *port = midi->in_port[i]; 537 520 struct snd_rawmidi_substream *substream = midi->in_substream[i]; 538 521 539 - if (!port || !port->active || !substream) 522 + if (!port) 523 + break; 524 + 525 + if (!port->active || !substream) 540 526 continue; 541 527 542 - while (req->length + 3 < midi->buflen) { 543 - uint8_t b; 544 - if (snd_rawmidi_transmit(substream, &b, 1) != 1) { 545 - port->active = 0; 528 + snd_rawmidi_drop_output(substream); 529 + } 530 + } 531 + 532 + static void f_midi_transmit(struct f_midi *midi) 533 + { 534 + struct usb_ep *ep = midi->in_ep; 535 + bool active; 536 + 537 + /* We only care about USB requests if IN endpoint is enabled */ 538 + if (!ep || !ep->enabled) 539 + goto drop_out; 540 + 541 + do { 542 + struct usb_request *req = NULL; 543 + unsigned int len, i; 544 + 545 + active = false; 546 + 547 + /* We peek the request in order to reuse it if it fails 548 + * to enqueue on its endpoint */ 549 + len = kfifo_peek(&midi->in_req_fifo, &req); 550 + if (len != 1) { 551 + ERROR(midi, "%s: Couldn't get usb request\n", __func__); 552 + goto drop_out; 553 + } 554 + 555 + /* If buffer overrun, then we ignore this transmission. 556 + * IMPORTANT: This will cause the user-space rawmidi device to block until a) usb 557 + * requests have been completed or b) snd_rawmidi_write() times out. */ 558 + if (req->length > 0) 559 + return; 560 + 561 + for (i = midi->in_last_port; i < MAX_PORTS; i++) { 562 + struct gmidi_in_port *port = midi->in_port[i]; 563 + struct snd_rawmidi_substream *substream = midi->in_substream[i]; 564 + 565 + if (!port) { 566 + /* Reset counter when we reach the last available port */ 567 + midi->in_last_port = 0; 546 568 break; 547 569 } 548 - f_midi_transmit_byte(req, port, b); 570 + 571 + if (!port->active || !substream) 572 + continue; 573 + 574 + while (req->length + 3 < midi->buflen) { 575 + uint8_t b; 576 + 577 + if (snd_rawmidi_transmit(substream, &b, 1) != 1) { 578 + port->active = 0; 579 + break; 580 + } 581 + f_midi_transmit_byte(req, port, b); 582 + } 583 + 584 + active = !!port->active; 585 + /* Check if last port is still active, which means that 586 + * there is still data on that substream but this current 587 + * request run out of space. */ 588 + if (active) { 589 + midi->in_last_port = i; 590 + /* There is no need to re-iterate though midi ports. */ 591 + break; 592 + } 549 593 } 550 - } 551 594 552 - if (req->length > 0 && ep->enabled) { 553 - int err; 595 + if (req->length > 0) { 596 + int err; 554 597 555 - err = usb_ep_queue(ep, req, GFP_ATOMIC); 556 - if (err < 0) 557 - ERROR(midi, "%s queue req: %d\n", 558 - midi->in_ep->name, err); 559 - } else { 560 - free_ep_req(ep, req); 561 - } 598 + err = usb_ep_queue(ep, req, GFP_ATOMIC); 599 + if (err < 0) { 600 + ERROR(midi, "%s failed to queue req: %d\n", 601 + midi->in_ep->name, err); 602 + req->length = 0; /* Re-use request next time. */ 603 + } else { 604 + /* Upon success, put request at the back of the queue. */ 605 + kfifo_skip(&midi->in_req_fifo); 606 + kfifo_put(&midi->in_req_fifo, req); 607 + } 608 + } 609 + } while (active); 610 + 611 + return; 612 + 613 + drop_out: 614 + f_midi_drop_out_substreams(midi); 562 615 } 563 616 564 617 static void f_midi_in_tasklet(unsigned long data) 565 618 { 566 619 struct f_midi *midi = (struct f_midi *) data; 567 - f_midi_transmit(midi, NULL); 620 + f_midi_transmit(midi); 568 621 } 569 622 570 623 static int f_midi_in_open(struct snd_rawmidi_substream *substream) ··· 746 687 goto fail; 747 688 } 748 689 midi->rmidi = rmidi; 690 + midi->in_last_port = 0; 749 691 strcpy(rmidi->name, card->shortname); 750 692 rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | 751 693 SNDRV_RAWMIDI_INFO_INPUT | ··· 815 755 goto fail; 816 756 ms_interface_desc.bInterfaceNumber = status; 817 757 ac_header_desc.baInterfaceNr[0] = status; 758 + midi->ms_id = status; 818 759 819 760 status = -ENODEV; 820 761 ··· 1136 1075 mutex_lock(&opts->lock); 1137 1076 for (i = opts->in_ports - 1; i >= 0; --i) 1138 1077 kfree(midi->in_port[i]); 1078 + kfifo_free(&midi->in_req_fifo); 1139 1079 kfree(midi); 1140 1080 --opts->refcnt; 1141 1081 mutex_unlock(&opts->lock); ··· 1210 1148 midi->index = opts->index; 1211 1149 midi->buflen = opts->buflen; 1212 1150 midi->qlen = opts->qlen; 1151 + midi->in_last_port = 0; 1152 + 1153 + status = kfifo_alloc(&midi->in_req_fifo, midi->qlen, GFP_KERNEL); 1154 + if (status) 1155 + goto setup_fail; 1156 + 1213 1157 ++opts->refcnt; 1214 1158 mutex_unlock(&opts->lock); 1215 1159
+109 -38
drivers/usb/gadget/function/f_sourcesink.c
··· 34 34 * plus two that support control-OUT tests. If the optional "autoresume" 35 35 * mode is enabled, it provides good functional coverage for the "USBCV" 36 36 * test harness from USB-IF. 37 - * 38 - * Note that because this doesn't queue more than one request at a time, 39 - * some other function must be used to test queueing logic. The network 40 - * link (g_ether) is the best overall option for that, since its TX and RX 41 - * queues are relatively independent, will receive a range of packet sizes, 42 - * and can often be made to run out completely. Those issues are important 43 - * when stress testing peripheral controller drivers. 44 37 */ 45 38 struct f_sourcesink { 46 39 struct usb_function function; ··· 50 57 unsigned isoc_mult; 51 58 unsigned isoc_maxburst; 52 59 unsigned buflen; 60 + unsigned bulk_qlen; 61 + unsigned iso_qlen; 53 62 }; 54 63 55 64 static inline struct f_sourcesink *func_to_ss(struct usb_function *f) ··· 296 301 struct f_sourcesink *ss = ep->driver_data; 297 302 298 303 return alloc_ep_req(ep, len, ss->buflen); 299 - } 300 - 301 - void free_ep_req(struct usb_ep *ep, struct usb_request *req) 302 - { 303 - kfree(req->buf); 304 - usb_ep_free_request(ep, req); 305 304 } 306 305 307 306 static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep) ··· 584 595 { 585 596 struct usb_ep *ep; 586 597 struct usb_request *req; 587 - int i, size, status; 598 + int i, size, qlen, status = 0; 588 599 589 - for (i = 0; i < 8; i++) { 590 - if (is_iso) { 591 - switch (speed) { 592 - case USB_SPEED_SUPER: 593 - size = ss->isoc_maxpacket * 594 - (ss->isoc_mult + 1) * 595 - (ss->isoc_maxburst + 1); 596 - break; 597 - case USB_SPEED_HIGH: 598 - size = ss->isoc_maxpacket * (ss->isoc_mult + 1); 599 - break; 600 - default: 601 - size = ss->isoc_maxpacket > 1023 ? 602 - 1023 : ss->isoc_maxpacket; 603 - break; 604 - } 605 - ep = is_in ? ss->iso_in_ep : ss->iso_out_ep; 606 - req = ss_alloc_ep_req(ep, size); 607 - } else { 608 - ep = is_in ? ss->in_ep : ss->out_ep; 609 - req = ss_alloc_ep_req(ep, 0); 600 + if (is_iso) { 601 + switch (speed) { 602 + case USB_SPEED_SUPER: 603 + size = ss->isoc_maxpacket * 604 + (ss->isoc_mult + 1) * 605 + (ss->isoc_maxburst + 1); 606 + break; 607 + case USB_SPEED_HIGH: 608 + size = ss->isoc_maxpacket * (ss->isoc_mult + 1); 609 + break; 610 + default: 611 + size = ss->isoc_maxpacket > 1023 ? 612 + 1023 : ss->isoc_maxpacket; 613 + break; 610 614 } 615 + ep = is_in ? ss->iso_in_ep : ss->iso_out_ep; 616 + qlen = ss->iso_qlen; 617 + } else { 618 + ep = is_in ? ss->in_ep : ss->out_ep; 619 + qlen = ss->bulk_qlen; 620 + size = 0; 621 + } 611 622 623 + for (i = 0; i < qlen; i++) { 624 + req = ss_alloc_ep_req(ep, size); 612 625 if (!req) 613 626 return -ENOMEM; 614 627 ··· 629 638 is_iso ? "ISO-" : "", is_in ? "IN" : "OUT", 630 639 ep->name, status); 631 640 free_ep_req(ep, req); 641 + return status; 632 642 } 633 - 634 - if (!is_iso) 635 - break; 636 643 } 637 644 638 645 return status; ··· 858 869 ss->isoc_mult = ss_opts->isoc_mult; 859 870 ss->isoc_maxburst = ss_opts->isoc_maxburst; 860 871 ss->buflen = ss_opts->bulk_buflen; 872 + ss->bulk_qlen = ss_opts->bulk_qlen; 873 + ss->iso_qlen = ss_opts->iso_qlen; 861 874 862 875 ss->function.name = "source/sink"; 863 876 ss->function.bind = sourcesink_bind; ··· 1144 1153 1145 1154 CONFIGFS_ATTR(f_ss_opts_, bulk_buflen); 1146 1155 1156 + static ssize_t f_ss_opts_bulk_qlen_show(struct config_item *item, char *page) 1157 + { 1158 + struct f_ss_opts *opts = to_f_ss_opts(item); 1159 + int result; 1160 + 1161 + mutex_lock(&opts->lock); 1162 + result = sprintf(page, "%u\n", opts->bulk_qlen); 1163 + mutex_unlock(&opts->lock); 1164 + 1165 + return result; 1166 + } 1167 + 1168 + static ssize_t f_ss_opts_bulk_qlen_store(struct config_item *item, 1169 + const char *page, size_t len) 1170 + { 1171 + struct f_ss_opts *opts = to_f_ss_opts(item); 1172 + int ret; 1173 + u32 num; 1174 + 1175 + mutex_lock(&opts->lock); 1176 + if (opts->refcnt) { 1177 + ret = -EBUSY; 1178 + goto end; 1179 + } 1180 + 1181 + ret = kstrtou32(page, 0, &num); 1182 + if (ret) 1183 + goto end; 1184 + 1185 + opts->bulk_qlen = num; 1186 + ret = len; 1187 + end: 1188 + mutex_unlock(&opts->lock); 1189 + return ret; 1190 + } 1191 + 1192 + CONFIGFS_ATTR(f_ss_opts_, bulk_qlen); 1193 + 1194 + static ssize_t f_ss_opts_iso_qlen_show(struct config_item *item, char *page) 1195 + { 1196 + struct f_ss_opts *opts = to_f_ss_opts(item); 1197 + int result; 1198 + 1199 + mutex_lock(&opts->lock); 1200 + result = sprintf(page, "%u\n", opts->iso_qlen); 1201 + mutex_unlock(&opts->lock); 1202 + 1203 + return result; 1204 + } 1205 + 1206 + static ssize_t f_ss_opts_iso_qlen_store(struct config_item *item, 1207 + const char *page, size_t len) 1208 + { 1209 + struct f_ss_opts *opts = to_f_ss_opts(item); 1210 + int ret; 1211 + u32 num; 1212 + 1213 + mutex_lock(&opts->lock); 1214 + if (opts->refcnt) { 1215 + ret = -EBUSY; 1216 + goto end; 1217 + } 1218 + 1219 + ret = kstrtou32(page, 0, &num); 1220 + if (ret) 1221 + goto end; 1222 + 1223 + opts->iso_qlen = num; 1224 + ret = len; 1225 + end: 1226 + mutex_unlock(&opts->lock); 1227 + return ret; 1228 + } 1229 + 1230 + CONFIGFS_ATTR(f_ss_opts_, iso_qlen); 1231 + 1147 1232 static struct configfs_attribute *ss_attrs[] = { 1148 1233 &f_ss_opts_attr_pattern, 1149 1234 &f_ss_opts_attr_isoc_interval, ··· 1227 1160 &f_ss_opts_attr_isoc_mult, 1228 1161 &f_ss_opts_attr_isoc_maxburst, 1229 1162 &f_ss_opts_attr_bulk_buflen, 1163 + &f_ss_opts_attr_bulk_qlen, 1164 + &f_ss_opts_attr_iso_qlen, 1230 1165 NULL, 1231 1166 }; 1232 1167 ··· 1258 1189 ss_opts->isoc_interval = GZERO_ISOC_INTERVAL; 1259 1190 ss_opts->isoc_maxpacket = GZERO_ISOC_MAXPACKET; 1260 1191 ss_opts->bulk_buflen = GZERO_BULK_BUFLEN; 1192 + ss_opts->bulk_qlen = GZERO_SS_BULK_QLEN; 1193 + ss_opts->iso_qlen = GZERO_SS_ISO_QLEN; 1261 1194 1262 1195 config_group_init_type_name(&ss_opts->func_inst.group, "", 1263 1196 &ss_func_type);
+6 -1
drivers/usb/gadget/function/g_zero.h
··· 10 10 #define GZERO_QLEN 32 11 11 #define GZERO_ISOC_INTERVAL 4 12 12 #define GZERO_ISOC_MAXPACKET 1024 13 + #define GZERO_SS_BULK_QLEN 1 14 + #define GZERO_SS_ISO_QLEN 8 13 15 14 16 struct usb_zero_options { 15 17 unsigned pattern; ··· 21 19 unsigned isoc_maxburst; 22 20 unsigned bulk_buflen; 23 21 unsigned qlen; 22 + unsigned ss_bulk_qlen; 23 + unsigned ss_iso_qlen; 24 24 }; 25 25 26 26 struct f_ss_opts { ··· 33 29 unsigned isoc_mult; 34 30 unsigned isoc_maxburst; 35 31 unsigned bulk_buflen; 32 + unsigned bulk_qlen; 33 + unsigned iso_qlen; 36 34 37 35 /* 38 36 * Read/write access to configfs attributes is handled by configfs. ··· 65 59 int lb_modinit(void); 66 60 67 61 /* common utilities */ 68 - void free_ep_req(struct usb_ep *ep, struct usb_request *req); 69 62 void disable_endpoints(struct usb_composite_dev *cdev, 70 63 struct usb_ep *in, struct usb_ep *out, 71 64 struct usb_ep *iso_in, struct usb_ep *iso_out);
+4 -14
drivers/usb/gadget/function/u_ether.c
··· 143 143 144 144 static int ueth_change_mtu(struct net_device *net, int new_mtu) 145 145 { 146 - struct eth_dev *dev = netdev_priv(net); 147 - unsigned long flags; 148 - int status = 0; 146 + if (new_mtu <= ETH_HLEN || new_mtu > GETHER_MAX_ETH_FRAME_LEN) 147 + return -ERANGE; 148 + net->mtu = new_mtu; 149 149 150 - /* don't change MTU on "live" link (peer won't know) */ 151 - spin_lock_irqsave(&dev->lock, flags); 152 - if (dev->port_usb) 153 - status = -EBUSY; 154 - else if (new_mtu <= ETH_HLEN || new_mtu > GETHER_MAX_ETH_FRAME_LEN) 155 - status = -ERANGE; 156 - else 157 - net->mtu = new_mtu; 158 - spin_unlock_irqrestore(&dev->lock, flags); 159 - 160 - return status; 150 + return 0; 161 151 } 162 152 163 153 static void eth_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *p)
+258
drivers/usb/gadget/function/u_serial.c
··· 27 27 #include <linux/slab.h> 28 28 #include <linux/export.h> 29 29 #include <linux/module.h> 30 + #include <linux/console.h> 31 + #include <linux/kthread.h> 30 32 31 33 #include "u_serial.h" 32 34 ··· 81 79 */ 82 80 #define QUEUE_SIZE 16 83 81 #define WRITE_BUF_SIZE 8192 /* TX only */ 82 + #define GS_CONSOLE_BUF_SIZE 8192 84 83 85 84 /* circular buffer */ 86 85 struct gs_buf { ··· 89 86 char *buf_buf; 90 87 char *buf_get; 91 88 char *buf_put; 89 + }; 90 + 91 + /* console info */ 92 + struct gscons_info { 93 + struct gs_port *port; 94 + struct task_struct *console_thread; 95 + struct gs_buf con_buf; 96 + /* protect the buf and busy flag */ 97 + spinlock_t con_lock; 98 + int req_busy; 99 + struct usb_request *console_req; 92 100 }; 93 101 94 102 /* ··· 1037 1023 1038 1024 static struct tty_driver *gs_tty_driver; 1039 1025 1026 + #ifdef CONFIG_U_SERIAL_CONSOLE 1027 + 1028 + static struct gscons_info gscons_info; 1029 + static struct console gserial_cons; 1030 + 1031 + static struct usb_request *gs_request_new(struct usb_ep *ep) 1032 + { 1033 + struct usb_request *req = usb_ep_alloc_request(ep, GFP_ATOMIC); 1034 + if (!req) 1035 + return NULL; 1036 + 1037 + req->buf = kmalloc(ep->maxpacket, GFP_ATOMIC); 1038 + if (!req->buf) { 1039 + usb_ep_free_request(ep, req); 1040 + return NULL; 1041 + } 1042 + 1043 + return req; 1044 + } 1045 + 1046 + static void gs_request_free(struct usb_request *req, struct usb_ep *ep) 1047 + { 1048 + if (!req) 1049 + return; 1050 + 1051 + kfree(req->buf); 1052 + usb_ep_free_request(ep, req); 1053 + } 1054 + 1055 + static void gs_complete_out(struct usb_ep *ep, struct usb_request *req) 1056 + { 1057 + struct gscons_info *info = &gscons_info; 1058 + 1059 + switch (req->status) { 1060 + default: 1061 + pr_warn("%s: unexpected %s status %d\n", 1062 + __func__, ep->name, req->status); 1063 + case 0: 1064 + /* normal completion */ 1065 + spin_lock(&info->con_lock); 1066 + info->req_busy = 0; 1067 + spin_unlock(&info->con_lock); 1068 + 1069 + wake_up_process(info->console_thread); 1070 + break; 1071 + case -ESHUTDOWN: 1072 + /* disconnect */ 1073 + pr_vdebug("%s: %s shutdown\n", __func__, ep->name); 1074 + break; 1075 + } 1076 + } 1077 + 1078 + static int gs_console_connect(int port_num) 1079 + { 1080 + struct gscons_info *info = &gscons_info; 1081 + struct gs_port *port; 1082 + struct usb_ep *ep; 1083 + 1084 + if (port_num != gserial_cons.index) { 1085 + pr_err("%s: port num [%d] is not support console\n", 1086 + __func__, port_num); 1087 + return -ENXIO; 1088 + } 1089 + 1090 + port = ports[port_num].port; 1091 + ep = port->port_usb->in; 1092 + if (!info->console_req) { 1093 + info->console_req = gs_request_new(ep); 1094 + if (!info->console_req) 1095 + return -ENOMEM; 1096 + info->console_req->complete = gs_complete_out; 1097 + } 1098 + 1099 + info->port = port; 1100 + spin_lock(&info->con_lock); 1101 + info->req_busy = 0; 1102 + spin_unlock(&info->con_lock); 1103 + pr_vdebug("port[%d] console connect!\n", port_num); 1104 + return 0; 1105 + } 1106 + 1107 + static void gs_console_disconnect(struct usb_ep *ep) 1108 + { 1109 + struct gscons_info *info = &gscons_info; 1110 + struct usb_request *req = info->console_req; 1111 + 1112 + gs_request_free(req, ep); 1113 + info->console_req = NULL; 1114 + } 1115 + 1116 + static int gs_console_thread(void *data) 1117 + { 1118 + struct gscons_info *info = &gscons_info; 1119 + struct gs_port *port; 1120 + struct usb_request *req; 1121 + struct usb_ep *ep; 1122 + int xfer, ret, count, size; 1123 + 1124 + do { 1125 + port = info->port; 1126 + set_current_state(TASK_INTERRUPTIBLE); 1127 + if (!port || !port->port_usb 1128 + || !port->port_usb->in || !info->console_req) 1129 + goto sched; 1130 + 1131 + req = info->console_req; 1132 + ep = port->port_usb->in; 1133 + 1134 + spin_lock_irq(&info->con_lock); 1135 + count = gs_buf_data_avail(&info->con_buf); 1136 + size = ep->maxpacket; 1137 + 1138 + if (count > 0 && !info->req_busy) { 1139 + set_current_state(TASK_RUNNING); 1140 + if (count < size) 1141 + size = count; 1142 + 1143 + xfer = gs_buf_get(&info->con_buf, req->buf, size); 1144 + req->length = xfer; 1145 + 1146 + spin_unlock(&info->con_lock); 1147 + ret = usb_ep_queue(ep, req, GFP_ATOMIC); 1148 + spin_lock(&info->con_lock); 1149 + if (ret < 0) 1150 + info->req_busy = 0; 1151 + else 1152 + info->req_busy = 1; 1153 + 1154 + spin_unlock_irq(&info->con_lock); 1155 + } else { 1156 + spin_unlock_irq(&info->con_lock); 1157 + sched: 1158 + if (kthread_should_stop()) { 1159 + set_current_state(TASK_RUNNING); 1160 + break; 1161 + } 1162 + schedule(); 1163 + } 1164 + } while (1); 1165 + 1166 + return 0; 1167 + } 1168 + 1169 + static int gs_console_setup(struct console *co, char *options) 1170 + { 1171 + struct gscons_info *info = &gscons_info; 1172 + int status; 1173 + 1174 + info->port = NULL; 1175 + info->console_req = NULL; 1176 + info->req_busy = 0; 1177 + spin_lock_init(&info->con_lock); 1178 + 1179 + status = gs_buf_alloc(&info->con_buf, GS_CONSOLE_BUF_SIZE); 1180 + if (status) { 1181 + pr_err("%s: allocate console buffer failed\n", __func__); 1182 + return status; 1183 + } 1184 + 1185 + info->console_thread = kthread_create(gs_console_thread, 1186 + co, "gs_console"); 1187 + if (IS_ERR(info->console_thread)) { 1188 + pr_err("%s: cannot create console thread\n", __func__); 1189 + gs_buf_free(&info->con_buf); 1190 + return PTR_ERR(info->console_thread); 1191 + } 1192 + wake_up_process(info->console_thread); 1193 + 1194 + return 0; 1195 + } 1196 + 1197 + static void gs_console_write(struct console *co, 1198 + const char *buf, unsigned count) 1199 + { 1200 + struct gscons_info *info = &gscons_info; 1201 + unsigned long flags; 1202 + 1203 + spin_lock_irqsave(&info->con_lock, flags); 1204 + gs_buf_put(&info->con_buf, buf, count); 1205 + spin_unlock_irqrestore(&info->con_lock, flags); 1206 + 1207 + wake_up_process(info->console_thread); 1208 + } 1209 + 1210 + static struct tty_driver *gs_console_device(struct console *co, int *index) 1211 + { 1212 + struct tty_driver **p = (struct tty_driver **)co->data; 1213 + 1214 + if (!*p) 1215 + return NULL; 1216 + 1217 + *index = co->index; 1218 + return *p; 1219 + } 1220 + 1221 + static struct console gserial_cons = { 1222 + .name = "ttyGS", 1223 + .write = gs_console_write, 1224 + .device = gs_console_device, 1225 + .setup = gs_console_setup, 1226 + .flags = CON_PRINTBUFFER, 1227 + .index = -1, 1228 + .data = &gs_tty_driver, 1229 + }; 1230 + 1231 + static void gserial_console_init(void) 1232 + { 1233 + register_console(&gserial_cons); 1234 + } 1235 + 1236 + static void gserial_console_exit(void) 1237 + { 1238 + struct gscons_info *info = &gscons_info; 1239 + 1240 + unregister_console(&gserial_cons); 1241 + kthread_stop(info->console_thread); 1242 + gs_buf_free(&info->con_buf); 1243 + } 1244 + 1245 + #else 1246 + 1247 + static int gs_console_connect(int port_num) 1248 + { 1249 + return 0; 1250 + } 1251 + 1252 + static void gs_console_disconnect(struct usb_ep *ep) 1253 + { 1254 + } 1255 + 1256 + static void gserial_console_init(void) 1257 + { 1258 + } 1259 + 1260 + static void gserial_console_exit(void) 1261 + { 1262 + } 1263 + 1264 + #endif 1265 + 1040 1266 static int 1041 1267 gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding) 1042 1268 { ··· 1350 1096 1351 1097 gserial_free_port(port); 1352 1098 tty_unregister_device(gs_tty_driver, port_num); 1099 + gserial_console_exit(); 1353 1100 } 1354 1101 EXPORT_SYMBOL_GPL(gserial_free_line); 1355 1102 ··· 1393 1138 goto err; 1394 1139 } 1395 1140 *line_num = port_num; 1141 + gserial_console_init(); 1396 1142 err: 1397 1143 return ret; 1398 1144 } ··· 1475 1219 gser->disconnect(gser); 1476 1220 } 1477 1221 1222 + status = gs_console_connect(port_num); 1478 1223 spin_unlock_irqrestore(&port->port_lock, flags); 1479 1224 1480 1225 return status; ··· 1534 1277 port->read_allocated = port->read_started = 1535 1278 port->write_allocated = port->write_started = 0; 1536 1279 1280 + gs_console_disconnect(gser->in); 1537 1281 spin_unlock_irqrestore(&port->port_lock, flags); 1538 1282 } 1539 1283 EXPORT_SYMBOL_GPL(gserial_disconnect);
+1 -1
drivers/usb/gadget/legacy/acm_ms.c
··· 40 40 .bLength = sizeof device_desc, 41 41 .bDescriptorType = USB_DT_DEVICE, 42 42 43 - .bcdUSB = cpu_to_le16(0x0200), 43 + /* .bcdUSB = DYNAMIC */ 44 44 45 45 .bDeviceClass = USB_CLASS_MISC /* 0xEF */, 46 46 .bDeviceSubClass = 2,
+1 -1
drivers/usb/gadget/legacy/audio.c
··· 123 123 .bLength = sizeof device_desc, 124 124 .bDescriptorType = USB_DT_DEVICE, 125 125 126 - .bcdUSB = cpu_to_le16(0x200), 126 + /* .bcdUSB = DYNAMIC */ 127 127 128 128 #ifdef CONFIG_GADGET_UAC1 129 129 .bDeviceClass = USB_CLASS_PER_INTERFACE,
+1 -1
drivers/usb/gadget/legacy/cdc2.c
··· 43 43 .bLength = sizeof device_desc, 44 44 .bDescriptorType = USB_DT_DEVICE, 45 45 46 - .bcdUSB = cpu_to_le16(0x0200), 46 + /* .bcdUSB = DYNAMIC */ 47 47 48 48 .bDeviceClass = USB_CLASS_COMM, 49 49 .bDeviceSubClass = 0,
+1 -1
drivers/usb/gadget/legacy/ether.c
··· 151 151 .bLength = sizeof device_desc, 152 152 .bDescriptorType = USB_DT_DEVICE, 153 153 154 - .bcdUSB = cpu_to_le16 (0x0200), 154 + /* .bcdUSB = DYNAMIC */ 155 155 156 156 .bDeviceClass = USB_CLASS_COMM, 157 157 .bDeviceSubClass = 0,
+1 -1
drivers/usb/gadget/legacy/g_ffs.c
··· 69 69 .bLength = sizeof gfs_dev_desc, 70 70 .bDescriptorType = USB_DT_DEVICE, 71 71 72 - .bcdUSB = cpu_to_le16(0x0200), 72 + /* .bcdUSB = DYNAMIC */ 73 73 .bDeviceClass = USB_CLASS_PER_INTERFACE, 74 74 75 75 .idVendor = cpu_to_le16(GFS_VENDOR_ID),
+2 -10
drivers/usb/gadget/legacy/gmidi.c
··· 21 21 /* #define VERBOSE_DEBUG */ 22 22 23 23 #include <linux/kernel.h> 24 - #include <linux/slab.h> 25 24 #include <linux/module.h> 26 - #include <linux/device.h> 27 25 28 - #include <sound/core.h> 29 26 #include <sound/initval.h> 30 - #include <sound/rawmidi.h> 31 27 32 - #include <linux/usb/ch9.h> 33 28 #include <linux/usb/composite.h> 34 29 #include <linux/usb/gadget.h> 35 - #include <linux/usb/audio.h> 36 - #include <linux/usb/midi.h> 37 30 38 31 #include "u_midi.h" 39 32 ··· 35 42 MODULE_AUTHOR("Ben Williamson"); 36 43 MODULE_LICENSE("GPL v2"); 37 44 38 - static const char shortname[] = "g_midi"; 39 45 static const char longname[] = "MIDI Gadget"; 40 46 41 47 USB_GADGET_COMPOSITE_OPTIONS(); ··· 53 61 54 62 static unsigned int qlen = 32; 55 63 module_param(qlen, uint, S_IRUGO); 56 - MODULE_PARM_DESC(qlen, "USB read request queue length"); 64 + MODULE_PARM_DESC(qlen, "USB read and write request queue length"); 57 65 58 66 static unsigned int in_ports = 1; 59 67 module_param(in_ports, uint, S_IRUGO); ··· 78 86 static struct usb_device_descriptor device_desc = { 79 87 .bLength = USB_DT_DEVICE_SIZE, 80 88 .bDescriptorType = USB_DT_DEVICE, 81 - .bcdUSB = cpu_to_le16(0x0200), 89 + /* .bcdUSB = DYNAMIC */ 82 90 .bDeviceClass = USB_CLASS_PER_INTERFACE, 83 91 .idVendor = cpu_to_le16(DRIVER_VENDOR_NUM), 84 92 .idProduct = cpu_to_le16(DRIVER_PRODUCT_NUM),
+1 -1
drivers/usb/gadget/legacy/hid.c
··· 47 47 .bLength = sizeof device_desc, 48 48 .bDescriptorType = USB_DT_DEVICE, 49 49 50 - .bcdUSB = cpu_to_le16(0x0200), 50 + /* .bcdUSB = DYNAMIC */ 51 51 52 52 /* .bDeviceClass = USB_CLASS_COMM, */ 53 53 /* .bDeviceSubClass = 0, */
+1 -2
drivers/usb/gadget/legacy/inode.c
··· 1137 1137 dev->gadget->ep0, dev->req, 1138 1138 GFP_KERNEL); 1139 1139 } 1140 + spin_lock_irq(&dev->lock); 1140 1141 if (retval < 0) { 1141 - spin_lock_irq (&dev->lock); 1142 1142 clean_req (dev->gadget->ep0, dev->req); 1143 - spin_unlock_irq (&dev->lock); 1144 1143 } else 1145 1144 retval = len; 1146 1145
+1 -1
drivers/usb/gadget/legacy/mass_storage.c
··· 55 55 .bLength = sizeof msg_device_desc, 56 56 .bDescriptorType = USB_DT_DEVICE, 57 57 58 - .bcdUSB = cpu_to_le16(0x0200), 58 + /* .bcdUSB = DYNAMIC */ 59 59 .bDeviceClass = USB_CLASS_PER_INTERFACE, 60 60 61 61 /* Vendor and product id can be overridden by module parameters. */
+1 -1
drivers/usb/gadget/legacy/multi.c
··· 67 67 .bLength = sizeof device_desc, 68 68 .bDescriptorType = USB_DT_DEVICE, 69 69 70 - .bcdUSB = cpu_to_le16(0x0200), 70 + /* .bcdUSB = DYNAMIC */ 71 71 72 72 .bDeviceClass = USB_CLASS_MISC /* 0xEF */, 73 73 .bDeviceSubClass = 2,
+1 -1
drivers/usb/gadget/legacy/ncm.c
··· 49 49 .bLength = sizeof device_desc, 50 50 .bDescriptorType = USB_DT_DEVICE, 51 51 52 - .bcdUSB = cpu_to_le16 (0x0200), 52 + /* .bcdUSB = DYNAMIC */ 53 53 54 54 .bDeviceClass = USB_CLASS_COMM, 55 55 .bDeviceSubClass = 0,
+1 -1
drivers/usb/gadget/legacy/nokia.c
··· 89 89 static struct usb_device_descriptor device_desc = { 90 90 .bLength = USB_DT_DEVICE_SIZE, 91 91 .bDescriptorType = USB_DT_DEVICE, 92 - .bcdUSB = cpu_to_le16(0x0200), 92 + /* .bcdUSB = DYNAMIC */ 93 93 .bDeviceClass = USB_CLASS_COMM, 94 94 .idVendor = cpu_to_le16(NOKIA_VENDOR_ID), 95 95 .idProduct = cpu_to_le16(NOKIA_PRODUCT_ID),
+1 -1
drivers/usb/gadget/legacy/printer.c
··· 71 71 static struct usb_device_descriptor device_desc = { 72 72 .bLength = sizeof device_desc, 73 73 .bDescriptorType = USB_DT_DEVICE, 74 - .bcdUSB = cpu_to_le16(0x0200), 74 + /* .bcdUSB = DYNAMIC */ 75 75 .bDeviceClass = USB_CLASS_PER_INTERFACE, 76 76 .bDeviceSubClass = 0, 77 77 .bDeviceProtocol = 0,
+1 -1
drivers/usb/gadget/legacy/serial.c
··· 65 65 static struct usb_device_descriptor device_desc = { 66 66 .bLength = USB_DT_DEVICE_SIZE, 67 67 .bDescriptorType = USB_DT_DEVICE, 68 - .bcdUSB = cpu_to_le16(0x0200), 68 + /* .bcdUSB = DYNAMIC */ 69 69 /* .bDeviceClass = f(use_acm) */ 70 70 .bDeviceSubClass = 0, 71 71 .bDeviceProtocol = 0,
+1 -1
drivers/usb/gadget/legacy/tcm_usb_gadget.c
··· 1974 1974 static struct usb_device_descriptor usbg_device_desc = { 1975 1975 .bLength = sizeof(usbg_device_desc), 1976 1976 .bDescriptorType = USB_DT_DEVICE, 1977 - .bcdUSB = cpu_to_le16(0x0200), 1977 + /* .bcdUSB = DYNAMIC */ 1978 1978 .bDeviceClass = USB_CLASS_PER_INTERFACE, 1979 1979 .idVendor = cpu_to_le16(UAS_VENDOR_ID), 1980 1980 .idProduct = cpu_to_le16(UAS_PRODUCT_ID),
+1 -1
drivers/usb/gadget/legacy/webcam.c
··· 77 77 static struct usb_device_descriptor webcam_device_descriptor = { 78 78 .bLength = USB_DT_DEVICE_SIZE, 79 79 .bDescriptorType = USB_DT_DEVICE, 80 - .bcdUSB = cpu_to_le16(0x0200), 80 + /* .bcdUSB = DYNAMIC */ 81 81 .bDeviceClass = USB_CLASS_MISC, 82 82 .bDeviceSubClass = 0x02, 83 83 .bDeviceProtocol = 0x01,
+13 -1
drivers/usb/gadget/legacy/zero.c
··· 68 68 .isoc_maxpacket = GZERO_ISOC_MAXPACKET, 69 69 .bulk_buflen = GZERO_BULK_BUFLEN, 70 70 .qlen = GZERO_QLEN, 71 + .ss_bulk_qlen = GZERO_SS_BULK_QLEN, 72 + .ss_iso_qlen = GZERO_SS_ISO_QLEN, 71 73 }; 72 74 73 75 /*-------------------------------------------------------------------------*/ ··· 115 113 .bLength = sizeof device_desc, 116 114 .bDescriptorType = USB_DT_DEVICE, 117 115 118 - .bcdUSB = cpu_to_le16(0x0200), 116 + /* .bcdUSB = DYNAMIC */ 119 117 .bDeviceClass = USB_CLASS_VENDOR_SPEC, 120 118 121 119 .idVendor = cpu_to_le16(DRIVER_VENDOR_NUM), ··· 257 255 module_param_named(qlen, gzero_options.qlen, uint, S_IRUGO|S_IWUSR); 258 256 MODULE_PARM_DESC(qlen, "depth of loopback queue"); 259 257 258 + module_param_named(ss_bulk_qlen, gzero_options.ss_bulk_qlen, uint, 259 + S_IRUGO|S_IWUSR); 260 + MODULE_PARM_DESC(bulk_qlen, "depth of sourcesink queue for bulk transfer"); 261 + 262 + module_param_named(ss_iso_qlen, gzero_options.ss_iso_qlen, uint, 263 + S_IRUGO|S_IWUSR); 264 + MODULE_PARM_DESC(iso_qlen, "depth of sourcesink queue for iso transfer"); 265 + 260 266 static int zero_bind(struct usb_composite_dev *cdev) 261 267 { 262 268 struct f_ss_opts *ss_opts; ··· 295 285 ss_opts->isoc_mult = gzero_options.isoc_mult; 296 286 ss_opts->isoc_maxburst = gzero_options.isoc_maxburst; 297 287 ss_opts->bulk_buflen = gzero_options.bulk_buflen; 288 + ss_opts->bulk_qlen = gzero_options.ss_bulk_qlen; 289 + ss_opts->iso_qlen = gzero_options.ss_iso_qlen; 298 290 299 291 func_ss = usb_get_function(func_inst_ss); 300 292 if (IS_ERR(func_ss)) {
-1
drivers/usb/gadget/u_f.c
··· 11 11 * published by the Free Software Foundation. 12 12 */ 13 13 14 - #include <linux/usb/gadget.h> 15 14 #include "u_f.h" 16 15 17 16 struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len)
+8 -2
drivers/usb/gadget/u_f.h
··· 16 16 #ifndef __U_F_H__ 17 17 #define __U_F_H__ 18 18 19 + #include <linux/usb/gadget.h> 20 + 19 21 /* Variable Length Array Macros **********************************************/ 20 22 #define vla_group(groupname) size_t groupname##__next = 0 21 23 #define vla_group_size(groupname) groupname##__next ··· 47 45 struct usb_ep; 48 46 struct usb_request; 49 47 48 + /* Requests allocated via alloc_ep_req() must be freed by free_ep_req(). */ 50 49 struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len); 50 + static inline void free_ep_req(struct usb_ep *ep, struct usb_request *req) 51 + { 52 + kfree(req->buf); 53 + usb_ep_free_request(ep, req); 54 + } 51 55 52 56 #endif /* __U_F_H__ */ 53 - 54 -
+11
drivers/usb/gadget/udc/Kconfig
··· 174 174 dynamically linked module called "renesas_usbhs" and force all 175 175 gadget drivers to also be dynamically linked. 176 176 177 + config USB_RENESAS_USB3 178 + tristate 'Renesas USB3.0 Peripheral controller' 179 + depends on ARCH_SHMOBILE || COMPILE_TEST 180 + help 181 + Renesas USB3.0 Peripheral controller is a USB peripheral controller 182 + that supports super, high, and full speed USB 3.0 data transfers. 183 + 184 + Say "y" to link the driver statically, or "m" to build a 185 + dynamically linked module called "renesas_usb3" and force all 186 + gadget drivers to also be dynamically linked. 187 + 177 188 config USB_PXA27X 178 189 tristate "PXA 27x" 179 190 help
+1
drivers/usb/gadget/udc/Makefile
··· 19 19 fsl_usb2_udc-$(CONFIG_ARCH_MXC) += fsl_mxc_udc.o 20 20 obj-$(CONFIG_USB_M66592) += m66592-udc.o 21 21 obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o 22 + obj-$(CONFIG_USB_RENESAS_USB3) += renesas_usb3.o 22 23 obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o 23 24 obj-$(CONFIG_USB_S3C_HSUDC) += s3c-hsudc.o 24 25 obj-$(CONFIG_USB_LPC32XX) += lpc32xx_udc.o
+2 -5
drivers/usb/gadget/udc/bcm63xx_udc.c
··· 1083 1083 struct bcm63xx_ep *bep = our_ep(ep); 1084 1084 struct bcm63xx_udc *udc = bep->udc; 1085 1085 struct iudma_ch *iudma = bep->iudma; 1086 - struct list_head *pos, *n; 1086 + struct bcm63xx_req *breq, *n; 1087 1087 unsigned long flags; 1088 1088 1089 1089 if (!ep || !ep->desc) ··· 1099 1099 iudma_reset_channel(udc, iudma); 1100 1100 1101 1101 if (!list_empty(&bep->queue)) { 1102 - list_for_each_safe(pos, n, &bep->queue) { 1103 - struct bcm63xx_req *breq = 1104 - list_entry(pos, struct bcm63xx_req, queue); 1105 - 1102 + list_for_each_entry_safe(breq, n, &bep->queue, queue) { 1106 1103 usb_gadget_unmap_request(&udc->gadget, &breq->req, 1107 1104 iudma->is_tx); 1108 1105 list_del(&breq->queue);
+1 -2
drivers/usb/gadget/udc/gr_udc.c
··· 253 253 dma_addr_t paddr; 254 254 struct gr_dma_desc *dma_desc; 255 255 256 - dma_desc = dma_pool_alloc(ep->dev->desc_pool, gfp_flags, &paddr); 256 + dma_desc = dma_pool_zalloc(ep->dev->desc_pool, gfp_flags, &paddr); 257 257 if (!dma_desc) { 258 258 dev_err(ep->dev->dev, "Could not allocate from DMA pool\n"); 259 259 return NULL; 260 260 } 261 261 262 - memset(dma_desc, 0, sizeof(*dma_desc)); 263 262 dma_desc->paddr = paddr; 264 263 265 264 return dma_desc;
+12 -25
drivers/usb/gadget/udc/lpc32xx_udc.c
··· 28 28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 29 29 */ 30 30 31 - #include <linux/kernel.h> 32 - #include <linux/module.h> 33 - #include <linux/platform_device.h> 34 - #include <linux/delay.h> 35 - #include <linux/ioport.h> 36 - #include <linux/slab.h> 37 - #include <linux/errno.h> 38 - #include <linux/init.h> 39 - #include <linux/list.h> 40 - #include <linux/interrupt.h> 41 - #include <linux/proc_fs.h> 42 31 #include <linux/clk.h> 43 - #include <linux/usb/ch9.h> 44 - #include <linux/usb/gadget.h> 45 - #include <linux/i2c.h> 46 - #include <linux/kthread.h> 47 - #include <linux/freezer.h> 32 + #include <linux/delay.h> 48 33 #include <linux/dma-mapping.h> 49 34 #include <linux/dmapool.h> 50 - #include <linux/workqueue.h> 35 + #include <linux/i2c.h> 36 + #include <linux/interrupt.h> 37 + #include <linux/module.h> 51 38 #include <linux/of.h> 39 + #include <linux/platform_device.h> 40 + #include <linux/proc_fs.h> 41 + #include <linux/slab.h> 42 + #include <linux/usb/ch9.h> 43 + #include <linux/usb/gadget.h> 52 44 #include <linux/usb/isp1301.h> 53 45 54 - #include <asm/byteorder.h> 55 - #include <mach/hardware.h> 56 - #include <linux/io.h> 57 - #include <asm/irq.h> 58 - 59 - #include <mach/platform.h> 60 - #include <mach/irqs.h> 61 - #include <mach/board.h> 62 46 #ifdef CONFIG_USB_GADGET_DEBUG_FILES 63 47 #include <linux/debugfs.h> 64 48 #include <linux/seq_file.h> 65 49 #endif 50 + 51 + #include <mach/hardware.h> 52 + #include <mach/platform.h> 66 53 67 54 /* 68 55 * USB device configuration structure
+1975
drivers/usb/gadget/udc/renesas_usb3.c
··· 1 + /* 2 + * Renesas USB3.0 Peripheral driver (USB gadget) 3 + * 4 + * Copyright (C) 2015 Renesas Electronics Corporation 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; version 2 of the License. 9 + */ 10 + 11 + #include <linux/delay.h> 12 + #include <linux/err.h> 13 + #include <linux/interrupt.h> 14 + #include <linux/io.h> 15 + #include <linux/module.h> 16 + #include <linux/of_device.h> 17 + #include <linux/platform_device.h> 18 + #include <linux/pm_runtime.h> 19 + #include <linux/sizes.h> 20 + #include <linux/slab.h> 21 + #include <linux/usb/ch9.h> 22 + #include <linux/usb/gadget.h> 23 + 24 + /* register definitions */ 25 + #define USB3_AXI_INT_STA 0x008 26 + #define USB3_AXI_INT_ENA 0x00c 27 + #define USB3_DMA_INT_STA 0x010 28 + #define USB3_DMA_INT_ENA 0x014 29 + #define USB3_USB_COM_CON 0x200 30 + #define USB3_USB20_CON 0x204 31 + #define USB3_USB30_CON 0x208 32 + #define USB3_USB_STA 0x210 33 + #define USB3_DRD_CON 0x218 34 + #define USB3_USB_INT_STA_1 0x220 35 + #define USB3_USB_INT_STA_2 0x224 36 + #define USB3_USB_INT_ENA_1 0x228 37 + #define USB3_USB_INT_ENA_2 0x22c 38 + #define USB3_STUP_DAT_0 0x230 39 + #define USB3_STUP_DAT_1 0x234 40 + #define USB3_P0_MOD 0x280 41 + #define USB3_P0_CON 0x288 42 + #define USB3_P0_STA 0x28c 43 + #define USB3_P0_INT_STA 0x290 44 + #define USB3_P0_INT_ENA 0x294 45 + #define USB3_P0_LNG 0x2a0 46 + #define USB3_P0_READ 0x2a4 47 + #define USB3_P0_WRITE 0x2a8 48 + #define USB3_PIPE_COM 0x2b0 49 + #define USB3_PN_MOD 0x2c0 50 + #define USB3_PN_RAMMAP 0x2c4 51 + #define USB3_PN_CON 0x2c8 52 + #define USB3_PN_STA 0x2cc 53 + #define USB3_PN_INT_STA 0x2d0 54 + #define USB3_PN_INT_ENA 0x2d4 55 + #define USB3_PN_LNG 0x2e0 56 + #define USB3_PN_READ 0x2e4 57 + #define USB3_PN_WRITE 0x2e8 58 + #define USB3_SSIFCMD 0x340 59 + 60 + /* AXI_INT_ENA and AXI_INT_STA */ 61 + #define AXI_INT_DMAINT BIT(31) 62 + #define AXI_INT_EPCINT BIT(30) 63 + 64 + /* LCLKSEL */ 65 + #define LCLKSEL_LSEL BIT(18) 66 + 67 + /* USB_COM_CON */ 68 + #define USB_COM_CON_CONF BIT(24) 69 + #define USB_COM_CON_SPD_MODE BIT(17) 70 + #define USB_COM_CON_EP0_EN BIT(16) 71 + #define USB_COM_CON_DEV_ADDR_SHIFT 8 72 + #define USB_COM_CON_DEV_ADDR_MASK GENMASK(14, USB_COM_CON_DEV_ADDR_SHIFT) 73 + #define USB_COM_CON_DEV_ADDR(n) (((n) << USB_COM_CON_DEV_ADDR_SHIFT) & \ 74 + USB_COM_CON_DEV_ADDR_MASK) 75 + #define USB_COM_CON_RX_DETECTION BIT(1) 76 + #define USB_COM_CON_PIPE_CLR BIT(0) 77 + 78 + /* USB20_CON */ 79 + #define USB20_CON_B2_PUE BIT(31) 80 + #define USB20_CON_B2_SUSPEND BIT(24) 81 + #define USB20_CON_B2_CONNECT BIT(17) 82 + #define USB20_CON_B2_TSTMOD_SHIFT 8 83 + #define USB20_CON_B2_TSTMOD_MASK GENMASK(10, USB20_CON_B2_TSTMOD_SHIFT) 84 + #define USB20_CON_B2_TSTMOD(n) (((n) << USB20_CON_B2_TSTMOD_SHIFT) & \ 85 + USB20_CON_B2_TSTMOD_MASK) 86 + #define USB20_CON_B2_TSTMOD_EN BIT(0) 87 + 88 + /* USB30_CON */ 89 + #define USB30_CON_POW_SEL_SHIFT 24 90 + #define USB30_CON_POW_SEL_MASK GENMASK(26, USB30_CON_POW_SEL_SHIFT) 91 + #define USB30_CON_POW_SEL_IN_U3 BIT(26) 92 + #define USB30_CON_POW_SEL_IN_DISCON 0 93 + #define USB30_CON_POW_SEL_P2_TO_P0 BIT(25) 94 + #define USB30_CON_POW_SEL_P0_TO_P3 BIT(24) 95 + #define USB30_CON_POW_SEL_P0_TO_P2 0 96 + #define USB30_CON_B3_PLLWAKE BIT(23) 97 + #define USB30_CON_B3_CONNECT BIT(17) 98 + #define USB30_CON_B3_HOTRST_CMP BIT(1) 99 + 100 + /* USB_STA */ 101 + #define USB_STA_SPEED_MASK (BIT(2) | BIT(1)) 102 + #define USB_STA_SPEED_HS BIT(2) 103 + #define USB_STA_SPEED_FS BIT(1) 104 + #define USB_STA_SPEED_SS 0 105 + #define USB_STA_VBUS_STA BIT(0) 106 + 107 + /* DRD_CON */ 108 + #define DRD_CON_PERI_CON BIT(24) 109 + 110 + /* USB_INT_ENA_1 and USB_INT_STA_1 */ 111 + #define USB_INT_1_B3_PLLWKUP BIT(31) 112 + #define USB_INT_1_B3_LUPSUCS BIT(30) 113 + #define USB_INT_1_B3_DISABLE BIT(27) 114 + #define USB_INT_1_B3_WRMRST BIT(21) 115 + #define USB_INT_1_B3_HOTRST BIT(20) 116 + #define USB_INT_1_B2_USBRST BIT(12) 117 + #define USB_INT_1_B2_L1SPND BIT(11) 118 + #define USB_INT_1_B2_SPND BIT(9) 119 + #define USB_INT_1_B2_RSUM BIT(8) 120 + #define USB_INT_1_SPEED BIT(1) 121 + #define USB_INT_1_VBUS_CNG BIT(0) 122 + 123 + /* USB_INT_ENA_2 and USB_INT_STA_2 */ 124 + #define USB_INT_2_PIPE(n) BIT(n) 125 + 126 + /* P0_MOD */ 127 + #define P0_MOD_DIR BIT(6) 128 + 129 + /* P0_CON and PN_CON */ 130 + #define PX_CON_BYTE_EN_MASK (BIT(10) | BIT(9)) 131 + #define PX_CON_BYTE_EN_SHIFT 9 132 + #define PX_CON_BYTE_EN_BYTES(n) (((n) << PX_CON_BYTE_EN_SHIFT) & \ 133 + PX_CON_BYTE_EN_MASK) 134 + #define PX_CON_SEND BIT(8) 135 + 136 + /* P0_CON */ 137 + #define P0_CON_ST_RES_MASK (BIT(27) | BIT(26)) 138 + #define P0_CON_ST_RES_FORCE_STALL BIT(27) 139 + #define P0_CON_ST_RES_NORMAL BIT(26) 140 + #define P0_CON_ST_RES_FORCE_NRDY 0 141 + #define P0_CON_OT_RES_MASK (BIT(25) | BIT(24)) 142 + #define P0_CON_OT_RES_FORCE_STALL BIT(25) 143 + #define P0_CON_OT_RES_NORMAL BIT(24) 144 + #define P0_CON_OT_RES_FORCE_NRDY 0 145 + #define P0_CON_IN_RES_MASK (BIT(17) | BIT(16)) 146 + #define P0_CON_IN_RES_FORCE_STALL BIT(17) 147 + #define P0_CON_IN_RES_NORMAL BIT(16) 148 + #define P0_CON_IN_RES_FORCE_NRDY 0 149 + #define P0_CON_RES_WEN BIT(7) 150 + #define P0_CON_BCLR BIT(1) 151 + 152 + /* P0_STA and PN_STA */ 153 + #define PX_STA_BUFSTS BIT(0) 154 + 155 + /* P0_INT_ENA and P0_INT_STA */ 156 + #define P0_INT_STSED BIT(18) 157 + #define P0_INT_STSST BIT(17) 158 + #define P0_INT_SETUP BIT(16) 159 + #define P0_INT_RCVNL BIT(8) 160 + #define P0_INT_ERDY BIT(7) 161 + #define P0_INT_FLOW BIT(6) 162 + #define P0_INT_STALL BIT(2) 163 + #define P0_INT_NRDY BIT(1) 164 + #define P0_INT_BFRDY BIT(0) 165 + #define P0_INT_ALL_BITS (P0_INT_STSED | P0_INT_SETUP | P0_INT_BFRDY) 166 + 167 + /* PN_MOD */ 168 + #define PN_MOD_DIR BIT(6) 169 + #define PN_MOD_TYPE_SHIFT 4 170 + #define PN_MOD_TYPE_MASK GENMASK(5, PN_MOD_TYPE_SHIFT) 171 + #define PN_MOD_TYPE(n) (((n) << PN_MOD_TYPE_SHIFT) & \ 172 + PN_MOD_TYPE_MASK) 173 + #define PN_MOD_EPNUM_MASK GENMASK(3, 0) 174 + #define PN_MOD_EPNUM(n) ((n) & PN_MOD_EPNUM_MASK) 175 + 176 + /* PN_RAMMAP */ 177 + #define PN_RAMMAP_RAMAREA_SHIFT 29 178 + #define PN_RAMMAP_RAMAREA_MASK GENMASK(31, PN_RAMMAP_RAMAREA_SHIFT) 179 + #define PN_RAMMAP_RAMAREA_16KB BIT(31) 180 + #define PN_RAMMAP_RAMAREA_8KB (BIT(30) | BIT(29)) 181 + #define PN_RAMMAP_RAMAREA_4KB BIT(30) 182 + #define PN_RAMMAP_RAMAREA_2KB BIT(29) 183 + #define PN_RAMMAP_RAMAREA_1KB 0 184 + #define PN_RAMMAP_MPKT_SHIFT 16 185 + #define PN_RAMMAP_MPKT_MASK GENMASK(26, PN_RAMMAP_MPKT_SHIFT) 186 + #define PN_RAMMAP_MPKT(n) (((n) << PN_RAMMAP_MPKT_SHIFT) & \ 187 + PN_RAMMAP_MPKT_MASK) 188 + #define PN_RAMMAP_RAMIF_SHIFT 14 189 + #define PN_RAMMAP_RAMIF_MASK GENMASK(15, PN_RAMMAP_RAMIF_SHIFT) 190 + #define PN_RAMMAP_RAMIF(n) (((n) << PN_RAMMAP_RAMIF_SHIFT) & \ 191 + PN_RAMMAP_RAMIF_MASK) 192 + #define PN_RAMMAP_BASEAD_MASK GENMASK(13, 0) 193 + #define PN_RAMMAP_BASEAD(offs) (((offs) >> 3) & PN_RAMMAP_BASEAD_MASK) 194 + #define PN_RAMMAP_DATA(area, ramif, basead) ((PN_RAMMAP_##area) | \ 195 + (PN_RAMMAP_RAMIF(ramif)) | \ 196 + (PN_RAMMAP_BASEAD(basead))) 197 + 198 + /* PN_CON */ 199 + #define PN_CON_EN BIT(31) 200 + #define PN_CON_DATAIF_EN BIT(30) 201 + #define PN_CON_RES_MASK (BIT(17) | BIT(16)) 202 + #define PN_CON_RES_FORCE_STALL BIT(17) 203 + #define PN_CON_RES_NORMAL BIT(16) 204 + #define PN_CON_RES_FORCE_NRDY 0 205 + #define PN_CON_LAST BIT(11) 206 + #define PN_CON_RES_WEN BIT(7) 207 + #define PN_CON_CLR BIT(0) 208 + 209 + /* PN_INT_STA and PN_INT_ENA */ 210 + #define PN_INT_LSTTR BIT(4) 211 + #define PN_INT_BFRDY BIT(0) 212 + 213 + /* USB3_SSIFCMD */ 214 + #define SSIFCMD_URES_U2 BIT(9) 215 + #define SSIFCMD_URES_U1 BIT(8) 216 + #define SSIFCMD_UDIR_U2 BIT(7) 217 + #define SSIFCMD_UDIR_U1 BIT(6) 218 + #define SSIFCMD_UREQ_U2 BIT(5) 219 + #define SSIFCMD_UREQ_U1 BIT(4) 220 + 221 + #define USB3_EP0_SS_MAX_PACKET_SIZE 512 222 + #define USB3_EP0_HSFS_MAX_PACKET_SIZE 64 223 + #define USB3_EP0_BUF_SIZE 8 224 + #define USB3_MAX_NUM_PIPES 30 225 + #define USB3_WAIT_US 3 226 + 227 + struct renesas_usb3; 228 + struct renesas_usb3_request { 229 + struct usb_request req; 230 + struct list_head queue; 231 + }; 232 + 233 + #define USB3_EP_NAME_SIZE 8 234 + struct renesas_usb3_ep { 235 + struct usb_ep ep; 236 + struct renesas_usb3 *usb3; 237 + int num; 238 + char ep_name[USB3_EP_NAME_SIZE]; 239 + struct list_head queue; 240 + u32 rammap_val; 241 + bool dir_in; 242 + bool halt; 243 + bool wedge; 244 + bool started; 245 + }; 246 + 247 + struct renesas_usb3_priv { 248 + int ramsize_per_ramif; /* unit = bytes */ 249 + int num_ramif; 250 + int ramsize_per_pipe; /* unit = bytes */ 251 + bool workaround_for_vbus; /* if true, don't check vbus signal */ 252 + }; 253 + 254 + struct renesas_usb3 { 255 + void __iomem *reg; 256 + 257 + struct usb_gadget gadget; 258 + struct usb_gadget_driver *driver; 259 + 260 + struct renesas_usb3_ep *usb3_ep; 261 + int num_usb3_eps; 262 + 263 + spinlock_t lock; 264 + int disabled_count; 265 + 266 + struct usb_request *ep0_req; 267 + u16 test_mode; 268 + u8 ep0_buf[USB3_EP0_BUF_SIZE]; 269 + bool softconnect; 270 + bool workaround_for_vbus; 271 + }; 272 + 273 + #define gadget_to_renesas_usb3(_gadget) \ 274 + container_of(_gadget, struct renesas_usb3, gadget) 275 + #define renesas_usb3_to_gadget(renesas_usb3) (&renesas_usb3->gadget) 276 + #define usb3_to_dev(_usb3) (_usb3->gadget.dev.parent) 277 + 278 + #define usb_ep_to_usb3_ep(_ep) container_of(_ep, struct renesas_usb3_ep, ep) 279 + #define usb3_ep_to_usb3(_usb3_ep) (_usb3_ep->usb3) 280 + #define usb_req_to_usb3_req(_req) container_of(_req, \ 281 + struct renesas_usb3_request, req) 282 + 283 + #define usb3_get_ep(usb3, n) ((usb3)->usb3_ep + (n)) 284 + #define usb3_for_each_ep(usb3_ep, usb3, i) \ 285 + for ((i) = 0, usb3_ep = usb3_get_ep(usb3, (i)); \ 286 + (i) < (usb3)->num_usb3_eps; \ 287 + (i)++, usb3_ep = usb3_get_ep(usb3, (i))) 288 + 289 + static const char udc_name[] = "renesas_usb3"; 290 + 291 + static void usb3_write(struct renesas_usb3 *usb3, u32 data, u32 offs) 292 + { 293 + iowrite32(data, usb3->reg + offs); 294 + } 295 + 296 + static u32 usb3_read(struct renesas_usb3 *usb3, u32 offs) 297 + { 298 + return ioread32(usb3->reg + offs); 299 + } 300 + 301 + static void usb3_set_bit(struct renesas_usb3 *usb3, u32 bits, u32 offs) 302 + { 303 + u32 val = usb3_read(usb3, offs); 304 + 305 + val |= bits; 306 + usb3_write(usb3, val, offs); 307 + } 308 + 309 + static void usb3_clear_bit(struct renesas_usb3 *usb3, u32 bits, u32 offs) 310 + { 311 + u32 val = usb3_read(usb3, offs); 312 + 313 + val &= ~bits; 314 + usb3_write(usb3, val, offs); 315 + } 316 + 317 + static int usb3_wait(struct renesas_usb3 *usb3, u32 reg, u32 mask, 318 + u32 expected) 319 + { 320 + int i; 321 + 322 + for (i = 0; i < USB3_WAIT_US; i++) { 323 + if ((usb3_read(usb3, reg) & mask) == expected) 324 + return 0; 325 + udelay(1); 326 + } 327 + 328 + dev_dbg(usb3_to_dev(usb3), "%s: timed out (%8x, %08x, %08x)\n", 329 + __func__, reg, mask, expected); 330 + 331 + return -EBUSY; 332 + } 333 + 334 + static void usb3_enable_irq_1(struct renesas_usb3 *usb3, u32 bits) 335 + { 336 + usb3_set_bit(usb3, bits, USB3_USB_INT_ENA_1); 337 + } 338 + 339 + static void usb3_disable_irq_1(struct renesas_usb3 *usb3, u32 bits) 340 + { 341 + usb3_clear_bit(usb3, bits, USB3_USB_INT_ENA_1); 342 + } 343 + 344 + static void usb3_enable_pipe_irq(struct renesas_usb3 *usb3, int num) 345 + { 346 + usb3_set_bit(usb3, USB_INT_2_PIPE(num), USB3_USB_INT_ENA_2); 347 + } 348 + 349 + static void usb3_disable_pipe_irq(struct renesas_usb3 *usb3, int num) 350 + { 351 + usb3_clear_bit(usb3, USB_INT_2_PIPE(num), USB3_USB_INT_ENA_2); 352 + } 353 + 354 + static void usb3_init_axi_bridge(struct renesas_usb3 *usb3) 355 + { 356 + /* Set AXI_INT */ 357 + usb3_write(usb3, ~0, USB3_DMA_INT_STA); 358 + usb3_write(usb3, 0, USB3_DMA_INT_ENA); 359 + usb3_set_bit(usb3, AXI_INT_DMAINT | AXI_INT_EPCINT, USB3_AXI_INT_ENA); 360 + } 361 + 362 + static void usb3_init_epc_registers(struct renesas_usb3 *usb3) 363 + { 364 + /* FIXME: How to change host / peripheral mode as well? */ 365 + usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); 366 + 367 + usb3_write(usb3, ~0, USB3_USB_INT_STA_1); 368 + usb3_enable_irq_1(usb3, USB_INT_1_VBUS_CNG); 369 + } 370 + 371 + static bool usb3_wakeup_usb2_phy(struct renesas_usb3 *usb3) 372 + { 373 + if (!(usb3_read(usb3, USB3_USB20_CON) & USB20_CON_B2_SUSPEND)) 374 + return true; /* already waked it up */ 375 + 376 + usb3_clear_bit(usb3, USB20_CON_B2_SUSPEND, USB3_USB20_CON); 377 + usb3_enable_irq_1(usb3, USB_INT_1_B2_RSUM); 378 + 379 + return false; 380 + } 381 + 382 + static void usb3_usb2_pullup(struct renesas_usb3 *usb3, int pullup) 383 + { 384 + u32 bits = USB20_CON_B2_PUE | USB20_CON_B2_CONNECT; 385 + 386 + if (usb3->softconnect && pullup) 387 + usb3_set_bit(usb3, bits, USB3_USB20_CON); 388 + else 389 + usb3_clear_bit(usb3, bits, USB3_USB20_CON); 390 + } 391 + 392 + static void usb3_set_test_mode(struct renesas_usb3 *usb3) 393 + { 394 + u32 val = usb3_read(usb3, USB3_USB20_CON); 395 + 396 + val &= ~USB20_CON_B2_TSTMOD_MASK; 397 + val |= USB20_CON_B2_TSTMOD(usb3->test_mode); 398 + usb3_write(usb3, val | USB20_CON_B2_TSTMOD_EN, USB3_USB20_CON); 399 + if (!usb3->test_mode) 400 + usb3_clear_bit(usb3, USB20_CON_B2_TSTMOD_EN, USB3_USB20_CON); 401 + } 402 + 403 + static void usb3_start_usb2_connection(struct renesas_usb3 *usb3) 404 + { 405 + usb3->disabled_count++; 406 + usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); 407 + usb3_set_bit(usb3, USB_COM_CON_SPD_MODE, USB3_USB_COM_CON); 408 + usb3_usb2_pullup(usb3, 1); 409 + } 410 + 411 + static int usb3_is_usb3_phy_in_u3(struct renesas_usb3 *usb3) 412 + { 413 + return usb3_read(usb3, USB3_USB30_CON) & USB30_CON_POW_SEL_IN_U3; 414 + } 415 + 416 + static bool usb3_wakeup_usb3_phy(struct renesas_usb3 *usb3) 417 + { 418 + if (!usb3_is_usb3_phy_in_u3(usb3)) 419 + return true; /* already waked it up */ 420 + 421 + usb3_set_bit(usb3, USB30_CON_B3_PLLWAKE, USB3_USB30_CON); 422 + usb3_enable_irq_1(usb3, USB_INT_1_B3_PLLWKUP); 423 + 424 + return false; 425 + } 426 + 427 + static u16 usb3_feature_get_un_enabled(struct renesas_usb3 *usb3) 428 + { 429 + u32 mask_u2 = SSIFCMD_UDIR_U2 | SSIFCMD_UREQ_U2; 430 + u32 mask_u1 = SSIFCMD_UDIR_U1 | SSIFCMD_UREQ_U1; 431 + u32 val = usb3_read(usb3, USB3_SSIFCMD); 432 + u16 ret = 0; 433 + 434 + /* Enables {U2,U1} if the bits of UDIR and UREQ are set to 0 */ 435 + if (!(val & mask_u2)) 436 + ret |= 1 << USB_DEV_STAT_U2_ENABLED; 437 + if (!(val & mask_u1)) 438 + ret |= 1 << USB_DEV_STAT_U1_ENABLED; 439 + 440 + return ret; 441 + } 442 + 443 + static void usb3_feature_u2_enable(struct renesas_usb3 *usb3, bool enable) 444 + { 445 + u32 bits = SSIFCMD_UDIR_U2 | SSIFCMD_UREQ_U2; 446 + 447 + /* Enables U2 if the bits of UDIR and UREQ are set to 0 */ 448 + if (enable) 449 + usb3_clear_bit(usb3, bits, USB3_SSIFCMD); 450 + else 451 + usb3_set_bit(usb3, bits, USB3_SSIFCMD); 452 + } 453 + 454 + static void usb3_feature_u1_enable(struct renesas_usb3 *usb3, bool enable) 455 + { 456 + u32 bits = SSIFCMD_UDIR_U1 | SSIFCMD_UREQ_U1; 457 + 458 + /* Enables U1 if the bits of UDIR and UREQ are set to 0 */ 459 + if (enable) 460 + usb3_clear_bit(usb3, bits, USB3_SSIFCMD); 461 + else 462 + usb3_set_bit(usb3, bits, USB3_SSIFCMD); 463 + } 464 + 465 + static void usb3_start_operation_for_usb3(struct renesas_usb3 *usb3) 466 + { 467 + usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); 468 + usb3_clear_bit(usb3, USB_COM_CON_SPD_MODE, USB3_USB_COM_CON); 469 + usb3_set_bit(usb3, USB30_CON_B3_CONNECT, USB3_USB30_CON); 470 + } 471 + 472 + static void usb3_start_usb3_connection(struct renesas_usb3 *usb3) 473 + { 474 + usb3_start_operation_for_usb3(usb3); 475 + usb3_set_bit(usb3, USB_COM_CON_RX_DETECTION, USB3_USB_COM_CON); 476 + 477 + usb3_enable_irq_1(usb3, USB_INT_1_B3_LUPSUCS | USB_INT_1_B3_DISABLE | 478 + USB_INT_1_SPEED); 479 + } 480 + 481 + static void usb3_stop_usb3_connection(struct renesas_usb3 *usb3) 482 + { 483 + usb3_clear_bit(usb3, USB30_CON_B3_CONNECT, USB3_USB30_CON); 484 + } 485 + 486 + static void usb3_transition_to_default_state(struct renesas_usb3 *usb3, 487 + bool is_usb3) 488 + { 489 + usb3_set_bit(usb3, USB_INT_2_PIPE(0), USB3_USB_INT_ENA_2); 490 + usb3_write(usb3, P0_INT_ALL_BITS, USB3_P0_INT_STA); 491 + usb3_set_bit(usb3, P0_INT_ALL_BITS, USB3_P0_INT_ENA); 492 + 493 + if (is_usb3) 494 + usb3_enable_irq_1(usb3, USB_INT_1_B3_WRMRST | 495 + USB_INT_1_B3_HOTRST); 496 + else 497 + usb3_enable_irq_1(usb3, USB_INT_1_B2_SPND | 498 + USB_INT_1_B2_L1SPND | USB_INT_1_B2_USBRST); 499 + } 500 + 501 + static void usb3_connect(struct renesas_usb3 *usb3) 502 + { 503 + if (usb3_wakeup_usb3_phy(usb3)) 504 + usb3_start_usb3_connection(usb3); 505 + } 506 + 507 + static void usb3_reset_epc(struct renesas_usb3 *usb3) 508 + { 509 + usb3_clear_bit(usb3, USB_COM_CON_CONF, USB3_USB_COM_CON); 510 + usb3_clear_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); 511 + usb3_set_bit(usb3, USB_COM_CON_PIPE_CLR, USB3_USB_COM_CON); 512 + usb3->test_mode = 0; 513 + usb3_set_test_mode(usb3); 514 + } 515 + 516 + static void usb3_disconnect(struct renesas_usb3 *usb3) 517 + { 518 + usb3->disabled_count = 0; 519 + usb3_usb2_pullup(usb3, 0); 520 + usb3_clear_bit(usb3, USB30_CON_B3_CONNECT, USB3_USB30_CON); 521 + usb3_reset_epc(usb3); 522 + 523 + if (usb3->driver) 524 + usb3->driver->disconnect(&usb3->gadget); 525 + } 526 + 527 + static void usb3_check_vbus(struct renesas_usb3 *usb3) 528 + { 529 + if (usb3->workaround_for_vbus) { 530 + usb3_connect(usb3); 531 + } else { 532 + if (usb3_read(usb3, USB3_USB_STA) & USB_STA_VBUS_STA) 533 + usb3_connect(usb3); 534 + else 535 + usb3_disconnect(usb3); 536 + } 537 + } 538 + 539 + static void renesas_usb3_init_controller(struct renesas_usb3 *usb3) 540 + { 541 + usb3_init_axi_bridge(usb3); 542 + usb3_init_epc_registers(usb3); 543 + 544 + usb3_check_vbus(usb3); 545 + } 546 + 547 + static void renesas_usb3_stop_controller(struct renesas_usb3 *usb3) 548 + { 549 + usb3_disconnect(usb3); 550 + usb3_write(usb3, 0, USB3_P0_INT_ENA); 551 + usb3_write(usb3, 0, USB3_PN_INT_ENA); 552 + usb3_write(usb3, 0, USB3_USB_INT_ENA_1); 553 + usb3_write(usb3, 0, USB3_USB_INT_ENA_2); 554 + usb3_write(usb3, 0, USB3_AXI_INT_ENA); 555 + } 556 + 557 + static void usb3_irq_epc_int_1_pll_wakeup(struct renesas_usb3 *usb3) 558 + { 559 + usb3_disable_irq_1(usb3, USB_INT_1_B3_PLLWKUP); 560 + usb3_clear_bit(usb3, USB30_CON_B3_PLLWAKE, USB3_USB30_CON); 561 + usb3_start_usb3_connection(usb3); 562 + } 563 + 564 + static void usb3_irq_epc_int_1_linkup_success(struct renesas_usb3 *usb3) 565 + { 566 + usb3_transition_to_default_state(usb3, true); 567 + } 568 + 569 + static void usb3_irq_epc_int_1_resume(struct renesas_usb3 *usb3) 570 + { 571 + usb3_disable_irq_1(usb3, USB_INT_1_B2_RSUM); 572 + usb3_start_usb2_connection(usb3); 573 + usb3_transition_to_default_state(usb3, false); 574 + } 575 + 576 + static void usb3_irq_epc_int_1_disable(struct renesas_usb3 *usb3) 577 + { 578 + usb3_stop_usb3_connection(usb3); 579 + if (usb3_wakeup_usb2_phy(usb3)) 580 + usb3_irq_epc_int_1_resume(usb3); 581 + } 582 + 583 + static void usb3_irq_epc_int_1_bus_reset(struct renesas_usb3 *usb3) 584 + { 585 + usb3_reset_epc(usb3); 586 + if (usb3->disabled_count < 3) 587 + usb3_start_usb3_connection(usb3); 588 + else 589 + usb3_start_usb2_connection(usb3); 590 + } 591 + 592 + static void usb3_irq_epc_int_1_vbus_change(struct renesas_usb3 *usb3) 593 + { 594 + usb3_check_vbus(usb3); 595 + } 596 + 597 + static void usb3_irq_epc_int_1_hot_reset(struct renesas_usb3 *usb3) 598 + { 599 + usb3_reset_epc(usb3); 600 + usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); 601 + 602 + /* This bit shall be set within 12ms from the start of HotReset */ 603 + usb3_set_bit(usb3, USB30_CON_B3_HOTRST_CMP, USB3_USB30_CON); 604 + } 605 + 606 + static void usb3_irq_epc_int_1_warm_reset(struct renesas_usb3 *usb3) 607 + { 608 + usb3_reset_epc(usb3); 609 + usb3_set_bit(usb3, USB_COM_CON_EP0_EN, USB3_USB_COM_CON); 610 + 611 + usb3_start_operation_for_usb3(usb3); 612 + usb3_enable_irq_1(usb3, USB_INT_1_SPEED); 613 + } 614 + 615 + static void usb3_irq_epc_int_1_speed(struct renesas_usb3 *usb3) 616 + { 617 + u32 speed = usb3_read(usb3, USB3_USB_STA) & USB_STA_SPEED_MASK; 618 + 619 + switch (speed) { 620 + case USB_STA_SPEED_SS: 621 + usb3->gadget.speed = USB_SPEED_SUPER; 622 + break; 623 + case USB_STA_SPEED_HS: 624 + usb3->gadget.speed = USB_SPEED_HIGH; 625 + break; 626 + case USB_STA_SPEED_FS: 627 + usb3->gadget.speed = USB_SPEED_FULL; 628 + break; 629 + default: 630 + usb3->gadget.speed = USB_SPEED_UNKNOWN; 631 + break; 632 + } 633 + } 634 + 635 + static void usb3_irq_epc_int_1(struct renesas_usb3 *usb3, u32 int_sta_1) 636 + { 637 + if (int_sta_1 & USB_INT_1_B3_PLLWKUP) 638 + usb3_irq_epc_int_1_pll_wakeup(usb3); 639 + 640 + if (int_sta_1 & USB_INT_1_B3_LUPSUCS) 641 + usb3_irq_epc_int_1_linkup_success(usb3); 642 + 643 + if (int_sta_1 & USB_INT_1_B3_HOTRST) 644 + usb3_irq_epc_int_1_hot_reset(usb3); 645 + 646 + if (int_sta_1 & USB_INT_1_B3_WRMRST) 647 + usb3_irq_epc_int_1_warm_reset(usb3); 648 + 649 + if (int_sta_1 & USB_INT_1_B3_DISABLE) 650 + usb3_irq_epc_int_1_disable(usb3); 651 + 652 + if (int_sta_1 & USB_INT_1_B2_USBRST) 653 + usb3_irq_epc_int_1_bus_reset(usb3); 654 + 655 + if (int_sta_1 & USB_INT_1_B2_RSUM) 656 + usb3_irq_epc_int_1_resume(usb3); 657 + 658 + if (int_sta_1 & USB_INT_1_SPEED) 659 + usb3_irq_epc_int_1_speed(usb3); 660 + 661 + if (int_sta_1 & USB_INT_1_VBUS_CNG) 662 + usb3_irq_epc_int_1_vbus_change(usb3); 663 + } 664 + 665 + static struct renesas_usb3_request *__usb3_get_request(struct renesas_usb3_ep 666 + *usb3_ep) 667 + { 668 + return list_first_entry_or_null(&usb3_ep->queue, 669 + struct renesas_usb3_request, queue); 670 + } 671 + 672 + static struct renesas_usb3_request *usb3_get_request(struct renesas_usb3_ep 673 + *usb3_ep) 674 + { 675 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 676 + struct renesas_usb3_request *usb3_req; 677 + unsigned long flags; 678 + 679 + spin_lock_irqsave(&usb3->lock, flags); 680 + usb3_req = __usb3_get_request(usb3_ep); 681 + spin_unlock_irqrestore(&usb3->lock, flags); 682 + 683 + return usb3_req; 684 + } 685 + 686 + static void usb3_request_done(struct renesas_usb3_ep *usb3_ep, 687 + struct renesas_usb3_request *usb3_req, int status) 688 + { 689 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 690 + unsigned long flags; 691 + 692 + dev_dbg(usb3_to_dev(usb3), "giveback: ep%2d, %u, %u, %d\n", 693 + usb3_ep->num, usb3_req->req.length, usb3_req->req.actual, 694 + status); 695 + usb3_req->req.status = status; 696 + spin_lock_irqsave(&usb3->lock, flags); 697 + usb3_ep->started = false; 698 + list_del_init(&usb3_req->queue); 699 + spin_unlock_irqrestore(&usb3->lock, flags); 700 + usb_gadget_giveback_request(&usb3_ep->ep, &usb3_req->req); 701 + } 702 + 703 + static void usb3_irq_epc_pipe0_status_end(struct renesas_usb3 *usb3) 704 + { 705 + struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); 706 + struct renesas_usb3_request *usb3_req = usb3_get_request(usb3_ep); 707 + 708 + if (usb3_req) 709 + usb3_request_done(usb3_ep, usb3_req, 0); 710 + if (usb3->test_mode) 711 + usb3_set_test_mode(usb3); 712 + } 713 + 714 + static void usb3_get_setup_data(struct renesas_usb3 *usb3, 715 + struct usb_ctrlrequest *ctrl) 716 + { 717 + struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); 718 + u32 *data = (u32 *)ctrl; 719 + 720 + *data++ = usb3_read(usb3, USB3_STUP_DAT_0); 721 + *data = usb3_read(usb3, USB3_STUP_DAT_1); 722 + 723 + /* update this driver's flag */ 724 + usb3_ep->dir_in = !!(ctrl->bRequestType & USB_DIR_IN); 725 + } 726 + 727 + static void usb3_set_p0_con_update_res(struct renesas_usb3 *usb3, u32 res) 728 + { 729 + u32 val = usb3_read(usb3, USB3_P0_CON); 730 + 731 + val &= ~(P0_CON_ST_RES_MASK | P0_CON_OT_RES_MASK | P0_CON_IN_RES_MASK); 732 + val |= res | P0_CON_RES_WEN; 733 + usb3_write(usb3, val, USB3_P0_CON); 734 + } 735 + 736 + static void usb3_set_p0_con_for_ctrl_read_data(struct renesas_usb3 *usb3) 737 + { 738 + usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_NRDY | 739 + P0_CON_OT_RES_FORCE_STALL | 740 + P0_CON_IN_RES_NORMAL); 741 + } 742 + 743 + static void usb3_set_p0_con_for_ctrl_read_status(struct renesas_usb3 *usb3) 744 + { 745 + usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_NORMAL | 746 + P0_CON_OT_RES_FORCE_STALL | 747 + P0_CON_IN_RES_NORMAL); 748 + } 749 + 750 + static void usb3_set_p0_con_for_ctrl_write_data(struct renesas_usb3 *usb3) 751 + { 752 + usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_NRDY | 753 + P0_CON_OT_RES_NORMAL | 754 + P0_CON_IN_RES_FORCE_STALL); 755 + } 756 + 757 + static void usb3_set_p0_con_for_ctrl_write_status(struct renesas_usb3 *usb3) 758 + { 759 + usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_NORMAL | 760 + P0_CON_OT_RES_NORMAL | 761 + P0_CON_IN_RES_FORCE_STALL); 762 + } 763 + 764 + static void usb3_set_p0_con_for_no_data(struct renesas_usb3 *usb3) 765 + { 766 + usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_NORMAL | 767 + P0_CON_OT_RES_FORCE_STALL | 768 + P0_CON_IN_RES_FORCE_STALL); 769 + } 770 + 771 + static void usb3_set_p0_con_stall(struct renesas_usb3 *usb3) 772 + { 773 + usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_STALL | 774 + P0_CON_OT_RES_FORCE_STALL | 775 + P0_CON_IN_RES_FORCE_STALL); 776 + } 777 + 778 + static void usb3_set_p0_con_stop(struct renesas_usb3 *usb3) 779 + { 780 + usb3_set_p0_con_update_res(usb3, P0_CON_ST_RES_FORCE_NRDY | 781 + P0_CON_OT_RES_FORCE_NRDY | 782 + P0_CON_IN_RES_FORCE_NRDY); 783 + } 784 + 785 + static int usb3_pn_change(struct renesas_usb3 *usb3, int num) 786 + { 787 + if (num == 0 || num > usb3->num_usb3_eps) 788 + return -ENXIO; 789 + 790 + usb3_write(usb3, num, USB3_PIPE_COM); 791 + 792 + return 0; 793 + } 794 + 795 + static void usb3_set_pn_con_update_res(struct renesas_usb3 *usb3, u32 res) 796 + { 797 + u32 val = usb3_read(usb3, USB3_PN_CON); 798 + 799 + val &= ~PN_CON_RES_MASK; 800 + val |= res & PN_CON_RES_MASK; 801 + val |= PN_CON_RES_WEN; 802 + usb3_write(usb3, val, USB3_PN_CON); 803 + } 804 + 805 + static void usb3_pn_start(struct renesas_usb3 *usb3) 806 + { 807 + usb3_set_pn_con_update_res(usb3, PN_CON_RES_NORMAL); 808 + } 809 + 810 + static void usb3_pn_stop(struct renesas_usb3 *usb3) 811 + { 812 + usb3_set_pn_con_update_res(usb3, PN_CON_RES_FORCE_NRDY); 813 + } 814 + 815 + static void usb3_pn_stall(struct renesas_usb3 *usb3) 816 + { 817 + usb3_set_pn_con_update_res(usb3, PN_CON_RES_FORCE_STALL); 818 + } 819 + 820 + static int usb3_pn_con_clear(struct renesas_usb3 *usb3) 821 + { 822 + usb3_set_bit(usb3, PN_CON_CLR, USB3_PN_CON); 823 + 824 + return usb3_wait(usb3, USB3_PN_CON, PN_CON_CLR, 0); 825 + } 826 + 827 + static bool usb3_is_transfer_complete(struct renesas_usb3_ep *usb3_ep, 828 + struct renesas_usb3_request *usb3_req) 829 + { 830 + struct usb_request *req = &usb3_req->req; 831 + 832 + if ((!req->zero && req->actual == req->length) || 833 + (req->actual % usb3_ep->ep.maxpacket) || (req->length == 0)) 834 + return true; 835 + else 836 + return false; 837 + } 838 + 839 + static int usb3_wait_pipe_status(struct renesas_usb3_ep *usb3_ep, u32 mask) 840 + { 841 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 842 + u32 sta_reg = usb3_ep->num ? USB3_PN_STA : USB3_P0_STA; 843 + 844 + return usb3_wait(usb3, sta_reg, mask, mask); 845 + } 846 + 847 + static void usb3_set_px_con_send(struct renesas_usb3_ep *usb3_ep, int bytes, 848 + bool last) 849 + { 850 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 851 + u32 con_reg = usb3_ep->num ? USB3_PN_CON : USB3_P0_CON; 852 + u32 val = usb3_read(usb3, con_reg); 853 + 854 + val |= PX_CON_SEND | PX_CON_BYTE_EN_BYTES(bytes); 855 + val |= (usb3_ep->num && last) ? PN_CON_LAST : 0; 856 + usb3_write(usb3, val, con_reg); 857 + } 858 + 859 + static int usb3_write_pipe(struct renesas_usb3_ep *usb3_ep, 860 + struct renesas_usb3_request *usb3_req, 861 + u32 fifo_reg) 862 + { 863 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 864 + int i; 865 + int len = min_t(unsigned, usb3_req->req.length - usb3_req->req.actual, 866 + usb3_ep->ep.maxpacket); 867 + u8 *buf = usb3_req->req.buf + usb3_req->req.actual; 868 + u32 tmp = 0; 869 + bool is_last; 870 + 871 + if (usb3_wait_pipe_status(usb3_ep, PX_STA_BUFSTS) < 0) 872 + return -EBUSY; 873 + 874 + /* Update gadget driver parameter */ 875 + usb3_req->req.actual += len; 876 + 877 + /* Write data to the register */ 878 + if (len >= 4) { 879 + iowrite32_rep(usb3->reg + fifo_reg, buf, len / 4); 880 + buf += (len / 4) * 4; 881 + len %= 4; /* update len to use usb3_set_pX_con_send() */ 882 + } 883 + 884 + if (len) { 885 + for (i = 0; i < len; i++) 886 + tmp |= buf[i] << (8 * i); 887 + usb3_write(usb3, tmp, fifo_reg); 888 + } 889 + 890 + is_last = usb3_is_transfer_complete(usb3_ep, usb3_req); 891 + /* Send the data */ 892 + usb3_set_px_con_send(usb3_ep, len, is_last); 893 + 894 + return is_last ? 0 : -EAGAIN; 895 + } 896 + 897 + static u32 usb3_get_received_length(struct renesas_usb3_ep *usb3_ep) 898 + { 899 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 900 + u32 lng_reg = usb3_ep->num ? USB3_PN_LNG : USB3_P0_LNG; 901 + 902 + return usb3_read(usb3, lng_reg); 903 + } 904 + 905 + static int usb3_read_pipe(struct renesas_usb3_ep *usb3_ep, 906 + struct renesas_usb3_request *usb3_req, u32 fifo_reg) 907 + { 908 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 909 + int i; 910 + int len = min_t(unsigned, usb3_req->req.length - usb3_req->req.actual, 911 + usb3_get_received_length(usb3_ep)); 912 + u8 *buf = usb3_req->req.buf + usb3_req->req.actual; 913 + u32 tmp = 0; 914 + 915 + if (!len) 916 + return 0; 917 + 918 + /* Update gadget driver parameter */ 919 + usb3_req->req.actual += len; 920 + 921 + /* Read data from the register */ 922 + if (len >= 4) { 923 + ioread32_rep(usb3->reg + fifo_reg, buf, len / 4); 924 + buf += (len / 4) * 4; 925 + len %= 4; 926 + } 927 + 928 + if (len) { 929 + tmp = usb3_read(usb3, fifo_reg); 930 + for (i = 0; i < len; i++) 931 + buf[i] = (tmp >> (8 * i)) & 0xff; 932 + } 933 + 934 + return usb3_is_transfer_complete(usb3_ep, usb3_req) ? 0 : -EAGAIN; 935 + } 936 + 937 + static void usb3_set_status_stage(struct renesas_usb3_ep *usb3_ep, 938 + struct renesas_usb3_request *usb3_req) 939 + { 940 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 941 + 942 + if (usb3_ep->dir_in) { 943 + usb3_set_p0_con_for_ctrl_read_status(usb3); 944 + } else { 945 + if (!usb3_req->req.length) 946 + usb3_set_p0_con_for_no_data(usb3); 947 + else 948 + usb3_set_p0_con_for_ctrl_write_status(usb3); 949 + } 950 + } 951 + 952 + static void usb3_p0_xfer(struct renesas_usb3_ep *usb3_ep, 953 + struct renesas_usb3_request *usb3_req) 954 + { 955 + int ret = -EAGAIN; 956 + 957 + if (usb3_ep->dir_in) 958 + ret = usb3_write_pipe(usb3_ep, usb3_req, USB3_P0_WRITE); 959 + else 960 + ret = usb3_read_pipe(usb3_ep, usb3_req, USB3_P0_READ); 961 + 962 + if (!ret) 963 + usb3_set_status_stage(usb3_ep, usb3_req); 964 + } 965 + 966 + static void usb3_start_pipe0(struct renesas_usb3_ep *usb3_ep, 967 + struct renesas_usb3_request *usb3_req) 968 + { 969 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 970 + 971 + if (usb3_ep->started) 972 + return; 973 + 974 + usb3_ep->started = true; 975 + 976 + if (usb3_ep->dir_in) { 977 + usb3_set_bit(usb3, P0_MOD_DIR, USB3_P0_MOD); 978 + usb3_set_p0_con_for_ctrl_read_data(usb3); 979 + } else { 980 + usb3_clear_bit(usb3, P0_MOD_DIR, USB3_P0_MOD); 981 + usb3_set_p0_con_for_ctrl_write_data(usb3); 982 + } 983 + 984 + usb3_p0_xfer(usb3_ep, usb3_req); 985 + } 986 + 987 + static void usb3_start_pipen(struct renesas_usb3_ep *usb3_ep, 988 + struct renesas_usb3_request *usb3_req) 989 + { 990 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 991 + struct renesas_usb3_request *usb3_req_first = usb3_get_request(usb3_ep); 992 + unsigned long flags; 993 + int ret = -EAGAIN; 994 + u32 enable_bits = 0; 995 + 996 + if (usb3_ep->halt || usb3_ep->started) 997 + return; 998 + if (usb3_req != usb3_req_first) 999 + return; 1000 + 1001 + spin_lock_irqsave(&usb3->lock, flags); 1002 + if (usb3_pn_change(usb3, usb3_ep->num) < 0) 1003 + goto out; 1004 + 1005 + usb3_ep->started = true; 1006 + usb3_pn_start(usb3); 1007 + 1008 + if (usb3_ep->dir_in) { 1009 + ret = usb3_write_pipe(usb3_ep, usb3_req, USB3_PN_WRITE); 1010 + enable_bits |= PN_INT_LSTTR; 1011 + } 1012 + 1013 + if (ret < 0) 1014 + enable_bits |= PN_INT_BFRDY; 1015 + 1016 + if (enable_bits) { 1017 + usb3_set_bit(usb3, enable_bits, USB3_PN_INT_ENA); 1018 + usb3_enable_pipe_irq(usb3, usb3_ep->num); 1019 + } 1020 + out: 1021 + spin_unlock_irqrestore(&usb3->lock, flags); 1022 + } 1023 + 1024 + static int renesas_usb3_ep_queue(struct usb_ep *_ep, struct usb_request *_req, 1025 + gfp_t gfp_flags) 1026 + { 1027 + struct renesas_usb3_ep *usb3_ep = usb_ep_to_usb3_ep(_ep); 1028 + struct renesas_usb3_request *usb3_req = usb_req_to_usb3_req(_req); 1029 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 1030 + unsigned long flags; 1031 + 1032 + dev_dbg(usb3_to_dev(usb3), "ep_queue: ep%2d, %u\n", usb3_ep->num, 1033 + _req->length); 1034 + 1035 + _req->status = -EINPROGRESS; 1036 + _req->actual = 0; 1037 + spin_lock_irqsave(&usb3->lock, flags); 1038 + list_add_tail(&usb3_req->queue, &usb3_ep->queue); 1039 + spin_unlock_irqrestore(&usb3->lock, flags); 1040 + 1041 + if (!usb3_ep->num) 1042 + usb3_start_pipe0(usb3_ep, usb3_req); 1043 + else 1044 + usb3_start_pipen(usb3_ep, usb3_req); 1045 + 1046 + return 0; 1047 + } 1048 + 1049 + static void usb3_set_device_address(struct renesas_usb3 *usb3, u16 addr) 1050 + { 1051 + /* DEV_ADDR bit field is cleared by WarmReset, HotReset and BusReset */ 1052 + usb3_set_bit(usb3, USB_COM_CON_DEV_ADDR(addr), USB3_USB_COM_CON); 1053 + } 1054 + 1055 + static bool usb3_std_req_set_address(struct renesas_usb3 *usb3, 1056 + struct usb_ctrlrequest *ctrl) 1057 + { 1058 + if (ctrl->wValue >= 128) 1059 + return true; /* stall */ 1060 + 1061 + usb3_set_device_address(usb3, ctrl->wValue); 1062 + usb3_set_p0_con_for_no_data(usb3); 1063 + 1064 + return false; 1065 + } 1066 + 1067 + static void usb3_pipe0_internal_xfer(struct renesas_usb3 *usb3, 1068 + void *tx_data, size_t len, 1069 + void (*complete)(struct usb_ep *ep, 1070 + struct usb_request *req)) 1071 + { 1072 + struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); 1073 + 1074 + if (tx_data) 1075 + memcpy(usb3->ep0_buf, tx_data, 1076 + min_t(size_t, len, USB3_EP0_BUF_SIZE)); 1077 + 1078 + usb3->ep0_req->buf = &usb3->ep0_buf; 1079 + usb3->ep0_req->length = len; 1080 + usb3->ep0_req->complete = complete; 1081 + renesas_usb3_ep_queue(&usb3_ep->ep, usb3->ep0_req, GFP_ATOMIC); 1082 + } 1083 + 1084 + static void usb3_pipe0_get_status_completion(struct usb_ep *ep, 1085 + struct usb_request *req) 1086 + { 1087 + } 1088 + 1089 + static bool usb3_std_req_get_status(struct renesas_usb3 *usb3, 1090 + struct usb_ctrlrequest *ctrl) 1091 + { 1092 + bool stall = false; 1093 + struct renesas_usb3_ep *usb3_ep; 1094 + int num; 1095 + u16 status = 0; 1096 + 1097 + switch (ctrl->bRequestType & USB_RECIP_MASK) { 1098 + case USB_RECIP_DEVICE: 1099 + if (usb3->gadget.is_selfpowered) 1100 + status |= 1 << USB_DEVICE_SELF_POWERED; 1101 + if (usb3->gadget.speed == USB_SPEED_SUPER) 1102 + status |= usb3_feature_get_un_enabled(usb3); 1103 + break; 1104 + case USB_RECIP_INTERFACE: 1105 + break; 1106 + case USB_RECIP_ENDPOINT: 1107 + num = le16_to_cpu(ctrl->wIndex) & USB_ENDPOINT_NUMBER_MASK; 1108 + usb3_ep = usb3_get_ep(usb3, num); 1109 + if (usb3_ep->halt) 1110 + status |= 1 << USB_ENDPOINT_HALT; 1111 + break; 1112 + default: 1113 + stall = true; 1114 + break; 1115 + } 1116 + 1117 + if (!stall) { 1118 + status = cpu_to_le16(status); 1119 + dev_dbg(usb3_to_dev(usb3), "get_status: req = %p\n", 1120 + usb_req_to_usb3_req(usb3->ep0_req)); 1121 + usb3_pipe0_internal_xfer(usb3, &status, sizeof(status), 1122 + usb3_pipe0_get_status_completion); 1123 + } 1124 + 1125 + return stall; 1126 + } 1127 + 1128 + static bool usb3_std_req_feature_device(struct renesas_usb3 *usb3, 1129 + struct usb_ctrlrequest *ctrl, bool set) 1130 + { 1131 + bool stall = true; 1132 + u16 w_value = le16_to_cpu(ctrl->wValue); 1133 + 1134 + switch (w_value) { 1135 + case USB_DEVICE_TEST_MODE: 1136 + if (!set) 1137 + break; 1138 + usb3->test_mode = le16_to_cpu(ctrl->wIndex) >> 8; 1139 + stall = false; 1140 + break; 1141 + case USB_DEVICE_U1_ENABLE: 1142 + case USB_DEVICE_U2_ENABLE: 1143 + if (usb3->gadget.speed != USB_SPEED_SUPER) 1144 + break; 1145 + if (w_value == USB_DEVICE_U1_ENABLE) 1146 + usb3_feature_u1_enable(usb3, set); 1147 + if (w_value == USB_DEVICE_U2_ENABLE) 1148 + usb3_feature_u2_enable(usb3, set); 1149 + stall = false; 1150 + break; 1151 + default: 1152 + break; 1153 + } 1154 + 1155 + return stall; 1156 + } 1157 + 1158 + static int usb3_set_halt_p0(struct renesas_usb3_ep *usb3_ep, bool halt) 1159 + { 1160 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 1161 + 1162 + if (unlikely(usb3_ep->num)) 1163 + return -EINVAL; 1164 + 1165 + usb3_ep->halt = halt; 1166 + if (halt) 1167 + usb3_set_p0_con_stall(usb3); 1168 + else 1169 + usb3_set_p0_con_stop(usb3); 1170 + 1171 + return 0; 1172 + } 1173 + 1174 + static int usb3_set_halt_pn(struct renesas_usb3_ep *usb3_ep, bool halt, 1175 + bool is_clear_feature) 1176 + { 1177 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 1178 + unsigned long flags; 1179 + 1180 + spin_lock_irqsave(&usb3->lock, flags); 1181 + if (!usb3_pn_change(usb3, usb3_ep->num)) { 1182 + usb3_ep->halt = halt; 1183 + if (halt) { 1184 + usb3_pn_stall(usb3); 1185 + } else if (!is_clear_feature || !usb3_ep->wedge) { 1186 + usb3_pn_con_clear(usb3); 1187 + usb3_set_bit(usb3, PN_CON_EN, USB3_PN_CON); 1188 + usb3_pn_stop(usb3); 1189 + } 1190 + } 1191 + spin_unlock_irqrestore(&usb3->lock, flags); 1192 + 1193 + return 0; 1194 + } 1195 + 1196 + static int usb3_set_halt(struct renesas_usb3_ep *usb3_ep, bool halt, 1197 + bool is_clear_feature) 1198 + { 1199 + int ret = 0; 1200 + 1201 + if (halt && usb3_ep->started) 1202 + return -EAGAIN; 1203 + 1204 + if (usb3_ep->num) 1205 + ret = usb3_set_halt_pn(usb3_ep, halt, is_clear_feature); 1206 + else 1207 + ret = usb3_set_halt_p0(usb3_ep, halt); 1208 + 1209 + return ret; 1210 + } 1211 + 1212 + static bool usb3_std_req_feature_endpoint(struct renesas_usb3 *usb3, 1213 + struct usb_ctrlrequest *ctrl, 1214 + bool set) 1215 + { 1216 + int num = le16_to_cpu(ctrl->wIndex) & USB_ENDPOINT_NUMBER_MASK; 1217 + struct renesas_usb3_ep *usb3_ep; 1218 + struct renesas_usb3_request *usb3_req; 1219 + 1220 + if (le16_to_cpu(ctrl->wValue) != USB_ENDPOINT_HALT) 1221 + return true; /* stall */ 1222 + 1223 + usb3_ep = usb3_get_ep(usb3, num); 1224 + usb3_set_halt(usb3_ep, set, true); 1225 + 1226 + /* Restarts a queue if clear feature */ 1227 + if (!set) { 1228 + usb3_ep->started = false; 1229 + usb3_req = usb3_get_request(usb3_ep); 1230 + if (usb3_req) 1231 + usb3_start_pipen(usb3_ep, usb3_req); 1232 + } 1233 + 1234 + return false; 1235 + } 1236 + 1237 + static bool usb3_std_req_feature(struct renesas_usb3 *usb3, 1238 + struct usb_ctrlrequest *ctrl, bool set) 1239 + { 1240 + bool stall = false; 1241 + 1242 + switch (ctrl->bRequestType & USB_RECIP_MASK) { 1243 + case USB_RECIP_DEVICE: 1244 + stall = usb3_std_req_feature_device(usb3, ctrl, set); 1245 + break; 1246 + case USB_RECIP_INTERFACE: 1247 + break; 1248 + case USB_RECIP_ENDPOINT: 1249 + stall = usb3_std_req_feature_endpoint(usb3, ctrl, set); 1250 + break; 1251 + default: 1252 + stall = true; 1253 + break; 1254 + } 1255 + 1256 + if (!stall) 1257 + usb3_set_p0_con_for_no_data(usb3); 1258 + 1259 + return stall; 1260 + } 1261 + 1262 + static void usb3_pipe0_set_sel_completion(struct usb_ep *ep, 1263 + struct usb_request *req) 1264 + { 1265 + /* TODO */ 1266 + } 1267 + 1268 + static bool usb3_std_req_set_sel(struct renesas_usb3 *usb3, 1269 + struct usb_ctrlrequest *ctrl) 1270 + { 1271 + u16 w_length = le16_to_cpu(ctrl->wLength); 1272 + 1273 + if (w_length != 6) 1274 + return true; /* stall */ 1275 + 1276 + dev_dbg(usb3_to_dev(usb3), "set_sel: req = %p\n", 1277 + usb_req_to_usb3_req(usb3->ep0_req)); 1278 + usb3_pipe0_internal_xfer(usb3, NULL, 6, usb3_pipe0_set_sel_completion); 1279 + 1280 + return false; 1281 + } 1282 + 1283 + static bool usb3_std_req_set_configuration(struct renesas_usb3 *usb3, 1284 + struct usb_ctrlrequest *ctrl) 1285 + { 1286 + if (ctrl->wValue > 0) 1287 + usb3_set_bit(usb3, USB_COM_CON_CONF, USB3_USB_COM_CON); 1288 + else 1289 + usb3_clear_bit(usb3, USB_COM_CON_CONF, USB3_USB_COM_CON); 1290 + 1291 + return false; 1292 + } 1293 + 1294 + /** 1295 + * usb3_handle_standard_request - handle some standard requests 1296 + * @usb3: the renesas_usb3 pointer 1297 + * @ctrl: a pointer of setup data 1298 + * 1299 + * Returns true if this function handled a standard request 1300 + */ 1301 + static bool usb3_handle_standard_request(struct renesas_usb3 *usb3, 1302 + struct usb_ctrlrequest *ctrl) 1303 + { 1304 + bool ret = false; 1305 + bool stall = false; 1306 + 1307 + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { 1308 + switch (ctrl->bRequest) { 1309 + case USB_REQ_SET_ADDRESS: 1310 + stall = usb3_std_req_set_address(usb3, ctrl); 1311 + ret = true; 1312 + break; 1313 + case USB_REQ_GET_STATUS: 1314 + stall = usb3_std_req_get_status(usb3, ctrl); 1315 + ret = true; 1316 + break; 1317 + case USB_REQ_CLEAR_FEATURE: 1318 + stall = usb3_std_req_feature(usb3, ctrl, false); 1319 + ret = true; 1320 + break; 1321 + case USB_REQ_SET_FEATURE: 1322 + stall = usb3_std_req_feature(usb3, ctrl, true); 1323 + ret = true; 1324 + break; 1325 + case USB_REQ_SET_SEL: 1326 + stall = usb3_std_req_set_sel(usb3, ctrl); 1327 + ret = true; 1328 + break; 1329 + case USB_REQ_SET_ISOCH_DELAY: 1330 + /* This hardware doesn't support Isochronous xfer */ 1331 + stall = true; 1332 + ret = true; 1333 + break; 1334 + case USB_REQ_SET_CONFIGURATION: 1335 + usb3_std_req_set_configuration(usb3, ctrl); 1336 + break; 1337 + default: 1338 + break; 1339 + } 1340 + } 1341 + 1342 + if (stall) 1343 + usb3_set_p0_con_stall(usb3); 1344 + 1345 + return ret; 1346 + } 1347 + 1348 + static int usb3_p0_con_clear_buffer(struct renesas_usb3 *usb3) 1349 + { 1350 + usb3_set_bit(usb3, P0_CON_BCLR, USB3_P0_CON); 1351 + 1352 + return usb3_wait(usb3, USB3_P0_CON, P0_CON_BCLR, 0); 1353 + } 1354 + 1355 + static void usb3_irq_epc_pipe0_setup(struct renesas_usb3 *usb3) 1356 + { 1357 + struct usb_ctrlrequest ctrl; 1358 + struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); 1359 + 1360 + /* Call giveback function if previous transfer is not completed */ 1361 + if (usb3_ep->started) 1362 + usb3_request_done(usb3_ep, usb3_get_request(usb3_ep), 1363 + -ECONNRESET); 1364 + 1365 + usb3_p0_con_clear_buffer(usb3); 1366 + usb3_get_setup_data(usb3, &ctrl); 1367 + if (!usb3_handle_standard_request(usb3, &ctrl)) 1368 + if (usb3->driver->setup(&usb3->gadget, &ctrl) < 0) 1369 + usb3_set_p0_con_stall(usb3); 1370 + } 1371 + 1372 + static void usb3_irq_epc_pipe0_bfrdy(struct renesas_usb3 *usb3) 1373 + { 1374 + struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, 0); 1375 + struct renesas_usb3_request *usb3_req = usb3_get_request(usb3_ep); 1376 + 1377 + if (!usb3_req) 1378 + return; 1379 + 1380 + usb3_p0_xfer(usb3_ep, usb3_req); 1381 + } 1382 + 1383 + static void usb3_irq_epc_pipe0(struct renesas_usb3 *usb3) 1384 + { 1385 + u32 p0_int_sta = usb3_read(usb3, USB3_P0_INT_STA); 1386 + 1387 + p0_int_sta &= usb3_read(usb3, USB3_P0_INT_ENA); 1388 + usb3_write(usb3, p0_int_sta, USB3_P0_INT_STA); 1389 + if (p0_int_sta & P0_INT_STSED) 1390 + usb3_irq_epc_pipe0_status_end(usb3); 1391 + if (p0_int_sta & P0_INT_SETUP) 1392 + usb3_irq_epc_pipe0_setup(usb3); 1393 + if (p0_int_sta & P0_INT_BFRDY) 1394 + usb3_irq_epc_pipe0_bfrdy(usb3); 1395 + } 1396 + 1397 + static void usb3_request_done_pipen(struct renesas_usb3 *usb3, 1398 + struct renesas_usb3_ep *usb3_ep, 1399 + struct renesas_usb3_request *usb3_req, 1400 + int status) 1401 + { 1402 + usb3_pn_stop(usb3); 1403 + usb3_disable_pipe_irq(usb3, usb3_ep->num); 1404 + usb3_request_done(usb3_ep, usb3_req, status); 1405 + 1406 + /* get next usb3_req */ 1407 + usb3_req = usb3_get_request(usb3_ep); 1408 + if (usb3_req) 1409 + usb3_start_pipen(usb3_ep, usb3_req); 1410 + } 1411 + 1412 + static void usb3_irq_epc_pipen_lsttr(struct renesas_usb3 *usb3, int num) 1413 + { 1414 + struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, num); 1415 + struct renesas_usb3_request *usb3_req = usb3_get_request(usb3_ep); 1416 + 1417 + if (!usb3_req) 1418 + return; 1419 + 1420 + if (usb3_ep->dir_in) { 1421 + dev_dbg(usb3_to_dev(usb3), "%s: len = %u, actual = %u\n", 1422 + __func__, usb3_req->req.length, usb3_req->req.actual); 1423 + usb3_request_done_pipen(usb3, usb3_ep, usb3_req, 0); 1424 + } 1425 + } 1426 + 1427 + static void usb3_irq_epc_pipen_bfrdy(struct renesas_usb3 *usb3, int num) 1428 + { 1429 + struct renesas_usb3_ep *usb3_ep = usb3_get_ep(usb3, num); 1430 + struct renesas_usb3_request *usb3_req = usb3_get_request(usb3_ep); 1431 + 1432 + if (!usb3_req) 1433 + return; 1434 + 1435 + if (usb3_ep->dir_in) { 1436 + /* Do not stop the IN pipe here to detect LSTTR interrupt */ 1437 + if (!usb3_write_pipe(usb3_ep, usb3_req, USB3_PN_WRITE)) 1438 + usb3_clear_bit(usb3, PN_INT_BFRDY, USB3_PN_INT_ENA); 1439 + } else { 1440 + if (!usb3_read_pipe(usb3_ep, usb3_req, USB3_PN_READ)) 1441 + usb3_request_done_pipen(usb3, usb3_ep, usb3_req, 0); 1442 + } 1443 + } 1444 + 1445 + static void usb3_irq_epc_pipen(struct renesas_usb3 *usb3, int num) 1446 + { 1447 + u32 pn_int_sta; 1448 + 1449 + if (usb3_pn_change(usb3, num) < 0) 1450 + return; 1451 + 1452 + pn_int_sta = usb3_read(usb3, USB3_PN_INT_STA); 1453 + pn_int_sta &= usb3_read(usb3, USB3_PN_INT_ENA); 1454 + usb3_write(usb3, pn_int_sta, USB3_PN_INT_STA); 1455 + if (pn_int_sta & PN_INT_LSTTR) 1456 + usb3_irq_epc_pipen_lsttr(usb3, num); 1457 + if (pn_int_sta & PN_INT_BFRDY) 1458 + usb3_irq_epc_pipen_bfrdy(usb3, num); 1459 + } 1460 + 1461 + static void usb3_irq_epc_int_2(struct renesas_usb3 *usb3, u32 int_sta_2) 1462 + { 1463 + int i; 1464 + 1465 + for (i = 0; i < usb3->num_usb3_eps; i++) { 1466 + if (int_sta_2 & USB_INT_2_PIPE(i)) { 1467 + if (!i) 1468 + usb3_irq_epc_pipe0(usb3); 1469 + else 1470 + usb3_irq_epc_pipen(usb3, i); 1471 + } 1472 + } 1473 + } 1474 + 1475 + static void usb3_irq_epc(struct renesas_usb3 *usb3) 1476 + { 1477 + u32 int_sta_1 = usb3_read(usb3, USB3_USB_INT_STA_1); 1478 + u32 int_sta_2 = usb3_read(usb3, USB3_USB_INT_STA_2); 1479 + 1480 + int_sta_1 &= usb3_read(usb3, USB3_USB_INT_ENA_1); 1481 + if (int_sta_1) { 1482 + usb3_write(usb3, int_sta_1, USB3_USB_INT_STA_1); 1483 + usb3_irq_epc_int_1(usb3, int_sta_1); 1484 + } 1485 + 1486 + int_sta_2 &= usb3_read(usb3, USB3_USB_INT_ENA_2); 1487 + if (int_sta_2) 1488 + usb3_irq_epc_int_2(usb3, int_sta_2); 1489 + } 1490 + 1491 + static irqreturn_t renesas_usb3_irq(int irq, void *_usb3) 1492 + { 1493 + struct renesas_usb3 *usb3 = _usb3; 1494 + irqreturn_t ret = IRQ_NONE; 1495 + u32 axi_int_sta = usb3_read(usb3, USB3_AXI_INT_STA); 1496 + 1497 + if (axi_int_sta & AXI_INT_EPCINT) { 1498 + usb3_irq_epc(usb3); 1499 + ret = IRQ_HANDLED; 1500 + } 1501 + 1502 + return ret; 1503 + } 1504 + 1505 + static void usb3_write_pn_mod(struct renesas_usb3_ep *usb3_ep, 1506 + const struct usb_endpoint_descriptor *desc) 1507 + { 1508 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 1509 + u32 val = 0; 1510 + 1511 + val |= usb3_ep->dir_in ? PN_MOD_DIR : 0; 1512 + val |= PN_MOD_TYPE(usb_endpoint_type(desc)); 1513 + val |= PN_MOD_EPNUM(usb_endpoint_num(desc)); 1514 + usb3_write(usb3, val, USB3_PN_MOD); 1515 + } 1516 + 1517 + static u32 usb3_calc_ramarea(int ram_size) 1518 + { 1519 + WARN_ON(ram_size > SZ_16K); 1520 + 1521 + if (ram_size <= SZ_1K) 1522 + return PN_RAMMAP_RAMAREA_1KB; 1523 + else if (ram_size <= SZ_2K) 1524 + return PN_RAMMAP_RAMAREA_2KB; 1525 + else if (ram_size <= SZ_4K) 1526 + return PN_RAMMAP_RAMAREA_4KB; 1527 + else if (ram_size <= SZ_8K) 1528 + return PN_RAMMAP_RAMAREA_8KB; 1529 + else 1530 + return PN_RAMMAP_RAMAREA_16KB; 1531 + } 1532 + 1533 + static u32 usb3_calc_rammap_val(struct renesas_usb3_ep *usb3_ep, 1534 + const struct usb_endpoint_descriptor *desc) 1535 + { 1536 + return usb3_ep->rammap_val | PN_RAMMAP_MPKT(usb_endpoint_maxp(desc)); 1537 + } 1538 + 1539 + static int usb3_enable_pipe_n(struct renesas_usb3_ep *usb3_ep, 1540 + const struct usb_endpoint_descriptor *desc) 1541 + { 1542 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 1543 + unsigned long flags; 1544 + 1545 + usb3_ep->dir_in = usb_endpoint_dir_in(desc); 1546 + 1547 + spin_lock_irqsave(&usb3->lock, flags); 1548 + if (!usb3_pn_change(usb3, usb3_ep->num)) { 1549 + usb3_write_pn_mod(usb3_ep, desc); 1550 + usb3_write(usb3, usb3_calc_rammap_val(usb3_ep, desc), 1551 + USB3_PN_RAMMAP); 1552 + usb3_pn_con_clear(usb3); 1553 + usb3_set_bit(usb3, PN_CON_EN, USB3_PN_CON); 1554 + } 1555 + spin_unlock_irqrestore(&usb3->lock, flags); 1556 + 1557 + return 0; 1558 + } 1559 + 1560 + static int usb3_disable_pipe_n(struct renesas_usb3_ep *usb3_ep) 1561 + { 1562 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 1563 + unsigned long flags; 1564 + 1565 + usb3_ep->halt = false; 1566 + 1567 + spin_lock_irqsave(&usb3->lock, flags); 1568 + if (!usb3_pn_change(usb3, usb3_ep->num)) { 1569 + usb3_write(usb3, 0, USB3_PN_RAMMAP); 1570 + usb3_clear_bit(usb3, PN_CON_EN, USB3_PN_CON); 1571 + } 1572 + spin_unlock_irqrestore(&usb3->lock, flags); 1573 + 1574 + return 0; 1575 + } 1576 + 1577 + /*------- usb_ep_ops -----------------------------------------------------*/ 1578 + static int renesas_usb3_ep_enable(struct usb_ep *_ep, 1579 + const struct usb_endpoint_descriptor *desc) 1580 + { 1581 + struct renesas_usb3_ep *usb3_ep = usb_ep_to_usb3_ep(_ep); 1582 + 1583 + return usb3_enable_pipe_n(usb3_ep, desc); 1584 + } 1585 + 1586 + static int renesas_usb3_ep_disable(struct usb_ep *_ep) 1587 + { 1588 + struct renesas_usb3_ep *usb3_ep = usb_ep_to_usb3_ep(_ep); 1589 + struct renesas_usb3_request *usb3_req; 1590 + 1591 + do { 1592 + usb3_req = usb3_get_request(usb3_ep); 1593 + if (!usb3_req) 1594 + break; 1595 + usb3_request_done(usb3_ep, usb3_req, -ESHUTDOWN); 1596 + } while (1); 1597 + 1598 + return usb3_disable_pipe_n(usb3_ep); 1599 + } 1600 + 1601 + static struct usb_request *__renesas_usb3_ep_alloc_request(gfp_t gfp_flags) 1602 + { 1603 + struct renesas_usb3_request *usb3_req; 1604 + 1605 + usb3_req = kzalloc(sizeof(struct renesas_usb3_request), gfp_flags); 1606 + if (!usb3_req) 1607 + return NULL; 1608 + 1609 + INIT_LIST_HEAD(&usb3_req->queue); 1610 + 1611 + return &usb3_req->req; 1612 + } 1613 + 1614 + static void __renesas_usb3_ep_free_request(struct usb_request *_req) 1615 + { 1616 + struct renesas_usb3_request *usb3_req = usb_req_to_usb3_req(_req); 1617 + 1618 + kfree(usb3_req); 1619 + } 1620 + 1621 + static struct usb_request *renesas_usb3_ep_alloc_request(struct usb_ep *_ep, 1622 + gfp_t gfp_flags) 1623 + { 1624 + return __renesas_usb3_ep_alloc_request(gfp_flags); 1625 + } 1626 + 1627 + static void renesas_usb3_ep_free_request(struct usb_ep *_ep, 1628 + struct usb_request *_req) 1629 + { 1630 + __renesas_usb3_ep_free_request(_req); 1631 + } 1632 + 1633 + static int renesas_usb3_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 1634 + { 1635 + struct renesas_usb3_ep *usb3_ep = usb_ep_to_usb3_ep(_ep); 1636 + struct renesas_usb3_request *usb3_req = usb_req_to_usb3_req(_req); 1637 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 1638 + 1639 + dev_dbg(usb3_to_dev(usb3), "ep_dequeue: ep%2d, %u\n", usb3_ep->num, 1640 + _req->length); 1641 + 1642 + usb3_request_done_pipen(usb3, usb3_ep, usb3_req, -ECONNRESET); 1643 + 1644 + return 0; 1645 + } 1646 + 1647 + static int renesas_usb3_ep_set_halt(struct usb_ep *_ep, int value) 1648 + { 1649 + return usb3_set_halt(usb_ep_to_usb3_ep(_ep), !!value, false); 1650 + } 1651 + 1652 + static int renesas_usb3_ep_set_wedge(struct usb_ep *_ep) 1653 + { 1654 + struct renesas_usb3_ep *usb3_ep = usb_ep_to_usb3_ep(_ep); 1655 + 1656 + usb3_ep->wedge = true; 1657 + return usb3_set_halt(usb3_ep, true, false); 1658 + } 1659 + 1660 + static void renesas_usb3_ep_fifo_flush(struct usb_ep *_ep) 1661 + { 1662 + struct renesas_usb3_ep *usb3_ep = usb_ep_to_usb3_ep(_ep); 1663 + struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); 1664 + unsigned long flags; 1665 + 1666 + if (usb3_ep->num) { 1667 + spin_lock_irqsave(&usb3->lock, flags); 1668 + if (!usb3_pn_change(usb3, usb3_ep->num)) { 1669 + usb3_pn_con_clear(usb3); 1670 + usb3_set_bit(usb3, PN_CON_EN, USB3_PN_CON); 1671 + } 1672 + spin_unlock_irqrestore(&usb3->lock, flags); 1673 + } else { 1674 + usb3_p0_con_clear_buffer(usb3); 1675 + } 1676 + } 1677 + 1678 + static struct usb_ep_ops renesas_usb3_ep_ops = { 1679 + .enable = renesas_usb3_ep_enable, 1680 + .disable = renesas_usb3_ep_disable, 1681 + 1682 + .alloc_request = renesas_usb3_ep_alloc_request, 1683 + .free_request = renesas_usb3_ep_free_request, 1684 + 1685 + .queue = renesas_usb3_ep_queue, 1686 + .dequeue = renesas_usb3_ep_dequeue, 1687 + 1688 + .set_halt = renesas_usb3_ep_set_halt, 1689 + .set_wedge = renesas_usb3_ep_set_wedge, 1690 + .fifo_flush = renesas_usb3_ep_fifo_flush, 1691 + }; 1692 + 1693 + /*------- usb_gadget_ops -------------------------------------------------*/ 1694 + static int renesas_usb3_start(struct usb_gadget *gadget, 1695 + struct usb_gadget_driver *driver) 1696 + { 1697 + struct renesas_usb3 *usb3; 1698 + 1699 + if (!driver || driver->max_speed < USB_SPEED_FULL || 1700 + !driver->setup) 1701 + return -EINVAL; 1702 + 1703 + usb3 = gadget_to_renesas_usb3(gadget); 1704 + 1705 + /* hook up the driver */ 1706 + usb3->driver = driver; 1707 + 1708 + renesas_usb3_init_controller(usb3); 1709 + 1710 + return 0; 1711 + } 1712 + 1713 + static int renesas_usb3_stop(struct usb_gadget *gadget) 1714 + { 1715 + struct renesas_usb3 *usb3 = gadget_to_renesas_usb3(gadget); 1716 + unsigned long flags; 1717 + 1718 + spin_lock_irqsave(&usb3->lock, flags); 1719 + usb3->softconnect = false; 1720 + usb3->gadget.speed = USB_SPEED_UNKNOWN; 1721 + usb3->driver = NULL; 1722 + renesas_usb3_stop_controller(usb3); 1723 + spin_unlock_irqrestore(&usb3->lock, flags); 1724 + 1725 + return 0; 1726 + } 1727 + 1728 + static int renesas_usb3_get_frame(struct usb_gadget *_gadget) 1729 + { 1730 + return -EOPNOTSUPP; 1731 + } 1732 + 1733 + static int renesas_usb3_pullup(struct usb_gadget *gadget, int is_on) 1734 + { 1735 + struct renesas_usb3 *usb3 = gadget_to_renesas_usb3(gadget); 1736 + 1737 + usb3->softconnect = !!is_on; 1738 + 1739 + return 0; 1740 + } 1741 + 1742 + static int renesas_usb3_set_selfpowered(struct usb_gadget *gadget, int is_self) 1743 + { 1744 + gadget->is_selfpowered = !!is_self; 1745 + 1746 + return 0; 1747 + } 1748 + 1749 + static const struct usb_gadget_ops renesas_usb3_gadget_ops = { 1750 + .get_frame = renesas_usb3_get_frame, 1751 + .udc_start = renesas_usb3_start, 1752 + .udc_stop = renesas_usb3_stop, 1753 + .pullup = renesas_usb3_pullup, 1754 + .set_selfpowered = renesas_usb3_set_selfpowered, 1755 + }; 1756 + 1757 + /*------- platform_driver ------------------------------------------------*/ 1758 + static int renesas_usb3_remove(struct platform_device *pdev) 1759 + { 1760 + struct renesas_usb3 *usb3 = platform_get_drvdata(pdev); 1761 + 1762 + pm_runtime_put(&pdev->dev); 1763 + pm_runtime_disable(&pdev->dev); 1764 + 1765 + usb_del_gadget_udc(&usb3->gadget); 1766 + 1767 + __renesas_usb3_ep_free_request(usb3->ep0_req); 1768 + 1769 + return 0; 1770 + } 1771 + 1772 + static int renesas_usb3_init_ep(struct renesas_usb3 *usb3, struct device *dev, 1773 + const struct renesas_usb3_priv *priv) 1774 + { 1775 + struct renesas_usb3_ep *usb3_ep; 1776 + int i; 1777 + 1778 + /* calculate num_usb3_eps from renesas_usb3_priv */ 1779 + usb3->num_usb3_eps = priv->ramsize_per_ramif * priv->num_ramif * 2 / 1780 + priv->ramsize_per_pipe + 1; 1781 + 1782 + if (usb3->num_usb3_eps > USB3_MAX_NUM_PIPES) 1783 + usb3->num_usb3_eps = USB3_MAX_NUM_PIPES; 1784 + 1785 + usb3->usb3_ep = devm_kzalloc(dev, sizeof(*usb3_ep) * usb3->num_usb3_eps, 1786 + GFP_KERNEL); 1787 + if (!usb3->usb3_ep) 1788 + return -ENOMEM; 1789 + 1790 + dev_dbg(dev, "%s: num_usb3_eps = %d\n", __func__, usb3->num_usb3_eps); 1791 + /* 1792 + * This driver prepares pipes as the followings: 1793 + * - odd pipes = IN pipe 1794 + * - even pipes = OUT pipe (except pipe 0) 1795 + */ 1796 + usb3_for_each_ep(usb3_ep, usb3, i) { 1797 + snprintf(usb3_ep->ep_name, sizeof(usb3_ep->ep_name), "ep%d", i); 1798 + usb3_ep->usb3 = usb3; 1799 + usb3_ep->num = i; 1800 + usb3_ep->ep.name = usb3_ep->ep_name; 1801 + usb3_ep->ep.ops = &renesas_usb3_ep_ops; 1802 + INIT_LIST_HEAD(&usb3_ep->queue); 1803 + INIT_LIST_HEAD(&usb3_ep->ep.ep_list); 1804 + if (!i) { 1805 + /* for control pipe */ 1806 + usb3->gadget.ep0 = &usb3_ep->ep; 1807 + usb_ep_set_maxpacket_limit(&usb3_ep->ep, 1808 + USB3_EP0_HSFS_MAX_PACKET_SIZE); 1809 + usb3_ep->ep.caps.type_control = true; 1810 + usb3_ep->ep.caps.dir_in = true; 1811 + usb3_ep->ep.caps.dir_out = true; 1812 + continue; 1813 + } 1814 + 1815 + /* for bulk or interrupt pipe */ 1816 + usb_ep_set_maxpacket_limit(&usb3_ep->ep, ~0); 1817 + list_add_tail(&usb3_ep->ep.ep_list, &usb3->gadget.ep_list); 1818 + usb3_ep->ep.caps.type_bulk = true; 1819 + usb3_ep->ep.caps.type_int = true; 1820 + if (i & 1) 1821 + usb3_ep->ep.caps.dir_in = true; 1822 + else 1823 + usb3_ep->ep.caps.dir_out = true; 1824 + } 1825 + 1826 + return 0; 1827 + } 1828 + 1829 + static void renesas_usb3_init_ram(struct renesas_usb3 *usb3, struct device *dev, 1830 + const struct renesas_usb3_priv *priv) 1831 + { 1832 + struct renesas_usb3_ep *usb3_ep; 1833 + int i; 1834 + u32 ramif[2], basead[2]; /* index 0 = for IN pipes */ 1835 + u32 *cur_ramif, *cur_basead; 1836 + u32 val; 1837 + 1838 + memset(ramif, 0, sizeof(ramif)); 1839 + memset(basead, 0, sizeof(basead)); 1840 + 1841 + /* 1842 + * This driver prepares pipes as the followings: 1843 + * - all pipes = the same size as "ramsize_per_pipe" 1844 + * Please refer to the "Method of Specifying RAM Mapping" 1845 + */ 1846 + usb3_for_each_ep(usb3_ep, usb3, i) { 1847 + if (!i) 1848 + continue; /* out of scope if ep num = 0 */ 1849 + if (usb3_ep->ep.caps.dir_in) { 1850 + cur_ramif = &ramif[0]; 1851 + cur_basead = &basead[0]; 1852 + } else { 1853 + cur_ramif = &ramif[1]; 1854 + cur_basead = &basead[1]; 1855 + } 1856 + 1857 + if (*cur_basead > priv->ramsize_per_ramif) 1858 + continue; /* out of memory for IN or OUT pipe */ 1859 + 1860 + /* calculate rammap_val */ 1861 + val = PN_RAMMAP_RAMIF(*cur_ramif); 1862 + val |= usb3_calc_ramarea(priv->ramsize_per_pipe); 1863 + val |= PN_RAMMAP_BASEAD(*cur_basead); 1864 + usb3_ep->rammap_val = val; 1865 + 1866 + dev_dbg(dev, "ep%2d: val = %08x, ramif = %d, base = %x\n", 1867 + i, val, *cur_ramif, *cur_basead); 1868 + 1869 + /* update current ramif */ 1870 + if (*cur_ramif + 1 == priv->num_ramif) { 1871 + *cur_ramif = 0; 1872 + *cur_basead += priv->ramsize_per_pipe; 1873 + } else { 1874 + (*cur_ramif)++; 1875 + } 1876 + } 1877 + } 1878 + 1879 + static const struct renesas_usb3_priv renesas_usb3_priv_r8a7795 = { 1880 + .ramsize_per_ramif = SZ_16K, 1881 + .num_ramif = 2, 1882 + .ramsize_per_pipe = SZ_4K, 1883 + .workaround_for_vbus = true, 1884 + }; 1885 + 1886 + static const struct of_device_id usb3_of_match[] = { 1887 + { 1888 + .compatible = "renesas,r8a7795-usb3-peri", 1889 + .data = &renesas_usb3_priv_r8a7795, 1890 + }, 1891 + { }, 1892 + }; 1893 + MODULE_DEVICE_TABLE(of, usb3_of_match); 1894 + 1895 + static int renesas_usb3_probe(struct platform_device *pdev) 1896 + { 1897 + struct renesas_usb3 *usb3; 1898 + struct resource *res; 1899 + const struct of_device_id *match; 1900 + int irq, ret; 1901 + const struct renesas_usb3_priv *priv; 1902 + 1903 + match = of_match_node(usb3_of_match, pdev->dev.of_node); 1904 + if (!match) 1905 + return -ENODEV; 1906 + priv = match->data; 1907 + 1908 + irq = platform_get_irq(pdev, 0); 1909 + if (irq < 0) 1910 + return -ENODEV; 1911 + 1912 + usb3 = devm_kzalloc(&pdev->dev, sizeof(*usb3), GFP_KERNEL); 1913 + if (!usb3) 1914 + return -ENOMEM; 1915 + 1916 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1917 + usb3->reg = devm_ioremap_resource(&pdev->dev, res); 1918 + if (IS_ERR(usb3->reg)) 1919 + return PTR_ERR(usb3->reg); 1920 + 1921 + platform_set_drvdata(pdev, usb3); 1922 + spin_lock_init(&usb3->lock); 1923 + 1924 + usb3->gadget.ops = &renesas_usb3_gadget_ops; 1925 + usb3->gadget.name = udc_name; 1926 + usb3->gadget.max_speed = USB_SPEED_SUPER; 1927 + INIT_LIST_HEAD(&usb3->gadget.ep_list); 1928 + ret = renesas_usb3_init_ep(usb3, &pdev->dev, priv); 1929 + if (ret < 0) 1930 + return ret; 1931 + renesas_usb3_init_ram(usb3, &pdev->dev, priv); 1932 + 1933 + ret = devm_request_irq(&pdev->dev, irq, renesas_usb3_irq, 0, 1934 + dev_name(&pdev->dev), usb3); 1935 + if (ret < 0) 1936 + return ret; 1937 + 1938 + /* for ep0 handling */ 1939 + usb3->ep0_req = __renesas_usb3_ep_alloc_request(GFP_KERNEL); 1940 + if (!usb3->ep0_req) 1941 + return -ENOMEM; 1942 + 1943 + ret = usb_add_gadget_udc(&pdev->dev, &usb3->gadget); 1944 + if (ret < 0) 1945 + goto err_add_udc; 1946 + 1947 + usb3->workaround_for_vbus = priv->workaround_for_vbus; 1948 + 1949 + pm_runtime_enable(&pdev->dev); 1950 + pm_runtime_get_sync(&pdev->dev); 1951 + 1952 + dev_info(&pdev->dev, "probed\n"); 1953 + 1954 + return 0; 1955 + 1956 + err_add_udc: 1957 + __renesas_usb3_ep_free_request(usb3->ep0_req); 1958 + 1959 + return ret; 1960 + } 1961 + 1962 + static struct platform_driver renesas_usb3_driver = { 1963 + .probe = renesas_usb3_probe, 1964 + .remove = renesas_usb3_remove, 1965 + .driver = { 1966 + .name = (char *)udc_name, 1967 + .of_match_table = of_match_ptr(usb3_of_match), 1968 + }, 1969 + }; 1970 + module_platform_driver(renesas_usb3_driver); 1971 + 1972 + MODULE_DESCRIPTION("Renesas USB3.0 Peripheral driver"); 1973 + MODULE_LICENSE("GPL v2"); 1974 + MODULE_AUTHOR("Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>"); 1975 + MODULE_ALIAS("platform:renesas_usb3");
+1 -1
drivers/usb/gadget/udc/s3c-hsudc.c
··· 569 569 hsep = &hsudc->ep[ep_num]; 570 570 switch (le16_to_cpu(ctrl->wValue)) { 571 571 case USB_ENDPOINT_HALT: 572 - if (set || (!set && !hsep->wedge)) 572 + if (set || !hsep->wedge) 573 573 s3c_hsudc_set_halt(&hsep->ep, set); 574 574 return 0; 575 575 }
+45 -34
drivers/usb/gadget/udc/udc-core.c
··· 51 51 52 52 static struct class *udc_class; 53 53 static LIST_HEAD(udc_list); 54 + static LIST_HEAD(gadget_driver_pending_list); 54 55 static DEFINE_MUTEX(udc_lock); 56 + 57 + static int udc_bind_to_driver(struct usb_udc *udc, 58 + struct usb_gadget_driver *driver); 55 59 56 60 /* ------------------------------------------------------------------------- */ 57 61 ··· 360 356 void (*release)(struct device *dev)) 361 357 { 362 358 struct usb_udc *udc; 359 + struct usb_gadget_driver *driver; 363 360 int ret = -ENOMEM; 364 361 365 362 udc = kzalloc(sizeof(*udc), GFP_KERNEL); ··· 407 402 408 403 usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED); 409 404 udc->vbus = true; 405 + 406 + /* pick up one of pending gadget drivers */ 407 + list_for_each_entry(driver, &gadget_driver_pending_list, pending) { 408 + if (!driver->udc_name || strcmp(driver->udc_name, 409 + dev_name(&udc->dev)) == 0) { 410 + ret = udc_bind_to_driver(udc, driver); 411 + if (ret) 412 + goto err4; 413 + list_del(&driver->pending); 414 + break; 415 + } 416 + } 410 417 411 418 mutex_unlock(&udc_lock); 412 419 ··· 490 473 491 474 mutex_lock(&udc_lock); 492 475 list_del(&udc->list); 493 - mutex_unlock(&udc_lock); 494 476 495 - if (udc->driver) 477 + if (udc->driver) { 478 + struct usb_gadget_driver *driver = udc->driver; 479 + 496 480 usb_gadget_remove_driver(udc); 481 + list_add(&driver->pending, &gadget_driver_pending_list); 482 + } 483 + mutex_unlock(&udc_lock); 497 484 498 485 kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); 499 486 flush_work(&gadget->work); ··· 541 520 return ret; 542 521 } 543 522 544 - int usb_udc_attach_driver(const char *name, struct usb_gadget_driver *driver) 545 - { 546 - struct usb_udc *udc = NULL; 547 - int ret = -ENODEV; 548 - 549 - mutex_lock(&udc_lock); 550 - list_for_each_entry(udc, &udc_list, list) { 551 - ret = strcmp(name, dev_name(&udc->dev)); 552 - if (!ret) 553 - break; 554 - } 555 - if (ret) { 556 - ret = -ENODEV; 557 - goto out; 558 - } 559 - if (udc->driver) { 560 - ret = -EBUSY; 561 - goto out; 562 - } 563 - ret = udc_bind_to_driver(udc, driver); 564 - out: 565 - mutex_unlock(&udc_lock); 566 - return ret; 567 - } 568 - EXPORT_SYMBOL_GPL(usb_udc_attach_driver); 569 - 570 523 int usb_gadget_probe_driver(struct usb_gadget_driver *driver) 571 524 { 572 525 struct usb_udc *udc = NULL; 573 - int ret; 526 + int ret = -ENODEV; 574 527 575 528 if (!driver || !driver->bind || !driver->setup) 576 529 return -EINVAL; 577 530 578 531 mutex_lock(&udc_lock); 579 - list_for_each_entry(udc, &udc_list, list) { 580 - /* For now we take the first one */ 581 - if (!udc->driver) 532 + if (driver->udc_name) { 533 + list_for_each_entry(udc, &udc_list, list) { 534 + ret = strcmp(driver->udc_name, dev_name(&udc->dev)); 535 + if (!ret) 536 + break; 537 + } 538 + if (!ret && !udc->driver) 582 539 goto found; 540 + } else { 541 + list_for_each_entry(udc, &udc_list, list) { 542 + /* For now we take the first one */ 543 + if (!udc->driver) 544 + goto found; 545 + } 583 546 } 584 547 585 - pr_debug("couldn't find an available UDC\n"); 548 + list_add_tail(&driver->pending, &gadget_driver_pending_list); 549 + pr_info("udc-core: couldn't find an available UDC - added [%s] to list of pending drivers\n", 550 + driver->function); 586 551 mutex_unlock(&udc_lock); 587 - return -ENODEV; 552 + return 0; 588 553 found: 589 554 ret = udc_bind_to_driver(udc, driver); 590 555 mutex_unlock(&udc_lock); ··· 596 589 break; 597 590 } 598 591 592 + if (ret) { 593 + list_del(&driver->pending); 594 + ret = 0; 595 + } 599 596 mutex_unlock(&udc_lock); 600 597 return ret; 601 598 }
+9
drivers/usb/host/Kconfig
··· 41 41 42 42 If unsure, say N. 43 43 44 + config USB_XHCI_MTK 45 + tristate "xHCI support for Mediatek MT65xx" 46 + select MFD_SYSCON 47 + depends on ARCH_MEDIATEK || COMPILE_TEST 48 + ---help--- 49 + Say 'Y' to enable the support for the xHCI host controller 50 + found in Mediatek MT65xx SoCs. 51 + If unsure, say N. 52 + 44 53 config USB_XHCI_MVEBU 45 54 tristate "xHCI support for Marvell Armada 375/38x" 46 55 select USB_XHCI_PLATFORM
+4
drivers/usb/host/Makefile
··· 13 13 xhci-hcd-y := xhci.o xhci-mem.o 14 14 xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o 15 15 xhci-hcd-y += xhci-trace.o 16 + ifneq ($(CONFIG_USB_XHCI_MTK), ) 17 + xhci-hcd-y += xhci-mtk-sch.o 18 + endif 16 19 17 20 xhci-plat-hcd-y := xhci-plat.o 18 21 ifneq ($(CONFIG_USB_XHCI_MVEBU), ) ··· 67 64 obj-$(CONFIG_USB_XHCI_HCD) += xhci-hcd.o 68 65 obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o 69 66 obj-$(CONFIG_USB_XHCI_PLATFORM) += xhci-plat-hcd.o 67 + obj-$(CONFIG_USB_XHCI_MTK) += xhci-mtk.o 70 68 obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o 71 69 obj-$(CONFIG_USB_SL811_CS) += sl811_cs.o 72 70 obj-$(CONFIG_USB_U132_HCD) += u132-hcd.o
+10 -11
drivers/usb/host/bcma-hcd.c
··· 21 21 */ 22 22 #include <linux/bcma/bcma.h> 23 23 #include <linux/delay.h> 24 + #include <linux/gpio/consumer.h> 24 25 #include <linux/platform_device.h> 25 26 #include <linux/module.h> 26 27 #include <linux/slab.h> ··· 37 36 struct bcma_hcd_device { 38 37 struct platform_device *ehci_dev; 39 38 struct platform_device *ohci_dev; 39 + struct gpio_desc *gpio_desc; 40 40 }; 41 41 42 42 /* Wait for bitmask in a register to get set or cleared. ··· 230 228 231 229 static void bcma_hci_platform_power_gpio(struct bcma_device *dev, bool val) 232 230 { 233 - int gpio; 231 + struct bcma_hcd_device *usb_dev = bcma_get_drvdata(dev); 234 232 235 - gpio = of_get_named_gpio(dev->dev.of_node, "vcc-gpio", 0); 236 - if (!gpio_is_valid(gpio)) 233 + if (IS_ERR_OR_NULL(usb_dev->gpio_desc)) 237 234 return; 238 235 239 - if (val) { 240 - gpio_request(gpio, "bcma-hcd-gpio"); 241 - gpio_set_value(gpio, 1); 242 - } else { 243 - gpio_set_value(gpio, 0); 244 - gpio_free(gpio); 245 - } 236 + gpiod_set_value(usb_dev->gpio_desc, val); 246 237 } 247 238 248 239 static const struct usb_ehci_pdata ehci_pdata = { ··· 309 314 if (!usb_dev) 310 315 return -ENOMEM; 311 316 312 - bcma_hci_platform_power_gpio(dev, true); 317 + if (dev->dev.of_node) 318 + usb_dev->gpio_desc = devm_get_gpiod_from_child(&dev->dev, "vcc", 319 + &dev->dev.of_node->fwnode); 320 + if (!IS_ERR_OR_NULL(usb_dev->gpio_desc)) 321 + gpiod_direction_output(usb_dev->gpio_desc, 1); 313 322 314 323 switch (dev->id.id) { 315 324 case BCMA_CORE_NS_USB20:
+11 -4
drivers/usb/host/ehci-dbg.c
··· 436 436 scratch = hc32_to_cpup(ehci, &hw->hw_info1); 437 437 hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &hw->hw_current) : 0; 438 438 temp = scnprintf (next, size, 439 - "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)", 439 + "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)" 440 + " [cur %08x next %08x buf[0] %08x]", 440 441 qh, scratch & 0x007f, 441 442 speed_char (scratch), 442 443 (scratch >> 8) & 0x000f, ··· 445 444 hc32_to_cpup(ehci, &hw->hw_token), mark, 446 445 (cpu_to_hc32(ehci, QTD_TOGGLE) & hw->hw_token) 447 446 ? "data1" : "data0", 448 - (hc32_to_cpup(ehci, &hw->hw_alt_next) >> 1) & 0x0f); 447 + (hc32_to_cpup(ehci, &hw->hw_alt_next) >> 1) & 0x0f, 448 + hc32_to_cpup(ehci, &hw->hw_current), 449 + hc32_to_cpup(ehci, &hw->hw_qtd_next), 450 + hc32_to_cpup(ehci, &hw->hw_buf[0])); 449 451 size -= temp; 450 452 next += temp; 451 453 ··· 468 464 mark = '/'; 469 465 } 470 466 temp = snprintf (next, size, 471 - "\n\t%p%c%s len=%d %08x urb %p", 467 + "\n\t%p%c%s len=%d %08x urb %p" 468 + " [td %08x buf[0] %08x]", 472 469 td, mark, ({ char *tmp; 473 470 switch ((scratch>>8)&0x03) { 474 471 case 0: tmp = "out"; break; ··· 479 474 } tmp;}), 480 475 (scratch >> 16) & 0x7fff, 481 476 scratch, 482 - td->urb); 477 + td->urb, 478 + (u32) td->qtd_dma, 479 + hc32_to_cpup(ehci, &td->hw_buf[0])); 483 480 if (size < temp) 484 481 temp = size; 485 482 size -= temp;
+1 -1
drivers/usb/host/ehci-hcd.c
··· 98 98 MODULE_PARM_DESC (park, "park setting; 1-3 back-to-back async packets"); 99 99 100 100 /* for flakey hardware, ignore overcurrent indicators */ 101 - static bool ignore_oc = 0; 101 + static bool ignore_oc; 102 102 module_param (ignore_oc, bool, S_IRUGO); 103 103 MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications"); 104 104
+5 -13
drivers/usb/host/ehci-mem.c
··· 128 128 ehci->dummy = NULL; 129 129 130 130 /* DMA consistent memory and pools */ 131 - if (ehci->qtd_pool) 132 - dma_pool_destroy (ehci->qtd_pool); 131 + dma_pool_destroy(ehci->qtd_pool); 133 132 ehci->qtd_pool = NULL; 134 - 135 - if (ehci->qh_pool) { 136 - dma_pool_destroy (ehci->qh_pool); 137 - ehci->qh_pool = NULL; 138 - } 139 - 140 - if (ehci->itd_pool) 141 - dma_pool_destroy (ehci->itd_pool); 133 + dma_pool_destroy(ehci->qh_pool); 134 + ehci->qh_pool = NULL; 135 + dma_pool_destroy(ehci->itd_pool); 142 136 ehci->itd_pool = NULL; 143 - 144 - if (ehci->sitd_pool) 145 - dma_pool_destroy (ehci->sitd_pool); 137 + dma_pool_destroy(ehci->sitd_pool); 146 138 ehci->sitd_pool = NULL; 147 139 148 140 if (ehci->periodic)
+2 -2
drivers/usb/host/ehci-msm.c
··· 57 57 58 58 /* bursts of unspecified length. */ 59 59 writel(0, USB_AHBBURST); 60 - /* Use the AHB transactor */ 61 - writel(0, USB_AHBMODE); 60 + /* Use the AHB transactor, allow posted data writes */ 61 + writel(0x8, USB_AHBMODE); 62 62 /* Disable streaming mode and select host mode */ 63 63 writel(0x13, USB_USBMODE); 64 64
+7 -2
drivers/usb/host/ehci-q.c
··· 132 132 * qtd is updated in qh_completions(). Update the QH 133 133 * overlay here. 134 134 */ 135 - if (qh->hw->hw_token & ACTIVE_BIT(ehci)) 135 + if (qh->hw->hw_token & ACTIVE_BIT(ehci)) { 136 136 qh->hw->hw_qtd_next = qtd->hw_next; 137 - else 137 + if (qh->should_be_inactive) 138 + ehci_warn(ehci, "qh %p should be inactive!\n", qh); 139 + } else { 138 140 qh_update(ehci, qh, qtd); 141 + } 142 + qh->should_be_inactive = 0; 139 143 } 140 144 141 145 /*-------------------------------------------------------------------------*/ ··· 442 438 (hw->hw_token & ACTIVE_BIT(ehci))) { 443 439 token = hc32_to_cpu(ehci, hw->hw_token); 444 440 hw->hw_token &= ~ACTIVE_BIT(ehci); 441 + qh->should_be_inactive = 1; 445 442 446 443 /* An unlink may leave an incomplete 447 444 * async transaction in the TT buffer.
+1
drivers/usb/host/ehci.h
··· 439 439 unsigned dequeue_during_giveback:1; 440 440 unsigned exception:1; /* got a fault, or an unlink 441 441 was requested */ 442 + unsigned should_be_inactive:1; 442 443 }; 443 444 444 445 /*-------------------------------------------------------------------------*/
+1 -1
drivers/usb/host/fhci-tds.c
··· 85 85 86 86 void fhci_push_dummy_bd(struct endpoint *ep) 87 87 { 88 - if (ep->already_pushed_dummy_bd == false) { 88 + if (!ep->already_pushed_dummy_bd) { 89 89 u16 td_status = in_be16(&ep->empty_td->status); 90 90 91 91 out_be32(&ep->empty_td->buf_ptr, DUMMY_BD_BUFFER);
+2 -2
drivers/usb/host/ohci-hcd.c
··· 99 99 100 100 101 101 /* Some boards misreport power switching/overcurrent */ 102 - static bool distrust_firmware = 1; 102 + static bool distrust_firmware = true; 103 103 module_param (distrust_firmware, bool, 0); 104 104 MODULE_PARM_DESC (distrust_firmware, 105 105 "true to distrust firmware power/overcurrent setup"); 106 106 107 107 /* Some boards leave IR set wrongly, since they fail BIOS/SMM handshakes */ 108 - static bool no_handshake = 0; 108 + static bool no_handshake; 109 109 module_param (no_handshake, bool, 0); 110 110 MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake"); 111 111
+7 -7
drivers/usb/host/ohci-pxa27x.c
··· 365 365 if (!pdata) 366 366 return -ENOMEM; 367 367 368 - if (of_get_property(np, "marvell,enable-port1", NULL)) 368 + if (of_property_read_bool(np, "marvell,enable-port1")) 369 369 pdata->flags |= ENABLE_PORT1; 370 - if (of_get_property(np, "marvell,enable-port2", NULL)) 370 + if (of_property_read_bool(np, "marvell,enable-port2")) 371 371 pdata->flags |= ENABLE_PORT2; 372 - if (of_get_property(np, "marvell,enable-port3", NULL)) 372 + if (of_property_read_bool(np, "marvell,enable-port3")) 373 373 pdata->flags |= ENABLE_PORT3; 374 - if (of_get_property(np, "marvell,port-sense-low", NULL)) 374 + if (of_property_read_bool(np, "marvell,port-sense-low")) 375 375 pdata->flags |= POWER_SENSE_LOW; 376 - if (of_get_property(np, "marvell,power-control-low", NULL)) 376 + if (of_property_read_bool(np, "marvell,power-control-low")) 377 377 pdata->flags |= POWER_CONTROL_LOW; 378 - if (of_get_property(np, "marvell,no-oc-protection", NULL)) 378 + if (of_property_read_bool(np, "marvell,no-oc-protection")) 379 379 pdata->flags |= NO_OC_PROTECTION; 380 - if (of_get_property(np, "marvell,oc-mode-perport", NULL)) 380 + if (of_property_read_bool(np, "marvell,oc-mode-perport")) 381 381 pdata->flags |= OC_MODE_PERPORT; 382 382 if (!of_property_read_u32(np, "marvell,power-on-delay", &tmp)) 383 383 pdata->power_on_delay = tmp;
+3 -5
drivers/usb/host/oxu210hp-hcd.c
··· 394 394 u32 temp; 395 395 396 396 #ifdef DEBUG 397 - if (!HC_IS_RUNNING(oxu_to_hcd(oxu)->state)) 398 - BUG(); 397 + BUG_ON(!HC_IS_RUNNING(oxu_to_hcd(oxu)->state)); 399 398 #endif 400 399 401 400 /* wait for any schedule enables/disables to take effect */ ··· 1708 1709 1709 1710 #ifdef DEBUG 1710 1711 assert_spin_locked(&oxu->lock); 1711 - if (oxu->reclaim || (qh->qh_state != QH_STATE_LINKED 1712 - && qh->qh_state != QH_STATE_UNLINK_WAIT)) 1713 - BUG(); 1712 + BUG_ON(oxu->reclaim || (qh->qh_state != QH_STATE_LINKED 1713 + && qh->qh_state != QH_STATE_UNLINK_WAIT)); 1714 1714 #endif 1715 1715 1716 1716 /* stop async schedule right now? */
+9 -16
drivers/usb/host/pci-quirks.c
··· 984 984 * Find the Legacy Support Capability register - 985 985 * this is optional for xHCI host controllers. 986 986 */ 987 - ext_cap_offset = xhci_find_next_cap_offset(base, XHCI_HCC_PARAMS_OFFSET); 988 - do { 989 - if ((ext_cap_offset + sizeof(val)) > len) { 990 - /* We're reading garbage from the controller */ 991 - dev_warn(&pdev->dev, 992 - "xHCI controller failing to respond"); 993 - return; 994 - } 987 + ext_cap_offset = xhci_find_next_ext_cap(base, 0, XHCI_EXT_CAPS_LEGACY); 995 988 996 - if (!ext_cap_offset) 997 - /* We've reached the end of the extended capabilities */ 998 - goto hc_init; 989 + if (!ext_cap_offset) 990 + goto hc_init; 999 991 1000 - val = readl(base + ext_cap_offset); 1001 - if (XHCI_EXT_CAPS_ID(val) == XHCI_EXT_CAPS_LEGACY) 1002 - break; 1003 - ext_cap_offset = xhci_find_next_cap_offset(base, ext_cap_offset); 1004 - } while (1); 992 + if ((ext_cap_offset + sizeof(val)) > len) { 993 + /* We're reading garbage from the controller */ 994 + dev_warn(&pdev->dev, "xHCI controller failing to respond"); 995 + return; 996 + } 997 + val = readl(base + ext_cap_offset); 1005 998 1006 999 /* If the BIOS owns the HC, signal that the OS wants it, and wait */ 1007 1000 if (val & XHCI_HC_BIOS_OWNED) {
+1 -1
drivers/usb/host/u132-hcd.c
··· 73 73 #define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444) 74 74 INT_MODULE_PARM(testing, 0); 75 75 /* Some boards misreport power switching/overcurrent*/ 76 - static bool distrust_firmware = 1; 76 + static bool distrust_firmware = true; 77 77 module_param(distrust_firmware, bool, 0); 78 78 MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren" 79 79 "t setup");
+1 -2
drivers/usb/host/uhci-q.c
··· 248 248 dma_addr_t dma_handle; 249 249 struct uhci_qh *qh; 250 250 251 - qh = dma_pool_alloc(uhci->qh_pool, GFP_ATOMIC, &dma_handle); 251 + qh = dma_pool_zalloc(uhci->qh_pool, GFP_ATOMIC, &dma_handle); 252 252 if (!qh) 253 253 return NULL; 254 254 255 - memset(qh, 0, sizeof(*qh)); 256 255 qh->dma_handle = dma_handle; 257 256 258 257 qh->element = UHCI_PTR_TERM(uhci);
+2 -3
drivers/usb/host/whci/qset.c
··· 30 30 struct whc_qset *qset; 31 31 dma_addr_t dma; 32 32 33 - qset = dma_pool_alloc(whc->qset_pool, mem_flags, &dma); 33 + qset = dma_pool_zalloc(whc->qset_pool, mem_flags, &dma); 34 34 if (qset == NULL) 35 35 return NULL; 36 - memset(qset, 0, sizeof(struct whc_qset)); 37 36 38 37 qset->qset_dma = dma; 39 38 qset->whc = whc; ··· 399 400 struct whc *whc = qset->whc; 400 401 unsigned long flags; 401 402 402 - if (wurb->is_async == true) 403 + if (wurb->is_async) 403 404 asl_update(whc, WUSBCMD_ASYNC_UPDATED 404 405 | WUSBCMD_ASYNC_SYNCED_DB 405 406 | WUSBCMD_ASYNC_QSET_RM);
+27 -54
drivers/usb/host/xhci-ext-caps.h
··· 91 91 #include <linux/io.h> 92 92 93 93 /** 94 - * Return the next extended capability pointer register. 95 - * 96 - * @base PCI register base address. 97 - * 98 - * @ext_offset Offset of the 32-bit register that contains the extended 99 - * capabilites pointer. If searching for the first extended capability, pass 100 - * in XHCI_HCC_PARAMS_OFFSET. If searching for the next extended capability, 101 - * pass in the offset of the current extended capability register. 102 - * 103 - * Returns 0 if there is no next extended capability register or returns the register offset 104 - * from the PCI registers base address. 105 - */ 106 - static inline int xhci_find_next_cap_offset(void __iomem *base, int ext_offset) 107 - { 108 - u32 next; 109 - 110 - next = readl(base + ext_offset); 111 - 112 - if (ext_offset == XHCI_HCC_PARAMS_OFFSET) { 113 - /* Find the first extended capability */ 114 - next = XHCI_HCC_EXT_CAPS(next); 115 - ext_offset = 0; 116 - } else { 117 - /* Find the next extended capability */ 118 - next = XHCI_EXT_CAPS_NEXT(next); 119 - } 120 - 121 - if (!next) 122 - return 0; 123 - /* 124 - * Address calculation from offset of extended capabilities 125 - * (or HCCPARAMS) register - see section 5.3.6 and section 7. 126 - */ 127 - return ext_offset + (next << 2); 128 - } 129 - 130 - /** 131 94 * Find the offset of the extended capabilities with capability ID id. 132 95 * 133 - * @base PCI MMIO registers base address. 134 - * @ext_offset Offset from base of the first extended capability to look at, 135 - * or the address of HCCPARAMS. 136 - * @id Extended capability ID to search for. 96 + * @base PCI MMIO registers base address. 97 + * @start address at which to start looking, (0 or HCC_PARAMS to start at 98 + * beginning of list) 99 + * @id Extended capability ID to search for. 137 100 * 138 - * This uses an arbitrary limit of XHCI_MAX_EXT_CAPS extended capabilities 139 - * to make sure that the list doesn't contain a loop. 101 + * Returns the offset of the next matching extended capability structure. 102 + * Some capabilities can occur several times, e.g., the XHCI_EXT_CAPS_PROTOCOL, 103 + * and this provides a way to find them all. 140 104 */ 141 - static inline int xhci_find_ext_cap_by_id(void __iomem *base, int ext_offset, int id) 105 + 106 + static inline int xhci_find_next_ext_cap(void __iomem *base, u32 start, int id) 142 107 { 143 108 u32 val; 144 - int limit = XHCI_MAX_EXT_CAPS; 109 + u32 next; 110 + u32 offset; 145 111 146 - while (ext_offset && limit > 0) { 147 - val = readl(base + ext_offset); 148 - if (XHCI_EXT_CAPS_ID(val) == id) 149 - break; 150 - ext_offset = xhci_find_next_cap_offset(base, ext_offset); 151 - limit--; 152 - } 153 - if (limit > 0) 154 - return ext_offset; 112 + offset = start; 113 + if (!start || start == XHCI_HCC_PARAMS_OFFSET) { 114 + val = readl(base + XHCI_HCC_PARAMS_OFFSET); 115 + offset = XHCI_HCC_EXT_CAPS(val) << 2; 116 + if (!offset) 117 + return 0; 118 + }; 119 + do { 120 + val = readl(base + offset); 121 + if (XHCI_EXT_CAPS_ID(val) == id && offset != start) 122 + return offset; 123 + 124 + next = XHCI_EXT_CAPS_NEXT(val); 125 + offset += next << 2; 126 + } while (next); 127 + 155 128 return 0; 156 129 }
+1 -1
drivers/usb/host/xhci-hub.c
··· 855 855 xhci_hub_report_usb2_link_state(&status, raw_port_status); 856 856 } 857 857 if (bus_state->port_c_suspend & (1 << wIndex)) 858 - status |= 1 << USB_PORT_FEAT_C_SUSPEND; 858 + status |= USB_PORT_STAT_C_SUSPEND << 16; 859 859 860 860 return status; 861 861 }
+29 -50
drivers/usb/host/xhci-mem.c
··· 47 47 if (!seg) 48 48 return NULL; 49 49 50 - seg->trbs = dma_pool_alloc(xhci->segment_pool, flags, &dma); 50 + seg->trbs = dma_pool_zalloc(xhci->segment_pool, flags, &dma); 51 51 if (!seg->trbs) { 52 52 kfree(seg); 53 53 return NULL; 54 54 } 55 55 56 - memset(seg->trbs, 0, TRB_SEGMENT_SIZE); 57 56 /* If the cycle state is 0, set the cycle bit to 1 for all the TRBs */ 58 57 if (cycle_state == 0) { 59 58 for (i = 0; i < TRBS_PER_SEGMENT; i++) ··· 516 517 if (type == XHCI_CTX_TYPE_INPUT) 517 518 ctx->size += CTX_SIZE(xhci->hcc_params); 518 519 519 - ctx->bytes = dma_pool_alloc(xhci->device_pool, flags, &ctx->dma); 520 + ctx->bytes = dma_pool_zalloc(xhci->device_pool, flags, &ctx->dma); 520 521 if (!ctx->bytes) { 521 522 kfree(ctx); 522 523 return NULL; 523 524 } 524 - memset(ctx->bytes, 0, ctx->size); 525 525 return ctx; 526 526 } 527 527 ··· 1243 1245 interval = fls(desc_interval) - 1; 1244 1246 interval = clamp_val(interval, min_exponent, max_exponent); 1245 1247 if ((1 << interval) != desc_interval) 1246 - dev_warn(&udev->dev, 1248 + dev_dbg(&udev->dev, 1247 1249 "ep %#x - rounding interval to %d microframes, ep desc says %d microframes\n", 1248 1250 ep->desc.bEndpointAddress, 1249 1251 1 << interval, ··· 2062 2064 } 2063 2065 2064 2066 static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports, 2065 - __le32 __iomem *addr, u8 major_revision, int max_caps) 2067 + __le32 __iomem *addr, int max_caps) 2066 2068 { 2067 2069 u32 temp, port_offset, port_count; 2068 2070 int i; 2071 + u8 major_revision; 2069 2072 struct xhci_hub *rhub; 2070 2073 2071 2074 temp = readl(addr); 2075 + major_revision = XHCI_EXT_PORT_MAJOR(temp); 2072 2076 2073 - if (XHCI_EXT_PORT_MAJOR(temp) == 0x03) { 2077 + if (major_revision == 0x03) { 2074 2078 rhub = &xhci->usb3_rhub; 2075 - } else if (XHCI_EXT_PORT_MAJOR(temp) <= 0x02) { 2079 + } else if (major_revision <= 0x02) { 2076 2080 rhub = &xhci->usb2_rhub; 2077 2081 } else { 2078 2082 xhci_warn(xhci, "Ignoring unknown port speed, " ··· 2190 2190 */ 2191 2191 static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags) 2192 2192 { 2193 - __le32 __iomem *addr, *tmp_addr; 2194 - u32 offset, tmp_offset; 2193 + void __iomem *base; 2194 + u32 offset; 2195 2195 unsigned int num_ports; 2196 2196 int i, j, port_index; 2197 2197 int cap_count = 0; 2198 - 2199 - addr = &xhci->cap_regs->hcc_params; 2200 - offset = XHCI_HCC_EXT_CAPS(readl(addr)); 2201 - if (offset == 0) { 2202 - xhci_err(xhci, "No Extended Capability registers, " 2203 - "unable to set up roothub.\n"); 2204 - return -ENODEV; 2205 - } 2198 + u32 cap_start; 2206 2199 2207 2200 num_ports = HCS_MAX_PORTS(xhci->hcs_params1); 2208 2201 xhci->port_array = kzalloc(sizeof(*xhci->port_array)*num_ports, flags); ··· 2213 2220 for (j = 0; j < XHCI_MAX_INTERVAL; j++) 2214 2221 INIT_LIST_HEAD(&bw_table->interval_bw[j].endpoints); 2215 2222 } 2223 + base = &xhci->cap_regs->hc_capbase; 2216 2224 2217 - /* 2218 - * For whatever reason, the first capability offset is from the 2219 - * capability register base, not from the HCCPARAMS register. 2220 - * See section 5.3.6 for offset calculation. 2221 - */ 2222 - addr = &xhci->cap_regs->hc_capbase + offset; 2225 + cap_start = xhci_find_next_ext_cap(base, 0, XHCI_EXT_CAPS_PROTOCOL); 2226 + if (!cap_start) { 2227 + xhci_err(xhci, "No Extended Capability registers, unable to set up roothub\n"); 2228 + return -ENODEV; 2229 + } 2223 2230 2224 - tmp_addr = addr; 2225 - tmp_offset = offset; 2226 - 2231 + offset = cap_start; 2227 2232 /* count extended protocol capability entries for later caching */ 2228 - do { 2229 - u32 cap_id; 2230 - cap_id = readl(tmp_addr); 2231 - if (XHCI_EXT_CAPS_ID(cap_id) == XHCI_EXT_CAPS_PROTOCOL) 2232 - cap_count++; 2233 - tmp_offset = XHCI_EXT_CAPS_NEXT(cap_id); 2234 - tmp_addr += tmp_offset; 2235 - } while (tmp_offset); 2233 + while (offset) { 2234 + cap_count++; 2235 + offset = xhci_find_next_ext_cap(base, offset, 2236 + XHCI_EXT_CAPS_PROTOCOL); 2237 + } 2236 2238 2237 2239 xhci->ext_caps = kzalloc(sizeof(*xhci->ext_caps) * cap_count, flags); 2238 2240 if (!xhci->ext_caps) 2239 2241 return -ENOMEM; 2240 2242 2241 - while (1) { 2242 - u32 cap_id; 2243 + offset = cap_start; 2243 2244 2244 - cap_id = readl(addr); 2245 - if (XHCI_EXT_CAPS_ID(cap_id) == XHCI_EXT_CAPS_PROTOCOL) 2246 - xhci_add_in_port(xhci, num_ports, addr, 2247 - (u8) XHCI_EXT_PORT_MAJOR(cap_id), 2248 - cap_count); 2249 - offset = XHCI_EXT_CAPS_NEXT(cap_id); 2250 - if (!offset || (xhci->num_usb2_ports + xhci->num_usb3_ports) 2251 - == num_ports) 2245 + while (offset) { 2246 + xhci_add_in_port(xhci, num_ports, base + offset, cap_count); 2247 + if (xhci->num_usb2_ports + xhci->num_usb3_ports == num_ports) 2252 2248 break; 2253 - /* 2254 - * Once you're into the Extended Capabilities, the offset is 2255 - * always relative to the register holding the offset. 2256 - */ 2257 - addr += offset; 2249 + offset = xhci_find_next_ext_cap(base, offset, 2250 + XHCI_EXT_CAPS_PROTOCOL); 2258 2251 } 2259 2252 2260 2253 if (xhci->num_usb2_ports == 0 && xhci->num_usb3_ports == 0) {
+415
drivers/usb/host/xhci-mtk-sch.c
··· 1 + /* 2 + * Copyright (c) 2015 MediaTek Inc. 3 + * Author: 4 + * Zhigang.Wei <zhigang.wei@mediatek.com> 5 + * Chunfeng.Yun <chunfeng.yun@mediatek.com> 6 + * 7 + * This software is licensed under the terms of the GNU General Public 8 + * License version 2, as published by the Free Software Foundation, and 9 + * may be copied, distributed, and modified under those terms. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + */ 17 + 18 + #include <linux/kernel.h> 19 + #include <linux/module.h> 20 + #include <linux/slab.h> 21 + 22 + #include "xhci.h" 23 + #include "xhci-mtk.h" 24 + 25 + #define SS_BW_BOUNDARY 51000 26 + /* table 5-5. High-speed Isoc Transaction Limits in usb_20 spec */ 27 + #define HS_BW_BOUNDARY 6144 28 + /* usb2 spec section11.18.1: at most 188 FS bytes per microframe */ 29 + #define FS_PAYLOAD_MAX 188 30 + 31 + /* mtk scheduler bitmasks */ 32 + #define EP_BPKTS(p) ((p) & 0x3f) 33 + #define EP_BCSCOUNT(p) (((p) & 0x7) << 8) 34 + #define EP_BBM(p) ((p) << 11) 35 + #define EP_BOFFSET(p) ((p) & 0x3fff) 36 + #define EP_BREPEAT(p) (((p) & 0x7fff) << 16) 37 + 38 + static int is_fs_or_ls(enum usb_device_speed speed) 39 + { 40 + return speed == USB_SPEED_FULL || speed == USB_SPEED_LOW; 41 + } 42 + 43 + /* 44 + * get the index of bandwidth domains array which @ep belongs to. 45 + * 46 + * the bandwidth domain array is saved to @sch_array of struct xhci_hcd_mtk, 47 + * each HS root port is treated as a single bandwidth domain, 48 + * but each SS root port is treated as two bandwidth domains, one for IN eps, 49 + * one for OUT eps. 50 + * @real_port value is defined as follow according to xHCI spec: 51 + * 1 for SSport0, ..., N+1 for SSportN, N+2 for HSport0, N+3 for HSport1, etc 52 + * so the bandwidth domain array is organized as follow for simplification: 53 + * SSport0-OUT, SSport0-IN, ..., SSportX-OUT, SSportX-IN, HSport0, ..., HSportY 54 + */ 55 + static int get_bw_index(struct xhci_hcd *xhci, struct usb_device *udev, 56 + struct usb_host_endpoint *ep) 57 + { 58 + struct xhci_virt_device *virt_dev; 59 + int bw_index; 60 + 61 + virt_dev = xhci->devs[udev->slot_id]; 62 + 63 + if (udev->speed == USB_SPEED_SUPER) { 64 + if (usb_endpoint_dir_out(&ep->desc)) 65 + bw_index = (virt_dev->real_port - 1) * 2; 66 + else 67 + bw_index = (virt_dev->real_port - 1) * 2 + 1; 68 + } else { 69 + /* add one more for each SS port */ 70 + bw_index = virt_dev->real_port + xhci->num_usb3_ports - 1; 71 + } 72 + 73 + return bw_index; 74 + } 75 + 76 + static void setup_sch_info(struct usb_device *udev, 77 + struct xhci_ep_ctx *ep_ctx, struct mu3h_sch_ep_info *sch_ep) 78 + { 79 + u32 ep_type; 80 + u32 ep_interval; 81 + u32 max_packet_size; 82 + u32 max_burst; 83 + u32 mult; 84 + u32 esit_pkts; 85 + 86 + ep_type = CTX_TO_EP_TYPE(le32_to_cpu(ep_ctx->ep_info2)); 87 + ep_interval = CTX_TO_EP_INTERVAL(le32_to_cpu(ep_ctx->ep_info)); 88 + max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2)); 89 + max_burst = CTX_TO_MAX_BURST(le32_to_cpu(ep_ctx->ep_info2)); 90 + mult = CTX_TO_EP_MULT(le32_to_cpu(ep_ctx->ep_info)); 91 + 92 + sch_ep->esit = 1 << ep_interval; 93 + sch_ep->offset = 0; 94 + sch_ep->burst_mode = 0; 95 + 96 + if (udev->speed == USB_SPEED_HIGH) { 97 + sch_ep->cs_count = 0; 98 + 99 + /* 100 + * usb_20 spec section5.9 101 + * a single microframe is enough for HS synchromous endpoints 102 + * in a interval 103 + */ 104 + sch_ep->num_budget_microframes = 1; 105 + sch_ep->repeat = 0; 106 + 107 + /* 108 + * xHCI spec section6.2.3.4 109 + * @max_burst is the number of additional transactions 110 + * opportunities per microframe 111 + */ 112 + sch_ep->pkts = max_burst + 1; 113 + sch_ep->bw_cost_per_microframe = max_packet_size * sch_ep->pkts; 114 + } else if (udev->speed == USB_SPEED_SUPER) { 115 + /* usb3_r1 spec section4.4.7 & 4.4.8 */ 116 + sch_ep->cs_count = 0; 117 + esit_pkts = (mult + 1) * (max_burst + 1); 118 + if (ep_type == INT_IN_EP || ep_type == INT_OUT_EP) { 119 + sch_ep->pkts = esit_pkts; 120 + sch_ep->num_budget_microframes = 1; 121 + sch_ep->repeat = 0; 122 + } 123 + 124 + if (ep_type == ISOC_IN_EP || ep_type == ISOC_OUT_EP) { 125 + if (esit_pkts <= sch_ep->esit) 126 + sch_ep->pkts = 1; 127 + else 128 + sch_ep->pkts = roundup_pow_of_two(esit_pkts) 129 + / sch_ep->esit; 130 + 131 + sch_ep->num_budget_microframes = 132 + DIV_ROUND_UP(esit_pkts, sch_ep->pkts); 133 + 134 + if (sch_ep->num_budget_microframes > 1) 135 + sch_ep->repeat = 1; 136 + else 137 + sch_ep->repeat = 0; 138 + } 139 + sch_ep->bw_cost_per_microframe = max_packet_size * sch_ep->pkts; 140 + } else if (is_fs_or_ls(udev->speed)) { 141 + 142 + /* 143 + * usb_20 spec section11.18.4 144 + * assume worst cases 145 + */ 146 + sch_ep->repeat = 0; 147 + sch_ep->pkts = 1; /* at most one packet for each microframe */ 148 + if (ep_type == INT_IN_EP || ep_type == INT_OUT_EP) { 149 + sch_ep->cs_count = 3; /* at most need 3 CS*/ 150 + /* one for SS and one for budgeted transaction */ 151 + sch_ep->num_budget_microframes = sch_ep->cs_count + 2; 152 + sch_ep->bw_cost_per_microframe = max_packet_size; 153 + } 154 + if (ep_type == ISOC_OUT_EP) { 155 + 156 + /* 157 + * the best case FS budget assumes that 188 FS bytes 158 + * occur in each microframe 159 + */ 160 + sch_ep->num_budget_microframes = DIV_ROUND_UP( 161 + max_packet_size, FS_PAYLOAD_MAX); 162 + sch_ep->bw_cost_per_microframe = FS_PAYLOAD_MAX; 163 + sch_ep->cs_count = sch_ep->num_budget_microframes; 164 + } 165 + if (ep_type == ISOC_IN_EP) { 166 + /* at most need additional two CS. */ 167 + sch_ep->cs_count = DIV_ROUND_UP( 168 + max_packet_size, FS_PAYLOAD_MAX) + 2; 169 + sch_ep->num_budget_microframes = sch_ep->cs_count + 2; 170 + sch_ep->bw_cost_per_microframe = FS_PAYLOAD_MAX; 171 + } 172 + } 173 + } 174 + 175 + /* Get maximum bandwidth when we schedule at offset slot. */ 176 + static u32 get_max_bw(struct mu3h_sch_bw_info *sch_bw, 177 + struct mu3h_sch_ep_info *sch_ep, u32 offset) 178 + { 179 + u32 num_esit; 180 + u32 max_bw = 0; 181 + int i; 182 + int j; 183 + 184 + num_esit = XHCI_MTK_MAX_ESIT / sch_ep->esit; 185 + for (i = 0; i < num_esit; i++) { 186 + u32 base = offset + i * sch_ep->esit; 187 + 188 + for (j = 0; j < sch_ep->num_budget_microframes; j++) { 189 + if (sch_bw->bus_bw[base + j] > max_bw) 190 + max_bw = sch_bw->bus_bw[base + j]; 191 + } 192 + } 193 + return max_bw; 194 + } 195 + 196 + static void update_bus_bw(struct mu3h_sch_bw_info *sch_bw, 197 + struct mu3h_sch_ep_info *sch_ep, int bw_cost) 198 + { 199 + u32 num_esit; 200 + u32 base; 201 + int i; 202 + int j; 203 + 204 + num_esit = XHCI_MTK_MAX_ESIT / sch_ep->esit; 205 + for (i = 0; i < num_esit; i++) { 206 + base = sch_ep->offset + i * sch_ep->esit; 207 + for (j = 0; j < sch_ep->num_budget_microframes; j++) 208 + sch_bw->bus_bw[base + j] += bw_cost; 209 + } 210 + } 211 + 212 + static int check_sch_bw(struct usb_device *udev, 213 + struct mu3h_sch_bw_info *sch_bw, struct mu3h_sch_ep_info *sch_ep) 214 + { 215 + u32 offset; 216 + u32 esit; 217 + u32 num_budget_microframes; 218 + u32 min_bw; 219 + u32 min_index; 220 + u32 worst_bw; 221 + u32 bw_boundary; 222 + 223 + if (sch_ep->esit > XHCI_MTK_MAX_ESIT) 224 + sch_ep->esit = XHCI_MTK_MAX_ESIT; 225 + 226 + esit = sch_ep->esit; 227 + num_budget_microframes = sch_ep->num_budget_microframes; 228 + 229 + /* 230 + * Search through all possible schedule microframes. 231 + * and find a microframe where its worst bandwidth is minimum. 232 + */ 233 + min_bw = ~0; 234 + min_index = 0; 235 + for (offset = 0; offset < esit; offset++) { 236 + if ((offset + num_budget_microframes) > sch_ep->esit) 237 + break; 238 + 239 + /* 240 + * usb_20 spec section11.18: 241 + * must never schedule Start-Split in Y6 242 + */ 243 + if (is_fs_or_ls(udev->speed) && (offset % 8 == 6)) 244 + continue; 245 + 246 + worst_bw = get_max_bw(sch_bw, sch_ep, offset); 247 + if (min_bw > worst_bw) { 248 + min_bw = worst_bw; 249 + min_index = offset; 250 + } 251 + if (min_bw == 0) 252 + break; 253 + } 254 + sch_ep->offset = min_index; 255 + 256 + bw_boundary = (udev->speed == USB_SPEED_SUPER) 257 + ? SS_BW_BOUNDARY : HS_BW_BOUNDARY; 258 + 259 + /* check bandwidth */ 260 + if (min_bw + sch_ep->bw_cost_per_microframe > bw_boundary) 261 + return -ERANGE; 262 + 263 + /* update bus bandwidth info */ 264 + update_bus_bw(sch_bw, sch_ep, sch_ep->bw_cost_per_microframe); 265 + 266 + return 0; 267 + } 268 + 269 + static bool need_bw_sch(struct usb_host_endpoint *ep, 270 + enum usb_device_speed speed, int has_tt) 271 + { 272 + /* only for periodic endpoints */ 273 + if (usb_endpoint_xfer_control(&ep->desc) 274 + || usb_endpoint_xfer_bulk(&ep->desc)) 275 + return false; 276 + 277 + /* 278 + * for LS & FS periodic endpoints which its device don't attach 279 + * to TT are also ignored, root-hub will schedule them directly 280 + */ 281 + if (is_fs_or_ls(speed) && !has_tt) 282 + return false; 283 + 284 + return true; 285 + } 286 + 287 + int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk) 288 + { 289 + struct mu3h_sch_bw_info *sch_array; 290 + int num_usb_bus; 291 + int i; 292 + 293 + /* ss IN and OUT are separated */ 294 + num_usb_bus = mtk->num_u3_ports * 2 + mtk->num_u2_ports; 295 + 296 + sch_array = kcalloc(num_usb_bus, sizeof(*sch_array), GFP_KERNEL); 297 + if (sch_array == NULL) 298 + return -ENOMEM; 299 + 300 + for (i = 0; i < num_usb_bus; i++) 301 + INIT_LIST_HEAD(&sch_array[i].bw_ep_list); 302 + 303 + mtk->sch_array = sch_array; 304 + 305 + return 0; 306 + } 307 + EXPORT_SYMBOL_GPL(xhci_mtk_sch_init); 308 + 309 + void xhci_mtk_sch_exit(struct xhci_hcd_mtk *mtk) 310 + { 311 + kfree(mtk->sch_array); 312 + } 313 + EXPORT_SYMBOL_GPL(xhci_mtk_sch_exit); 314 + 315 + int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev, 316 + struct usb_host_endpoint *ep) 317 + { 318 + struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd); 319 + struct xhci_hcd *xhci; 320 + struct xhci_ep_ctx *ep_ctx; 321 + struct xhci_slot_ctx *slot_ctx; 322 + struct xhci_virt_device *virt_dev; 323 + struct mu3h_sch_bw_info *sch_bw; 324 + struct mu3h_sch_ep_info *sch_ep; 325 + struct mu3h_sch_bw_info *sch_array; 326 + unsigned int ep_index; 327 + int bw_index; 328 + int ret = 0; 329 + 330 + xhci = hcd_to_xhci(hcd); 331 + virt_dev = xhci->devs[udev->slot_id]; 332 + ep_index = xhci_get_endpoint_index(&ep->desc); 333 + slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); 334 + ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); 335 + sch_array = mtk->sch_array; 336 + 337 + xhci_dbg(xhci, "%s() type:%d, speed:%d, mpkt:%d, dir:%d, ep:%p\n", 338 + __func__, usb_endpoint_type(&ep->desc), udev->speed, 339 + GET_MAX_PACKET(usb_endpoint_maxp(&ep->desc)), 340 + usb_endpoint_dir_in(&ep->desc), ep); 341 + 342 + if (!need_bw_sch(ep, udev->speed, slot_ctx->tt_info & TT_SLOT)) 343 + return 0; 344 + 345 + bw_index = get_bw_index(xhci, udev, ep); 346 + sch_bw = &sch_array[bw_index]; 347 + 348 + sch_ep = kzalloc(sizeof(struct mu3h_sch_ep_info), GFP_NOIO); 349 + if (!sch_ep) 350 + return -ENOMEM; 351 + 352 + setup_sch_info(udev, ep_ctx, sch_ep); 353 + 354 + ret = check_sch_bw(udev, sch_bw, sch_ep); 355 + if (ret) { 356 + xhci_err(xhci, "Not enough bandwidth!\n"); 357 + kfree(sch_ep); 358 + return -ENOSPC; 359 + } 360 + 361 + list_add_tail(&sch_ep->endpoint, &sch_bw->bw_ep_list); 362 + sch_ep->ep = ep; 363 + 364 + ep_ctx->reserved[0] |= cpu_to_le32(EP_BPKTS(sch_ep->pkts) 365 + | EP_BCSCOUNT(sch_ep->cs_count) | EP_BBM(sch_ep->burst_mode)); 366 + ep_ctx->reserved[1] |= cpu_to_le32(EP_BOFFSET(sch_ep->offset) 367 + | EP_BREPEAT(sch_ep->repeat)); 368 + 369 + xhci_dbg(xhci, " PKTS:%x, CSCOUNT:%x, BM:%x, OFFSET:%x, REPEAT:%x\n", 370 + sch_ep->pkts, sch_ep->cs_count, sch_ep->burst_mode, 371 + sch_ep->offset, sch_ep->repeat); 372 + 373 + return 0; 374 + } 375 + EXPORT_SYMBOL_GPL(xhci_mtk_add_ep_quirk); 376 + 377 + void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev, 378 + struct usb_host_endpoint *ep) 379 + { 380 + struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd); 381 + struct xhci_hcd *xhci; 382 + struct xhci_slot_ctx *slot_ctx; 383 + struct xhci_virt_device *virt_dev; 384 + struct mu3h_sch_bw_info *sch_array; 385 + struct mu3h_sch_bw_info *sch_bw; 386 + struct mu3h_sch_ep_info *sch_ep; 387 + int bw_index; 388 + 389 + xhci = hcd_to_xhci(hcd); 390 + virt_dev = xhci->devs[udev->slot_id]; 391 + slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); 392 + sch_array = mtk->sch_array; 393 + 394 + xhci_dbg(xhci, "%s() type:%d, speed:%d, mpks:%d, dir:%d, ep:%p\n", 395 + __func__, usb_endpoint_type(&ep->desc), udev->speed, 396 + GET_MAX_PACKET(usb_endpoint_maxp(&ep->desc)), 397 + usb_endpoint_dir_in(&ep->desc), ep); 398 + 399 + if (!need_bw_sch(ep, udev->speed, slot_ctx->tt_info & TT_SLOT)) 400 + return; 401 + 402 + bw_index = get_bw_index(xhci, udev, ep); 403 + sch_bw = &sch_array[bw_index]; 404 + 405 + list_for_each_entry(sch_ep, &sch_bw->bw_ep_list, endpoint) { 406 + if (sch_ep->ep == ep) { 407 + update_bus_bw(sch_bw, sch_ep, 408 + -sch_ep->bw_cost_per_microframe); 409 + list_del(&sch_ep->endpoint); 410 + kfree(sch_ep); 411 + break; 412 + } 413 + } 414 + } 415 + EXPORT_SYMBOL_GPL(xhci_mtk_drop_ep_quirk);
+763
drivers/usb/host/xhci-mtk.c
··· 1 + /* 2 + * MediaTek xHCI Host Controller Driver 3 + * 4 + * Copyright (c) 2015 MediaTek Inc. 5 + * Author: 6 + * Chunfeng Yun <chunfeng.yun@mediatek.com> 7 + * 8 + * This software is licensed under the terms of the GNU General Public 9 + * License version 2, as published by the Free Software Foundation, and 10 + * may be copied, distributed, and modified under those terms. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + * 17 + */ 18 + 19 + #include <linux/clk.h> 20 + #include <linux/dma-mapping.h> 21 + #include <linux/iopoll.h> 22 + #include <linux/kernel.h> 23 + #include <linux/mfd/syscon.h> 24 + #include <linux/module.h> 25 + #include <linux/of.h> 26 + #include <linux/phy/phy.h> 27 + #include <linux/platform_device.h> 28 + #include <linux/pm_runtime.h> 29 + #include <linux/regmap.h> 30 + #include <linux/regulator/consumer.h> 31 + 32 + #include "xhci.h" 33 + #include "xhci-mtk.h" 34 + 35 + /* ip_pw_ctrl0 register */ 36 + #define CTRL0_IP_SW_RST BIT(0) 37 + 38 + /* ip_pw_ctrl1 register */ 39 + #define CTRL1_IP_HOST_PDN BIT(0) 40 + 41 + /* ip_pw_ctrl2 register */ 42 + #define CTRL2_IP_DEV_PDN BIT(0) 43 + 44 + /* ip_pw_sts1 register */ 45 + #define STS1_IP_SLEEP_STS BIT(30) 46 + #define STS1_XHCI_RST BIT(11) 47 + #define STS1_SYS125_RST BIT(10) 48 + #define STS1_REF_RST BIT(8) 49 + #define STS1_SYSPLL_STABLE BIT(0) 50 + 51 + /* ip_xhci_cap register */ 52 + #define CAP_U3_PORT_NUM(p) ((p) & 0xff) 53 + #define CAP_U2_PORT_NUM(p) (((p) >> 8) & 0xff) 54 + 55 + /* u3_ctrl_p register */ 56 + #define CTRL_U3_PORT_HOST_SEL BIT(2) 57 + #define CTRL_U3_PORT_PDN BIT(1) 58 + #define CTRL_U3_PORT_DIS BIT(0) 59 + 60 + /* u2_ctrl_p register */ 61 + #define CTRL_U2_PORT_HOST_SEL BIT(2) 62 + #define CTRL_U2_PORT_PDN BIT(1) 63 + #define CTRL_U2_PORT_DIS BIT(0) 64 + 65 + /* u2_phy_pll register */ 66 + #define CTRL_U2_FORCE_PLL_STB BIT(28) 67 + 68 + #define PERI_WK_CTRL0 0x400 69 + #define UWK_CTR0_0P_LS_PE BIT(8) /* posedge */ 70 + #define UWK_CTR0_0P_LS_NE BIT(7) /* negedge for 0p linestate*/ 71 + #define UWK_CTL1_1P_LS_C(x) (((x) & 0xf) << 1) 72 + #define UWK_CTL1_1P_LS_E BIT(0) 73 + 74 + #define PERI_WK_CTRL1 0x404 75 + #define UWK_CTL1_IS_C(x) (((x) & 0xf) << 26) 76 + #define UWK_CTL1_IS_E BIT(25) 77 + #define UWK_CTL1_0P_LS_C(x) (((x) & 0xf) << 21) 78 + #define UWK_CTL1_0P_LS_E BIT(20) 79 + #define UWK_CTL1_IDDIG_C(x) (((x) & 0xf) << 11) /* cycle debounce */ 80 + #define UWK_CTL1_IDDIG_E BIT(10) /* enable debounce */ 81 + #define UWK_CTL1_IDDIG_P BIT(9) /* polarity */ 82 + #define UWK_CTL1_0P_LS_P BIT(7) 83 + #define UWK_CTL1_IS_P BIT(6) /* polarity for ip sleep */ 84 + 85 + enum ssusb_wakeup_src { 86 + SSUSB_WK_IP_SLEEP = 1, 87 + SSUSB_WK_LINE_STATE = 2, 88 + }; 89 + 90 + static int xhci_mtk_host_enable(struct xhci_hcd_mtk *mtk) 91 + { 92 + struct mu3c_ippc_regs __iomem *ippc = mtk->ippc_regs; 93 + u32 value, check_val; 94 + int ret; 95 + int i; 96 + 97 + /* power on host ip */ 98 + value = readl(&ippc->ip_pw_ctr1); 99 + value &= ~CTRL1_IP_HOST_PDN; 100 + writel(value, &ippc->ip_pw_ctr1); 101 + 102 + /* power on and enable all u3 ports */ 103 + for (i = 0; i < mtk->num_u3_ports; i++) { 104 + value = readl(&ippc->u3_ctrl_p[i]); 105 + value &= ~(CTRL_U3_PORT_PDN | CTRL_U3_PORT_DIS); 106 + value |= CTRL_U3_PORT_HOST_SEL; 107 + writel(value, &ippc->u3_ctrl_p[i]); 108 + } 109 + 110 + /* power on and enable all u2 ports */ 111 + for (i = 0; i < mtk->num_u2_ports; i++) { 112 + value = readl(&ippc->u2_ctrl_p[i]); 113 + value &= ~(CTRL_U2_PORT_PDN | CTRL_U2_PORT_DIS); 114 + value |= CTRL_U2_PORT_HOST_SEL; 115 + writel(value, &ippc->u2_ctrl_p[i]); 116 + } 117 + 118 + /* 119 + * wait for clocks to be stable, and clock domains reset to 120 + * be inactive after power on and enable ports 121 + */ 122 + check_val = STS1_SYSPLL_STABLE | STS1_REF_RST | 123 + STS1_SYS125_RST | STS1_XHCI_RST; 124 + 125 + ret = readl_poll_timeout(&ippc->ip_pw_sts1, value, 126 + (check_val == (value & check_val)), 100, 20000); 127 + if (ret) { 128 + dev_err(mtk->dev, "clocks are not stable (0x%x)\n", value); 129 + return ret; 130 + } 131 + 132 + return 0; 133 + } 134 + 135 + static int xhci_mtk_host_disable(struct xhci_hcd_mtk *mtk) 136 + { 137 + struct mu3c_ippc_regs __iomem *ippc = mtk->ippc_regs; 138 + u32 value; 139 + int ret; 140 + int i; 141 + 142 + /* power down all u3 ports */ 143 + for (i = 0; i < mtk->num_u3_ports; i++) { 144 + value = readl(&ippc->u3_ctrl_p[i]); 145 + value |= CTRL_U3_PORT_PDN; 146 + writel(value, &ippc->u3_ctrl_p[i]); 147 + } 148 + 149 + /* power down all u2 ports */ 150 + for (i = 0; i < mtk->num_u2_ports; i++) { 151 + value = readl(&ippc->u2_ctrl_p[i]); 152 + value |= CTRL_U2_PORT_PDN; 153 + writel(value, &ippc->u2_ctrl_p[i]); 154 + } 155 + 156 + /* power down host ip */ 157 + value = readl(&ippc->ip_pw_ctr1); 158 + value |= CTRL1_IP_HOST_PDN; 159 + writel(value, &ippc->ip_pw_ctr1); 160 + 161 + /* wait for host ip to sleep */ 162 + ret = readl_poll_timeout(&ippc->ip_pw_sts1, value, 163 + (value & STS1_IP_SLEEP_STS), 100, 100000); 164 + if (ret) { 165 + dev_err(mtk->dev, "ip sleep failed!!!\n"); 166 + return ret; 167 + } 168 + return 0; 169 + } 170 + 171 + static int xhci_mtk_ssusb_config(struct xhci_hcd_mtk *mtk) 172 + { 173 + struct mu3c_ippc_regs __iomem *ippc = mtk->ippc_regs; 174 + u32 value; 175 + 176 + /* reset whole ip */ 177 + value = readl(&ippc->ip_pw_ctr0); 178 + value |= CTRL0_IP_SW_RST; 179 + writel(value, &ippc->ip_pw_ctr0); 180 + udelay(1); 181 + value = readl(&ippc->ip_pw_ctr0); 182 + value &= ~CTRL0_IP_SW_RST; 183 + writel(value, &ippc->ip_pw_ctr0); 184 + 185 + /* 186 + * device ip is default power-on in fact 187 + * power down device ip, otherwise ip-sleep will fail 188 + */ 189 + value = readl(&ippc->ip_pw_ctr2); 190 + value |= CTRL2_IP_DEV_PDN; 191 + writel(value, &ippc->ip_pw_ctr2); 192 + 193 + value = readl(&ippc->ip_xhci_cap); 194 + mtk->num_u3_ports = CAP_U3_PORT_NUM(value); 195 + mtk->num_u2_ports = CAP_U2_PORT_NUM(value); 196 + dev_dbg(mtk->dev, "%s u2p:%d, u3p:%d\n", __func__, 197 + mtk->num_u2_ports, mtk->num_u3_ports); 198 + 199 + return xhci_mtk_host_enable(mtk); 200 + } 201 + 202 + static int xhci_mtk_clks_enable(struct xhci_hcd_mtk *mtk) 203 + { 204 + int ret; 205 + 206 + ret = clk_prepare_enable(mtk->sys_clk); 207 + if (ret) { 208 + dev_err(mtk->dev, "failed to enable sys_clk\n"); 209 + goto sys_clk_err; 210 + } 211 + 212 + if (mtk->wakeup_src) { 213 + ret = clk_prepare_enable(mtk->wk_deb_p0); 214 + if (ret) { 215 + dev_err(mtk->dev, "failed to enable wk_deb_p0\n"); 216 + goto usb_p0_err; 217 + } 218 + 219 + ret = clk_prepare_enable(mtk->wk_deb_p1); 220 + if (ret) { 221 + dev_err(mtk->dev, "failed to enable wk_deb_p1\n"); 222 + goto usb_p1_err; 223 + } 224 + } 225 + return 0; 226 + 227 + usb_p1_err: 228 + clk_disable_unprepare(mtk->wk_deb_p0); 229 + usb_p0_err: 230 + clk_disable_unprepare(mtk->sys_clk); 231 + sys_clk_err: 232 + return -EINVAL; 233 + } 234 + 235 + static void xhci_mtk_clks_disable(struct xhci_hcd_mtk *mtk) 236 + { 237 + if (mtk->wakeup_src) { 238 + clk_disable_unprepare(mtk->wk_deb_p1); 239 + clk_disable_unprepare(mtk->wk_deb_p0); 240 + } 241 + clk_disable_unprepare(mtk->sys_clk); 242 + } 243 + 244 + /* only clocks can be turn off for ip-sleep wakeup mode */ 245 + static void usb_wakeup_ip_sleep_en(struct xhci_hcd_mtk *mtk) 246 + { 247 + u32 tmp; 248 + struct regmap *pericfg = mtk->pericfg; 249 + 250 + regmap_read(pericfg, PERI_WK_CTRL1, &tmp); 251 + tmp &= ~UWK_CTL1_IS_P; 252 + tmp &= ~(UWK_CTL1_IS_C(0xf)); 253 + tmp |= UWK_CTL1_IS_C(0x8); 254 + regmap_write(pericfg, PERI_WK_CTRL1, tmp); 255 + regmap_write(pericfg, PERI_WK_CTRL1, tmp | UWK_CTL1_IS_E); 256 + 257 + regmap_read(pericfg, PERI_WK_CTRL1, &tmp); 258 + dev_dbg(mtk->dev, "%s(): WK_CTRL1[P6,E25,C26:29]=%#x\n", 259 + __func__, tmp); 260 + } 261 + 262 + static void usb_wakeup_ip_sleep_dis(struct xhci_hcd_mtk *mtk) 263 + { 264 + u32 tmp; 265 + 266 + regmap_read(mtk->pericfg, PERI_WK_CTRL1, &tmp); 267 + tmp &= ~UWK_CTL1_IS_E; 268 + regmap_write(mtk->pericfg, PERI_WK_CTRL1, tmp); 269 + } 270 + 271 + /* 272 + * for line-state wakeup mode, phy's power should not power-down 273 + * and only support cable plug in/out 274 + */ 275 + static void usb_wakeup_line_state_en(struct xhci_hcd_mtk *mtk) 276 + { 277 + u32 tmp; 278 + struct regmap *pericfg = mtk->pericfg; 279 + 280 + /* line-state of u2-port0 */ 281 + regmap_read(pericfg, PERI_WK_CTRL1, &tmp); 282 + tmp &= ~UWK_CTL1_0P_LS_P; 283 + tmp &= ~(UWK_CTL1_0P_LS_C(0xf)); 284 + tmp |= UWK_CTL1_0P_LS_C(0x8); 285 + regmap_write(pericfg, PERI_WK_CTRL1, tmp); 286 + regmap_read(pericfg, PERI_WK_CTRL1, &tmp); 287 + regmap_write(pericfg, PERI_WK_CTRL1, tmp | UWK_CTL1_0P_LS_E); 288 + 289 + /* line-state of u2-port1 */ 290 + regmap_read(pericfg, PERI_WK_CTRL0, &tmp); 291 + tmp &= ~(UWK_CTL1_1P_LS_C(0xf)); 292 + tmp |= UWK_CTL1_1P_LS_C(0x8); 293 + regmap_write(pericfg, PERI_WK_CTRL0, tmp); 294 + regmap_write(pericfg, PERI_WK_CTRL0, tmp | UWK_CTL1_1P_LS_E); 295 + } 296 + 297 + static void usb_wakeup_line_state_dis(struct xhci_hcd_mtk *mtk) 298 + { 299 + u32 tmp; 300 + struct regmap *pericfg = mtk->pericfg; 301 + 302 + /* line-state of u2-port0 */ 303 + regmap_read(pericfg, PERI_WK_CTRL1, &tmp); 304 + tmp &= ~UWK_CTL1_0P_LS_E; 305 + regmap_write(pericfg, PERI_WK_CTRL1, tmp); 306 + 307 + /* line-state of u2-port1 */ 308 + regmap_read(pericfg, PERI_WK_CTRL0, &tmp); 309 + tmp &= ~UWK_CTL1_1P_LS_E; 310 + regmap_write(pericfg, PERI_WK_CTRL0, tmp); 311 + } 312 + 313 + static void usb_wakeup_enable(struct xhci_hcd_mtk *mtk) 314 + { 315 + if (mtk->wakeup_src == SSUSB_WK_IP_SLEEP) 316 + usb_wakeup_ip_sleep_en(mtk); 317 + else if (mtk->wakeup_src == SSUSB_WK_LINE_STATE) 318 + usb_wakeup_line_state_en(mtk); 319 + } 320 + 321 + static void usb_wakeup_disable(struct xhci_hcd_mtk *mtk) 322 + { 323 + if (mtk->wakeup_src == SSUSB_WK_IP_SLEEP) 324 + usb_wakeup_ip_sleep_dis(mtk); 325 + else if (mtk->wakeup_src == SSUSB_WK_LINE_STATE) 326 + usb_wakeup_line_state_dis(mtk); 327 + } 328 + 329 + static int usb_wakeup_of_property_parse(struct xhci_hcd_mtk *mtk, 330 + struct device_node *dn) 331 + { 332 + struct device *dev = mtk->dev; 333 + 334 + /* 335 + * wakeup function is optional, so it is not an error if this property 336 + * does not exist, and in such case, no need to get relative 337 + * properties anymore. 338 + */ 339 + of_property_read_u32(dn, "mediatek,wakeup-src", &mtk->wakeup_src); 340 + if (!mtk->wakeup_src) 341 + return 0; 342 + 343 + mtk->wk_deb_p0 = devm_clk_get(dev, "wakeup_deb_p0"); 344 + if (IS_ERR(mtk->wk_deb_p0)) { 345 + dev_err(dev, "fail to get wakeup_deb_p0\n"); 346 + return PTR_ERR(mtk->wk_deb_p0); 347 + } 348 + 349 + mtk->wk_deb_p1 = devm_clk_get(dev, "wakeup_deb_p1"); 350 + if (IS_ERR(mtk->wk_deb_p1)) { 351 + dev_err(dev, "fail to get wakeup_deb_p1\n"); 352 + return PTR_ERR(mtk->wk_deb_p1); 353 + } 354 + 355 + mtk->pericfg = syscon_regmap_lookup_by_phandle(dn, 356 + "mediatek,syscon-wakeup"); 357 + if (IS_ERR(mtk->pericfg)) { 358 + dev_err(dev, "fail to get pericfg regs\n"); 359 + return PTR_ERR(mtk->pericfg); 360 + } 361 + 362 + return 0; 363 + } 364 + 365 + static int xhci_mtk_setup(struct usb_hcd *hcd); 366 + static const struct xhci_driver_overrides xhci_mtk_overrides __initconst = { 367 + .extra_priv_size = sizeof(struct xhci_hcd), 368 + .reset = xhci_mtk_setup, 369 + }; 370 + 371 + static struct hc_driver __read_mostly xhci_mtk_hc_driver; 372 + 373 + static int xhci_mtk_phy_init(struct xhci_hcd_mtk *mtk) 374 + { 375 + int i; 376 + int ret; 377 + 378 + for (i = 0; i < mtk->num_phys; i++) { 379 + ret = phy_init(mtk->phys[i]); 380 + if (ret) 381 + goto exit_phy; 382 + } 383 + return 0; 384 + 385 + exit_phy: 386 + for (; i > 0; i--) 387 + phy_exit(mtk->phys[i - 1]); 388 + 389 + return ret; 390 + } 391 + 392 + static int xhci_mtk_phy_exit(struct xhci_hcd_mtk *mtk) 393 + { 394 + int i; 395 + 396 + for (i = 0; i < mtk->num_phys; i++) 397 + phy_exit(mtk->phys[i]); 398 + 399 + return 0; 400 + } 401 + 402 + static int xhci_mtk_phy_power_on(struct xhci_hcd_mtk *mtk) 403 + { 404 + int i; 405 + int ret; 406 + 407 + for (i = 0; i < mtk->num_phys; i++) { 408 + ret = phy_power_on(mtk->phys[i]); 409 + if (ret) 410 + goto power_off_phy; 411 + } 412 + return 0; 413 + 414 + power_off_phy: 415 + for (; i > 0; i--) 416 + phy_power_off(mtk->phys[i - 1]); 417 + 418 + return ret; 419 + } 420 + 421 + static void xhci_mtk_phy_power_off(struct xhci_hcd_mtk *mtk) 422 + { 423 + unsigned int i; 424 + 425 + for (i = 0; i < mtk->num_phys; i++) 426 + phy_power_off(mtk->phys[i]); 427 + } 428 + 429 + static int xhci_mtk_ldos_enable(struct xhci_hcd_mtk *mtk) 430 + { 431 + int ret; 432 + 433 + ret = regulator_enable(mtk->vbus); 434 + if (ret) { 435 + dev_err(mtk->dev, "failed to enable vbus\n"); 436 + return ret; 437 + } 438 + 439 + ret = regulator_enable(mtk->vusb33); 440 + if (ret) { 441 + dev_err(mtk->dev, "failed to enable vusb33\n"); 442 + regulator_disable(mtk->vbus); 443 + return ret; 444 + } 445 + return 0; 446 + } 447 + 448 + static void xhci_mtk_ldos_disable(struct xhci_hcd_mtk *mtk) 449 + { 450 + regulator_disable(mtk->vbus); 451 + regulator_disable(mtk->vusb33); 452 + } 453 + 454 + static void xhci_mtk_quirks(struct device *dev, struct xhci_hcd *xhci) 455 + { 456 + struct usb_hcd *hcd = xhci_to_hcd(xhci); 457 + struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd); 458 + 459 + /* 460 + * As of now platform drivers don't provide MSI support so we ensure 461 + * here that the generic code does not try to make a pci_dev from our 462 + * dev struct in order to setup MSI 463 + */ 464 + xhci->quirks |= XHCI_PLAT; 465 + xhci->quirks |= XHCI_MTK_HOST; 466 + /* 467 + * MTK host controller gives a spurious successful event after a 468 + * short transfer. Ignore it. 469 + */ 470 + xhci->quirks |= XHCI_SPURIOUS_SUCCESS; 471 + if (mtk->lpm_support) 472 + xhci->quirks |= XHCI_LPM_SUPPORT; 473 + } 474 + 475 + /* called during probe() after chip reset completes */ 476 + static int xhci_mtk_setup(struct usb_hcd *hcd) 477 + { 478 + struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd); 479 + int ret; 480 + 481 + if (usb_hcd_is_primary_hcd(hcd)) { 482 + ret = xhci_mtk_ssusb_config(mtk); 483 + if (ret) 484 + return ret; 485 + ret = xhci_mtk_sch_init(mtk); 486 + if (ret) 487 + return ret; 488 + } 489 + 490 + return xhci_gen_setup(hcd, xhci_mtk_quirks); 491 + } 492 + 493 + static int xhci_mtk_probe(struct platform_device *pdev) 494 + { 495 + struct device *dev = &pdev->dev; 496 + struct device_node *node = dev->of_node; 497 + struct xhci_hcd_mtk *mtk; 498 + const struct hc_driver *driver; 499 + struct xhci_hcd *xhci; 500 + struct resource *res; 501 + struct usb_hcd *hcd; 502 + struct phy *phy; 503 + int phy_num; 504 + int ret = -ENODEV; 505 + int irq; 506 + 507 + if (usb_disabled()) 508 + return -ENODEV; 509 + 510 + driver = &xhci_mtk_hc_driver; 511 + mtk = devm_kzalloc(dev, sizeof(*mtk), GFP_KERNEL); 512 + if (!mtk) 513 + return -ENOMEM; 514 + 515 + mtk->dev = dev; 516 + mtk->vbus = devm_regulator_get(dev, "vbus"); 517 + if (IS_ERR(mtk->vbus)) { 518 + dev_err(dev, "fail to get vbus\n"); 519 + return PTR_ERR(mtk->vbus); 520 + } 521 + 522 + mtk->vusb33 = devm_regulator_get(dev, "vusb33"); 523 + if (IS_ERR(mtk->vusb33)) { 524 + dev_err(dev, "fail to get vusb33\n"); 525 + return PTR_ERR(mtk->vusb33); 526 + } 527 + 528 + mtk->sys_clk = devm_clk_get(dev, "sys_ck"); 529 + if (IS_ERR(mtk->sys_clk)) { 530 + dev_err(dev, "fail to get sys_ck\n"); 531 + return PTR_ERR(mtk->sys_clk); 532 + } 533 + 534 + mtk->lpm_support = of_property_read_bool(node, "usb3-lpm-capable"); 535 + 536 + ret = usb_wakeup_of_property_parse(mtk, node); 537 + if (ret) 538 + return ret; 539 + 540 + mtk->num_phys = of_count_phandle_with_args(node, 541 + "phys", "#phy-cells"); 542 + if (mtk->num_phys > 0) { 543 + mtk->phys = devm_kcalloc(dev, mtk->num_phys, 544 + sizeof(*mtk->phys), GFP_KERNEL); 545 + if (!mtk->phys) 546 + return -ENOMEM; 547 + } else { 548 + mtk->num_phys = 0; 549 + } 550 + pm_runtime_enable(dev); 551 + pm_runtime_get_sync(dev); 552 + device_enable_async_suspend(dev); 553 + 554 + ret = xhci_mtk_ldos_enable(mtk); 555 + if (ret) 556 + goto disable_pm; 557 + 558 + ret = xhci_mtk_clks_enable(mtk); 559 + if (ret) 560 + goto disable_ldos; 561 + 562 + irq = platform_get_irq(pdev, 0); 563 + if (irq < 0) 564 + goto disable_clk; 565 + 566 + /* Initialize dma_mask and coherent_dma_mask to 32-bits */ 567 + ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32)); 568 + if (ret) 569 + goto disable_clk; 570 + 571 + if (!dev->dma_mask) 572 + dev->dma_mask = &dev->coherent_dma_mask; 573 + else 574 + dma_set_mask(dev, DMA_BIT_MASK(32)); 575 + 576 + hcd = usb_create_hcd(driver, dev, dev_name(dev)); 577 + if (!hcd) { 578 + ret = -ENOMEM; 579 + goto disable_clk; 580 + } 581 + 582 + /* 583 + * USB 2.0 roothub is stored in the platform_device. 584 + * Swap it with mtk HCD. 585 + */ 586 + mtk->hcd = platform_get_drvdata(pdev); 587 + platform_set_drvdata(pdev, mtk); 588 + 589 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 590 + hcd->regs = devm_ioremap_resource(dev, res); 591 + if (IS_ERR(hcd->regs)) { 592 + ret = PTR_ERR(hcd->regs); 593 + goto put_usb2_hcd; 594 + } 595 + hcd->rsrc_start = res->start; 596 + hcd->rsrc_len = resource_size(res); 597 + 598 + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 599 + mtk->ippc_regs = devm_ioremap_resource(dev, res); 600 + if (IS_ERR(mtk->ippc_regs)) { 601 + ret = PTR_ERR(mtk->ippc_regs); 602 + goto put_usb2_hcd; 603 + } 604 + 605 + for (phy_num = 0; phy_num < mtk->num_phys; phy_num++) { 606 + phy = devm_of_phy_get_by_index(dev, node, phy_num); 607 + if (IS_ERR(phy)) { 608 + ret = PTR_ERR(phy); 609 + goto put_usb2_hcd; 610 + } 611 + mtk->phys[phy_num] = phy; 612 + } 613 + 614 + ret = xhci_mtk_phy_init(mtk); 615 + if (ret) 616 + goto put_usb2_hcd; 617 + 618 + ret = xhci_mtk_phy_power_on(mtk); 619 + if (ret) 620 + goto exit_phys; 621 + 622 + device_init_wakeup(dev, true); 623 + 624 + xhci = hcd_to_xhci(hcd); 625 + xhci->main_hcd = hcd; 626 + xhci->shared_hcd = usb_create_shared_hcd(driver, dev, 627 + dev_name(dev), hcd); 628 + if (!xhci->shared_hcd) { 629 + ret = -ENOMEM; 630 + goto power_off_phys; 631 + } 632 + 633 + if (HCC_MAX_PSA(xhci->hcc_params) >= 4) 634 + xhci->shared_hcd->can_do_streams = 1; 635 + 636 + ret = usb_add_hcd(hcd, irq, IRQF_SHARED); 637 + if (ret) 638 + goto put_usb3_hcd; 639 + 640 + ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED); 641 + if (ret) 642 + goto dealloc_usb2_hcd; 643 + 644 + return 0; 645 + 646 + dealloc_usb2_hcd: 647 + usb_remove_hcd(hcd); 648 + 649 + put_usb3_hcd: 650 + xhci_mtk_sch_exit(mtk); 651 + usb_put_hcd(xhci->shared_hcd); 652 + 653 + power_off_phys: 654 + xhci_mtk_phy_power_off(mtk); 655 + device_init_wakeup(dev, false); 656 + 657 + exit_phys: 658 + xhci_mtk_phy_exit(mtk); 659 + 660 + put_usb2_hcd: 661 + usb_put_hcd(hcd); 662 + 663 + disable_clk: 664 + xhci_mtk_clks_disable(mtk); 665 + 666 + disable_ldos: 667 + xhci_mtk_ldos_disable(mtk); 668 + 669 + disable_pm: 670 + pm_runtime_put_sync(dev); 671 + pm_runtime_disable(dev); 672 + return ret; 673 + } 674 + 675 + static int xhci_mtk_remove(struct platform_device *dev) 676 + { 677 + struct xhci_hcd_mtk *mtk = platform_get_drvdata(dev); 678 + struct usb_hcd *hcd = mtk->hcd; 679 + struct xhci_hcd *xhci = hcd_to_xhci(hcd); 680 + 681 + usb_remove_hcd(xhci->shared_hcd); 682 + xhci_mtk_phy_power_off(mtk); 683 + xhci_mtk_phy_exit(mtk); 684 + device_init_wakeup(&dev->dev, false); 685 + 686 + usb_remove_hcd(hcd); 687 + usb_put_hcd(xhci->shared_hcd); 688 + usb_put_hcd(hcd); 689 + xhci_mtk_sch_exit(mtk); 690 + xhci_mtk_clks_disable(mtk); 691 + xhci_mtk_ldos_disable(mtk); 692 + pm_runtime_put_sync(&dev->dev); 693 + pm_runtime_disable(&dev->dev); 694 + 695 + return 0; 696 + } 697 + 698 + #ifdef CONFIG_PM_SLEEP 699 + static int xhci_mtk_suspend(struct device *dev) 700 + { 701 + struct xhci_hcd_mtk *mtk = dev_get_drvdata(dev); 702 + 703 + xhci_mtk_host_disable(mtk); 704 + xhci_mtk_phy_power_off(mtk); 705 + xhci_mtk_clks_disable(mtk); 706 + usb_wakeup_enable(mtk); 707 + return 0; 708 + } 709 + 710 + static int xhci_mtk_resume(struct device *dev) 711 + { 712 + struct xhci_hcd_mtk *mtk = dev_get_drvdata(dev); 713 + 714 + usb_wakeup_disable(mtk); 715 + xhci_mtk_clks_enable(mtk); 716 + xhci_mtk_phy_power_on(mtk); 717 + xhci_mtk_host_enable(mtk); 718 + return 0; 719 + } 720 + 721 + static const struct dev_pm_ops xhci_mtk_pm_ops = { 722 + SET_SYSTEM_SLEEP_PM_OPS(xhci_mtk_suspend, xhci_mtk_resume) 723 + }; 724 + #define DEV_PM_OPS (&xhci_mtk_pm_ops) 725 + #else 726 + #define DEV_PM_OPS NULL 727 + #endif /* CONFIG_PM */ 728 + 729 + #ifdef CONFIG_OF 730 + static const struct of_device_id mtk_xhci_of_match[] = { 731 + { .compatible = "mediatek,mt8173-xhci"}, 732 + { }, 733 + }; 734 + MODULE_DEVICE_TABLE(of, mtk_xhci_of_match); 735 + #endif 736 + 737 + static struct platform_driver mtk_xhci_driver = { 738 + .probe = xhci_mtk_probe, 739 + .remove = xhci_mtk_remove, 740 + .driver = { 741 + .name = "xhci-mtk", 742 + .pm = DEV_PM_OPS, 743 + .of_match_table = of_match_ptr(mtk_xhci_of_match), 744 + }, 745 + }; 746 + MODULE_ALIAS("platform:xhci-mtk"); 747 + 748 + static int __init xhci_mtk_init(void) 749 + { 750 + xhci_init_driver(&xhci_mtk_hc_driver, &xhci_mtk_overrides); 751 + return platform_driver_register(&mtk_xhci_driver); 752 + } 753 + module_init(xhci_mtk_init); 754 + 755 + static void __exit xhci_mtk_exit(void) 756 + { 757 + platform_driver_unregister(&mtk_xhci_driver); 758 + } 759 + module_exit(xhci_mtk_exit); 760 + 761 + MODULE_AUTHOR("Chunfeng Yun <chunfeng.yun@mediatek.com>"); 762 + MODULE_DESCRIPTION("MediaTek xHCI Host Controller Driver"); 763 + MODULE_LICENSE("GPL v2");
+162
drivers/usb/host/xhci-mtk.h
··· 1 + /* 2 + * Copyright (c) 2015 MediaTek Inc. 3 + * Author: 4 + * Zhigang.Wei <zhigang.wei@mediatek.com> 5 + * Chunfeng.Yun <chunfeng.yun@mediatek.com> 6 + * 7 + * This software is licensed under the terms of the GNU General Public 8 + * License version 2, as published by the Free Software Foundation, and 9 + * may be copied, distributed, and modified under those terms. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + */ 17 + 18 + #ifndef _XHCI_MTK_H_ 19 + #define _XHCI_MTK_H_ 20 + 21 + #include "xhci.h" 22 + 23 + /** 24 + * To simplify scheduler algorithm, set a upper limit for ESIT, 25 + * if a synchromous ep's ESIT is larger than @XHCI_MTK_MAX_ESIT, 26 + * round down to the limit value, that means allocating more 27 + * bandwidth to it. 28 + */ 29 + #define XHCI_MTK_MAX_ESIT 64 30 + 31 + /** 32 + * struct mu3h_sch_bw_info: schedule information for bandwidth domain 33 + * 34 + * @bus_bw: array to keep track of bandwidth already used at each uframes 35 + * @bw_ep_list: eps in the bandwidth domain 36 + * 37 + * treat a HS root port as a bandwidth domain, but treat a SS root port as 38 + * two bandwidth domains, one for IN eps and another for OUT eps. 39 + */ 40 + struct mu3h_sch_bw_info { 41 + u32 bus_bw[XHCI_MTK_MAX_ESIT]; 42 + struct list_head bw_ep_list; 43 + }; 44 + 45 + /** 46 + * struct mu3h_sch_ep_info: schedule information for endpoint 47 + * 48 + * @esit: unit is 125us, equal to 2 << Interval field in ep-context 49 + * @num_budget_microframes: number of continuous uframes 50 + * (@repeat==1) scheduled within the interval 51 + * @bw_cost_per_microframe: bandwidth cost per microframe 52 + * @endpoint: linked into bandwidth domain which it belongs to 53 + * @ep: address of usb_host_endpoint struct 54 + * @offset: which uframe of the interval that transfer should be 55 + * scheduled first time within the interval 56 + * @repeat: the time gap between two uframes that transfers are 57 + * scheduled within a interval. in the simple algorithm, only 58 + * assign 0 or 1 to it; 0 means using only one uframe in a 59 + * interval, and 1 means using @num_budget_microframes 60 + * continuous uframes 61 + * @pkts: number of packets to be transferred in the scheduled uframes 62 + * @cs_count: number of CS that host will trigger 63 + * @burst_mode: burst mode for scheduling. 0: normal burst mode, 64 + * distribute the bMaxBurst+1 packets for a single burst 65 + * according to @pkts and @repeat, repeate the burst multiple 66 + * times; 1: distribute the (bMaxBurst+1)*(Mult+1) packets 67 + * according to @pkts and @repeat. normal mode is used by 68 + * default 69 + */ 70 + struct mu3h_sch_ep_info { 71 + u32 esit; 72 + u32 num_budget_microframes; 73 + u32 bw_cost_per_microframe; 74 + struct list_head endpoint; 75 + void *ep; 76 + /* 77 + * mtk xHCI scheduling information put into reserved DWs 78 + * in ep context 79 + */ 80 + u32 offset; 81 + u32 repeat; 82 + u32 pkts; 83 + u32 cs_count; 84 + u32 burst_mode; 85 + }; 86 + 87 + #define MU3C_U3_PORT_MAX 4 88 + #define MU3C_U2_PORT_MAX 5 89 + 90 + /** 91 + * struct mu3c_ippc_regs: MTK ssusb ip port control registers 92 + * @ip_pw_ctr0~3: ip power and clock control registers 93 + * @ip_pw_sts1~2: ip power and clock status registers 94 + * @ip_xhci_cap: ip xHCI capability register 95 + * @u3_ctrl_p[x]: ip usb3 port x control register, only low 4bytes are used 96 + * @u2_ctrl_p[x]: ip usb2 port x control register, only low 4bytes are used 97 + * @u2_phy_pll: usb2 phy pll control register 98 + */ 99 + struct mu3c_ippc_regs { 100 + __le32 ip_pw_ctr0; 101 + __le32 ip_pw_ctr1; 102 + __le32 ip_pw_ctr2; 103 + __le32 ip_pw_ctr3; 104 + __le32 ip_pw_sts1; 105 + __le32 ip_pw_sts2; 106 + __le32 reserved0[3]; 107 + __le32 ip_xhci_cap; 108 + __le32 reserved1[2]; 109 + __le64 u3_ctrl_p[MU3C_U3_PORT_MAX]; 110 + __le64 u2_ctrl_p[MU3C_U2_PORT_MAX]; 111 + __le32 reserved2; 112 + __le32 u2_phy_pll; 113 + __le32 reserved3[33]; /* 0x80 ~ 0xff */ 114 + }; 115 + 116 + struct xhci_hcd_mtk { 117 + struct device *dev; 118 + struct usb_hcd *hcd; 119 + struct mu3h_sch_bw_info *sch_array; 120 + struct mu3c_ippc_regs __iomem *ippc_regs; 121 + int num_u2_ports; 122 + int num_u3_ports; 123 + struct regulator *vusb33; 124 + struct regulator *vbus; 125 + struct clk *sys_clk; /* sys and mac clock */ 126 + struct clk *wk_deb_p0; /* port0's wakeup debounce clock */ 127 + struct clk *wk_deb_p1; 128 + struct regmap *pericfg; 129 + struct phy **phys; 130 + int num_phys; 131 + int wakeup_src; 132 + bool lpm_support; 133 + }; 134 + 135 + static inline struct xhci_hcd_mtk *hcd_to_mtk(struct usb_hcd *hcd) 136 + { 137 + return dev_get_drvdata(hcd->self.controller); 138 + } 139 + 140 + #if IS_ENABLED(CONFIG_USB_XHCI_MTK) 141 + int xhci_mtk_sch_init(struct xhci_hcd_mtk *mtk); 142 + void xhci_mtk_sch_exit(struct xhci_hcd_mtk *mtk); 143 + int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev, 144 + struct usb_host_endpoint *ep); 145 + void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd, struct usb_device *udev, 146 + struct usb_host_endpoint *ep); 147 + 148 + #else 149 + static inline int xhci_mtk_add_ep_quirk(struct usb_hcd *hcd, 150 + struct usb_device *udev, struct usb_host_endpoint *ep) 151 + { 152 + return 0; 153 + } 154 + 155 + static inline void xhci_mtk_drop_ep_quirk(struct usb_hcd *hcd, 156 + struct usb_device *udev, struct usb_host_endpoint *ep) 157 + { 158 + } 159 + 160 + #endif 161 + 162 + #endif /* _XHCI_MTK_H_ */
-1
drivers/usb/host/xhci-pci.c
··· 53 53 static int xhci_pci_setup(struct usb_hcd *hcd); 54 54 55 55 static const struct xhci_driver_overrides xhci_pci_overrides __initconst = { 56 - .extra_priv_size = sizeof(struct xhci_hcd), 57 56 .reset = xhci_pci_setup, 58 57 }; 59 58
+62 -26
drivers/usb/host/xhci-plat.c
··· 22 22 #include <linux/acpi.h> 23 23 24 24 #include "xhci.h" 25 + #include "xhci-plat.h" 25 26 #include "xhci-mvebu.h" 26 27 #include "xhci-rcar.h" 27 28 ··· 32 31 static int xhci_plat_start(struct usb_hcd *hcd); 33 32 34 33 static const struct xhci_driver_overrides xhci_plat_overrides __initconst = { 35 - .extra_priv_size = sizeof(struct xhci_hcd), 34 + .extra_priv_size = sizeof(struct xhci_plat_priv), 36 35 .reset = xhci_plat_setup, 37 36 .start = xhci_plat_start, 38 37 }; ··· 50 49 /* called during probe() after chip reset completes */ 51 50 static int xhci_plat_setup(struct usb_hcd *hcd) 52 51 { 53 - struct device_node *of_node = hcd->self.controller->of_node; 54 52 int ret; 55 53 56 - if (of_device_is_compatible(of_node, "renesas,xhci-r8a7790") || 57 - of_device_is_compatible(of_node, "renesas,xhci-r8a7791")) { 54 + if (xhci_plat_type_is(hcd, XHCI_PLAT_TYPE_RENESAS_RCAR_GEN2) || 55 + xhci_plat_type_is(hcd, XHCI_PLAT_TYPE_RENESAS_RCAR_GEN3)) { 58 56 ret = xhci_rcar_init_quirk(hcd); 59 57 if (ret) 60 58 return ret; ··· 64 64 65 65 static int xhci_plat_start(struct usb_hcd *hcd) 66 66 { 67 - struct device_node *of_node = hcd->self.controller->of_node; 68 - 69 - if (of_device_is_compatible(of_node, "renesas,xhci-r8a7790") || 70 - of_device_is_compatible(of_node, "renesas,xhci-r8a7791")) 67 + if (xhci_plat_type_is(hcd, XHCI_PLAT_TYPE_RENESAS_RCAR_GEN2) || 68 + xhci_plat_type_is(hcd, XHCI_PLAT_TYPE_RENESAS_RCAR_GEN3)) 71 69 xhci_rcar_start(hcd); 72 70 73 71 return xhci_run(hcd); 74 72 } 75 73 74 + #ifdef CONFIG_OF 75 + static const struct xhci_plat_priv xhci_plat_marvell_armada = { 76 + .type = XHCI_PLAT_TYPE_MARVELL_ARMADA, 77 + }; 78 + 79 + static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen2 = { 80 + .type = XHCI_PLAT_TYPE_RENESAS_RCAR_GEN2, 81 + .firmware_name = XHCI_RCAR_FIRMWARE_NAME_V1, 82 + }; 83 + 84 + static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen3 = { 85 + .type = XHCI_PLAT_TYPE_RENESAS_RCAR_GEN3, 86 + .firmware_name = XHCI_RCAR_FIRMWARE_NAME_V2, 87 + }; 88 + 89 + static const struct of_device_id usb_xhci_of_match[] = { 90 + { 91 + .compatible = "generic-xhci", 92 + }, { 93 + .compatible = "xhci-platform", 94 + }, { 95 + .compatible = "marvell,armada-375-xhci", 96 + .data = &xhci_plat_marvell_armada, 97 + }, { 98 + .compatible = "marvell,armada-380-xhci", 99 + .data = &xhci_plat_marvell_armada, 100 + }, { 101 + .compatible = "renesas,xhci-r8a7790", 102 + .data = &xhci_plat_renesas_rcar_gen2, 103 + }, { 104 + .compatible = "renesas,xhci-r8a7791", 105 + .data = &xhci_plat_renesas_rcar_gen2, 106 + }, { 107 + .compatible = "renesas,xhci-r8a7793", 108 + .data = &xhci_plat_renesas_rcar_gen2, 109 + }, { 110 + .compatible = "renesas,xhci-r8a7795", 111 + .data = &xhci_plat_renesas_rcar_gen3, 112 + }, { 113 + }, 114 + }; 115 + MODULE_DEVICE_TABLE(of, usb_xhci_of_match); 116 + #endif 117 + 76 118 static int xhci_plat_probe(struct platform_device *pdev) 77 119 { 78 120 struct device_node *node = pdev->dev.of_node; 79 121 struct usb_xhci_pdata *pdata = dev_get_platdata(&pdev->dev); 122 + const struct of_device_id *match; 80 123 const struct hc_driver *driver; 81 124 struct xhci_hcd *xhci; 82 125 struct resource *res; ··· 177 134 goto put_hcd; 178 135 } 179 136 180 - if (of_device_is_compatible(pdev->dev.of_node, 181 - "marvell,armada-375-xhci") || 182 - of_device_is_compatible(pdev->dev.of_node, 183 - "marvell,armada-380-xhci")) { 137 + xhci = hcd_to_xhci(hcd); 138 + match = of_match_node(usb_xhci_of_match, node); 139 + if (match) { 140 + const struct xhci_plat_priv *priv_match = match->data; 141 + struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); 142 + 143 + /* Just copy data for now */ 144 + *priv = *priv_match; 145 + } 146 + 147 + if (xhci_plat_type_is(hcd, XHCI_PLAT_TYPE_MARVELL_ARMADA)) { 184 148 ret = xhci_mvebu_mbus_init_quirk(pdev); 185 149 if (ret) 186 150 goto disable_clk; ··· 195 145 196 146 device_wakeup_enable(hcd->self.controller); 197 147 198 - xhci = hcd_to_xhci(hcd); 199 148 xhci->clk = clk; 200 149 xhci->main_hcd = hcd; 201 150 xhci->shared_hcd = usb_create_shared_hcd(driver, &pdev->dev, ··· 304 255 #else 305 256 #define DEV_PM_OPS NULL 306 257 #endif /* CONFIG_PM */ 307 - 308 - #ifdef CONFIG_OF 309 - static const struct of_device_id usb_xhci_of_match[] = { 310 - { .compatible = "generic-xhci" }, 311 - { .compatible = "xhci-platform" }, 312 - { .compatible = "marvell,armada-375-xhci"}, 313 - { .compatible = "marvell,armada-380-xhci"}, 314 - { .compatible = "renesas,xhci-r8a7790"}, 315 - { .compatible = "renesas,xhci-r8a7791"}, 316 - { }, 317 - }; 318 - MODULE_DEVICE_TABLE(of, usb_xhci_of_match); 319 - #endif 320 258 321 259 static const struct acpi_device_id usb_xhci_acpi_match[] = { 322 260 /* XHCI-compliant USB Controller */
+39
drivers/usb/host/xhci-plat.h
··· 1 + /* 2 + * xhci-plat.h - xHCI host controller driver platform Bus Glue. 3 + * 4 + * Copyright (C) 2015 Renesas Electronics Corporation 5 + * 6 + * This program is free software; you can redistribute it and/or 7 + * modify it under the terms of the GNU General Public License 8 + * version 2 as published by the Free Software Foundation. 9 + */ 10 + 11 + #ifndef _XHCI_PLAT_H 12 + #define _XHCI_PLAT_H 13 + 14 + #include "xhci.h" /* for hcd_to_xhci() */ 15 + 16 + enum xhci_plat_type { 17 + XHCI_PLAT_TYPE_MARVELL_ARMADA, 18 + XHCI_PLAT_TYPE_RENESAS_RCAR_GEN2, 19 + XHCI_PLAT_TYPE_RENESAS_RCAR_GEN3, 20 + }; 21 + 22 + struct xhci_plat_priv { 23 + enum xhci_plat_type type; 24 + const char *firmware_name; 25 + }; 26 + 27 + #define hcd_to_xhci_priv(h) ((struct xhci_plat_priv *)hcd_to_xhci(h)->priv) 28 + 29 + static inline bool xhci_plat_type_is(struct usb_hcd *hcd, 30 + enum xhci_plat_type type) 31 + { 32 + struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); 33 + 34 + if (priv && priv->type == type) 35 + return true; 36 + else 37 + return false; 38 + } 39 + #endif /* _XHCI_PLAT_H */
+30 -14
drivers/usb/host/xhci-rcar.c
··· 14 14 #include <linux/usb/phy.h> 15 15 16 16 #include "xhci.h" 17 + #include "xhci-plat.h" 17 18 #include "xhci-rcar.h" 18 19 19 - #define FIRMWARE_NAME "r8a779x_usb3_v1.dlmem" 20 - MODULE_FIRMWARE(FIRMWARE_NAME); 20 + /* 21 + * - The V2 firmware is possible to use on R-Car Gen2. However, the V2 causes 22 + * performance degradation. So, this driver continues to use the V1 if R-Car 23 + * Gen2. 24 + * - The V1 firmware is impossible to use on R-Car Gen3. 25 + */ 26 + MODULE_FIRMWARE(XHCI_RCAR_FIRMWARE_NAME_V1); 27 + MODULE_FIRMWARE(XHCI_RCAR_FIRMWARE_NAME_V2); 21 28 22 29 /*** Register Offset ***/ 23 30 #define RCAR_USB3_INT_ENA 0x224 /* Interrupt Enable */ ··· 63 56 #define RCAR_USB3_RX_POL_VAL BIT(21) 64 57 #define RCAR_USB3_TX_POL_VAL BIT(4) 65 58 59 + static void xhci_rcar_start_gen2(struct usb_hcd *hcd) 60 + { 61 + /* LCLK Select */ 62 + writel(RCAR_USB3_LCLK_ENA_VAL, hcd->regs + RCAR_USB3_LCLK); 63 + /* USB3.0 Configuration */ 64 + writel(RCAR_USB3_CONF1_VAL, hcd->regs + RCAR_USB3_CONF1); 65 + writel(RCAR_USB3_CONF2_VAL, hcd->regs + RCAR_USB3_CONF2); 66 + writel(RCAR_USB3_CONF3_VAL, hcd->regs + RCAR_USB3_CONF3); 67 + /* USB3.0 Polarity */ 68 + writel(RCAR_USB3_RX_POL_VAL, hcd->regs + RCAR_USB3_RX_POL); 69 + writel(RCAR_USB3_TX_POL_VAL, hcd->regs + RCAR_USB3_TX_POL); 70 + } 71 + 66 72 void xhci_rcar_start(struct usb_hcd *hcd) 67 73 { 68 74 u32 temp; ··· 85 65 temp = readl(hcd->regs + RCAR_USB3_INT_ENA); 86 66 temp |= RCAR_USB3_INT_ENA_VAL; 87 67 writel(temp, hcd->regs + RCAR_USB3_INT_ENA); 88 - /* LCLK Select */ 89 - writel(RCAR_USB3_LCLK_ENA_VAL, hcd->regs + RCAR_USB3_LCLK); 90 - /* USB3.0 Configuration */ 91 - writel(RCAR_USB3_CONF1_VAL, hcd->regs + RCAR_USB3_CONF1); 92 - writel(RCAR_USB3_CONF2_VAL, hcd->regs + RCAR_USB3_CONF2); 93 - writel(RCAR_USB3_CONF3_VAL, hcd->regs + RCAR_USB3_CONF3); 94 - /* USB3.0 Polarity */ 95 - writel(RCAR_USB3_RX_POL_VAL, hcd->regs + RCAR_USB3_RX_POL); 96 - writel(RCAR_USB3_TX_POL_VAL, hcd->regs + RCAR_USB3_TX_POL); 68 + if (xhci_plat_type_is(hcd, XHCI_PLAT_TYPE_RENESAS_RCAR_GEN2)) 69 + xhci_rcar_start_gen2(hcd); 97 70 } 98 71 } 99 72 100 - static int xhci_rcar_download_firmware(struct device *dev, void __iomem *regs) 73 + static int xhci_rcar_download_firmware(struct usb_hcd *hcd) 101 74 { 75 + struct device *dev = hcd->self.controller; 76 + void __iomem *regs = hcd->regs; 77 + struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); 102 78 const struct firmware *fw; 103 79 int retval, index, j, time; 104 80 int timeout = 10000; 105 81 u32 data, val, temp; 106 82 107 83 /* request R-Car USB3.0 firmware */ 108 - retval = request_firmware(&fw, FIRMWARE_NAME, dev); 84 + retval = request_firmware(&fw, priv->firmware_name, dev); 109 85 if (retval) 110 86 return retval; 111 87 ··· 160 144 if (!hcd->regs) 161 145 return 0; 162 146 163 - return xhci_rcar_download_firmware(hcd->self.controller, hcd->regs); 147 + return xhci_rcar_download_firmware(hcd); 164 148 }
+3
drivers/usb/host/xhci-rcar.h
··· 11 11 #ifndef _XHCI_RCAR_H 12 12 #define _XHCI_RCAR_H 13 13 14 + #define XHCI_RCAR_FIRMWARE_NAME_V1 "r8a779x_usb3_v1.dlmem" 15 + #define XHCI_RCAR_FIRMWARE_NAME_V2 "r8a779x_usb3_v2.dlmem" 16 + 14 17 #if IS_ENABLED(CONFIG_USB_XHCI_RCAR) 15 18 void xhci_rcar_start(struct usb_hcd *hcd); 16 19 int xhci_rcar_init_quirk(struct usb_hcd *hcd);
+11 -5
drivers/usb/host/xhci-ring.c
··· 68 68 #include <linux/slab.h> 69 69 #include "xhci.h" 70 70 #include "xhci-trace.h" 71 + #include "xhci-mtk.h" 71 72 72 73 /* 73 74 * Returns zero if the TRB isn't in this segment, otherwise it returns the DMA ··· 3076 3075 { 3077 3076 u32 maxp, total_packet_count; 3078 3077 3079 - if (xhci->hci_version < 0x100) 3078 + /* MTK xHCI is mostly 0.97 but contains some features from 1.0 */ 3079 + if (xhci->hci_version < 0x100 && !(xhci->quirks & XHCI_MTK_HOST)) 3080 3080 return ((td_total_len - transferred) >> 10); 3081 - 3082 - maxp = GET_MAX_PACKET(usb_endpoint_maxp(&urb->ep->desc)); 3083 - total_packet_count = DIV_ROUND_UP(td_total_len, maxp); 3084 3081 3085 3082 /* One TRB with a zero-length data packet. */ 3086 3083 if (num_trbs_left == 0 || (transferred == 0 && trb_buff_len == 0) || 3087 3084 trb_buff_len == td_total_len) 3088 3085 return 0; 3086 + 3087 + /* for MTK xHCI, TD size doesn't include this TRB */ 3088 + if (xhci->quirks & XHCI_MTK_HOST) 3089 + trb_buff_len = 0; 3090 + 3091 + maxp = GET_MAX_PACKET(usb_endpoint_maxp(&urb->ep->desc)); 3092 + total_packet_count = DIV_ROUND_UP(td_total_len, maxp); 3089 3093 3090 3094 /* Queueing functions don't count the current TRB into transferred */ 3091 3095 return (total_packet_count - ((transferred + trb_buff_len) / maxp)); ··· 3479 3473 field |= 0x1; 3480 3474 3481 3475 /* xHCI 1.0/1.1 6.4.1.2.1: Transfer Type field */ 3482 - if (xhci->hci_version >= 0x100) { 3476 + if ((xhci->hci_version >= 0x100) || (xhci->quirks & XHCI_MTK_HOST)) { 3483 3477 if (urb->transfer_buffer_length > 0) { 3484 3478 if (setup->bRequestType & USB_DIR_IN) 3485 3479 field |= TRB_TX_TYPE(TRB_DATA_IN);
+23 -2
drivers/usb/host/xhci.c
··· 31 31 32 32 #include "xhci.h" 33 33 #include "xhci-trace.h" 34 + #include "xhci-mtk.h" 34 35 35 36 #define DRIVER_AUTHOR "Sarah Sharp" 36 37 #define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver" ··· 635 634 "// Set the interrupt modulation register"); 636 635 temp = readl(&xhci->ir_set->irq_control); 637 636 temp &= ~ER_IRQ_INTERVAL_MASK; 638 - temp |= (u32) 160; 637 + /* 638 + * the increment interval is 8 times as much as that defined 639 + * in xHCI spec on MTK's controller 640 + */ 641 + temp |= (u32) ((xhci->quirks & XHCI_MTK_HOST) ? 20 : 160); 639 642 writel(temp, &xhci->ir_set->irq_control); 640 643 641 644 /* Set the HCD state before we enable the irqs */ ··· 1703 1698 1704 1699 xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep); 1705 1700 1701 + if (xhci->quirks & XHCI_MTK_HOST) 1702 + xhci_mtk_drop_ep_quirk(hcd, udev, ep); 1703 + 1706 1704 xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add flags = %#x\n", 1707 1705 (unsigned int) ep->desc.bEndpointAddress, 1708 1706 udev->slot_id, ··· 1799 1791 dev_dbg(&udev->dev, "%s - could not initialize ep %#x\n", 1800 1792 __func__, ep->desc.bEndpointAddress); 1801 1793 return -ENOMEM; 1794 + } 1795 + 1796 + if (xhci->quirks & XHCI_MTK_HOST) { 1797 + ret = xhci_mtk_add_ep_quirk(hcd, udev, ep); 1798 + if (ret < 0) { 1799 + xhci_free_or_cache_endpoint_ring(xhci, 1800 + virt_dev, ep_index); 1801 + return ret; 1802 + } 1802 1803 } 1803 1804 1804 1805 ctrl_ctx->add_flags |= cpu_to_le32(added_ctxs); ··· 4977 4960 static const struct hc_driver xhci_hc_driver = { 4978 4961 .description = "xhci-hcd", 4979 4962 .product_desc = "xHCI Host Controller", 4980 - .hcd_priv_size = sizeof(struct xhci_hcd *), 4963 + .hcd_priv_size = sizeof(struct xhci_hcd), 4981 4964 4982 4965 /* 4983 4966 * generic hardware linkage ··· 5076 5059 BUILD_BUG_ON(sizeof(struct xhci_intr_reg) != 8*32/8); 5077 5060 /* xhci_run_regs has eight fields and embeds 128 xhci_intr_regs */ 5078 5061 BUILD_BUG_ON(sizeof(struct xhci_run_regs) != (8+8*128)*32/8); 5062 + 5063 + if (usb_disabled()) 5064 + return -ENODEV; 5065 + 5079 5066 return 0; 5080 5067 } 5081 5068
+4
drivers/usb/host/xhci.h
··· 1630 1630 /* For controllers with a broken beyond repair streams implementation */ 1631 1631 #define XHCI_BROKEN_STREAMS (1 << 19) 1632 1632 #define XHCI_PME_STUCK_QUIRK (1 << 20) 1633 + #define XHCI_MTK_HOST (1 << 21) 1633 1634 unsigned int num_active_eps; 1634 1635 unsigned int limit_active_eps; 1635 1636 /* There are two roothubs to keep track of bus suspend info for */ ··· 1657 1656 u32 port_status_u0; 1658 1657 /* Compliance Mode Timer Triggered every 2 seconds */ 1659 1658 #define COMP_MODE_RCVRY_MSECS 2000 1659 + 1660 + /* platform-specific data -- must come last */ 1661 + unsigned long priv[0] __aligned(sizeof(s64)); 1660 1662 }; 1661 1663 1662 1664 /* Platform specific overrides to generic XHCI hc_driver ops */
+149 -84
drivers/usb/misc/usbtest.c
··· 22 22 /*-------------------------------------------------------------------------*/ 23 23 24 24 /* FIXME make these public somewhere; usbdevfs.h? */ 25 - struct usbtest_param { 25 + 26 + /* Parameter for usbtest driver. */ 27 + struct usbtest_param_32 { 26 28 /* inputs */ 27 - unsigned test_num; /* 0..(TEST_CASES-1) */ 28 - unsigned iterations; 29 - unsigned length; 30 - unsigned vary; 31 - unsigned sglen; 29 + __u32 test_num; /* 0..(TEST_CASES-1) */ 30 + __u32 iterations; 31 + __u32 length; 32 + __u32 vary; 33 + __u32 sglen; 32 34 33 35 /* outputs */ 34 - struct timeval duration; 36 + __s32 duration_sec; 37 + __s32 duration_usec; 35 38 }; 36 - #define USBTEST_REQUEST _IOWR('U', 100, struct usbtest_param) 39 + 40 + /* 41 + * Compat parameter to the usbtest driver. 42 + * This supports older user space binaries compiled with 64 bit compiler. 43 + */ 44 + struct usbtest_param_64 { 45 + /* inputs */ 46 + __u32 test_num; /* 0..(TEST_CASES-1) */ 47 + __u32 iterations; 48 + __u32 length; 49 + __u32 vary; 50 + __u32 sglen; 51 + 52 + /* outputs */ 53 + __s64 duration_sec; 54 + __s64 duration_usec; 55 + }; 56 + 57 + /* IOCTL interface to the driver. */ 58 + #define USBTEST_REQUEST_32 _IOWR('U', 100, struct usbtest_param_32) 59 + /* COMPAT IOCTL interface to the driver. */ 60 + #define USBTEST_REQUEST_64 _IOWR('U', 100, struct usbtest_param_64) 37 61 38 62 /*-------------------------------------------------------------------------*/ 39 63 ··· 1054 1030 unsigned pending; 1055 1031 int status; 1056 1032 struct urb **urb; 1057 - struct usbtest_param *param; 1033 + struct usbtest_param_32 *param; 1058 1034 int last; 1059 1035 }; 1060 1036 ··· 1179 1155 } 1180 1156 1181 1157 static int 1182 - test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param *param) 1158 + test_ctrl_queue(struct usbtest_dev *dev, struct usbtest_param_32 *param) 1183 1159 { 1184 1160 struct usb_device *udev = testdev_to_usbdev(dev); 1185 1161 struct urb **urb; ··· 1873 1849 goto done; 1874 1850 default: 1875 1851 dev_err(&ctx->dev->intf->dev, 1876 - "iso resubmit err %d\n", 1852 + "resubmit err %d\n", 1877 1853 status); 1878 1854 /* FALLTHROUGH */ 1879 1855 case -ENODEV: /* disconnected */ ··· 1887 1863 if (ctx->pending == 0) { 1888 1864 if (ctx->errors) 1889 1865 dev_err(&ctx->dev->intf->dev, 1890 - "iso test, %lu errors out of %lu\n", 1866 + "during the test, %lu errors out of %lu\n", 1891 1867 ctx->errors, ctx->packet_count); 1892 1868 complete(&ctx->done); 1893 1869 } ··· 1954 1930 } 1955 1931 1956 1932 static int 1957 - test_queue(struct usbtest_dev *dev, struct usbtest_param *param, 1933 + test_queue(struct usbtest_dev *dev, struct usbtest_param_32 *param, 1958 1934 int pipe, struct usb_endpoint_descriptor *desc, unsigned offset) 1959 1935 { 1960 1936 struct transfer_context context; ··· 2073 2049 return retval; 2074 2050 } 2075 2051 2076 - /*-------------------------------------------------------------------------*/ 2077 - 2078 - /* We only have this one interface to user space, through usbfs. 2079 - * User mode code can scan usbfs to find N different devices (maybe on 2080 - * different busses) to use when testing, and allocate one thread per 2081 - * test. So discovery is simplified, and we have no device naming issues. 2082 - * 2083 - * Don't use these only as stress/load tests. Use them along with with 2084 - * other USB bus activity: plugging, unplugging, mousing, mp3 playback, 2085 - * video capture, and so on. Run different tests at different times, in 2086 - * different sequences. Nothing here should interact with other devices, 2087 - * except indirectly by consuming USB bandwidth and CPU resources for test 2088 - * threads and request completion. But the only way to know that for sure 2089 - * is to test when HC queues are in use by many devices. 2090 - * 2091 - * WARNING: Because usbfs grabs udev->dev.sem before calling this ioctl(), 2092 - * it locks out usbcore in certain code paths. Notably, if you disconnect 2093 - * the device-under-test, hub_wq will wait block forever waiting for the 2094 - * ioctl to complete ... so that usb_disconnect() can abort the pending 2095 - * urbs and then call usbtest_disconnect(). To abort a test, you're best 2096 - * off just killing the userspace task and waiting for it to exit. 2097 - */ 2098 - 2052 + /* Run tests. */ 2099 2053 static int 2100 - usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf) 2054 + usbtest_do_ioctl(struct usb_interface *intf, struct usbtest_param_32 *param) 2101 2055 { 2102 2056 struct usbtest_dev *dev = usb_get_intfdata(intf); 2103 2057 struct usb_device *udev = testdev_to_usbdev(dev); 2104 - struct usbtest_param *param = buf; 2105 - int retval = -EOPNOTSUPP; 2106 2058 struct urb *urb; 2107 2059 struct scatterlist *sg; 2108 2060 struct usb_sg_request req; 2109 - struct timeval start; 2110 2061 unsigned i; 2111 - 2112 - /* FIXME USBDEVFS_CONNECTINFO doesn't say how fast the device is. */ 2113 - 2114 - pattern = mod_pattern; 2115 - 2116 - if (code != USBTEST_REQUEST) 2117 - return -EOPNOTSUPP; 2062 + int retval = -EOPNOTSUPP; 2118 2063 2119 2064 if (param->iterations <= 0) 2120 2065 return -EINVAL; 2121 - 2122 - if (param->sglen > MAX_SGLEN) 2123 - return -EINVAL; 2124 - 2125 - if (mutex_lock_interruptible(&dev->lock)) 2126 - return -ERESTARTSYS; 2127 - 2128 - /* FIXME: What if a system sleep starts while a test is running? */ 2129 - 2130 - /* some devices, like ez-usb default devices, need a non-default 2131 - * altsetting to have any active endpoints. some tests change 2132 - * altsettings; force a default so most tests don't need to check. 2133 - */ 2134 - if (dev->info->alt >= 0) { 2135 - int res; 2136 - 2137 - if (intf->altsetting->desc.bInterfaceNumber) { 2138 - mutex_unlock(&dev->lock); 2139 - return -ENODEV; 2140 - } 2141 - res = set_altsetting(dev, dev->info->alt); 2142 - if (res) { 2143 - dev_err(&intf->dev, 2144 - "set altsetting to %d failed, %d\n", 2145 - dev->info->alt, res); 2146 - mutex_unlock(&dev->lock); 2147 - return res; 2148 - } 2149 - } 2150 - 2151 2066 /* 2152 2067 * Just a bunch of test cases that every HCD is expected to handle. 2153 2068 * ··· 2096 2133 * FIXME add more tests! cancel requests, verify the data, control 2097 2134 * queueing, concurrent read+write threads, and so on. 2098 2135 */ 2099 - do_gettimeofday(&start); 2100 2136 switch (param->test_num) { 2101 2137 2102 2138 case 0: ··· 2510 2548 dev->in_pipe, NULL, 0); 2511 2549 break; 2512 2550 } 2513 - do_gettimeofday(&param->duration); 2514 - param->duration.tv_sec -= start.tv_sec; 2515 - param->duration.tv_usec -= start.tv_usec; 2516 - if (param->duration.tv_usec < 0) { 2517 - param->duration.tv_usec += 1000 * 1000; 2518 - param->duration.tv_sec -= 1; 2551 + return retval; 2552 + } 2553 + 2554 + /*-------------------------------------------------------------------------*/ 2555 + 2556 + /* We only have this one interface to user space, through usbfs. 2557 + * User mode code can scan usbfs to find N different devices (maybe on 2558 + * different busses) to use when testing, and allocate one thread per 2559 + * test. So discovery is simplified, and we have no device naming issues. 2560 + * 2561 + * Don't use these only as stress/load tests. Use them along with with 2562 + * other USB bus activity: plugging, unplugging, mousing, mp3 playback, 2563 + * video capture, and so on. Run different tests at different times, in 2564 + * different sequences. Nothing here should interact with other devices, 2565 + * except indirectly by consuming USB bandwidth and CPU resources for test 2566 + * threads and request completion. But the only way to know that for sure 2567 + * is to test when HC queues are in use by many devices. 2568 + * 2569 + * WARNING: Because usbfs grabs udev->dev.sem before calling this ioctl(), 2570 + * it locks out usbcore in certain code paths. Notably, if you disconnect 2571 + * the device-under-test, hub_wq will wait block forever waiting for the 2572 + * ioctl to complete ... so that usb_disconnect() can abort the pending 2573 + * urbs and then call usbtest_disconnect(). To abort a test, you're best 2574 + * off just killing the userspace task and waiting for it to exit. 2575 + */ 2576 + 2577 + static int 2578 + usbtest_ioctl(struct usb_interface *intf, unsigned int code, void *buf) 2579 + { 2580 + 2581 + struct usbtest_dev *dev = usb_get_intfdata(intf); 2582 + struct usbtest_param_64 *param_64 = buf; 2583 + struct usbtest_param_32 temp; 2584 + struct usbtest_param_32 *param_32 = buf; 2585 + struct timespec64 start; 2586 + struct timespec64 end; 2587 + struct timespec64 duration; 2588 + int retval = -EOPNOTSUPP; 2589 + 2590 + /* FIXME USBDEVFS_CONNECTINFO doesn't say how fast the device is. */ 2591 + 2592 + pattern = mod_pattern; 2593 + 2594 + if (mutex_lock_interruptible(&dev->lock)) 2595 + return -ERESTARTSYS; 2596 + 2597 + /* FIXME: What if a system sleep starts while a test is running? */ 2598 + 2599 + /* some devices, like ez-usb default devices, need a non-default 2600 + * altsetting to have any active endpoints. some tests change 2601 + * altsettings; force a default so most tests don't need to check. 2602 + */ 2603 + if (dev->info->alt >= 0) { 2604 + if (intf->altsetting->desc.bInterfaceNumber) { 2605 + retval = -ENODEV; 2606 + goto free_mutex; 2607 + } 2608 + retval = set_altsetting(dev, dev->info->alt); 2609 + if (retval) { 2610 + dev_err(&intf->dev, 2611 + "set altsetting to %d failed, %d\n", 2612 + dev->info->alt, retval); 2613 + goto free_mutex; 2614 + } 2519 2615 } 2616 + 2617 + switch (code) { 2618 + case USBTEST_REQUEST_64: 2619 + temp.test_num = param_64->test_num; 2620 + temp.iterations = param_64->iterations; 2621 + temp.length = param_64->length; 2622 + temp.sglen = param_64->sglen; 2623 + temp.vary = param_64->vary; 2624 + param_32 = &temp; 2625 + break; 2626 + 2627 + case USBTEST_REQUEST_32: 2628 + break; 2629 + 2630 + default: 2631 + retval = -EOPNOTSUPP; 2632 + goto free_mutex; 2633 + } 2634 + 2635 + ktime_get_ts64(&start); 2636 + 2637 + retval = usbtest_do_ioctl(intf, param_32); 2638 + if (retval) 2639 + goto free_mutex; 2640 + 2641 + ktime_get_ts64(&end); 2642 + 2643 + duration = timespec64_sub(end, start); 2644 + 2645 + temp.duration_sec = duration.tv_sec; 2646 + temp.duration_usec = duration.tv_nsec/NSEC_PER_USEC; 2647 + 2648 + switch (code) { 2649 + case USBTEST_REQUEST_32: 2650 + param_32->duration_sec = temp.duration_sec; 2651 + param_32->duration_usec = temp.duration_usec; 2652 + break; 2653 + 2654 + case USBTEST_REQUEST_64: 2655 + param_64->duration_sec = temp.duration_sec; 2656 + param_64->duration_usec = temp.duration_usec; 2657 + break; 2658 + } 2659 + 2660 + free_mutex: 2520 2661 mutex_unlock(&dev->lock); 2521 2662 return retval; 2522 2663 }
+9 -8
drivers/usb/mon/mon_bin.c
··· 18 18 #include <linux/mm.h> 19 19 #include <linux/scatterlist.h> 20 20 #include <linux/slab.h> 21 + #include <linux/time64.h> 21 22 22 23 #include <asm/uaccess.h> 23 24 ··· 93 92 unsigned short busnum; /* Bus number */ 94 93 char flag_setup; 95 94 char flag_data; 96 - s64 ts_sec; /* gettimeofday */ 97 - s32 ts_usec; /* gettimeofday */ 95 + s64 ts_sec; /* getnstimeofday64 */ 96 + s32 ts_usec; /* getnstimeofday64 */ 98 97 int status; 99 98 unsigned int len_urb; /* Length of data (submitted or actual) */ 100 99 unsigned int len_cap; /* Delivered length */ ··· 484 483 char ev_type, int status) 485 484 { 486 485 const struct usb_endpoint_descriptor *epd = &urb->ep->desc; 487 - struct timeval ts; 486 + struct timespec64 ts; 488 487 unsigned long flags; 489 488 unsigned int urb_length; 490 489 unsigned int offset; ··· 495 494 struct mon_bin_hdr *ep; 496 495 char data_tag = 0; 497 496 498 - do_gettimeofday(&ts); 497 + getnstimeofday64(&ts); 499 498 500 499 spin_lock_irqsave(&rp->b_lock, flags); 501 500 ··· 569 568 ep->busnum = urb->dev->bus->busnum; 570 569 ep->id = (unsigned long) urb; 571 570 ep->ts_sec = ts.tv_sec; 572 - ep->ts_usec = ts.tv_usec; 571 + ep->ts_usec = ts.tv_nsec / NSEC_PER_USEC; 573 572 ep->status = status; 574 573 ep->len_urb = urb_length; 575 574 ep->len_cap = length + lendesc; ··· 630 629 static void mon_bin_error(void *data, struct urb *urb, int error) 631 630 { 632 631 struct mon_reader_bin *rp = data; 633 - struct timeval ts; 632 + struct timespec64 ts; 634 633 unsigned long flags; 635 634 unsigned int offset; 636 635 struct mon_bin_hdr *ep; 637 636 638 - do_gettimeofday(&ts); 637 + getnstimeofday64(&ts); 639 638 640 639 spin_lock_irqsave(&rp->b_lock, flags); 641 640 ··· 657 656 ep->busnum = urb->dev->bus->busnum; 658 657 ep->id = (unsigned long) urb; 659 658 ep->ts_sec = ts.tv_sec; 660 - ep->ts_usec = ts.tv_usec; 659 + ep->ts_usec = ts.tv_nsec / NSEC_PER_USEC; 661 660 ep->status = error; 662 661 663 662 ep->flag_setup = '-';
+1 -1
drivers/usb/mon/mon_main.c
··· 241 241 /* 242 242 * Ops 243 243 */ 244 - static struct usb_mon_operations mon_ops_0 = { 244 + static const struct usb_mon_operations mon_ops_0 = { 245 245 .urb_submit = mon_submit, 246 246 .urb_submit_error = mon_submit_error, 247 247 .urb_complete = mon_complete,
+9 -6
drivers/usb/mon/mon_text.c
··· 9 9 #include <linux/usb.h> 10 10 #include <linux/slab.h> 11 11 #include <linux/time.h> 12 + #include <linux/ktime.h> 12 13 #include <linux/export.h> 13 14 #include <linux/mutex.h> 14 15 #include <linux/debugfs.h> ··· 177 176 178 177 static inline unsigned int mon_get_timestamp(void) 179 178 { 180 - struct timeval tval; 179 + struct timespec64 now; 181 180 unsigned int stamp; 182 181 183 - do_gettimeofday(&tval); 184 - stamp = tval.tv_sec & 0xFFF; /* 2^32 = 4294967296. Limit to 4096s. */ 185 - stamp = stamp * 1000000 + tval.tv_usec; 182 + ktime_get_ts64(&now); 183 + stamp = now.tv_sec & 0xFFF; /* 2^32 = 4294967296. Limit to 4096s. */ 184 + stamp = stamp * USEC_PER_SEC + now.tv_nsec / NSEC_PER_USEC; 186 185 return stamp; 187 186 } 188 187 ··· 387 386 struct mon_event_text *ep; 388 387 struct mon_text_ptr ptr; 389 388 390 - if (IS_ERR(ep = mon_text_read_wait(rp, file))) 389 + ep = mon_text_read_wait(rp, file); 390 + if (IS_ERR(ep)) 391 391 return PTR_ERR(ep); 392 392 mutex_lock(&rp->printf_lock); 393 393 ptr.cnt = 0; ··· 415 413 struct mon_event_text *ep; 416 414 struct mon_text_ptr ptr; 417 415 418 - if (IS_ERR(ep = mon_text_read_wait(rp, file))) 416 + ep = mon_text_read_wait(rp, file); 417 + if (IS_ERR(ep)) 419 418 return PTR_ERR(ep); 420 419 mutex_lock(&rp->printf_lock); 421 420 ptr.cnt = 0;
+38 -10
drivers/usb/musb/musb_core.c
··· 1360 1360 break; 1361 1361 } 1362 1362 1363 - printk(KERN_DEBUG "%s: setup fifo_mode %d\n", 1364 - musb_driver_name, fifo_mode); 1363 + pr_debug("%s: setup fifo_mode %d\n", musb_driver_name, fifo_mode); 1365 1364 1366 1365 1367 1366 done: ··· 1389 1390 musb->nr_endpoints = max(epn, musb->nr_endpoints); 1390 1391 } 1391 1392 1392 - printk(KERN_DEBUG "%s: %d/%d max ep, %d/%d memory\n", 1393 + pr_debug("%s: %d/%d max ep, %d/%d memory\n", 1393 1394 musb_driver_name, 1394 1395 n + 1, musb->config->num_eps * 2 - 1, 1395 1396 offset, (1 << (musb->config->ram_bits + 2))); ··· 1490 1491 if (reg & MUSB_CONFIGDATA_SOFTCONE) 1491 1492 strcat(aInfo, ", SoftConn"); 1492 1493 1493 - printk(KERN_DEBUG "%s: ConfigData=0x%02x (%s)\n", 1494 - musb_driver_name, reg, aInfo); 1494 + pr_debug("%s: ConfigData=0x%02x (%s)\n", musb_driver_name, reg, aInfo); 1495 1495 1496 1496 aDate[0] = 0; 1497 1497 if (MUSB_CONTROLLER_MHDRC == musb_type) { ··· 1500 1502 musb->is_multipoint = 0; 1501 1503 type = ""; 1502 1504 #ifndef CONFIG_USB_OTG_BLACKLIST_HUB 1503 - printk(KERN_ERR 1504 - "%s: kernel must blacklist external hubs\n", 1505 - musb_driver_name); 1505 + pr_err("%s: kernel must blacklist external hubs\n", 1506 + musb_driver_name); 1506 1507 #endif 1507 1508 } 1508 1509 ··· 1510 1513 snprintf(aRevision, 32, "%d.%d%s", MUSB_HWVERS_MAJOR(musb->hwvers), 1511 1514 MUSB_HWVERS_MINOR(musb->hwvers), 1512 1515 (musb->hwvers & MUSB_HWVERS_RC) ? "RC" : ""); 1513 - printk(KERN_DEBUG "%s: %sHDRC RTL version %s %s\n", 1514 - musb_driver_name, type, aRevision, aDate); 1516 + pr_debug("%s: %sHDRC RTL version %s %s\n", 1517 + musb_driver_name, type, aRevision, aDate); 1515 1518 1516 1519 /* configure ep0 */ 1517 1520 musb_configure_ep0(musb); ··· 1701 1704 #else 1702 1705 #define use_dma 0 1703 1706 #endif 1707 + 1708 + static void (*musb_phy_callback)(enum musb_vbus_id_status status); 1709 + 1710 + /* 1711 + * musb_mailbox - optional phy notifier function 1712 + * @status phy state change 1713 + * 1714 + * Optionally gets called from the USB PHY. Note that the USB PHY must be 1715 + * disabled at the point the phy_callback is registered or unregistered. 1716 + */ 1717 + void musb_mailbox(enum musb_vbus_id_status status) 1718 + { 1719 + if (musb_phy_callback) 1720 + musb_phy_callback(status); 1721 + 1722 + }; 1723 + EXPORT_SYMBOL_GPL(musb_mailbox); 1704 1724 1705 1725 /*-------------------------------------------------------------------------*/ 1706 1726 ··· 2131 2117 musb->xceiv->io_ops = &musb_ulpi_access; 2132 2118 } 2133 2119 2120 + if (musb->ops->phy_callback) 2121 + musb_phy_callback = musb->ops->phy_callback; 2122 + 2134 2123 pm_runtime_get_sync(musb->controller); 2124 + 2125 + status = usb_phy_init(musb->xceiv); 2126 + if (status < 0) 2127 + goto err_usb_phy_init; 2135 2128 2136 2129 if (use_dma && dev->dma_mask) { 2137 2130 musb->dma_controller = ··· 2260 2239 cancel_delayed_work_sync(&musb->deassert_reset_work); 2261 2240 if (musb->dma_controller) 2262 2241 musb_dma_controller_destroy(musb->dma_controller); 2242 + 2263 2243 fail2_5: 2244 + usb_phy_shutdown(musb->xceiv); 2245 + 2246 + err_usb_phy_init: 2264 2247 pm_runtime_put_sync(musb->controller); 2265 2248 2266 2249 fail2: ··· 2320 2295 */ 2321 2296 musb_exit_debugfs(musb); 2322 2297 musb_shutdown(pdev); 2298 + musb_phy_callback = NULL; 2323 2299 2324 2300 if (musb->dma_controller) 2325 2301 musb_dma_controller_destroy(musb->dma_controller); 2302 + 2303 + usb_phy_shutdown(musb->xceiv); 2326 2304 2327 2305 cancel_work_sync(&musb->irq_work); 2328 2306 cancel_delayed_work_sync(&musb->finish_resume_work);
+2
drivers/usb/musb/musb_core.h
··· 168 168 * @adjust_channel_params: pre check for standard dma channel_program func 169 169 * @pre_root_reset_end: called before the root usb port reset flag gets cleared 170 170 * @post_root_reset_end: called after the root usb port reset flag gets cleared 171 + * @phy_callback: optional callback function for the phy to call 171 172 */ 172 173 struct musb_platform_ops { 173 174 ··· 215 214 dma_addr_t *dma_addr, u32 *len); 216 215 void (*pre_root_reset_end)(struct musb *musb); 217 216 void (*post_root_reset_end)(struct musb *musb); 217 + void (*phy_callback)(enum musb_vbus_id_status status); 218 218 }; 219 219 220 220 /*
+2 -3
drivers/usb/musb/musb_gadget.c
··· 353 353 * 1 >0 Yes(FS bulk) 354 354 */ 355 355 if (!musb_ep->hb_mult || 356 - (musb_ep->hb_mult && 357 - can_bulk_split(musb, 358 - musb_ep->type))) 356 + can_bulk_split(musb, 357 + musb_ep->type)) 359 358 csr |= MUSB_TXCSR_AUTOSET; 360 359 } 361 360 csr &= ~MUSB_TXCSR_P_UNDERRUN;
+17 -13
drivers/usb/musb/omap2430.c
··· 36 36 #include <linux/pm_runtime.h> 37 37 #include <linux/err.h> 38 38 #include <linux/delay.h> 39 - #include <linux/usb/musb-omap.h> 39 + #include <linux/usb/musb.h> 40 40 #include <linux/phy/omap_control_phy.h> 41 41 #include <linux/of_platform.h> 42 42 ··· 46 46 struct omap2430_glue { 47 47 struct device *dev; 48 48 struct platform_device *musb; 49 - enum omap_musb_vbus_id_status status; 49 + enum musb_vbus_id_status status; 50 50 struct work_struct omap_musb_mailbox_work; 51 51 struct device *control_otghs; 52 52 }; ··· 234 234 musb_writel(musb->mregs, OTG_FORCESTDBY, l); 235 235 } 236 236 237 - void omap_musb_mailbox(enum omap_musb_vbus_id_status status) 237 + static void omap2430_musb_mailbox(enum musb_vbus_id_status status) 238 238 { 239 239 struct omap2430_glue *glue = _glue; 240 240 ··· 251 251 252 252 schedule_work(&glue->omap_musb_mailbox_work); 253 253 } 254 - EXPORT_SYMBOL_GPL(omap_musb_mailbox); 255 254 256 255 static void omap_musb_set_mailbox(struct omap2430_glue *glue) 257 256 { ··· 261 262 struct usb_otg *otg = musb->xceiv->otg; 262 263 263 264 switch (glue->status) { 264 - case OMAP_MUSB_ID_GROUND: 265 + case MUSB_ID_GROUND: 265 266 dev_dbg(dev, "ID GND\n"); 266 267 267 268 otg->default_a = true; ··· 275 276 } 276 277 break; 277 278 278 - case OMAP_MUSB_VBUS_VALID: 279 + case MUSB_VBUS_VALID: 279 280 dev_dbg(dev, "VBUS Connect\n"); 280 281 281 282 otg->default_a = false; ··· 286 287 omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE); 287 288 break; 288 289 289 - case OMAP_MUSB_ID_FLOAT: 290 - case OMAP_MUSB_VBUS_OFF: 290 + case MUSB_ID_FLOAT: 291 + case MUSB_VBUS_OFF: 291 292 dev_dbg(dev, "VBUS Disconnect\n"); 292 293 293 294 musb->xceiv->last_event = USB_EVENT_NONE; ··· 429 430 430 431 setup_timer(&musb_idle_timer, musb_do_idle, (unsigned long) musb); 431 432 432 - if (glue->status != OMAP_MUSB_UNKNOWN) 433 + if (glue->status != MUSB_UNKNOWN) 433 434 omap_musb_set_mailbox(glue); 434 435 435 436 phy_init(musb->phy); ··· 454 455 455 456 switch (glue->status) { 456 457 457 - case OMAP_MUSB_ID_GROUND: 458 + case MUSB_ID_GROUND: 458 459 omap_control_usb_set_mode(glue->control_otghs, USB_MODE_HOST); 459 460 if (data->interface_type != MUSB_INTERFACE_UTMI) 460 461 break; ··· 473 474 } 474 475 break; 475 476 476 - case OMAP_MUSB_VBUS_VALID: 477 + case MUSB_VBUS_VALID: 477 478 omap_control_usb_set_mode(glue->control_otghs, USB_MODE_DEVICE); 478 479 break; 479 480 ··· 487 488 struct device *dev = musb->controller; 488 489 struct omap2430_glue *glue = dev_get_drvdata(dev->parent); 489 490 490 - if (glue->status != OMAP_MUSB_UNKNOWN) 491 + if (glue->status != MUSB_UNKNOWN) 491 492 omap_control_usb_set_mode(glue->control_otghs, 492 493 USB_MODE_DISCONNECT); 493 494 } ··· 519 520 520 521 .enable = omap2430_musb_enable, 521 522 .disable = omap2430_musb_disable, 523 + 524 + .phy_callback = omap2430_musb_mailbox, 522 525 }; 523 526 524 527 static u64 omap2430_dmamask = DMA_BIT_MASK(32); ··· 552 551 553 552 glue->dev = &pdev->dev; 554 553 glue->musb = musb; 555 - glue->status = OMAP_MUSB_UNKNOWN; 554 + glue->status = MUSB_UNKNOWN; 556 555 glue->control_otghs = ERR_PTR(-ENODEV); 557 556 558 557 if (np) { ··· 664 663 { 665 664 struct omap2430_glue *glue = platform_get_drvdata(pdev); 666 665 666 + pm_runtime_get_sync(glue->dev); 667 667 cancel_work_sync(&glue->omap_musb_mailbox_work); 668 668 platform_device_unregister(glue->musb); 669 + pm_runtime_put_sync(glue->dev); 670 + pm_runtime_disable(glue->dev); 669 671 670 672 return 0; 671 673 }
+1 -13
drivers/usb/phy/Kconfig
··· 66 66 select USB_PHY 67 67 select AM335X_CONTROL_USB 68 68 select NOP_USB_XCEIV 69 + select USB_COMMON 69 70 help 70 71 This driver provides PHY support for that phy which part for the 71 72 AM335x SoC. ··· 186 185 Enable this to support the Freescale MXS USB PHY. 187 186 188 187 MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x. 189 - 190 - config USB_RCAR_PHY 191 - tristate "Renesas R-Car USB PHY support" 192 - depends on USB || USB_GADGET 193 - depends on ARCH_R8A7778 || ARCH_R8A7779 || COMPILE_TEST 194 - select USB_PHY 195 - help 196 - Say Y here to add support for the Renesas R-Car USB common PHY driver. 197 - This chip is typically used as USB PHY for USB host, gadget. 198 - This driver supports R8A7778 and R8A7779. 199 - 200 - To compile this driver as a module, choose M here: the 201 - module will be called phy-rcar-usb. 202 188 203 189 config USB_ULPI 204 190 bool "Generic ULPI Transceiver Driver"
-1
drivers/usb/phy/Makefile
··· 23 23 obj-$(CONFIG_USB_QCOM_8X16_PHY) += phy-qcom-8x16-usb.o 24 24 obj-$(CONFIG_USB_MV_OTG) += phy-mv-usb.o 25 25 obj-$(CONFIG_USB_MXS_PHY) += phy-mxs-usb.o 26 - obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o 27 26 obj-$(CONFIG_USB_ULPI) += phy-ulpi.o 28 27 obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o 29 28 obj-$(CONFIG_KEYSTONE_USB_PHY) += phy-keystone.o
+5 -3
drivers/usb/phy/am35x-phy-control.h drivers/usb/phy/phy-am335x-control.h
··· 2 2 #define _AM335x_PHY_CONTROL_H_ 3 3 4 4 struct phy_control { 5 - void (*phy_power)(struct phy_control *phy_ctrl, u32 id, bool on); 5 + void (*phy_power)(struct phy_control *phy_ctrl, u32 id, 6 + enum usb_dr_mode dr_mode, bool on); 6 7 void (*phy_wkup)(struct phy_control *phy_ctrl, u32 id, bool on); 7 8 }; 8 9 9 - static inline void phy_ctrl_power(struct phy_control *phy_ctrl, u32 id, bool on) 10 + static inline void phy_ctrl_power(struct phy_control *phy_ctrl, u32 id, 11 + enum usb_dr_mode dr_mode, bool on) 10 12 { 11 - phy_ctrl->phy_power(phy_ctrl, id, on); 13 + phy_ctrl->phy_power(phy_ctrl, id, dr_mode, on); 12 14 } 13 15 14 16 static inline void phy_ctrl_wkup(struct phy_control *phy_ctrl, u32 id, bool on)
+12 -4
drivers/usb/phy/phy-am335x-control.c
··· 4 4 #include <linux/of.h> 5 5 #include <linux/io.h> 6 6 #include <linux/delay.h> 7 - #include "am35x-phy-control.h" 7 + #include <linux/usb/otg.h> 8 + #include "phy-am335x-control.h" 8 9 9 10 struct am335x_control_usb { 10 11 struct device *dev; ··· 59 58 spin_unlock(&usb_ctrl->lock); 60 59 } 61 60 62 - static void am335x_phy_power(struct phy_control *phy_ctrl, u32 id, bool on) 61 + static void am335x_phy_power(struct phy_control *phy_ctrl, u32 id, 62 + enum usb_dr_mode dr_mode, bool on) 63 63 { 64 64 struct am335x_control_usb *usb_ctrl; 65 65 u32 val; ··· 82 80 83 81 val = readl(usb_ctrl->phy_reg + reg); 84 82 if (on) { 85 - val &= ~(USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN); 86 - val |= USBPHY_OTGVDET_EN | USBPHY_OTGSESSEND_EN; 83 + if (dr_mode == USB_DR_MODE_HOST) { 84 + val &= ~(USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN | 85 + USBPHY_OTGVDET_EN); 86 + val |= USBPHY_OTGSESSEND_EN; 87 + } else { 88 + val &= ~(USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN); 89 + val |= USBPHY_OTGVDET_EN | USBPHY_OTGSESSEND_EN; 90 + } 87 91 } else { 88 92 val |= USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN; 89 93 }
+11 -6
drivers/usb/phy/phy-am335x.c
··· 8 8 #include <linux/regulator/consumer.h> 9 9 #include <linux/of.h> 10 10 #include <linux/of_address.h> 11 + #include <linux/usb/of.h> 11 12 12 - #include "am35x-phy-control.h" 13 + #include "phy-am335x-control.h" 13 14 #include "phy-generic.h" 14 15 15 16 struct am335x_phy { 16 17 struct usb_phy_generic usb_phy_gen; 17 18 struct phy_control *phy_ctrl; 18 19 int id; 20 + enum usb_dr_mode dr_mode; 19 21 }; 20 22 21 23 static int am335x_init(struct usb_phy *phy) 22 24 { 23 25 struct am335x_phy *am_phy = dev_get_drvdata(phy->dev); 24 26 25 - phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true); 27 + phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, true); 26 28 return 0; 27 29 } 28 30 ··· 32 30 { 33 31 struct am335x_phy *am_phy = dev_get_drvdata(phy->dev); 34 32 35 - phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); 33 + phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, false); 36 34 } 37 35 38 36 static int am335x_phy_probe(struct platform_device *pdev) ··· 48 46 am_phy->phy_ctrl = am335x_get_phy_control(dev); 49 47 if (!am_phy->phy_ctrl) 50 48 return -EPROBE_DEFER; 49 + 51 50 am_phy->id = of_alias_get_id(pdev->dev.of_node, "phy"); 52 51 if (am_phy->id < 0) { 53 52 dev_err(&pdev->dev, "Missing PHY id: %d\n", am_phy->id); 54 53 return am_phy->id; 55 54 } 55 + 56 + am_phy->dr_mode = of_usb_get_dr_mode_by_phy(pdev->dev.of_node); 56 57 57 58 ret = usb_phy_gen_create_phy(dev, &am_phy->usb_phy_gen, NULL); 58 59 if (ret) ··· 80 75 */ 81 76 82 77 device_set_wakeup_enable(dev, false); 83 - phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); 78 + phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, false); 84 79 85 80 return 0; 86 81 } ··· 110 105 if (device_may_wakeup(dev)) 111 106 phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, true); 112 107 113 - phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, false); 108 + phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, false); 114 109 115 110 return 0; 116 111 } ··· 120 115 struct platform_device *pdev = to_platform_device(dev); 121 116 struct am335x_phy *am_phy = platform_get_drvdata(pdev); 122 117 123 - phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, true); 118 + phy_ctrl_power(am_phy->phy_ctrl, am_phy->id, am_phy->dr_mode, true); 124 119 125 120 if (device_may_wakeup(dev)) 126 121 phy_ctrl_wkup(am_phy->phy_ctrl, am_phy->id, false);
-247
drivers/usb/phy/phy-rcar-usb.c
··· 1 - /* 2 - * Renesas R-Car USB phy driver 3 - * 4 - * Copyright (C) 2012-2013 Renesas Solutions Corp. 5 - * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 6 - * Copyright (C) 2013 Cogent Embedded, Inc. 7 - * 8 - * This program is free software; you can redistribute it and/or modify 9 - * it under the terms of the GNU General Public License version 2 as 10 - * published by the Free Software Foundation. 11 - */ 12 - 13 - #include <linux/delay.h> 14 - #include <linux/io.h> 15 - #include <linux/usb/otg.h> 16 - #include <linux/platform_device.h> 17 - #include <linux/spinlock.h> 18 - #include <linux/module.h> 19 - #include <linux/platform_data/usb-rcar-phy.h> 20 - 21 - /* REGS block */ 22 - #define USBPCTRL0 0x00 23 - #define USBPCTRL1 0x04 24 - #define USBST 0x08 25 - #define USBEH0 0x0C 26 - #define USBOH0 0x1C 27 - #define USBCTL0 0x58 28 - 29 - /* High-speed signal quality characteristic control registers (R8A7778 only) */ 30 - #define HSQCTL1 0x24 31 - #define HSQCTL2 0x28 32 - 33 - /* USBPCTRL0 */ 34 - #define OVC2 (1 << 10) /* (R8A7779 only) */ 35 - /* Switches the OVC input pin for port 2: */ 36 - /* 1: USB_OVC2, 0: OVC2 */ 37 - #define OVC1_VBUS1 (1 << 9) /* Switches the OVC input pin for port 1: */ 38 - /* 1: USB_OVC1, 0: OVC1/VBUS1 */ 39 - /* Function mode: set to 0 */ 40 - #define OVC0 (1 << 8) /* Switches the OVC input pin for port 0: */ 41 - /* 1: USB_OVC0 pin, 0: OVC0 */ 42 - #define OVC2_ACT (1 << 6) /* (R8A7779 only) */ 43 - /* Host mode: OVC2 polarity: */ 44 - /* 1: active-high, 0: active-low */ 45 - #define PENC (1 << 4) /* Function mode: output level of PENC1 pin: */ 46 - /* 1: high, 0: low */ 47 - #define OVC0_ACT (1 << 3) /* Host mode: OVC0 polarity: */ 48 - /* 1: active-high, 0: active-low */ 49 - #define OVC1_ACT (1 << 1) /* Host mode: OVC1 polarity: */ 50 - /* 1: active-high, 0: active-low */ 51 - /* Function mode: be sure to set to 1 */ 52 - #define PORT1 (1 << 0) /* Selects port 1 mode: */ 53 - /* 1: function, 0: host */ 54 - /* USBPCTRL1 */ 55 - #define PHY_RST (1 << 2) 56 - #define PLL_ENB (1 << 1) 57 - #define PHY_ENB (1 << 0) 58 - 59 - /* USBST */ 60 - #define ST_ACT (1 << 31) 61 - #define ST_PLL (1 << 30) 62 - 63 - struct rcar_usb_phy_priv { 64 - struct usb_phy phy; 65 - spinlock_t lock; 66 - 67 - void __iomem *reg0; 68 - void __iomem *reg1; 69 - int counter; 70 - }; 71 - 72 - #define usb_phy_to_priv(p) container_of(p, struct rcar_usb_phy_priv, phy) 73 - 74 - 75 - /* 76 - * USB initial/install operation. 77 - * 78 - * This function setup USB phy. 79 - * The used value and setting order came from 80 - * [USB :: Initial setting] on datasheet. 81 - */ 82 - static int rcar_usb_phy_init(struct usb_phy *phy) 83 - { 84 - struct rcar_usb_phy_priv *priv = usb_phy_to_priv(phy); 85 - struct device *dev = phy->dev; 86 - struct rcar_phy_platform_data *pdata = dev_get_platdata(dev); 87 - void __iomem *reg0 = priv->reg0; 88 - void __iomem *reg1 = priv->reg1; 89 - static const u8 ovcn_act[] = { OVC0_ACT, OVC1_ACT, OVC2_ACT }; 90 - int i; 91 - u32 val; 92 - unsigned long flags; 93 - 94 - spin_lock_irqsave(&priv->lock, flags); 95 - if (priv->counter++ == 0) { 96 - 97 - /* 98 - * USB phy start-up 99 - */ 100 - 101 - /* (1) USB-PHY standby release */ 102 - iowrite32(PHY_ENB, (reg0 + USBPCTRL1)); 103 - 104 - /* (2) start USB-PHY internal PLL */ 105 - iowrite32(PHY_ENB | PLL_ENB, (reg0 + USBPCTRL1)); 106 - 107 - /* (3) set USB-PHY in accord with the conditions of usage */ 108 - if (reg1) { 109 - u32 hsqctl1 = pdata->ferrite_bead ? 0x41 : 0; 110 - u32 hsqctl2 = pdata->ferrite_bead ? 0x0d : 7; 111 - 112 - iowrite32(hsqctl1, reg1 + HSQCTL1); 113 - iowrite32(hsqctl2, reg1 + HSQCTL2); 114 - } 115 - 116 - /* (4) USB module status check */ 117 - for (i = 0; i < 1024; i++) { 118 - udelay(10); 119 - val = ioread32(reg0 + USBST); 120 - if (val == (ST_ACT | ST_PLL)) 121 - break; 122 - } 123 - 124 - if (val != (ST_ACT | ST_PLL)) { 125 - dev_err(dev, "USB phy not ready\n"); 126 - goto phy_init_end; 127 - } 128 - 129 - /* (5) USB-PHY reset clear */ 130 - iowrite32(PHY_ENB | PLL_ENB | PHY_RST, (reg0 + USBPCTRL1)); 131 - 132 - /* Board specific port settings */ 133 - val = 0; 134 - if (pdata->port1_func) 135 - val |= PORT1; 136 - if (pdata->penc1) 137 - val |= PENC; 138 - for (i = 0; i < 3; i++) { 139 - /* OVCn bits follow each other in the right order */ 140 - if (pdata->ovc_pin[i].select_3_3v) 141 - val |= OVC0 << i; 142 - /* OVCn_ACT bits are spaced by irregular intervals */ 143 - if (pdata->ovc_pin[i].active_high) 144 - val |= ovcn_act[i]; 145 - } 146 - iowrite32(val, (reg0 + USBPCTRL0)); 147 - 148 - /* 149 - * Bus alignment settings 150 - */ 151 - 152 - /* (1) EHCI bus alignment (little endian) */ 153 - iowrite32(0x00000000, (reg0 + USBEH0)); 154 - 155 - /* (1) OHCI bus alignment (little endian) */ 156 - iowrite32(0x00000000, (reg0 + USBOH0)); 157 - } 158 - 159 - phy_init_end: 160 - spin_unlock_irqrestore(&priv->lock, flags); 161 - 162 - return 0; 163 - } 164 - 165 - static void rcar_usb_phy_shutdown(struct usb_phy *phy) 166 - { 167 - struct rcar_usb_phy_priv *priv = usb_phy_to_priv(phy); 168 - void __iomem *reg0 = priv->reg0; 169 - unsigned long flags; 170 - 171 - spin_lock_irqsave(&priv->lock, flags); 172 - 173 - if (priv->counter-- == 1) /* last user */ 174 - iowrite32(0x00000000, (reg0 + USBPCTRL1)); 175 - 176 - spin_unlock_irqrestore(&priv->lock, flags); 177 - } 178 - 179 - static int rcar_usb_phy_probe(struct platform_device *pdev) 180 - { 181 - struct rcar_usb_phy_priv *priv; 182 - struct resource *res0, *res1; 183 - struct device *dev = &pdev->dev; 184 - void __iomem *reg0, *reg1 = NULL; 185 - int ret; 186 - 187 - if (!dev_get_platdata(&pdev->dev)) { 188 - dev_err(dev, "No platform data\n"); 189 - return -EINVAL; 190 - } 191 - 192 - res0 = platform_get_resource(pdev, IORESOURCE_MEM, 0); 193 - reg0 = devm_ioremap_resource(dev, res0); 194 - if (IS_ERR(reg0)) 195 - return PTR_ERR(reg0); 196 - 197 - res1 = platform_get_resource(pdev, IORESOURCE_MEM, 1); 198 - reg1 = devm_ioremap_resource(dev, res1); 199 - if (IS_ERR(reg1)) 200 - return PTR_ERR(reg1); 201 - 202 - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 203 - if (!priv) 204 - return -ENOMEM; 205 - 206 - priv->reg0 = reg0; 207 - priv->reg1 = reg1; 208 - priv->counter = 0; 209 - priv->phy.dev = dev; 210 - priv->phy.label = dev_name(dev); 211 - priv->phy.init = rcar_usb_phy_init; 212 - priv->phy.shutdown = rcar_usb_phy_shutdown; 213 - spin_lock_init(&priv->lock); 214 - 215 - ret = usb_add_phy(&priv->phy, USB_PHY_TYPE_USB2); 216 - if (ret < 0) { 217 - dev_err(dev, "usb phy addition error\n"); 218 - return ret; 219 - } 220 - 221 - platform_set_drvdata(pdev, priv); 222 - 223 - return ret; 224 - } 225 - 226 - static int rcar_usb_phy_remove(struct platform_device *pdev) 227 - { 228 - struct rcar_usb_phy_priv *priv = platform_get_drvdata(pdev); 229 - 230 - usb_remove_phy(&priv->phy); 231 - 232 - return 0; 233 - } 234 - 235 - static struct platform_driver rcar_usb_phy_driver = { 236 - .driver = { 237 - .name = "rcar_usb_phy", 238 - }, 239 - .probe = rcar_usb_phy_probe, 240 - .remove = rcar_usb_phy_remove, 241 - }; 242 - 243 - module_platform_driver(rcar_usb_phy_driver); 244 - 245 - MODULE_LICENSE("GPL v2"); 246 - MODULE_DESCRIPTION("Renesas R-Car USB phy"); 247 - MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
+15 -15
drivers/usb/phy/phy-twl6030-usb.c
··· 25 25 #include <linux/interrupt.h> 26 26 #include <linux/platform_device.h> 27 27 #include <linux/io.h> 28 - #include <linux/usb/musb-omap.h> 28 + #include <linux/usb/musb.h> 29 29 #include <linux/usb/phy_companion.h> 30 30 #include <linux/phy/omap_usb.h> 31 31 #include <linux/i2c/twl.h> ··· 102 102 103 103 int irq1; 104 104 int irq2; 105 - enum omap_musb_vbus_id_status linkstat; 105 + enum musb_vbus_id_status linkstat; 106 106 u8 asleep; 107 107 bool vbus_enable; 108 108 const char *regulator; ··· 189 189 spin_lock_irqsave(&twl->lock, flags); 190 190 191 191 switch (twl->linkstat) { 192 - case OMAP_MUSB_VBUS_VALID: 192 + case MUSB_VBUS_VALID: 193 193 ret = snprintf(buf, PAGE_SIZE, "vbus\n"); 194 194 break; 195 - case OMAP_MUSB_ID_GROUND: 195 + case MUSB_ID_GROUND: 196 196 ret = snprintf(buf, PAGE_SIZE, "id\n"); 197 197 break; 198 - case OMAP_MUSB_VBUS_OFF: 198 + case MUSB_VBUS_OFF: 199 199 ret = snprintf(buf, PAGE_SIZE, "none\n"); 200 200 break; 201 201 default: ··· 210 210 static irqreturn_t twl6030_usb_irq(int irq, void *_twl) 211 211 { 212 212 struct twl6030_usb *twl = _twl; 213 - enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN; 213 + enum musb_vbus_id_status status = MUSB_UNKNOWN; 214 214 u8 vbus_state, hw_state; 215 215 int ret; 216 216 ··· 225 225 dev_err(twl->dev, "Failed to enable usb3v3\n"); 226 226 227 227 twl->asleep = 1; 228 - status = OMAP_MUSB_VBUS_VALID; 228 + status = MUSB_VBUS_VALID; 229 229 twl->linkstat = status; 230 - omap_musb_mailbox(status); 230 + musb_mailbox(status); 231 231 } else { 232 - if (twl->linkstat != OMAP_MUSB_UNKNOWN) { 233 - status = OMAP_MUSB_VBUS_OFF; 232 + if (twl->linkstat != MUSB_UNKNOWN) { 233 + status = MUSB_VBUS_OFF; 234 234 twl->linkstat = status; 235 - omap_musb_mailbox(status); 235 + musb_mailbox(status); 236 236 if (twl->asleep) { 237 237 regulator_disable(twl->usb3v3); 238 238 twl->asleep = 0; ··· 248 248 static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl) 249 249 { 250 250 struct twl6030_usb *twl = _twl; 251 - enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN; 251 + enum musb_vbus_id_status status = MUSB_UNKNOWN; 252 252 u8 hw_state; 253 253 int ret; 254 254 ··· 262 262 twl->asleep = 1; 263 263 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_CLR); 264 264 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_SET); 265 - status = OMAP_MUSB_ID_GROUND; 265 + status = MUSB_ID_GROUND; 266 266 twl->linkstat = status; 267 - omap_musb_mailbox(status); 267 + musb_mailbox(status); 268 268 } else { 269 269 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_CLR); 270 270 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_SET); ··· 334 334 twl->dev = &pdev->dev; 335 335 twl->irq1 = platform_get_irq(pdev, 0); 336 336 twl->irq2 = platform_get_irq(pdev, 1); 337 - twl->linkstat = OMAP_MUSB_UNKNOWN; 337 + twl->linkstat = MUSB_UNKNOWN; 338 338 339 339 twl->comparator.set_vbus = twl6030_set_vbus; 340 340 twl->comparator.start_srp = twl6030_start_srp;
+43 -35
drivers/usb/renesas_usbhs/common.c
··· 302 302 */ 303 303 304 304 /* commonly used on old SH-Mobile SoCs */ 305 - static u32 usbhsc_default_pipe_type[] = { 306 - USB_ENDPOINT_XFER_CONTROL, 307 - USB_ENDPOINT_XFER_ISOC, 308 - USB_ENDPOINT_XFER_ISOC, 309 - USB_ENDPOINT_XFER_BULK, 310 - USB_ENDPOINT_XFER_BULK, 311 - USB_ENDPOINT_XFER_BULK, 312 - USB_ENDPOINT_XFER_INT, 313 - USB_ENDPOINT_XFER_INT, 314 - USB_ENDPOINT_XFER_INT, 315 - USB_ENDPOINT_XFER_INT, 305 + static struct renesas_usbhs_driver_pipe_config usbhsc_default_pipe[] = { 306 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_CONTROL, 64, 0x00, false), 307 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x08, false), 308 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x18, false), 309 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x28, true), 310 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x38, true), 311 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x48, true), 312 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x04, false), 313 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x05, false), 314 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x06, false), 315 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x07, false), 316 316 }; 317 317 318 318 /* commonly used on newer SH-Mobile and R-Car SoCs */ 319 - static u32 usbhsc_new_pipe_type[] = { 320 - USB_ENDPOINT_XFER_CONTROL, 321 - USB_ENDPOINT_XFER_ISOC, 322 - USB_ENDPOINT_XFER_ISOC, 323 - USB_ENDPOINT_XFER_BULK, 324 - USB_ENDPOINT_XFER_BULK, 325 - USB_ENDPOINT_XFER_BULK, 326 - USB_ENDPOINT_XFER_INT, 327 - USB_ENDPOINT_XFER_INT, 328 - USB_ENDPOINT_XFER_INT, 329 - USB_ENDPOINT_XFER_BULK, 330 - USB_ENDPOINT_XFER_BULK, 331 - USB_ENDPOINT_XFER_BULK, 332 - USB_ENDPOINT_XFER_BULK, 333 - USB_ENDPOINT_XFER_BULK, 334 - USB_ENDPOINT_XFER_BULK, 335 - USB_ENDPOINT_XFER_BULK, 319 + static struct renesas_usbhs_driver_pipe_config usbhsc_new_pipe[] = { 320 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_CONTROL, 64, 0x00, false), 321 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x08, true), 322 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_ISOC, 1024, 0x28, true), 323 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x48, true), 324 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x58, true), 325 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x68, true), 326 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x04, false), 327 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x05, false), 328 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_INT, 64, 0x06, false), 329 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x78, true), 330 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x88, true), 331 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0x98, true), 332 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xa8, true), 333 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xb8, true), 334 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xc8, true), 335 + RENESAS_USBHS_PIPE(USB_ENDPOINT_XFER_BULK, 512, 0xd8, true), 336 336 }; 337 337 338 338 /* ··· 481 481 .compatible = "renesas,usbhs-r8a7795", 482 482 .data = (void *)USBHS_TYPE_RCAR_GEN2, 483 483 }, 484 + { 485 + .compatible = "renesas,rcar-gen2-usbhs", 486 + .data = (void *)USBHS_TYPE_RCAR_GEN2, 487 + }, 488 + { 489 + /* Gen3 is compatible with Gen2 */ 490 + .compatible = "renesas,rcar-gen3-usbhs", 491 + .data = (void *)USBHS_TYPE_RCAR_GEN2, 492 + }, 484 493 { }, 485 494 }; 486 495 MODULE_DEVICE_TABLE(of, usbhs_of_match); ··· 573 564 switch (priv->dparam.type) { 574 565 case USBHS_TYPE_RCAR_GEN2: 575 566 priv->pfunc = usbhs_rcar2_ops; 576 - if (!priv->dparam.pipe_type) { 577 - priv->dparam.pipe_type = usbhsc_new_pipe_type; 578 - priv->dparam.pipe_size = 579 - ARRAY_SIZE(usbhsc_new_pipe_type); 567 + if (!priv->dparam.pipe_configs) { 568 + priv->dparam.pipe_configs = usbhsc_new_pipe; 569 + priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_new_pipe); 580 570 } 581 571 break; 582 572 default: ··· 594 586 dfunc->notify_hotplug = usbhsc_drvcllbck_notify_hotplug; 595 587 596 588 /* set default param if platform doesn't have */ 597 - if (!priv->dparam.pipe_type) { 598 - priv->dparam.pipe_type = usbhsc_default_pipe_type; 599 - priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_default_pipe_type); 589 + if (!priv->dparam.pipe_configs) { 590 + priv->dparam.pipe_configs = usbhsc_default_pipe; 591 + priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_default_pipe); 600 592 } 601 593 if (!priv->dparam.pio_dma_border) 602 594 priv->dparam.pio_dma_border = 64; /* 64byte */
+12 -7
drivers/usb/renesas_usbhs/mod_gadget.c
··· 1042 1042 struct usbhsg_gpriv *gpriv; 1043 1043 struct usbhsg_uep *uep; 1044 1044 struct device *dev = usbhs_priv_to_dev(priv); 1045 + struct renesas_usbhs_driver_pipe_config *pipe_configs = 1046 + usbhs_get_dparam(priv, pipe_configs); 1045 1047 int pipe_size = usbhs_get_dparam(priv, pipe_size); 1046 1048 int i; 1047 1049 int ret; ··· 1113 1111 gpriv->gadget.ep0 = &uep->ep; 1114 1112 usb_ep_set_maxpacket_limit(&uep->ep, 64); 1115 1113 uep->ep.caps.type_control = true; 1116 - } 1117 - /* init normal pipe */ 1118 - else { 1119 - usb_ep_set_maxpacket_limit(&uep->ep, 512); 1120 - uep->ep.caps.type_iso = true; 1121 - uep->ep.caps.type_bulk = true; 1122 - uep->ep.caps.type_int = true; 1114 + } else { 1115 + /* init normal pipe */ 1116 + if (pipe_configs[i].type == USB_ENDPOINT_XFER_ISOC) 1117 + uep->ep.caps.type_iso = true; 1118 + if (pipe_configs[i].type == USB_ENDPOINT_XFER_BULK) 1119 + uep->ep.caps.type_bulk = true; 1120 + if (pipe_configs[i].type == USB_ENDPOINT_XFER_INT) 1121 + uep->ep.caps.type_int = true; 1122 + usb_ep_set_maxpacket_limit(&uep->ep, 1123 + pipe_configs[i].bufsize); 1123 1124 list_add_tail(&uep->ep.ep_list, &gpriv->gadget.ep_list); 1124 1125 } 1125 1126 uep->ep.caps.dir_in = true;
+6 -5
drivers/usb/renesas_usbhs/mod_host.c
··· 1414 1414 { 1415 1415 struct usbhsh_hpriv *hpriv = usbhsh_priv_to_hpriv(priv); 1416 1416 struct usbhs_pipe *pipe; 1417 - u32 *pipe_type = usbhs_get_dparam(priv, pipe_type); 1417 + struct renesas_usbhs_driver_pipe_config *pipe_configs = 1418 + usbhs_get_dparam(priv, pipe_configs); 1418 1419 int pipe_size = usbhs_get_dparam(priv, pipe_size); 1419 1420 int old_type, dir_in, i; 1420 1421 ··· 1443 1442 * USB_ENDPOINT_XFER_BULK -> dir in 1444 1443 * ... 1445 1444 */ 1446 - dir_in = (pipe_type[i] == old_type); 1447 - old_type = pipe_type[i]; 1445 + dir_in = (pipe_configs[i].type == old_type); 1446 + old_type = pipe_configs[i].type; 1448 1447 1449 - if (USB_ENDPOINT_XFER_CONTROL == pipe_type[i]) { 1448 + if (USB_ENDPOINT_XFER_CONTROL == pipe_configs[i].type) { 1450 1449 pipe = usbhs_dcp_malloc(priv); 1451 1450 usbhsh_hpriv_to_dcp(hpriv) = pipe; 1452 1451 } else { 1453 1452 pipe = usbhs_pipe_malloc(priv, 1454 - pipe_type[i], 1453 + pipe_configs[i].type, 1455 1454 dir_in); 1456 1455 } 1457 1456
+26 -86
drivers/usb/renesas_usbhs/pipe.c
··· 44 44 return usbhsp_pipe_name[usbhs_pipe_type(pipe)]; 45 45 } 46 46 47 + static struct renesas_usbhs_driver_pipe_config 48 + *usbhsp_get_pipe_config(struct usbhs_priv *priv, int pipe_num) 49 + { 50 + struct renesas_usbhs_driver_pipe_config *pipe_configs = 51 + usbhs_get_dparam(priv, pipe_configs); 52 + 53 + return &pipe_configs[pipe_num]; 54 + } 55 + 47 56 /* 48 57 * DCPCTR/PIPEnCTR functions 49 58 */ ··· 393 384 /* 394 385 * pipe setup 395 386 */ 396 - static int usbhsp_possible_double_buffer(struct usbhs_pipe *pipe) 397 - { 398 - /* 399 - * only ISO / BULK pipe can use double buffer 400 - */ 401 - if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK) || 402 - usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_ISOC)) 403 - return 1; 404 - 405 - return 0; 406 - } 407 - 408 387 static u16 usbhsp_setup_pipecfg(struct usbhs_pipe *pipe, 409 388 int is_host, 410 389 int dir_in) ··· 409 412 [USB_ENDPOINT_XFER_INT] = TYPE_INT, 410 413 [USB_ENDPOINT_XFER_ISOC] = TYPE_ISO, 411 414 }; 412 - int is_double = usbhsp_possible_double_buffer(pipe); 413 415 414 416 if (usbhs_pipe_is_dcp(pipe)) 415 417 return -EINVAL; ··· 430 434 usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK)) 431 435 bfre = 0; /* FIXME */ 432 436 433 - /* DBLB */ 434 - if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_ISOC) || 435 - usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK)) 436 - dblb = (is_double) ? DBLB : 0; 437 + /* DBLB: see usbhs_pipe_config_update() */ 437 438 438 439 /* CNTMD */ 439 440 if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_BULK)) ··· 466 473 static u16 usbhsp_setup_pipebuff(struct usbhs_pipe *pipe) 467 474 { 468 475 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); 469 - struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv); 470 476 struct device *dev = usbhs_priv_to_dev(priv); 471 477 int pipe_num = usbhs_pipe_number(pipe); 472 - int is_double = usbhsp_possible_double_buffer(pipe); 473 478 u16 buff_size; 474 479 u16 bufnmb; 475 480 u16 bufnmb_cnt; 481 + struct renesas_usbhs_driver_pipe_config *pipe_config = 482 + usbhsp_get_pipe_config(priv, pipe_num); 476 483 477 484 /* 478 485 * PIPEBUF ··· 482 489 * - "Features" - "Pipe configuration" 483 490 * - "Operation" - "FIFO Buffer Memory" 484 491 * - "Operation" - "Pipe Control" 485 - * 486 - * ex) if pipe6 - pipe9 are USB_ENDPOINT_XFER_INT (SH7724) 487 - * 488 - * BUFNMB: PIPE 489 - * 0: pipe0 (DCP 256byte) 490 - * 1: - 491 - * 2: - 492 - * 3: - 493 - * 4: pipe6 (INT 64byte) 494 - * 5: pipe7 (INT 64byte) 495 - * 6: pipe8 (INT 64byte) 496 - * 7: pipe9 (INT 64byte) 497 - * 8 - xx: free (for BULK, ISOC) 498 492 */ 499 - 500 - /* 501 - * FIXME 502 - * 503 - * it doesn't have good buffer allocator 504 - * 505 - * DCP : 256 byte 506 - * BULK: 512 byte 507 - * INT : 64 byte 508 - * ISOC: 512 byte 509 - */ 510 - if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_CONTROL)) 511 - buff_size = 256; 512 - else if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_INT)) 513 - buff_size = 64; 514 - else 515 - buff_size = 512; 493 + buff_size = pipe_config->bufsize; 494 + bufnmb = pipe_config->bufnum; 516 495 517 496 /* change buff_size to register value */ 518 497 bufnmb_cnt = (buff_size / 64) - 1; 519 - 520 - /* BUFNMB has been reserved for INT pipe 521 - * see above */ 522 - if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_INT)) { 523 - bufnmb = pipe_num - 2; 524 - } else { 525 - bufnmb = info->bufnmb_last; 526 - info->bufnmb_last += bufnmb_cnt + 1; 527 - 528 - /* 529 - * double buffer 530 - */ 531 - if (is_double) 532 - info->bufnmb_last += bufnmb_cnt + 1; 533 - } 534 498 535 499 dev_dbg(dev, "pipe : %d : buff_size 0x%x: bufnmb 0x%x\n", 536 500 pipe_num, buff_size, bufnmb); ··· 499 549 void usbhs_pipe_config_update(struct usbhs_pipe *pipe, u16 devsel, 500 550 u16 epnum, u16 maxp) 501 551 { 552 + struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); 553 + int pipe_num = usbhs_pipe_number(pipe); 554 + struct renesas_usbhs_driver_pipe_config *pipe_config = 555 + usbhsp_get_pipe_config(priv, pipe_num); 556 + u16 dblb = pipe_config->double_buf ? DBLB : 0; 557 + 502 558 if (devsel > 0xA) { 503 - struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); 504 559 struct device *dev = usbhs_priv_to_dev(priv); 505 560 506 561 dev_err(dev, "devsel error %d\n", devsel); ··· 523 568 maxp); 524 569 525 570 if (!usbhs_pipe_is_dcp(pipe)) 526 - usbhsp_pipe_cfg_set(pipe, 0x000F, epnum); 571 + usbhsp_pipe_cfg_set(pipe, 0x000F | DBLB, epnum | dblb); 527 572 } 528 573 529 574 /* ··· 663 708 struct usbhs_pipe *pipe; 664 709 int i; 665 710 666 - /* 667 - * FIXME 668 - * 669 - * driver needs good allocator. 670 - * 671 - * find first free buffer area (BULK, ISOC) 672 - * (DCP, INT area is fixed) 673 - * 674 - * buffer number 0 - 3 have been reserved for DCP 675 - * see 676 - * usbhsp_to_bufnmb 677 - */ 678 - info->bufnmb_last = 4; 679 711 usbhs_for_each_pipe_with_dcp(pipe, priv, i) { 680 - if (usbhs_pipe_type_is(pipe, USB_ENDPOINT_XFER_INT)) 681 - info->bufnmb_last++; 682 - 683 712 usbhsp_flags_init(pipe); 684 713 pipe->fifo = NULL; 685 714 pipe->mod_private = NULL; ··· 790 851 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv); 791 852 struct usbhs_pipe *pipe; 792 853 struct device *dev = usbhs_priv_to_dev(priv); 793 - u32 *pipe_type = usbhs_get_dparam(priv, pipe_type); 854 + struct renesas_usbhs_driver_pipe_config *pipe_configs = 855 + usbhs_get_dparam(priv, pipe_configs); 794 856 int pipe_size = usbhs_get_dparam(priv, pipe_size); 795 857 int i; 796 858 797 859 /* This driver expects 1st pipe is DCP */ 798 - if (pipe_type[0] != USB_ENDPOINT_XFER_CONTROL) { 860 + if (pipe_configs[0].type != USB_ENDPOINT_XFER_CONTROL) { 799 861 dev_err(dev, "1st PIPE is not DCP\n"); 800 862 return -EINVAL; 801 863 } ··· 816 876 pipe->priv = priv; 817 877 818 878 usbhs_pipe_type(pipe) = 819 - pipe_type[i] & USB_ENDPOINT_XFERTYPE_MASK; 879 + pipe_configs[i].type & USB_ENDPOINT_XFERTYPE_MASK; 820 880 821 881 dev_dbg(dev, "pipe %x\t: %s\n", 822 - i, usbhsp_pipe_name[pipe_type[i]]); 882 + i, usbhsp_pipe_name[pipe_configs[i].type]); 823 883 } 824 884 825 885 return 0;
-1
drivers/usb/renesas_usbhs/pipe.h
··· 46 46 struct usbhs_pipe_info { 47 47 struct usbhs_pipe *pipe; 48 48 int size; /* array size of "pipe" */ 49 - int bufnmb_last; /* FIXME : driver needs good allocator */ 50 49 51 50 int (*dma_map_ctrl)(struct usbhs_pkt *pkt, int map); 52 51 };
+16
drivers/usb/serial/Kconfig
··· 475 475 To compile this driver as a module, choose M here: the 476 476 module will be called mos7840. If unsure, choose N. 477 477 478 + config USB_SERIAL_MXUPORT11 479 + tristate "USB Moxa UPORT 11x0 Serial Driver" 480 + ---help--- 481 + Say Y here if you want to use a MOXA UPort 11x0 Serial hub. 482 + 483 + This driver supports: 484 + 485 + - UPort 1110 : 1 port RS-232 USB to Serial Hub. 486 + - UPort 1130 : 1 port RS-422/485 USB to Serial Hub. 487 + - UPort 1130I : 1 port RS-422/485 USB to Serial Hub with Isolation. 488 + - UPort 1150 : 1 port RS-232/422/485 USB to Serial Hub. 489 + - UPort 1150I : 1 port RS-232/422/485 USB to Serial Hub with Isolation. 490 + 491 + To compile this driver as a module, choose M here: the 492 + module will be called mxu11x0. 493 + 478 494 config USB_SERIAL_MXUPORT 479 495 tristate "USB Moxa UPORT Serial Driver" 480 496 ---help---
+1
drivers/usb/serial/Makefile
··· 38 38 obj-$(CONFIG_USB_SERIAL_MOS7720) += mos7720.o 39 39 obj-$(CONFIG_USB_SERIAL_MOS7840) += mos7840.o 40 40 obj-$(CONFIG_USB_SERIAL_MXUPORT) += mxuport.o 41 + obj-$(CONFIG_USB_SERIAL_MXUPORT11) += mxu11x0.o 41 42 obj-$(CONFIG_USB_SERIAL_NAVMAN) += navman.o 42 43 obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o 43 44 obj-$(CONFIG_USB_SERIAL_OPTICON) += opticon.o
+163 -24
drivers/usb/serial/cp210x.c
··· 38 38 struct ktermios *); 39 39 static void cp210x_set_termios(struct tty_struct *, struct usb_serial_port *, 40 40 struct ktermios*); 41 + static bool cp210x_tx_empty(struct usb_serial_port *port); 41 42 static int cp210x_tiocmget(struct tty_struct *); 42 43 static int cp210x_tiocmset(struct tty_struct *, unsigned int, unsigned int); 43 44 static int cp210x_tiocmset_port(struct usb_serial_port *port, 44 45 unsigned int, unsigned int); 45 46 static void cp210x_break_ctl(struct tty_struct *, int); 46 - static int cp210x_startup(struct usb_serial *); 47 - static void cp210x_release(struct usb_serial *); 47 + static int cp210x_port_probe(struct usb_serial_port *); 48 + static int cp210x_port_remove(struct usb_serial_port *); 48 49 static void cp210x_dtr_rts(struct usb_serial_port *p, int on); 49 50 50 51 static const struct usb_device_id id_table[] = { ··· 161 160 { USB_DEVICE(0x17F4, 0xAAAA) }, /* Wavesense Jazz blood glucose meter */ 162 161 { USB_DEVICE(0x1843, 0x0200) }, /* Vaisala USB Instrument Cable */ 163 162 { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */ 163 + { USB_DEVICE(0x18EF, 0xE025) }, /* ELV Marble Sound Board 1 */ 164 164 { USB_DEVICE(0x1ADB, 0x0001) }, /* Schweitzer Engineering C662 Cable */ 165 165 { USB_DEVICE(0x1B1C, 0x1C00) }, /* Corsair USB Dongle */ 166 166 { USB_DEVICE(0x1BA4, 0x0002) }, /* Silicon Labs 358x factory default */ ··· 198 196 199 197 MODULE_DEVICE_TABLE(usb, id_table); 200 198 201 - struct cp210x_serial_private { 199 + struct cp210x_port_private { 202 200 __u8 bInterfaceNumber; 201 + bool has_swapped_line_ctl; 203 202 }; 204 203 205 204 static struct usb_serial_driver cp210x_device = { ··· 216 213 .close = cp210x_close, 217 214 .break_ctl = cp210x_break_ctl, 218 215 .set_termios = cp210x_set_termios, 216 + .tx_empty = cp210x_tx_empty, 219 217 .tiocmget = cp210x_tiocmget, 220 218 .tiocmset = cp210x_tiocmset, 221 - .attach = cp210x_startup, 222 - .release = cp210x_release, 219 + .port_probe = cp210x_port_probe, 220 + .port_remove = cp210x_port_remove, 223 221 .dtr_rts = cp210x_dtr_rts 224 222 }; 225 223 ··· 303 299 #define CONTROL_WRITE_DTR 0x0100 304 300 #define CONTROL_WRITE_RTS 0x0200 305 301 302 + /* CP210X_GET_COMM_STATUS returns these 0x13 bytes */ 303 + struct cp210x_comm_status { 304 + __le32 ulErrors; 305 + __le32 ulHoldReasons; 306 + __le32 ulAmountInInQueue; 307 + __le32 ulAmountInOutQueue; 308 + u8 bEofReceived; 309 + u8 bWaitForImmediate; 310 + u8 bReserved; 311 + } __packed; 312 + 313 + /* 314 + * CP210X_PURGE - 16 bits passed in wValue of USB request. 315 + * SiLabs app note AN571 gives a strange description of the 4 bits: 316 + * bit 0 or bit 2 clears the transmit queue and 1 or 3 receive. 317 + * writing 1 to all, however, purges cp2108 well enough to avoid the hang. 318 + */ 319 + #define PURGE_ALL 0x000f 320 + 306 321 /* 307 322 * cp210x_get_config 308 323 * Reads from the CP210x configuration registers ··· 333 310 unsigned int *data, int size) 334 311 { 335 312 struct usb_serial *serial = port->serial; 336 - struct cp210x_serial_private *spriv = usb_get_serial_data(serial); 313 + struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); 337 314 __le32 *buf; 338 315 int result, i, length; 339 316 ··· 347 324 /* Issue the request, attempting to read 'size' bytes */ 348 325 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 349 326 request, REQTYPE_INTERFACE_TO_HOST, 0x0000, 350 - spriv->bInterfaceNumber, buf, size, 327 + port_priv->bInterfaceNumber, buf, size, 351 328 USB_CTRL_GET_TIMEOUT); 352 329 353 330 /* Convert data into an array of integers */ ··· 378 355 unsigned int *data, int size) 379 356 { 380 357 struct usb_serial *serial = port->serial; 381 - struct cp210x_serial_private *spriv = usb_get_serial_data(serial); 358 + struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); 382 359 __le32 *buf; 383 360 int result, i, length; 384 361 ··· 397 374 result = usb_control_msg(serial->dev, 398 375 usb_sndctrlpipe(serial->dev, 0), 399 376 request, REQTYPE_HOST_TO_INTERFACE, 0x0000, 400 - spriv->bInterfaceNumber, buf, size, 377 + port_priv->bInterfaceNumber, buf, size, 401 378 USB_CTRL_SET_TIMEOUT); 402 379 } else { 403 380 result = usb_control_msg(serial->dev, 404 381 usb_sndctrlpipe(serial->dev, 0), 405 382 request, REQTYPE_HOST_TO_INTERFACE, data[0], 406 - spriv->bInterfaceNumber, NULL, 0, 383 + port_priv->bInterfaceNumber, NULL, 0, 407 384 USB_CTRL_SET_TIMEOUT); 408 385 } 409 386 ··· 430 407 u8 request, unsigned int data) 431 408 { 432 409 return cp210x_set_config(port, request, &data, 2); 410 + } 411 + 412 + /* 413 + * Detect CP2108 GET_LINE_CTL bug and activate workaround. 414 + * Write a known good value 0x800, read it back. 415 + * If it comes back swapped the bug is detected. 416 + * Preserve the original register value. 417 + */ 418 + static int cp210x_detect_swapped_line_ctl(struct usb_serial_port *port) 419 + { 420 + struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); 421 + unsigned int line_ctl_save; 422 + unsigned int line_ctl_test; 423 + int err; 424 + 425 + err = cp210x_get_config(port, CP210X_GET_LINE_CTL, &line_ctl_save, 2); 426 + if (err) 427 + return err; 428 + 429 + line_ctl_test = 0x800; 430 + err = cp210x_set_config(port, CP210X_SET_LINE_CTL, &line_ctl_test, 2); 431 + if (err) 432 + return err; 433 + 434 + err = cp210x_get_config(port, CP210X_GET_LINE_CTL, &line_ctl_test, 2); 435 + if (err) 436 + return err; 437 + 438 + if (line_ctl_test == 8) { 439 + port_priv->has_swapped_line_ctl = true; 440 + line_ctl_save = swab16((u16)line_ctl_save); 441 + } 442 + 443 + return cp210x_set_config(port, CP210X_SET_LINE_CTL, &line_ctl_save, 2); 444 + } 445 + 446 + /* 447 + * Must always be called instead of cp210x_get_config(CP210X_GET_LINE_CTL) 448 + * to workaround cp2108 bug and get correct value. 449 + */ 450 + static int cp210x_get_line_ctl(struct usb_serial_port *port, unsigned int *ctl) 451 + { 452 + struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); 453 + int err; 454 + 455 + err = cp210x_get_config(port, CP210X_GET_LINE_CTL, ctl, 2); 456 + if (err) 457 + return err; 458 + 459 + /* Workaround swapped bytes in 16-bit value from CP210X_GET_LINE_CTL */ 460 + if (port_priv->has_swapped_line_ctl) 461 + *ctl = swab16((u16)(*ctl)); 462 + 463 + return 0; 433 464 } 434 465 435 466 /* ··· 551 474 552 475 static void cp210x_close(struct usb_serial_port *port) 553 476 { 477 + unsigned int purge_ctl; 478 + 554 479 usb_serial_generic_close(port); 480 + 481 + /* Clear both queues; cp2108 needs this to avoid an occasional hang */ 482 + purge_ctl = PURGE_ALL; 483 + cp210x_set_config(port, CP210X_PURGE, &purge_ctl, 2); 484 + 555 485 cp210x_set_config_single(port, CP210X_IFC_ENABLE, UART_DISABLE); 486 + } 487 + 488 + /* 489 + * Read how many bytes are waiting in the TX queue. 490 + */ 491 + static int cp210x_get_tx_queue_byte_count(struct usb_serial_port *port, 492 + u32 *count) 493 + { 494 + struct usb_serial *serial = port->serial; 495 + struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); 496 + struct cp210x_comm_status *sts; 497 + int result; 498 + 499 + sts = kmalloc(sizeof(*sts), GFP_KERNEL); 500 + if (!sts) 501 + return -ENOMEM; 502 + 503 + result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 504 + CP210X_GET_COMM_STATUS, REQTYPE_INTERFACE_TO_HOST, 505 + 0, port_priv->bInterfaceNumber, sts, sizeof(*sts), 506 + USB_CTRL_GET_TIMEOUT); 507 + if (result == sizeof(*sts)) { 508 + *count = le32_to_cpu(sts->ulAmountInOutQueue); 509 + result = 0; 510 + } else { 511 + dev_err(&port->dev, "failed to get comm status: %d\n", result); 512 + if (result >= 0) 513 + result = -EPROTO; 514 + } 515 + 516 + kfree(sts); 517 + 518 + return result; 519 + } 520 + 521 + static bool cp210x_tx_empty(struct usb_serial_port *port) 522 + { 523 + int err; 524 + u32 count; 525 + 526 + err = cp210x_get_tx_queue_byte_count(port, &count); 527 + if (err) 528 + return true; 529 + 530 + return !count; 556 531 } 557 532 558 533 /* ··· 648 519 649 520 cflag = *cflagp; 650 521 651 - cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); 522 + cp210x_get_line_ctl(port, &bits); 652 523 cflag &= ~CSIZE; 653 524 switch (bits & BITS_DATA_MASK) { 654 525 case BITS_DATA_5: ··· 816 687 817 688 /* If the number of data bits is to be updated */ 818 689 if ((cflag & CSIZE) != (old_cflag & CSIZE)) { 819 - cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); 690 + cp210x_get_line_ctl(port, &bits); 820 691 bits &= ~BITS_DATA_MASK; 821 692 switch (cflag & CSIZE) { 822 693 case CS5: ··· 850 721 851 722 if ((cflag & (PARENB|PARODD|CMSPAR)) != 852 723 (old_cflag & (PARENB|PARODD|CMSPAR))) { 853 - cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); 724 + cp210x_get_line_ctl(port, &bits); 854 725 bits &= ~BITS_PARITY_MASK; 855 726 if (cflag & PARENB) { 856 727 if (cflag & CMSPAR) { ··· 876 747 } 877 748 878 749 if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) { 879 - cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); 750 + cp210x_get_line_ctl(port, &bits); 880 751 bits &= ~BITS_STOP_MASK; 881 752 if (cflag & CSTOPB) { 882 753 bits |= BITS_STOP_2; ··· 991 862 cp210x_set_config(port, CP210X_SET_BREAK, &state, 2); 992 863 } 993 864 994 - static int cp210x_startup(struct usb_serial *serial) 865 + static int cp210x_port_probe(struct usb_serial_port *port) 995 866 { 867 + struct usb_serial *serial = port->serial; 996 868 struct usb_host_interface *cur_altsetting; 997 - struct cp210x_serial_private *spriv; 869 + struct cp210x_port_private *port_priv; 870 + int ret; 998 871 999 - spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); 1000 - if (!spriv) 872 + port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL); 873 + if (!port_priv) 1001 874 return -ENOMEM; 1002 875 1003 876 cur_altsetting = serial->interface->cur_altsetting; 1004 - spriv->bInterfaceNumber = cur_altsetting->desc.bInterfaceNumber; 877 + port_priv->bInterfaceNumber = cur_altsetting->desc.bInterfaceNumber; 1005 878 1006 - usb_set_serial_data(serial, spriv); 879 + usb_set_serial_port_data(port, port_priv); 880 + 881 + ret = cp210x_detect_swapped_line_ctl(port); 882 + if (ret) { 883 + kfree(port_priv); 884 + return ret; 885 + } 1007 886 1008 887 return 0; 1009 888 } 1010 889 1011 - static void cp210x_release(struct usb_serial *serial) 890 + static int cp210x_port_remove(struct usb_serial_port *port) 1012 891 { 1013 - struct cp210x_serial_private *spriv; 892 + struct cp210x_port_private *port_priv; 1014 893 1015 - spriv = usb_get_serial_data(serial); 1016 - kfree(spriv); 894 + port_priv = usb_get_serial_port_data(port); 895 + kfree(port_priv); 896 + 897 + return 0; 1017 898 } 1018 899 1019 900 module_usb_serial_driver(serial_drivers, id_table);
+14 -21
drivers/usb/serial/io_edgeport.c
··· 1046 1046 1047 1047 edge_port->closePending = true; 1048 1048 1049 - if ((!edge_serial->is_epic) || 1050 - ((edge_serial->is_epic) && 1051 - (edge_serial->epic_descriptor.Supports.IOSPChase))) { 1049 + if (!edge_serial->is_epic || 1050 + edge_serial->epic_descriptor.Supports.IOSPChase) { 1052 1051 /* flush and chase */ 1053 1052 edge_port->chaseResponsePending = true; 1054 1053 ··· 1060 1061 edge_port->chaseResponsePending = false; 1061 1062 } 1062 1063 1063 - if ((!edge_serial->is_epic) || 1064 - ((edge_serial->is_epic) && 1065 - (edge_serial->epic_descriptor.Supports.IOSPClose))) { 1064 + if (!edge_serial->is_epic || 1065 + edge_serial->epic_descriptor.Supports.IOSPClose) { 1066 1066 /* close the port */ 1067 1067 dev_dbg(&port->dev, "%s - Sending IOSP_CMD_CLOSE_PORT\n", __func__); 1068 1068 send_iosp_ext_cmd(edge_port, IOSP_CMD_CLOSE_PORT, 0); ··· 1610 1612 struct edgeport_serial *edge_serial = usb_get_serial_data(port->serial); 1611 1613 int status; 1612 1614 1613 - if ((!edge_serial->is_epic) || 1614 - ((edge_serial->is_epic) && 1615 - (edge_serial->epic_descriptor.Supports.IOSPChase))) { 1615 + if (!edge_serial->is_epic || 1616 + edge_serial->epic_descriptor.Supports.IOSPChase) { 1616 1617 /* flush and chase */ 1617 1618 edge_port->chaseResponsePending = true; 1618 1619 ··· 1625 1628 } 1626 1629 } 1627 1630 1628 - if ((!edge_serial->is_epic) || 1629 - ((edge_serial->is_epic) && 1630 - (edge_serial->epic_descriptor.Supports.IOSPSetClrBreak))) { 1631 + if (!edge_serial->is_epic || 1632 + edge_serial->epic_descriptor.Supports.IOSPSetClrBreak) { 1631 1633 if (break_state == -1) { 1632 1634 dev_dbg(&port->dev, "%s - Sending IOSP_CMD_SET_BREAK\n", __func__); 1633 1635 status = send_iosp_ext_cmd(edge_port, ··· 2461 2465 unsigned char stop_char = STOP_CHAR(tty); 2462 2466 unsigned char start_char = START_CHAR(tty); 2463 2467 2464 - if ((!edge_serial->is_epic) || 2465 - ((edge_serial->is_epic) && 2466 - (edge_serial->epic_descriptor.Supports.IOSPSetXChar))) { 2468 + if (!edge_serial->is_epic || 2469 + edge_serial->epic_descriptor.Supports.IOSPSetXChar) { 2467 2470 send_iosp_ext_cmd(edge_port, 2468 2471 IOSP_CMD_SET_XON_CHAR, start_char); 2469 2472 send_iosp_ext_cmd(edge_port, ··· 2489 2494 } 2490 2495 2491 2496 /* Set flow control to the configured value */ 2492 - if ((!edge_serial->is_epic) || 2493 - ((edge_serial->is_epic) && 2494 - (edge_serial->epic_descriptor.Supports.IOSPSetRxFlow))) 2497 + if (!edge_serial->is_epic || 2498 + edge_serial->epic_descriptor.Supports.IOSPSetRxFlow) 2495 2499 send_iosp_ext_cmd(edge_port, IOSP_CMD_SET_RX_FLOW, rxFlow); 2496 - if ((!edge_serial->is_epic) || 2497 - ((edge_serial->is_epic) && 2498 - (edge_serial->epic_descriptor.Supports.IOSPSetTxFlow))) 2500 + if (!edge_serial->is_epic || 2501 + edge_serial->epic_descriptor.Supports.IOSPSetTxFlow) 2499 2502 send_iosp_ext_cmd(edge_port, IOSP_CMD_SET_TX_FLOW, txFlow); 2500 2503 2501 2504
+1 -1
drivers/usb/serial/mos7840.c
··· 635 635 * Byte 4 IIR Port 4 (port.number is 3) 636 636 * Byte 5 FIFO status for both */ 637 637 638 - if (length && length > 5) { 638 + if (length > 5) { 639 639 dev_dbg(&urb->dev->dev, "%s", "Wrong data !!!\n"); 640 640 return; 641 641 }
+986
drivers/usb/serial/mxu11x0.c
··· 1 + /* 2 + * USB Moxa UPORT 11x0 Serial Driver 3 + * 4 + * Copyright (C) 2007 MOXA Technologies Co., Ltd. 5 + * Copyright (C) 2015 Mathieu Othacehe <m.othacehe@gmail.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; either version 2 of the License, or 10 + * (at your option) any later version. 11 + * 12 + * 13 + * Supports the following Moxa USB to serial converters: 14 + * UPort 1110, 1 port RS-232 USB to Serial Hub. 15 + * UPort 1130, 1 port RS-422/485 USB to Serial Hub. 16 + * UPort 1130I, 1 port RS-422/485 USB to Serial Hub with isolation 17 + * protection. 18 + * UPort 1150, 1 port RS-232/422/485 USB to Serial Hub. 19 + * UPort 1150I, 1 port RS-232/422/485 USB to Serial Hub with isolation 20 + * protection. 21 + */ 22 + 23 + #include <linux/kernel.h> 24 + #include <linux/module.h> 25 + #include <linux/firmware.h> 26 + #include <linux/jiffies.h> 27 + #include <linux/serial.h> 28 + #include <linux/serial_reg.h> 29 + #include <linux/slab.h> 30 + #include <linux/spinlock.h> 31 + #include <linux/mutex.h> 32 + #include <linux/tty.h> 33 + #include <linux/tty_driver.h> 34 + #include <linux/tty_flip.h> 35 + #include <linux/uaccess.h> 36 + #include <linux/usb.h> 37 + #include <linux/usb/serial.h> 38 + 39 + /* Vendor and product ids */ 40 + #define MXU1_VENDOR_ID 0x110a 41 + #define MXU1_1110_PRODUCT_ID 0x1110 42 + #define MXU1_1130_PRODUCT_ID 0x1130 43 + #define MXU1_1150_PRODUCT_ID 0x1150 44 + #define MXU1_1151_PRODUCT_ID 0x1151 45 + #define MXU1_1131_PRODUCT_ID 0x1131 46 + 47 + /* Commands */ 48 + #define MXU1_GET_VERSION 0x01 49 + #define MXU1_GET_PORT_STATUS 0x02 50 + #define MXU1_GET_PORT_DEV_INFO 0x03 51 + #define MXU1_GET_CONFIG 0x04 52 + #define MXU1_SET_CONFIG 0x05 53 + #define MXU1_OPEN_PORT 0x06 54 + #define MXU1_CLOSE_PORT 0x07 55 + #define MXU1_START_PORT 0x08 56 + #define MXU1_STOP_PORT 0x09 57 + #define MXU1_TEST_PORT 0x0A 58 + #define MXU1_PURGE_PORT 0x0B 59 + #define MXU1_RESET_EXT_DEVICE 0x0C 60 + #define MXU1_GET_OUTQUEUE 0x0D 61 + #define MXU1_WRITE_DATA 0x80 62 + #define MXU1_READ_DATA 0x81 63 + #define MXU1_REQ_TYPE_CLASS 0x82 64 + 65 + /* Module identifiers */ 66 + #define MXU1_I2C_PORT 0x01 67 + #define MXU1_IEEE1284_PORT 0x02 68 + #define MXU1_UART1_PORT 0x03 69 + #define MXU1_UART2_PORT 0x04 70 + #define MXU1_RAM_PORT 0x05 71 + 72 + /* Modem status */ 73 + #define MXU1_MSR_DELTA_CTS 0x01 74 + #define MXU1_MSR_DELTA_DSR 0x02 75 + #define MXU1_MSR_DELTA_RI 0x04 76 + #define MXU1_MSR_DELTA_CD 0x08 77 + #define MXU1_MSR_CTS 0x10 78 + #define MXU1_MSR_DSR 0x20 79 + #define MXU1_MSR_RI 0x40 80 + #define MXU1_MSR_CD 0x80 81 + #define MXU1_MSR_DELTA_MASK 0x0F 82 + #define MXU1_MSR_MASK 0xF0 83 + 84 + /* Line status */ 85 + #define MXU1_LSR_OVERRUN_ERROR 0x01 86 + #define MXU1_LSR_PARITY_ERROR 0x02 87 + #define MXU1_LSR_FRAMING_ERROR 0x04 88 + #define MXU1_LSR_BREAK 0x08 89 + #define MXU1_LSR_ERROR 0x0F 90 + #define MXU1_LSR_RX_FULL 0x10 91 + #define MXU1_LSR_TX_EMPTY 0x20 92 + 93 + /* Modem control */ 94 + #define MXU1_MCR_LOOP 0x04 95 + #define MXU1_MCR_DTR 0x10 96 + #define MXU1_MCR_RTS 0x20 97 + 98 + /* Mask settings */ 99 + #define MXU1_UART_ENABLE_RTS_IN 0x0001 100 + #define MXU1_UART_DISABLE_RTS 0x0002 101 + #define MXU1_UART_ENABLE_PARITY_CHECKING 0x0008 102 + #define MXU1_UART_ENABLE_DSR_OUT 0x0010 103 + #define MXU1_UART_ENABLE_CTS_OUT 0x0020 104 + #define MXU1_UART_ENABLE_X_OUT 0x0040 105 + #define MXU1_UART_ENABLE_XA_OUT 0x0080 106 + #define MXU1_UART_ENABLE_X_IN 0x0100 107 + #define MXU1_UART_ENABLE_DTR_IN 0x0800 108 + #define MXU1_UART_DISABLE_DTR 0x1000 109 + #define MXU1_UART_ENABLE_MS_INTS 0x2000 110 + #define MXU1_UART_ENABLE_AUTO_START_DMA 0x4000 111 + #define MXU1_UART_SEND_BREAK_SIGNAL 0x8000 112 + 113 + /* Parity */ 114 + #define MXU1_UART_NO_PARITY 0x00 115 + #define MXU1_UART_ODD_PARITY 0x01 116 + #define MXU1_UART_EVEN_PARITY 0x02 117 + #define MXU1_UART_MARK_PARITY 0x03 118 + #define MXU1_UART_SPACE_PARITY 0x04 119 + 120 + /* Stop bits */ 121 + #define MXU1_UART_1_STOP_BITS 0x00 122 + #define MXU1_UART_1_5_STOP_BITS 0x01 123 + #define MXU1_UART_2_STOP_BITS 0x02 124 + 125 + /* Bits per character */ 126 + #define MXU1_UART_5_DATA_BITS 0x00 127 + #define MXU1_UART_6_DATA_BITS 0x01 128 + #define MXU1_UART_7_DATA_BITS 0x02 129 + #define MXU1_UART_8_DATA_BITS 0x03 130 + 131 + /* Operation modes */ 132 + #define MXU1_UART_232 0x00 133 + #define MXU1_UART_485_RECEIVER_DISABLED 0x01 134 + #define MXU1_UART_485_RECEIVER_ENABLED 0x02 135 + 136 + /* Pipe transfer mode and timeout */ 137 + #define MXU1_PIPE_MODE_CONTINUOUS 0x01 138 + #define MXU1_PIPE_MODE_MASK 0x03 139 + #define MXU1_PIPE_TIMEOUT_MASK 0x7C 140 + #define MXU1_PIPE_TIMEOUT_ENABLE 0x80 141 + 142 + /* Config struct */ 143 + struct mxu1_uart_config { 144 + __be16 wBaudRate; 145 + __be16 wFlags; 146 + u8 bDataBits; 147 + u8 bParity; 148 + u8 bStopBits; 149 + char cXon; 150 + char cXoff; 151 + u8 bUartMode; 152 + } __packed; 153 + 154 + /* Purge modes */ 155 + #define MXU1_PURGE_OUTPUT 0x00 156 + #define MXU1_PURGE_INPUT 0x80 157 + 158 + /* Read/Write data */ 159 + #define MXU1_RW_DATA_ADDR_SFR 0x10 160 + #define MXU1_RW_DATA_ADDR_IDATA 0x20 161 + #define MXU1_RW_DATA_ADDR_XDATA 0x30 162 + #define MXU1_RW_DATA_ADDR_CODE 0x40 163 + #define MXU1_RW_DATA_ADDR_GPIO 0x50 164 + #define MXU1_RW_DATA_ADDR_I2C 0x60 165 + #define MXU1_RW_DATA_ADDR_FLASH 0x70 166 + #define MXU1_RW_DATA_ADDR_DSP 0x80 167 + 168 + #define MXU1_RW_DATA_UNSPECIFIED 0x00 169 + #define MXU1_RW_DATA_BYTE 0x01 170 + #define MXU1_RW_DATA_WORD 0x02 171 + #define MXU1_RW_DATA_DOUBLE_WORD 0x04 172 + 173 + struct mxu1_write_data_bytes { 174 + u8 bAddrType; 175 + u8 bDataType; 176 + u8 bDataCounter; 177 + __be16 wBaseAddrHi; 178 + __be16 wBaseAddrLo; 179 + u8 bData[0]; 180 + } __packed; 181 + 182 + /* Interrupt codes */ 183 + #define MXU1_CODE_HARDWARE_ERROR 0xFF 184 + #define MXU1_CODE_DATA_ERROR 0x03 185 + #define MXU1_CODE_MODEM_STATUS 0x04 186 + 187 + static inline int mxu1_get_func_from_code(unsigned char code) 188 + { 189 + return code & 0x0f; 190 + } 191 + 192 + /* Download firmware max packet size */ 193 + #define MXU1_DOWNLOAD_MAX_PACKET_SIZE 64 194 + 195 + /* Firmware image header */ 196 + struct mxu1_firmware_header { 197 + __le16 wLength; 198 + u8 bCheckSum; 199 + } __packed; 200 + 201 + #define MXU1_UART_BASE_ADDR 0xFFA0 202 + #define MXU1_UART_OFFSET_MCR 0x0004 203 + 204 + #define MXU1_BAUD_BASE 923077 205 + 206 + #define MXU1_TRANSFER_TIMEOUT 2 207 + #define MXU1_DOWNLOAD_TIMEOUT 1000 208 + #define MXU1_DEFAULT_CLOSING_WAIT 4000 /* in .01 secs */ 209 + 210 + struct mxu1_port { 211 + u8 msr; 212 + u8 mcr; 213 + u8 uart_mode; 214 + spinlock_t spinlock; /* Protects msr */ 215 + struct mutex mutex; /* Protects mcr */ 216 + bool send_break; 217 + }; 218 + 219 + struct mxu1_device { 220 + u16 mxd_model; 221 + }; 222 + 223 + static const struct usb_device_id mxu1_idtable[] = { 224 + { USB_DEVICE(MXU1_VENDOR_ID, MXU1_1110_PRODUCT_ID) }, 225 + { USB_DEVICE(MXU1_VENDOR_ID, MXU1_1130_PRODUCT_ID) }, 226 + { USB_DEVICE(MXU1_VENDOR_ID, MXU1_1150_PRODUCT_ID) }, 227 + { USB_DEVICE(MXU1_VENDOR_ID, MXU1_1151_PRODUCT_ID) }, 228 + { USB_DEVICE(MXU1_VENDOR_ID, MXU1_1131_PRODUCT_ID) }, 229 + { } 230 + }; 231 + 232 + MODULE_DEVICE_TABLE(usb, mxu1_idtable); 233 + 234 + /* Write the given buffer out to the control pipe. */ 235 + static int mxu1_send_ctrl_data_urb(struct usb_serial *serial, 236 + u8 request, 237 + u16 value, u16 index, 238 + void *data, size_t size) 239 + { 240 + int status; 241 + 242 + status = usb_control_msg(serial->dev, 243 + usb_sndctrlpipe(serial->dev, 0), 244 + request, 245 + (USB_DIR_OUT | USB_TYPE_VENDOR | 246 + USB_RECIP_DEVICE), value, index, 247 + data, size, 248 + USB_CTRL_SET_TIMEOUT); 249 + if (status < 0) { 250 + dev_err(&serial->interface->dev, 251 + "%s - usb_control_msg failed: %d\n", 252 + __func__, status); 253 + return status; 254 + } 255 + 256 + if (status != size) { 257 + dev_err(&serial->interface->dev, 258 + "%s - short write (%d / %zd)\n", 259 + __func__, status, size); 260 + return -EIO; 261 + } 262 + 263 + return 0; 264 + } 265 + 266 + /* Send a vendor request without any data */ 267 + static int mxu1_send_ctrl_urb(struct usb_serial *serial, 268 + u8 request, u16 value, u16 index) 269 + { 270 + return mxu1_send_ctrl_data_urb(serial, request, value, index, 271 + NULL, 0); 272 + } 273 + 274 + static int mxu1_download_firmware(struct usb_serial *serial, 275 + const struct firmware *fw_p) 276 + { 277 + int status = 0; 278 + int buffer_size; 279 + int pos; 280 + int len; 281 + int done; 282 + u8 cs = 0; 283 + u8 *buffer; 284 + struct usb_device *dev = serial->dev; 285 + struct mxu1_firmware_header *header; 286 + unsigned int pipe; 287 + 288 + pipe = usb_sndbulkpipe(dev, serial->port[0]->bulk_out_endpointAddress); 289 + 290 + buffer_size = fw_p->size + sizeof(*header); 291 + buffer = kmalloc(buffer_size, GFP_KERNEL); 292 + if (!buffer) 293 + return -ENOMEM; 294 + 295 + memcpy(buffer, fw_p->data, fw_p->size); 296 + memset(buffer + fw_p->size, 0xff, buffer_size - fw_p->size); 297 + 298 + for (pos = sizeof(*header); pos < buffer_size; pos++) 299 + cs = (u8)(cs + buffer[pos]); 300 + 301 + header = (struct mxu1_firmware_header *)buffer; 302 + header->wLength = cpu_to_le16(buffer_size - sizeof(*header)); 303 + header->bCheckSum = cs; 304 + 305 + dev_dbg(&dev->dev, "%s - downloading firmware\n", __func__); 306 + 307 + for (pos = 0; pos < buffer_size; pos += done) { 308 + len = min(buffer_size - pos, MXU1_DOWNLOAD_MAX_PACKET_SIZE); 309 + 310 + status = usb_bulk_msg(dev, pipe, buffer + pos, len, &done, 311 + MXU1_DOWNLOAD_TIMEOUT); 312 + if (status) 313 + break; 314 + } 315 + 316 + kfree(buffer); 317 + 318 + if (status) { 319 + dev_err(&dev->dev, "failed to download firmware: %d\n", status); 320 + return status; 321 + } 322 + 323 + msleep_interruptible(100); 324 + usb_reset_device(dev); 325 + 326 + dev_dbg(&dev->dev, "%s - download successful\n", __func__); 327 + 328 + return 0; 329 + } 330 + 331 + static int mxu1_port_probe(struct usb_serial_port *port) 332 + { 333 + struct mxu1_port *mxport; 334 + struct mxu1_device *mxdev; 335 + 336 + if (!port->interrupt_in_urb) { 337 + dev_err(&port->dev, "no interrupt urb\n"); 338 + return -ENODEV; 339 + } 340 + 341 + mxport = kzalloc(sizeof(struct mxu1_port), GFP_KERNEL); 342 + if (!mxport) 343 + return -ENOMEM; 344 + 345 + spin_lock_init(&mxport->spinlock); 346 + mutex_init(&mxport->mutex); 347 + 348 + mxdev = usb_get_serial_data(port->serial); 349 + 350 + switch (mxdev->mxd_model) { 351 + case MXU1_1110_PRODUCT_ID: 352 + case MXU1_1150_PRODUCT_ID: 353 + case MXU1_1151_PRODUCT_ID: 354 + mxport->uart_mode = MXU1_UART_232; 355 + break; 356 + case MXU1_1130_PRODUCT_ID: 357 + case MXU1_1131_PRODUCT_ID: 358 + mxport->uart_mode = MXU1_UART_485_RECEIVER_DISABLED; 359 + break; 360 + } 361 + 362 + usb_set_serial_port_data(port, mxport); 363 + 364 + port->port.closing_wait = 365 + msecs_to_jiffies(MXU1_DEFAULT_CLOSING_WAIT * 10); 366 + port->port.drain_delay = 1; 367 + 368 + return 0; 369 + } 370 + 371 + static int mxu1_startup(struct usb_serial *serial) 372 + { 373 + struct mxu1_device *mxdev; 374 + struct usb_device *dev = serial->dev; 375 + struct usb_host_interface *cur_altsetting; 376 + char fw_name[32]; 377 + const struct firmware *fw_p = NULL; 378 + int err; 379 + 380 + dev_dbg(&serial->interface->dev, "%s - product 0x%04X, num configurations %d, configuration value %d\n", 381 + __func__, le16_to_cpu(dev->descriptor.idProduct), 382 + dev->descriptor.bNumConfigurations, 383 + dev->actconfig->desc.bConfigurationValue); 384 + 385 + /* create device structure */ 386 + mxdev = kzalloc(sizeof(struct mxu1_device), GFP_KERNEL); 387 + if (!mxdev) 388 + return -ENOMEM; 389 + 390 + usb_set_serial_data(serial, mxdev); 391 + 392 + mxdev->mxd_model = le16_to_cpu(dev->descriptor.idProduct); 393 + 394 + cur_altsetting = serial->interface->cur_altsetting; 395 + 396 + /* if we have only 1 configuration, download firmware */ 397 + if (cur_altsetting->desc.bNumEndpoints == 1) { 398 + 399 + snprintf(fw_name, 400 + sizeof(fw_name), 401 + "moxa/moxa-%04x.fw", 402 + mxdev->mxd_model); 403 + 404 + err = request_firmware(&fw_p, fw_name, &serial->interface->dev); 405 + if (err) { 406 + dev_err(&serial->interface->dev, "failed to request firmware: %d\n", 407 + err); 408 + goto err_free_mxdev; 409 + } 410 + 411 + err = mxu1_download_firmware(serial, fw_p); 412 + if (err) 413 + goto err_release_firmware; 414 + 415 + /* device is being reset */ 416 + err = -ENODEV; 417 + goto err_release_firmware; 418 + } 419 + 420 + return 0; 421 + 422 + err_release_firmware: 423 + release_firmware(fw_p); 424 + err_free_mxdev: 425 + kfree(mxdev); 426 + 427 + return err; 428 + } 429 + 430 + static int mxu1_write_byte(struct usb_serial_port *port, u32 addr, 431 + u8 mask, u8 byte) 432 + { 433 + int status; 434 + size_t size; 435 + struct mxu1_write_data_bytes *data; 436 + 437 + dev_dbg(&port->dev, "%s - addr 0x%08X, mask 0x%02X, byte 0x%02X\n", 438 + __func__, addr, mask, byte); 439 + 440 + size = sizeof(struct mxu1_write_data_bytes) + 2; 441 + data = kzalloc(size, GFP_KERNEL); 442 + if (!data) 443 + return -ENOMEM; 444 + 445 + data->bAddrType = MXU1_RW_DATA_ADDR_XDATA; 446 + data->bDataType = MXU1_RW_DATA_BYTE; 447 + data->bDataCounter = 1; 448 + data->wBaseAddrHi = cpu_to_be16(addr >> 16); 449 + data->wBaseAddrLo = cpu_to_be16(addr); 450 + data->bData[0] = mask; 451 + data->bData[1] = byte; 452 + 453 + status = mxu1_send_ctrl_data_urb(port->serial, MXU1_WRITE_DATA, 0, 454 + MXU1_RAM_PORT, data, size); 455 + if (status < 0) 456 + dev_err(&port->dev, "%s - failed: %d\n", __func__, status); 457 + 458 + kfree(data); 459 + 460 + return status; 461 + } 462 + 463 + static int mxu1_set_mcr(struct usb_serial_port *port, unsigned int mcr) 464 + { 465 + int status; 466 + 467 + status = mxu1_write_byte(port, 468 + MXU1_UART_BASE_ADDR + MXU1_UART_OFFSET_MCR, 469 + MXU1_MCR_RTS | MXU1_MCR_DTR | MXU1_MCR_LOOP, 470 + mcr); 471 + return status; 472 + } 473 + 474 + static void mxu1_set_termios(struct tty_struct *tty, 475 + struct usb_serial_port *port, 476 + struct ktermios *old_termios) 477 + { 478 + struct mxu1_port *mxport = usb_get_serial_port_data(port); 479 + struct mxu1_uart_config *config; 480 + tcflag_t cflag, iflag; 481 + speed_t baud; 482 + int status; 483 + unsigned int mcr; 484 + 485 + cflag = tty->termios.c_cflag; 486 + iflag = tty->termios.c_iflag; 487 + 488 + if (old_termios && 489 + !tty_termios_hw_change(&tty->termios, old_termios) && 490 + tty->termios.c_iflag == old_termios->c_iflag) { 491 + dev_dbg(&port->dev, "%s - nothing to change\n", __func__); 492 + return; 493 + } 494 + 495 + dev_dbg(&port->dev, 496 + "%s - cflag 0x%08x, iflag 0x%08x\n", __func__, cflag, iflag); 497 + 498 + if (old_termios) { 499 + dev_dbg(&port->dev, "%s - old cflag 0x%08x, old iflag 0x%08x\n", 500 + __func__, 501 + old_termios->c_cflag, 502 + old_termios->c_iflag); 503 + } 504 + 505 + config = kzalloc(sizeof(*config), GFP_KERNEL); 506 + if (!config) 507 + return; 508 + 509 + /* these flags must be set */ 510 + config->wFlags |= MXU1_UART_ENABLE_MS_INTS; 511 + config->wFlags |= MXU1_UART_ENABLE_AUTO_START_DMA; 512 + if (mxport->send_break) 513 + config->wFlags |= MXU1_UART_SEND_BREAK_SIGNAL; 514 + config->bUartMode = mxport->uart_mode; 515 + 516 + switch (C_CSIZE(tty)) { 517 + case CS5: 518 + config->bDataBits = MXU1_UART_5_DATA_BITS; 519 + break; 520 + case CS6: 521 + config->bDataBits = MXU1_UART_6_DATA_BITS; 522 + break; 523 + case CS7: 524 + config->bDataBits = MXU1_UART_7_DATA_BITS; 525 + break; 526 + default: 527 + case CS8: 528 + config->bDataBits = MXU1_UART_8_DATA_BITS; 529 + break; 530 + } 531 + 532 + if (C_PARENB(tty)) { 533 + config->wFlags |= MXU1_UART_ENABLE_PARITY_CHECKING; 534 + if (C_CMSPAR(tty)) { 535 + if (C_PARODD(tty)) 536 + config->bParity = MXU1_UART_MARK_PARITY; 537 + else 538 + config->bParity = MXU1_UART_SPACE_PARITY; 539 + } else { 540 + if (C_PARODD(tty)) 541 + config->bParity = MXU1_UART_ODD_PARITY; 542 + else 543 + config->bParity = MXU1_UART_EVEN_PARITY; 544 + } 545 + } else { 546 + config->bParity = MXU1_UART_NO_PARITY; 547 + } 548 + 549 + if (C_CSTOPB(tty)) 550 + config->bStopBits = MXU1_UART_2_STOP_BITS; 551 + else 552 + config->bStopBits = MXU1_UART_1_STOP_BITS; 553 + 554 + if (C_CRTSCTS(tty)) { 555 + /* RTS flow control must be off to drop RTS for baud rate B0 */ 556 + if (C_BAUD(tty) != B0) 557 + config->wFlags |= MXU1_UART_ENABLE_RTS_IN; 558 + config->wFlags |= MXU1_UART_ENABLE_CTS_OUT; 559 + } 560 + 561 + if (I_IXOFF(tty) || I_IXON(tty)) { 562 + config->cXon = START_CHAR(tty); 563 + config->cXoff = STOP_CHAR(tty); 564 + 565 + if (I_IXOFF(tty)) 566 + config->wFlags |= MXU1_UART_ENABLE_X_IN; 567 + 568 + if (I_IXON(tty)) 569 + config->wFlags |= MXU1_UART_ENABLE_X_OUT; 570 + } 571 + 572 + baud = tty_get_baud_rate(tty); 573 + if (!baud) 574 + baud = 9600; 575 + config->wBaudRate = MXU1_BAUD_BASE / baud; 576 + 577 + dev_dbg(&port->dev, "%s - BaudRate=%d, wBaudRate=%d, wFlags=0x%04X, bDataBits=%d, bParity=%d, bStopBits=%d, cXon=%d, cXoff=%d, bUartMode=%d\n", 578 + __func__, baud, config->wBaudRate, config->wFlags, 579 + config->bDataBits, config->bParity, config->bStopBits, 580 + config->cXon, config->cXoff, config->bUartMode); 581 + 582 + cpu_to_be16s(&config->wBaudRate); 583 + cpu_to_be16s(&config->wFlags); 584 + 585 + status = mxu1_send_ctrl_data_urb(port->serial, MXU1_SET_CONFIG, 0, 586 + MXU1_UART1_PORT, config, 587 + sizeof(*config)); 588 + if (status) 589 + dev_err(&port->dev, "cannot set config: %d\n", status); 590 + 591 + mutex_lock(&mxport->mutex); 592 + mcr = mxport->mcr; 593 + 594 + if (C_BAUD(tty) == B0) 595 + mcr &= ~(MXU1_MCR_DTR | MXU1_MCR_RTS); 596 + else if (old_termios && (old_termios->c_cflag & CBAUD) == B0) 597 + mcr |= MXU1_MCR_DTR | MXU1_MCR_RTS; 598 + 599 + status = mxu1_set_mcr(port, mcr); 600 + if (status) 601 + dev_err(&port->dev, "cannot set modem control: %d\n", status); 602 + else 603 + mxport->mcr = mcr; 604 + 605 + mutex_unlock(&mxport->mutex); 606 + 607 + kfree(config); 608 + } 609 + 610 + static int mxu1_get_serial_info(struct usb_serial_port *port, 611 + struct serial_struct __user *ret_arg) 612 + { 613 + struct serial_struct ret_serial; 614 + unsigned cwait; 615 + 616 + if (!ret_arg) 617 + return -EFAULT; 618 + 619 + cwait = port->port.closing_wait; 620 + if (cwait != ASYNC_CLOSING_WAIT_NONE) 621 + cwait = jiffies_to_msecs(cwait) / 10; 622 + 623 + memset(&ret_serial, 0, sizeof(ret_serial)); 624 + 625 + ret_serial.type = PORT_16550A; 626 + ret_serial.line = port->minor; 627 + ret_serial.port = 0; 628 + ret_serial.xmit_fifo_size = port->bulk_out_size; 629 + ret_serial.baud_base = MXU1_BAUD_BASE; 630 + ret_serial.close_delay = 5*HZ; 631 + ret_serial.closing_wait = cwait; 632 + 633 + if (copy_to_user(ret_arg, &ret_serial, sizeof(*ret_arg))) 634 + return -EFAULT; 635 + 636 + return 0; 637 + } 638 + 639 + 640 + static int mxu1_set_serial_info(struct usb_serial_port *port, 641 + struct serial_struct __user *new_arg) 642 + { 643 + struct serial_struct new_serial; 644 + unsigned cwait; 645 + 646 + if (copy_from_user(&new_serial, new_arg, sizeof(new_serial))) 647 + return -EFAULT; 648 + 649 + cwait = new_serial.closing_wait; 650 + if (cwait != ASYNC_CLOSING_WAIT_NONE) 651 + cwait = msecs_to_jiffies(10 * new_serial.closing_wait); 652 + 653 + port->port.closing_wait = cwait; 654 + 655 + return 0; 656 + } 657 + 658 + static int mxu1_ioctl(struct tty_struct *tty, 659 + unsigned int cmd, unsigned long arg) 660 + { 661 + struct usb_serial_port *port = tty->driver_data; 662 + 663 + switch (cmd) { 664 + case TIOCGSERIAL: 665 + return mxu1_get_serial_info(port, 666 + (struct serial_struct __user *)arg); 667 + case TIOCSSERIAL: 668 + return mxu1_set_serial_info(port, 669 + (struct serial_struct __user *)arg); 670 + } 671 + 672 + return -ENOIOCTLCMD; 673 + } 674 + 675 + static int mxu1_tiocmget(struct tty_struct *tty) 676 + { 677 + struct usb_serial_port *port = tty->driver_data; 678 + struct mxu1_port *mxport = usb_get_serial_port_data(port); 679 + unsigned int result; 680 + unsigned int msr; 681 + unsigned int mcr; 682 + unsigned long flags; 683 + 684 + mutex_lock(&mxport->mutex); 685 + spin_lock_irqsave(&mxport->spinlock, flags); 686 + 687 + msr = mxport->msr; 688 + mcr = mxport->mcr; 689 + 690 + spin_unlock_irqrestore(&mxport->spinlock, flags); 691 + mutex_unlock(&mxport->mutex); 692 + 693 + result = ((mcr & MXU1_MCR_DTR) ? TIOCM_DTR : 0) | 694 + ((mcr & MXU1_MCR_RTS) ? TIOCM_RTS : 0) | 695 + ((mcr & MXU1_MCR_LOOP) ? TIOCM_LOOP : 0) | 696 + ((msr & MXU1_MSR_CTS) ? TIOCM_CTS : 0) | 697 + ((msr & MXU1_MSR_CD) ? TIOCM_CAR : 0) | 698 + ((msr & MXU1_MSR_RI) ? TIOCM_RI : 0) | 699 + ((msr & MXU1_MSR_DSR) ? TIOCM_DSR : 0); 700 + 701 + dev_dbg(&port->dev, "%s - 0x%04X\n", __func__, result); 702 + 703 + return result; 704 + } 705 + 706 + static int mxu1_tiocmset(struct tty_struct *tty, 707 + unsigned int set, unsigned int clear) 708 + { 709 + struct usb_serial_port *port = tty->driver_data; 710 + struct mxu1_port *mxport = usb_get_serial_port_data(port); 711 + int err; 712 + unsigned int mcr; 713 + 714 + mutex_lock(&mxport->mutex); 715 + mcr = mxport->mcr; 716 + 717 + if (set & TIOCM_RTS) 718 + mcr |= MXU1_MCR_RTS; 719 + if (set & TIOCM_DTR) 720 + mcr |= MXU1_MCR_DTR; 721 + if (set & TIOCM_LOOP) 722 + mcr |= MXU1_MCR_LOOP; 723 + 724 + if (clear & TIOCM_RTS) 725 + mcr &= ~MXU1_MCR_RTS; 726 + if (clear & TIOCM_DTR) 727 + mcr &= ~MXU1_MCR_DTR; 728 + if (clear & TIOCM_LOOP) 729 + mcr &= ~MXU1_MCR_LOOP; 730 + 731 + err = mxu1_set_mcr(port, mcr); 732 + if (!err) 733 + mxport->mcr = mcr; 734 + 735 + mutex_unlock(&mxport->mutex); 736 + 737 + return err; 738 + } 739 + 740 + static void mxu1_break(struct tty_struct *tty, int break_state) 741 + { 742 + struct usb_serial_port *port = tty->driver_data; 743 + struct mxu1_port *mxport = usb_get_serial_port_data(port); 744 + 745 + if (break_state == -1) 746 + mxport->send_break = true; 747 + else 748 + mxport->send_break = false; 749 + 750 + mxu1_set_termios(tty, port, NULL); 751 + } 752 + 753 + static int mxu1_open(struct tty_struct *tty, struct usb_serial_port *port) 754 + { 755 + struct mxu1_port *mxport = usb_get_serial_port_data(port); 756 + struct usb_serial *serial = port->serial; 757 + int status; 758 + u16 open_settings; 759 + 760 + open_settings = (MXU1_PIPE_MODE_CONTINUOUS | 761 + MXU1_PIPE_TIMEOUT_ENABLE | 762 + (MXU1_TRANSFER_TIMEOUT << 2)); 763 + 764 + mxport->msr = 0; 765 + 766 + status = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 767 + if (status) { 768 + dev_err(&port->dev, "failed to submit interrupt urb: %d\n", 769 + status); 770 + return status; 771 + } 772 + 773 + if (tty) 774 + mxu1_set_termios(tty, port, NULL); 775 + 776 + status = mxu1_send_ctrl_urb(serial, MXU1_OPEN_PORT, 777 + open_settings, MXU1_UART1_PORT); 778 + if (status) { 779 + dev_err(&port->dev, "cannot send open command: %d\n", status); 780 + goto unlink_int_urb; 781 + } 782 + 783 + status = mxu1_send_ctrl_urb(serial, MXU1_START_PORT, 784 + 0, MXU1_UART1_PORT); 785 + if (status) { 786 + dev_err(&port->dev, "cannot send start command: %d\n", status); 787 + goto unlink_int_urb; 788 + } 789 + 790 + status = mxu1_send_ctrl_urb(serial, MXU1_PURGE_PORT, 791 + MXU1_PURGE_INPUT, MXU1_UART1_PORT); 792 + if (status) { 793 + dev_err(&port->dev, "cannot clear input buffers: %d\n", 794 + status); 795 + 796 + goto unlink_int_urb; 797 + } 798 + 799 + status = mxu1_send_ctrl_urb(serial, MXU1_PURGE_PORT, 800 + MXU1_PURGE_OUTPUT, MXU1_UART1_PORT); 801 + if (status) { 802 + dev_err(&port->dev, "cannot clear output buffers: %d\n", 803 + status); 804 + 805 + goto unlink_int_urb; 806 + } 807 + 808 + /* 809 + * reset the data toggle on the bulk endpoints to work around bug in 810 + * host controllers where things get out of sync some times 811 + */ 812 + usb_clear_halt(serial->dev, port->write_urb->pipe); 813 + usb_clear_halt(serial->dev, port->read_urb->pipe); 814 + 815 + if (tty) 816 + mxu1_set_termios(tty, port, NULL); 817 + 818 + status = mxu1_send_ctrl_urb(serial, MXU1_OPEN_PORT, 819 + open_settings, MXU1_UART1_PORT); 820 + if (status) { 821 + dev_err(&port->dev, "cannot send open command: %d\n", status); 822 + goto unlink_int_urb; 823 + } 824 + 825 + status = mxu1_send_ctrl_urb(serial, MXU1_START_PORT, 826 + 0, MXU1_UART1_PORT); 827 + if (status) { 828 + dev_err(&port->dev, "cannot send start command: %d\n", status); 829 + goto unlink_int_urb; 830 + } 831 + 832 + status = usb_serial_generic_open(tty, port); 833 + if (status) 834 + goto unlink_int_urb; 835 + 836 + return 0; 837 + 838 + unlink_int_urb: 839 + usb_kill_urb(port->interrupt_in_urb); 840 + 841 + return status; 842 + } 843 + 844 + static void mxu1_close(struct usb_serial_port *port) 845 + { 846 + int status; 847 + 848 + usb_serial_generic_close(port); 849 + usb_kill_urb(port->interrupt_in_urb); 850 + 851 + status = mxu1_send_ctrl_urb(port->serial, MXU1_CLOSE_PORT, 852 + 0, MXU1_UART1_PORT); 853 + if (status) { 854 + dev_err(&port->dev, "failed to send close port command: %d\n", 855 + status); 856 + } 857 + } 858 + 859 + static void mxu1_handle_new_msr(struct usb_serial_port *port, u8 msr) 860 + { 861 + struct mxu1_port *mxport = usb_get_serial_port_data(port); 862 + struct async_icount *icount; 863 + unsigned long flags; 864 + 865 + dev_dbg(&port->dev, "%s - msr 0x%02X\n", __func__, msr); 866 + 867 + spin_lock_irqsave(&mxport->spinlock, flags); 868 + mxport->msr = msr & MXU1_MSR_MASK; 869 + spin_unlock_irqrestore(&mxport->spinlock, flags); 870 + 871 + if (msr & MXU1_MSR_DELTA_MASK) { 872 + icount = &port->icount; 873 + if (msr & MXU1_MSR_DELTA_CTS) 874 + icount->cts++; 875 + if (msr & MXU1_MSR_DELTA_DSR) 876 + icount->dsr++; 877 + if (msr & MXU1_MSR_DELTA_CD) 878 + icount->dcd++; 879 + if (msr & MXU1_MSR_DELTA_RI) 880 + icount->rng++; 881 + 882 + wake_up_interruptible(&port->port.delta_msr_wait); 883 + } 884 + } 885 + 886 + static void mxu1_interrupt_callback(struct urb *urb) 887 + { 888 + struct usb_serial_port *port = urb->context; 889 + unsigned char *data = urb->transfer_buffer; 890 + int length = urb->actual_length; 891 + int function; 892 + int status; 893 + u8 msr; 894 + 895 + switch (urb->status) { 896 + case 0: 897 + break; 898 + case -ECONNRESET: 899 + case -ENOENT: 900 + case -ESHUTDOWN: 901 + dev_dbg(&port->dev, "%s - urb shutting down: %d\n", 902 + __func__, urb->status); 903 + return; 904 + default: 905 + dev_dbg(&port->dev, "%s - nonzero urb status: %d\n", 906 + __func__, urb->status); 907 + goto exit; 908 + } 909 + 910 + if (length != 2) { 911 + dev_dbg(&port->dev, "%s - bad packet size: %d\n", 912 + __func__, length); 913 + goto exit; 914 + } 915 + 916 + if (data[0] == MXU1_CODE_HARDWARE_ERROR) { 917 + dev_err(&port->dev, "hardware error: %d\n", data[1]); 918 + goto exit; 919 + } 920 + 921 + function = mxu1_get_func_from_code(data[0]); 922 + 923 + dev_dbg(&port->dev, "%s - function %d, data 0x%02X\n", 924 + __func__, function, data[1]); 925 + 926 + switch (function) { 927 + case MXU1_CODE_DATA_ERROR: 928 + dev_dbg(&port->dev, "%s - DATA ERROR, data 0x%02X\n", 929 + __func__, data[1]); 930 + break; 931 + 932 + case MXU1_CODE_MODEM_STATUS: 933 + msr = data[1]; 934 + mxu1_handle_new_msr(port, msr); 935 + break; 936 + 937 + default: 938 + dev_err(&port->dev, "unknown interrupt code: 0x%02X\n", 939 + data[1]); 940 + break; 941 + } 942 + 943 + exit: 944 + status = usb_submit_urb(urb, GFP_ATOMIC); 945 + if (status) { 946 + dev_err(&port->dev, "resubmit interrupt urb failed: %d\n", 947 + status); 948 + } 949 + } 950 + 951 + static struct usb_serial_driver mxu11x0_device = { 952 + .driver = { 953 + .owner = THIS_MODULE, 954 + .name = "mxu11x0", 955 + }, 956 + .description = "MOXA UPort 11x0", 957 + .id_table = mxu1_idtable, 958 + .num_ports = 1, 959 + .port_probe = mxu1_port_probe, 960 + .attach = mxu1_startup, 961 + .open = mxu1_open, 962 + .close = mxu1_close, 963 + .ioctl = mxu1_ioctl, 964 + .set_termios = mxu1_set_termios, 965 + .tiocmget = mxu1_tiocmget, 966 + .tiocmset = mxu1_tiocmset, 967 + .tiocmiwait = usb_serial_generic_tiocmiwait, 968 + .get_icount = usb_serial_generic_get_icount, 969 + .break_ctl = mxu1_break, 970 + .read_int_callback = mxu1_interrupt_callback, 971 + }; 972 + 973 + static struct usb_serial_driver *const serial_drivers[] = { 974 + &mxu11x0_device, NULL 975 + }; 976 + 977 + module_usb_serial_driver(serial_drivers, mxu1_idtable); 978 + 979 + MODULE_AUTHOR("Mathieu Othacehe <m.othacehe@gmail.com>"); 980 + MODULE_DESCRIPTION("MOXA UPort 11x0 USB to Serial Hub Driver"); 981 + MODULE_LICENSE("GPL"); 982 + MODULE_FIRMWARE("moxa/moxa-1110.fw"); 983 + MODULE_FIRMWARE("moxa/moxa-1130.fw"); 984 + MODULE_FIRMWARE("moxa/moxa-1131.fw"); 985 + MODULE_FIRMWARE("moxa/moxa-1150.fw"); 986 + MODULE_FIRMWARE("moxa/moxa-1151.fw");
+24 -24
drivers/usb/storage/uas.c
··· 49 49 }; 50 50 51 51 enum { 52 - SUBMIT_STATUS_URB = (1 << 1), 53 - ALLOC_DATA_IN_URB = (1 << 2), 54 - SUBMIT_DATA_IN_URB = (1 << 3), 55 - ALLOC_DATA_OUT_URB = (1 << 4), 56 - SUBMIT_DATA_OUT_URB = (1 << 5), 57 - ALLOC_CMD_URB = (1 << 6), 58 - SUBMIT_CMD_URB = (1 << 7), 59 - COMMAND_INFLIGHT = (1 << 8), 60 - DATA_IN_URB_INFLIGHT = (1 << 9), 61 - DATA_OUT_URB_INFLIGHT = (1 << 10), 62 - COMMAND_ABORTED = (1 << 11), 63 - IS_IN_WORK_LIST = (1 << 12), 52 + SUBMIT_STATUS_URB = BIT(1), 53 + ALLOC_DATA_IN_URB = BIT(2), 54 + SUBMIT_DATA_IN_URB = BIT(3), 55 + ALLOC_DATA_OUT_URB = BIT(4), 56 + SUBMIT_DATA_OUT_URB = BIT(5), 57 + ALLOC_CMD_URB = BIT(6), 58 + SUBMIT_CMD_URB = BIT(7), 59 + COMMAND_INFLIGHT = BIT(8), 60 + DATA_IN_URB_INFLIGHT = BIT(9), 61 + DATA_OUT_URB_INFLIGHT = BIT(10), 62 + COMMAND_ABORTED = BIT(11), 63 + IS_IN_WORK_LIST = BIT(12), 64 64 }; 65 65 66 66 /* Overrides scsi_pointer */ ··· 74 74 75 75 /* I hate forward declarations, but I actually have a loop */ 76 76 static int uas_submit_urbs(struct scsi_cmnd *cmnd, 77 - struct uas_dev_info *devinfo, gfp_t gfp); 77 + struct uas_dev_info *devinfo); 78 78 static void uas_do_work(struct work_struct *work); 79 79 static int uas_try_complete(struct scsi_cmnd *cmnd, const char *caller); 80 80 static void uas_free_streams(struct uas_dev_info *devinfo); ··· 105 105 if (!(cmdinfo->state & IS_IN_WORK_LIST)) 106 106 continue; 107 107 108 - err = uas_submit_urbs(cmnd, cmnd->device->hostdata, GFP_ATOMIC); 108 + err = uas_submit_urbs(cmnd, cmnd->device->hostdata); 109 109 if (!err) 110 110 cmdinfo->state &= ~IS_IN_WORK_LIST; 111 111 else ··· 240 240 int err; 241 241 242 242 cmdinfo->state |= direction | SUBMIT_STATUS_URB; 243 - err = uas_submit_urbs(cmnd, cmnd->device->hostdata, GFP_ATOMIC); 243 + err = uas_submit_urbs(cmnd, cmnd->device->hostdata); 244 244 if (err) { 245 245 uas_add_work(cmdinfo); 246 246 } ··· 512 512 } 513 513 514 514 static int uas_submit_urbs(struct scsi_cmnd *cmnd, 515 - struct uas_dev_info *devinfo, gfp_t gfp) 515 + struct uas_dev_info *devinfo) 516 516 { 517 517 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; 518 518 struct urb *urb; ··· 520 520 521 521 lockdep_assert_held(&devinfo->lock); 522 522 if (cmdinfo->state & SUBMIT_STATUS_URB) { 523 - urb = uas_submit_sense_urb(cmnd, gfp); 523 + urb = uas_submit_sense_urb(cmnd, GFP_ATOMIC); 524 524 if (!urb) 525 525 return SCSI_MLQUEUE_DEVICE_BUSY; 526 526 cmdinfo->state &= ~SUBMIT_STATUS_URB; 527 527 } 528 528 529 529 if (cmdinfo->state & ALLOC_DATA_IN_URB) { 530 - cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, gfp, 530 + cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, GFP_ATOMIC, 531 531 cmnd, DMA_FROM_DEVICE); 532 532 if (!cmdinfo->data_in_urb) 533 533 return SCSI_MLQUEUE_DEVICE_BUSY; ··· 536 536 537 537 if (cmdinfo->state & SUBMIT_DATA_IN_URB) { 538 538 usb_anchor_urb(cmdinfo->data_in_urb, &devinfo->data_urbs); 539 - err = usb_submit_urb(cmdinfo->data_in_urb, gfp); 539 + err = usb_submit_urb(cmdinfo->data_in_urb, GFP_ATOMIC); 540 540 if (err) { 541 541 usb_unanchor_urb(cmdinfo->data_in_urb); 542 542 uas_log_cmd_state(cmnd, "data in submit err", err); ··· 547 547 } 548 548 549 549 if (cmdinfo->state & ALLOC_DATA_OUT_URB) { 550 - cmdinfo->data_out_urb = uas_alloc_data_urb(devinfo, gfp, 550 + cmdinfo->data_out_urb = uas_alloc_data_urb(devinfo, GFP_ATOMIC, 551 551 cmnd, DMA_TO_DEVICE); 552 552 if (!cmdinfo->data_out_urb) 553 553 return SCSI_MLQUEUE_DEVICE_BUSY; ··· 556 556 557 557 if (cmdinfo->state & SUBMIT_DATA_OUT_URB) { 558 558 usb_anchor_urb(cmdinfo->data_out_urb, &devinfo->data_urbs); 559 - err = usb_submit_urb(cmdinfo->data_out_urb, gfp); 559 + err = usb_submit_urb(cmdinfo->data_out_urb, GFP_ATOMIC); 560 560 if (err) { 561 561 usb_unanchor_urb(cmdinfo->data_out_urb); 562 562 uas_log_cmd_state(cmnd, "data out submit err", err); ··· 567 567 } 568 568 569 569 if (cmdinfo->state & ALLOC_CMD_URB) { 570 - cmdinfo->cmd_urb = uas_alloc_cmd_urb(devinfo, gfp, cmnd); 570 + cmdinfo->cmd_urb = uas_alloc_cmd_urb(devinfo, GFP_ATOMIC, cmnd); 571 571 if (!cmdinfo->cmd_urb) 572 572 return SCSI_MLQUEUE_DEVICE_BUSY; 573 573 cmdinfo->state &= ~ALLOC_CMD_URB; ··· 575 575 576 576 if (cmdinfo->state & SUBMIT_CMD_URB) { 577 577 usb_anchor_urb(cmdinfo->cmd_urb, &devinfo->cmd_urbs); 578 - err = usb_submit_urb(cmdinfo->cmd_urb, gfp); 578 + err = usb_submit_urb(cmdinfo->cmd_urb, GFP_ATOMIC); 579 579 if (err) { 580 580 usb_unanchor_urb(cmdinfo->cmd_urb); 581 581 uas_log_cmd_state(cmnd, "cmd submit err", err); ··· 653 653 if (!devinfo->use_streams) 654 654 cmdinfo->state &= ~(SUBMIT_DATA_IN_URB | SUBMIT_DATA_OUT_URB); 655 655 656 - err = uas_submit_urbs(cmnd, devinfo, GFP_ATOMIC); 656 + err = uas_submit_urbs(cmnd, devinfo); 657 657 if (err) { 658 658 /* If we did nothing, give up now */ 659 659 if (cmdinfo->state & SUBMIT_STATUS_URB) {
-1
drivers/uwb/uwbd.c
··· 279 279 HZ); 280 280 if (should_stop) 281 281 break; 282 - try_to_freeze(); 283 282 284 283 spin_lock_irqsave(&rc->uwbd.event_list_lock, flags); 285 284 if (!list_empty(&rc->uwbd.event_list)) {
+23
include/linux/phy/omap_usb.h
··· 30 30 u32 mf; 31 31 }; 32 32 33 + enum omap_usb_phy_type { 34 + TYPE_USB2, /* USB2_PHY, power down in CONTROL_DEV_CONF */ 35 + TYPE_DRA7USB2, /* USB2 PHY, power and power_aux e.g. DRA7 */ 36 + TYPE_AM437USB2, /* USB2 PHY, power e.g. AM437x */ 37 + }; 38 + 33 39 struct omap_usb { 34 40 struct usb_phy phy; 35 41 struct phy_companion *comparator; ··· 46 40 struct clk *wkupclk; 47 41 struct clk *optclk; 48 42 u8 flags; 43 + enum omap_usb_phy_type type; 44 + struct regmap *syscon_phy_power; /* ctrl. reg. acces */ 45 + unsigned int power_reg; /* power reg. index within syscon */ 46 + u32 mask; 47 + u32 power_on; 48 + u32 power_off; 49 49 }; 50 50 51 51 struct usb_phy_data { 52 52 const char *label; 53 53 u8 flags; 54 + u32 mask; 55 + u32 power_on; 56 + u32 power_off; 54 57 }; 55 58 56 59 /* Driver Flags */ 57 60 #define OMAP_USB2_HAS_START_SRP (1 << 0) 58 61 #define OMAP_USB2_HAS_SET_VBUS (1 << 1) 59 62 #define OMAP_USB2_CALIBRATE_FALSE_DISCONNECT (1 << 2) 63 + 64 + #define OMAP_DEV_PHY_PD BIT(0) 65 + #define OMAP_USB2_PHY_PD BIT(28) 66 + 67 + #define AM437X_USB2_PHY_PD BIT(0) 68 + #define AM437X_USB2_OTG_PD BIT(1) 69 + #define AM437X_USB2_OTGVDET_EN BIT(19) 70 + #define AM437X_USB2_OTGSESSEND_EN BIT(20) 60 71 61 72 #define phy_to_omapusb(x) container_of((x), struct omap_usb, phy) 62 73
-28
include/linux/platform_data/usb-rcar-phy.h
··· 1 - /* 2 - * Copyright (C) 2013 Renesas Solutions Corp. 3 - * Copyright (C) 2013 Cogent Embedded, Inc. 4 - * 5 - * This program is free software; you can redistribute it and/or modify 6 - * it under the terms of the GNU General Public License version 2 as 7 - * published by the Free Software Foundation. 8 - */ 9 - 10 - #ifndef __USB_RCAR_PHY_H 11 - #define __USB_RCAR_PHY_H 12 - 13 - #include <linux/types.h> 14 - 15 - struct rcar_phy_platform_data { 16 - bool ferrite_bead:1; /* (R8A7778 only) */ 17 - 18 - bool port1_func:1; /* true: port 1 used by function, false: host */ 19 - unsigned penc1:1; /* Output of the PENC1 pin in function mode */ 20 - struct { /* Overcurrent pin control for ports 0..2 */ 21 - bool select_3_3v:1; /* true: USB_OVCn pin, false: OVCn pin */ 22 - /* Set to false on port 1 in function mode */ 23 - bool active_high:1; /* true: active high, false: active low */ 24 - /* Set to true on port 1 in function mode */ 25 - } ovc_pin[3]; /* (R8A7778 only has 2 ports) */ 26 - }; 27 - 28 - #endif /* __USB_RCAR_PHY_H */
+4 -2
include/linux/usb.h
··· 510 510 * @usb2_hw_lpm_besl_capable: device can perform USB2 hardware BESL LPM 511 511 * @usb2_hw_lpm_enabled: USB2 hardware LPM is enabled 512 512 * @usb2_hw_lpm_allowed: Userspace allows USB 2.0 LPM to be enabled 513 - * @usb3_lpm_enabled: USB3 hardware LPM enabled 513 + * @usb3_lpm_u1_enabled: USB3 hardware U1 LPM enabled 514 + * @usb3_lpm_u2_enabled: USB3 hardware U2 LPM enabled 514 515 * @string_langid: language ID for strings 515 516 * @product: iProduct string, if present (static) 516 517 * @manufacturer: iManufacturer string, if present (static) ··· 584 583 unsigned usb2_hw_lpm_besl_capable:1; 585 584 unsigned usb2_hw_lpm_enabled:1; 586 585 unsigned usb2_hw_lpm_allowed:1; 587 - unsigned usb3_lpm_enabled:1; 586 + unsigned usb3_lpm_u1_enabled:1; 587 + unsigned usb3_lpm_u2_enabled:1; 588 588 int string_langid; 589 589 590 590 /* static strings from the device */
+9 -2
include/linux/usb/gadget.h
··· 402 402 static inline int usb_ep_queue(struct usb_ep *ep, 403 403 struct usb_request *req, gfp_t gfp_flags) 404 404 { 405 + if (WARN_ON_ONCE(!ep->enabled && ep->address)) 406 + return -ESHUTDOWN; 407 + 405 408 return ep->ops->queue(ep, req, gfp_flags); 406 409 } 407 410 ··· 1015 1012 * @reset: Invoked on USB bus reset. It is mandatory for all gadget drivers 1016 1013 * and should be called in_interrupt. 1017 1014 * @driver: Driver model state for this driver. 1015 + * @udc_name: A name of UDC this driver should be bound to. If udc_name is NULL, 1016 + * this driver will be bound to any available UDC. 1017 + * @pending: UDC core private data used for deferred probe of this driver. 1018 1018 * 1019 1019 * Devices are disabled till a gadget driver successfully bind()s, which 1020 1020 * means the driver will handle setup() requests needed to enumerate (and ··· 1078 1072 1079 1073 /* FIXME support safe rmmod */ 1080 1074 struct device_driver driver; 1075 + 1076 + char *udc_name; 1077 + struct list_head pending; 1081 1078 }; 1082 1079 1083 1080 ··· 1126 1117 struct usb_gadget *gadget, void (*release)(struct device *dev)); 1127 1118 extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget); 1128 1119 extern void usb_del_gadget_udc(struct usb_gadget *gadget); 1129 - extern int usb_udc_attach_driver(const char *name, 1130 - struct usb_gadget_driver *driver); 1131 1120 1132 1121 /*-------------------------------------------------------------------------*/ 1133 1122
+2 -2
include/linux/usb/hcd.h
··· 660 660 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */ 661 661 }; 662 662 663 - extern struct usb_mon_operations *mon_ops; 663 + extern const struct usb_mon_operations *mon_ops; 664 664 665 665 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb) 666 666 { ··· 682 682 (*mon_ops->urb_complete)(bus, urb, status); 683 683 } 684 684 685 - int usb_mon_register(struct usb_mon_operations *ops); 685 + int usb_mon_register(const struct usb_mon_operations *ops); 686 686 void usb_mon_deregister(void); 687 687 688 688 #else
-30
include/linux/usb/musb-omap.h
··· 1 - /* 2 - * Copyright (C) 2011-2012 by Texas Instruments 3 - * 4 - * The Inventra Controller Driver for Linux is free software; you 5 - * can redistribute it and/or modify it under the terms of the GNU 6 - * General Public License version 2 as published by the Free Software 7 - * Foundation. 8 - */ 9 - 10 - #ifndef __MUSB_OMAP_H__ 11 - #define __MUSB_OMAP_H__ 12 - 13 - enum omap_musb_vbus_id_status { 14 - OMAP_MUSB_UNKNOWN = 0, 15 - OMAP_MUSB_ID_GROUND, 16 - OMAP_MUSB_ID_FLOAT, 17 - OMAP_MUSB_VBUS_VALID, 18 - OMAP_MUSB_VBUS_OFF, 19 - }; 20 - 21 - #if (defined(CONFIG_USB_MUSB_OMAP2PLUS) || \ 22 - defined(CONFIG_USB_MUSB_OMAP2PLUS_MODULE)) 23 - void omap_musb_mailbox(enum omap_musb_vbus_id_status status); 24 - #else 25 - static inline void omap_musb_mailbox(enum omap_musb_vbus_id_status status) 26 - { 27 - } 28 - #endif 29 - 30 - #endif /* __MUSB_OMAP_H__ */
+15
include/linux/usb/musb.h
··· 133 133 const void *platform_ops; 134 134 }; 135 135 136 + enum musb_vbus_id_status { 137 + MUSB_UNKNOWN = 0, 138 + MUSB_ID_GROUND, 139 + MUSB_ID_FLOAT, 140 + MUSB_VBUS_VALID, 141 + MUSB_VBUS_OFF, 142 + }; 143 + 144 + #if IS_ENABLED(CONFIG_USB_MUSB_HDRC) 145 + void musb_mailbox(enum musb_vbus_id_status status); 146 + #else 147 + static inline void musb_mailbox(enum musb_vbus_id_status status) 148 + { 149 + } 150 + #endif 136 151 137 152 /* TUSB 6010 support */ 138 153
+6
include/linux/usb/of.h
··· 12 12 #include <linux/usb/phy.h> 13 13 14 14 #if IS_ENABLED(CONFIG_OF) 15 + enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np); 15 16 bool of_usb_host_tpl_support(struct device_node *np); 16 17 int of_usb_update_otg_caps(struct device_node *np, 17 18 struct usb_otg_caps *otg_caps); 18 19 #else 20 + static inline enum usb_dr_mode 21 + of_usb_get_dr_mode_by_phy(struct device_node *phy_np) 22 + { 23 + return USB_DR_MODE_UNKNOWN; 24 + } 19 25 static inline bool of_usb_host_tpl_support(struct device_node *np) 20 26 { 21 27 return false;
+16 -2
include/linux/usb/renesas_usbhs.h
··· 105 105 * some register needs USB chip specific parameters. 106 106 * This struct show it to driver 107 107 */ 108 + 109 + struct renesas_usbhs_driver_pipe_config { 110 + u8 type; /* USB_ENDPOINT_XFER_xxx */ 111 + u16 bufsize; 112 + u8 bufnum; 113 + bool double_buf; 114 + }; 115 + #define RENESAS_USBHS_PIPE(_type, _size, _num, _double_buf) { \ 116 + .type = (_type), \ 117 + .bufsize = (_size), \ 118 + .bufnum = (_num), \ 119 + .double_buf = (_double_buf), \ 120 + } 121 + 108 122 struct renesas_usbhs_driver_param { 109 123 /* 110 124 * pipe settings 111 125 */ 112 - u32 *pipe_type; /* array of USB_ENDPOINT_XFER_xxx (from ep0) */ 113 - int pipe_size; /* pipe_type array size */ 126 + struct renesas_usbhs_driver_pipe_config *pipe_configs; 127 + int pipe_size; /* pipe_configs array size */ 114 128 115 129 /* 116 130 * option: