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

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

Felipe writes:

usb: changes for v3.18 merge window

Quite big pull request this time. Audio and UVC gadgets
can now be used with our configfs-based binding. We have
three PHY drivers being removed because a new one has been
added using new PHY framework.

Gadget framework got a new ->reset callback preparing for
some other changes to come on next merge window.

A few new drivers came in as well; among those we have a
new UDC driver from Xilinx and two new glue layers for
DWC3 (ST and Qualcomm).

DWC3 also learned about tracepoints which will help debugging
quite a bit.

Other than that, a big series of non-critical fixes and
cleanups.

All patches have been on linux-next for quite a bit of time
and I boot tested these changes on platforms I have access
to and work with mainline.

Signed-of-by: Felipe Balbi <balbi@ti.com>

+6014 -2581
+12
Documentation/ABI/testing/configfs-usb-gadget-uac1
··· 1 + What: /config/usb-gadget/gadget/functions/uac1.name 2 + Date: Sep 2014 3 + KernelVersion: 3.18 4 + Description: 5 + The attributes: 6 + 7 + audio_buf_size - audio buffer size 8 + fn_cap - capture pcm device file name 9 + fn_cntl - control device file name 10 + fn_play - playback pcm device file name 11 + req_buf_size - ISO OUT endpoint request buffer size 12 + req_count - ISO OUT endpoint request count
+12
Documentation/ABI/testing/configfs-usb-gadget-uac2
··· 1 + What: /config/usb-gadget/gadget/functions/uac2.name 2 + Date: Sep 2014 3 + KernelVersion: 3.18 4 + Description: 5 + The attributes: 6 + 7 + c_chmask - capture channel mask 8 + c_srate - capture sampling rate 9 + c_ssize - capture sample size (bytes) 10 + p_chmask - playback channel mask 11 + p_srate - playback sampling rate 12 + p_ssize - playback sample size (bytes)
+39
Documentation/devicetree/bindings/phy/qcom-dwc3-usb-phy.txt
··· 1 + Qualcomm DWC3 HS AND SS PHY CONTROLLER 2 + -------------------------------------- 3 + 4 + DWC3 PHY nodes are defined to describe on-chip Synopsis Physical layer 5 + controllers. Each DWC3 PHY controller should have its own node. 6 + 7 + Required properties: 8 + - compatible: should contain one of the following: 9 + - "qcom,dwc3-hs-usb-phy" for High Speed Synopsis PHY controller 10 + - "qcom,dwc3-ss-usb-phy" for Super Speed Synopsis PHY controller 11 + - reg: offset and length of the DWC3 PHY controller register set 12 + - #phy-cells: must be zero 13 + - clocks: a list of phandles and clock-specifier pairs, one for each entry in 14 + clock-names. 15 + - clock-names: Should contain "ref" for the PHY reference clock 16 + 17 + Optional clocks: 18 + "xo" External reference clock 19 + 20 + Example: 21 + phy@100f8800 { 22 + compatible = "qcom,dwc3-hs-usb-phy"; 23 + reg = <0x100f8800 0x30>; 24 + clocks = <&gcc USB30_0_UTMI_CLK>; 25 + clock-names = "ref"; 26 + #phy-cells = <0>; 27 + 28 + status = "ok"; 29 + }; 30 + 31 + phy@100f8830 { 32 + compatible = "qcom,dwc3-ss-usb-phy"; 33 + reg = <0x100f8830 0x30>; 34 + clocks = <&gcc USB30_0_MASTER_CLK>; 35 + clock-names = "ref"; 36 + #phy-cells = <0>; 37 + 38 + status = "ok"; 39 + };
+68
Documentation/devicetree/bindings/usb/dwc3-st.txt
··· 1 + ST DWC3 glue logic 2 + 3 + This file documents the parameters for the dwc3-st driver. 4 + This driver controls the glue logic used to configure the dwc3 core on 5 + STiH407 based platforms. 6 + 7 + Required properties: 8 + - compatible : must be "st,stih407-dwc3" 9 + - reg : glue logic base address and USB syscfg ctrl register offset 10 + - reg-names : should be "reg-glue" and "syscfg-reg" 11 + - st,syscon : should be phandle to system configuration node which 12 + encompasses the glue registers 13 + - resets : list of phandle and reset specifier pairs. There should be two entries, one 14 + for the powerdown and softreset lines of the usb3 IP 15 + - reset-names : list of reset signal names. Names should be "powerdown" and "softreset" 16 + See: Documentation/devicetree/bindings/reset/st,sti-powerdown.txt 17 + See: Documentation/devicetree/bindings/reset/reset.txt 18 + 19 + - #address-cells, #size-cells : should be '1' if the device has sub-nodes 20 + with 'reg' property 21 + 22 + - pinctl-names : A pinctrl state named "default" must be defined 23 + See: Documentation/devicetree/bindings/pinctrl/pinctrl-binding.txt 24 + 25 + - pinctrl-0 : Pin control group 26 + See: Documentation/devicetree/bindings/pinctrl/pinctrl-binding.txt 27 + 28 + - ranges : allows valid 1:1 translation between child's address space and 29 + parent's address space 30 + 31 + Sub-nodes: 32 + The dwc3 core should be added as subnode to ST DWC3 glue as shown in the 33 + example below. The DT binding details of dwc3 can be found in: 34 + Documentation/devicetree/bindings/usb/dwc3.txt 35 + 36 + NB: The dr_mode property described in [1] is NOT optional for this driver, as the default value 37 + is "otg", which isn't supported by this SoC. Valid dr_mode values for dwc3-st are either "host" 38 + or "device". 39 + 40 + [1] Documentation/devicetree/bindings/usb/generic.txt 41 + 42 + Example: 43 + 44 + st_dwc3: dwc3@8f94000 { 45 + status = "disabled"; 46 + compatible = "st,stih407-dwc3"; 47 + reg = <0x08f94000 0x1000>, <0x110 0x4>; 48 + reg-names = "reg-glue", "syscfg-reg"; 49 + st,syscfg = <&syscfg_core>; 50 + resets = <&powerdown STIH407_USB3_POWERDOWN>, 51 + <&softreset STIH407_MIPHY2_SOFTRESET>; 52 + reset-names = "powerdown", 53 + "softreset"; 54 + #address-cells = <1>; 55 + #size-cells = <1>; 56 + pinctrl-names = "default"; 57 + pinctrl-0 = <&pinctrl_usb3>; 58 + ranges; 59 + 60 + dwc3: dwc3@9900000 { 61 + compatible = "snps,dwc3"; 62 + reg = <0x09900000 0x100000>; 63 + interrupts = <GIC_SPI 155 IRQ_TYPE_NONE>; 64 + dr_mode = "host"; 65 + phys-names = "usb2-phy", "usb3-phy"; 66 + phys = <&usb2_picophy2>, <&phy_port2 MIPHY_TYPE_USB>; 67 + }; 68 + };
+1
Documentation/devicetree/bindings/usb/mxs-phy.txt
··· 5 5 * "fsl,imx23-usbphy" for imx23 and imx28 6 6 * "fsl,imx6q-usbphy" for imx6dq and imx6dl 7 7 * "fsl,imx6sl-usbphy" for imx6sl 8 + * "fsl,vf610-usbphy" for Vybrid vf610 8 9 * "fsl,imx6sx-usbphy" for imx6sx 9 10 "fsl,imx23-usbphy" is still a fallback for other strings 10 11 - reg: Should contain registers location and length
+66
Documentation/devicetree/bindings/usb/qcom,dwc3.txt
··· 1 + Qualcomm SuperSpeed DWC3 USB SoC controller 2 + 3 + Required properties: 4 + - compatible: should contain "qcom,dwc3" 5 + - clocks: A list of phandle + clock-specifier pairs for the 6 + clocks listed in clock-names 7 + - clock-names: Should contain the following: 8 + "core" Master/Core clock, have to be >= 125 MHz for SS 9 + operation and >= 60MHz for HS operation 10 + 11 + Optional clocks: 12 + "iface" System bus AXI clock. Not present on all platforms 13 + "sleep" Sleep clock, used when USB3 core goes into low 14 + power mode (U3). 15 + 16 + Required child node: 17 + A child node must exist to represent the core DWC3 IP block. The name of 18 + the node is not important. The content of the node is defined in dwc3.txt. 19 + 20 + Phy documentation is provided in the following places: 21 + Documentation/devicetree/bindings/phy/qcom,dwc3-usb-phy.txt 22 + 23 + Example device nodes: 24 + 25 + hs_phy: phy@100f8800 { 26 + compatible = "qcom,dwc3-hs-usb-phy"; 27 + reg = <0x100f8800 0x30>; 28 + clocks = <&gcc USB30_0_UTMI_CLK>; 29 + clock-names = "ref"; 30 + #phy-cells = <0>; 31 + 32 + status = "ok"; 33 + }; 34 + 35 + ss_phy: phy@100f8830 { 36 + compatible = "qcom,dwc3-ss-usb-phy"; 37 + reg = <0x100f8830 0x30>; 38 + clocks = <&gcc USB30_0_MASTER_CLK>; 39 + clock-names = "ref"; 40 + #phy-cells = <0>; 41 + 42 + status = "ok"; 43 + }; 44 + 45 + usb3_0: usb30@0 { 46 + compatible = "qcom,dwc3"; 47 + #address-cells = <1>; 48 + #size-cells = <1>; 49 + clocks = <&gcc USB30_0_MASTER_CLK>; 50 + clock-names = "core"; 51 + 52 + ranges; 53 + 54 + status = "ok"; 55 + 56 + dwc3@10000000 { 57 + compatible = "snps,dwc3"; 58 + reg = <0x10000000 0xcd00>; 59 + interrupts = <0 205 0x4>; 60 + phys = <&hs_phy>, <&ss_phy>; 61 + phy-names = "usb2-phy", "usb3-phy"; 62 + tx-fifo-resize; 63 + dr_mode = "host"; 64 + }; 65 + }; 66 +
+24
Documentation/devicetree/bindings/usb/renesas_usbhs.txt
··· 1 + Renesas Electronics USBHS driver 2 + 3 + Required properties: 4 + - compatible: Must contain one of the following: 5 + - "renesas,usbhs-r8a7790" 6 + - "renesas,usbhs-r8a7791" 7 + - reg: Base address and length of the register for the USBHS 8 + - interrupts: Interrupt specifier for the USBHS 9 + - clocks: A list of phandle + clock specifier pairs 10 + 11 + Optional properties: 12 + - renesas,buswait: Integer to use BUSWAIT register 13 + - renesas,enable-gpio: A gpio specifier to check GPIO determining if USB 14 + function should be enabled 15 + - phys: phandle + phy specifier pair 16 + - phy-names: must be "usb" 17 + 18 + Example: 19 + usbhs: usb@e6590000 { 20 + compatible = "renesas,usbhs-r8a7790"; 21 + reg = <0 0xe6590000 0 0x100>; 22 + interrupts = <0 107 IRQ_TYPE_LEVEL_HIGH>; 23 + clocks = <&mstp7_clks R8A7790_CLK_HSUSB>; 24 + };
+18
Documentation/devicetree/bindings/usb/udc-xilinx.txt
··· 1 + Xilinx USB2 device controller 2 + 3 + Required properties: 4 + - compatible : Should be "xlnx,usb2-device-4.00.a" 5 + - reg : Physical base address and size of the USB2 6 + device registers map. 7 + - interrupts : Should contain single irq line of USB2 device 8 + controller 9 + - xlnx,has-builtin-dma : if DMA is included 10 + 11 + Example: 12 + axi-usb2-device@42e00000 { 13 + compatible = "xlnx,usb2-device-4.00.a"; 14 + interrupts = <0x0 0x39 0x1>; 15 + reg = <0x42e00000 0x10000>; 16 + xlnx,has-builtin-dma; 17 + }; 18 +
+2 -1
MAINTAINERS
··· 1398 1398 F: drivers/i2c/busses/i2c-st.c 1399 1399 F: drivers/tty/serial/st-asc.c 1400 1400 F: drivers/mmc/host/sdhci-st.c 1401 + F: drivers/usb/dwc3/dwc3-st.c 1401 1402 1402 1403 ARM/TECHNOLOGIC SYSTEMS TS7250 MACHINE SUPPORT 1403 1404 M: Lennert Buytenhek <kernel@wantstofly.org> ··· 9684 9683 M: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 9685 9684 L: linux-usb@vger.kernel.org 9686 9685 S: Maintained 9687 - F: drivers/usb/gadget/function/*uvc*.c 9686 + F: drivers/usb/gadget/function/*uvc* 9688 9687 F: drivers/usb/gadget/legacy/webcam.c 9689 9688 9690 9689 USB WIRELESS RNDIS DRIVER (rndis_wlan)
+17
drivers/usb/dwc3/Kconfig
··· 80 80 Support of USB2/3 functionality in TI Keystone2 platforms. 81 81 Say 'Y' or 'M' here if you have one such device 82 82 83 + config USB_DWC3_ST 84 + tristate "STMicroelectronics Platforms" 85 + depends on ARCH_STI && OF 86 + default USB_DWC3 87 + help 88 + STMicroelectronics SoCs with one DesignWare Core USB3 IP 89 + inside (i.e. STiH407). 90 + Say 'Y' or 'M' if you have one such device. 91 + 92 + config USB_DWC3_QCOM 93 + tristate "Qualcomm Platforms" 94 + depends on ARCH_QCOM || COMPILE_TEST 95 + default USB_DWC3 96 + help 97 + Recent Qualcomm SoCs ship with one DesignWare Core USB3 IP inside, 98 + say 'Y' or 'M' if you have one such device. 99 + 83 100 comment "Debugging features" 84 101 85 102 config USB_DWC3_DEBUG
+6 -1
drivers/usb/dwc3/Makefile
··· 1 + # define_trace.h needs to know how to find our header 2 + CFLAGS_trace.o := -I$(src) 3 + 1 4 ccflags-$(CONFIG_USB_DWC3_DEBUG) := -DDEBUG 2 5 ccflags-$(CONFIG_USB_DWC3_VERBOSE) += -DVERBOSE_DEBUG 3 6 4 7 obj-$(CONFIG_USB_DWC3) += dwc3.o 5 8 6 - dwc3-y := core.o 9 + dwc3-y := core.o debug.o trace.o 7 10 8 11 ifneq ($(filter y,$(CONFIG_USB_DWC3_HOST) $(CONFIG_USB_DWC3_DUAL_ROLE)),) 9 12 dwc3-y += host.o ··· 36 33 obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o 37 34 obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o 38 35 obj-$(CONFIG_USB_DWC3_KEYSTONE) += dwc3-keystone.o 36 + obj-$(CONFIG_USB_DWC3_QCOM) += dwc3-qcom.o 37 + obj-$(CONFIG_USB_DWC3_ST) += dwc3-st.o
+3 -6
drivers/usb/dwc3/core.c
··· 186 186 187 187 dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs) * num, 188 188 GFP_KERNEL); 189 - if (!dwc->ev_buffs) { 190 - dev_err(dwc->dev, "can't allocate event buffers array\n"); 189 + if (!dwc->ev_buffs) 191 190 return -ENOMEM; 192 - } 193 191 194 192 for (i = 0; i < num; i++) { 195 193 struct dwc3_event_buffer *evt; ··· 637 639 void *mem; 638 640 639 641 mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL); 640 - if (!mem) { 641 - dev_err(dev, "not enough memory\n"); 642 + if (!mem) 642 643 return -ENOMEM; 643 - } 644 + 644 645 dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1); 645 646 dwc->mem = mem; 646 647 dwc->dev = dev;
+3 -1
drivers/usb/dwc3/core.h
··· 33 33 34 34 #include <linux/phy/phy.h> 35 35 36 + #define DWC3_MSG_MAX 500 37 + 36 38 /* Global constants */ 37 39 #define DWC3_EP0_BOUNCE_SIZE 512 38 40 #define DWC3_ENDPOINTS_NUM 32 ··· 940 938 int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state); 941 939 int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep, 942 940 unsigned cmd, struct dwc3_gadget_ep_cmd_params *params); 943 - int dwc3_send_gadget_generic_command(struct dwc3 *dwc, int cmd, u32 param); 941 + int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param); 944 942 #else 945 943 static inline int dwc3_gadget_init(struct dwc3 *dwc) 946 944 { return 0; }
+32
drivers/usb/dwc3/debug.c
··· 1 + /** 2 + * debug.c - DesignWare USB3 DRD Controller Debug/Trace Support 3 + * 4 + * Copyright (C) 2014 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 + 18 + #include "debug.h" 19 + 20 + void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...) 21 + { 22 + struct va_format vaf; 23 + va_list args; 24 + 25 + va_start(args, fmt); 26 + vaf.fmt = fmt; 27 + vaf.va = &args; 28 + 29 + trace(&vaf); 30 + 31 + va_end(args); 32 + }
+199 -1
drivers/usb/dwc3/debug.h
··· 16 16 * GNU General Public License for more details. 17 17 */ 18 18 19 + #ifndef __DWC3_DEBUG_H 20 + #define __DWC3_DEBUG_H 21 + 19 22 #include "core.h" 23 + 24 + /** 25 + * dwc3_gadget_ep_cmd_string - returns endpoint command string 26 + * @cmd: command code 27 + */ 28 + static inline const char * 29 + dwc3_gadget_ep_cmd_string(u8 cmd) 30 + { 31 + switch (cmd) { 32 + case DWC3_DEPCMD_DEPSTARTCFG: 33 + return "Start New Configuration"; 34 + case DWC3_DEPCMD_ENDTRANSFER: 35 + return "End Transfer"; 36 + case DWC3_DEPCMD_UPDATETRANSFER: 37 + return "Update Transfer"; 38 + case DWC3_DEPCMD_STARTTRANSFER: 39 + return "Start Transfer"; 40 + case DWC3_DEPCMD_CLEARSTALL: 41 + return "Clear Stall"; 42 + case DWC3_DEPCMD_SETSTALL: 43 + return "Set Stall"; 44 + case DWC3_DEPCMD_GETEPSTATE: 45 + return "Get Endpoint State"; 46 + case DWC3_DEPCMD_SETTRANSFRESOURCE: 47 + return "Set Endpoint Transfer Resource"; 48 + case DWC3_DEPCMD_SETEPCONFIG: 49 + return "Set Endpoint Configuration"; 50 + default: 51 + return "UNKNOWN command"; 52 + } 53 + } 54 + 55 + /** 56 + * dwc3_gadget_generic_cmd_string - returns generic command string 57 + * @cmd: command code 58 + */ 59 + static inline const char * 60 + dwc3_gadget_generic_cmd_string(u8 cmd) 61 + { 62 + switch (cmd) { 63 + case DWC3_DGCMD_SET_LMP: 64 + return "Set LMP"; 65 + case DWC3_DGCMD_SET_PERIODIC_PAR: 66 + return "Set Periodic Parameters"; 67 + case DWC3_DGCMD_XMIT_FUNCTION: 68 + return "Transmit Function Wake Device Notification"; 69 + case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO: 70 + return "Set Scratchpad Buffer Array Address Lo"; 71 + case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI: 72 + return "Set Scratchpad Buffer Array Address Hi"; 73 + case DWC3_DGCMD_SELECTED_FIFO_FLUSH: 74 + return "Selected FIFO Flush"; 75 + case DWC3_DGCMD_ALL_FIFO_FLUSH: 76 + return "All FIFO Flush"; 77 + case DWC3_DGCMD_SET_ENDPOINT_NRDY: 78 + return "Set Endpoint NRDY"; 79 + case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK: 80 + return "Run SoC Bus Loopback Test"; 81 + default: 82 + return "UNKNOWN"; 83 + } 84 + } 85 + 86 + /** 87 + * dwc3_gadget_link_string - returns link name 88 + * @link_state: link state code 89 + */ 90 + static inline const char * 91 + dwc3_gadget_link_string(enum dwc3_link_state link_state) 92 + { 93 + switch (link_state) { 94 + case DWC3_LINK_STATE_U0: 95 + return "U0"; 96 + case DWC3_LINK_STATE_U1: 97 + return "U1"; 98 + case DWC3_LINK_STATE_U2: 99 + return "U2"; 100 + case DWC3_LINK_STATE_U3: 101 + return "U3"; 102 + case DWC3_LINK_STATE_SS_DIS: 103 + return "SS.Disabled"; 104 + case DWC3_LINK_STATE_RX_DET: 105 + return "RX.Detect"; 106 + case DWC3_LINK_STATE_SS_INACT: 107 + return "SS.Inactive"; 108 + case DWC3_LINK_STATE_POLL: 109 + return "Polling"; 110 + case DWC3_LINK_STATE_RECOV: 111 + return "Recovery"; 112 + case DWC3_LINK_STATE_HRESET: 113 + return "Hot Reset"; 114 + case DWC3_LINK_STATE_CMPLY: 115 + return "Compliance"; 116 + case DWC3_LINK_STATE_LPBK: 117 + return "Loopback"; 118 + case DWC3_LINK_STATE_RESET: 119 + return "Reset"; 120 + case DWC3_LINK_STATE_RESUME: 121 + return "Resume"; 122 + default: 123 + return "UNKNOWN link state\n"; 124 + } 125 + } 126 + 127 + /** 128 + * dwc3_gadget_event_string - returns event name 129 + * @event: the event code 130 + */ 131 + static inline const char *dwc3_gadget_event_string(u8 event) 132 + { 133 + switch (event) { 134 + case DWC3_DEVICE_EVENT_DISCONNECT: 135 + return "Disconnect"; 136 + case DWC3_DEVICE_EVENT_RESET: 137 + return "Reset"; 138 + case DWC3_DEVICE_EVENT_CONNECT_DONE: 139 + return "Connection Done"; 140 + case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE: 141 + return "Link Status Change"; 142 + case DWC3_DEVICE_EVENT_WAKEUP: 143 + return "WakeUp"; 144 + case DWC3_DEVICE_EVENT_EOPF: 145 + return "End-Of-Frame"; 146 + case DWC3_DEVICE_EVENT_SOF: 147 + return "Start-Of-Frame"; 148 + case DWC3_DEVICE_EVENT_ERRATIC_ERROR: 149 + return "Erratic Error"; 150 + case DWC3_DEVICE_EVENT_CMD_CMPL: 151 + return "Command Complete"; 152 + case DWC3_DEVICE_EVENT_OVERFLOW: 153 + return "Overflow"; 154 + } 155 + 156 + return "UNKNOWN"; 157 + } 158 + 159 + /** 160 + * dwc3_ep_event_string - returns event name 161 + * @event: then event code 162 + */ 163 + static inline const char *dwc3_ep_event_string(u8 event) 164 + { 165 + switch (event) { 166 + case DWC3_DEPEVT_XFERCOMPLETE: 167 + return "Transfer Complete"; 168 + case DWC3_DEPEVT_XFERINPROGRESS: 169 + return "Transfer In-Progress"; 170 + case DWC3_DEPEVT_XFERNOTREADY: 171 + return "Transfer Not Ready"; 172 + case DWC3_DEPEVT_RXTXFIFOEVT: 173 + return "FIFO"; 174 + case DWC3_DEPEVT_STREAMEVT: 175 + return "Stream"; 176 + case DWC3_DEPEVT_EPCMDCMPLT: 177 + return "Endpoint Command Complete"; 178 + } 179 + 180 + return "UNKNOWN"; 181 + } 182 + 183 + /** 184 + * dwc3_gadget_event_type_string - return event name 185 + * @event: the event code 186 + */ 187 + static inline const char *dwc3_gadget_event_type_string(u8 event) 188 + { 189 + switch (event) { 190 + case DWC3_DEVICE_EVENT_DISCONNECT: 191 + return "Disconnect"; 192 + case DWC3_DEVICE_EVENT_RESET: 193 + return "Reset"; 194 + case DWC3_DEVICE_EVENT_CONNECT_DONE: 195 + return "Connect Done"; 196 + case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE: 197 + return "Link Status Change"; 198 + case DWC3_DEVICE_EVENT_WAKEUP: 199 + return "Wake-Up"; 200 + case DWC3_DEVICE_EVENT_HIBER_REQ: 201 + return "Hibernation"; 202 + case DWC3_DEVICE_EVENT_EOPF: 203 + return "End of Periodic Frame"; 204 + case DWC3_DEVICE_EVENT_SOF: 205 + return "Start of Frame"; 206 + case DWC3_DEVICE_EVENT_ERRATIC_ERROR: 207 + return "Erratic Error"; 208 + case DWC3_DEVICE_EVENT_CMD_CMPL: 209 + return "Command Complete"; 210 + case DWC3_DEVICE_EVENT_OVERFLOW: 211 + return "Overflow"; 212 + default: 213 + return "UNKNOWN"; 214 + } 215 + } 216 + 217 + void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...); 20 218 21 219 #ifdef CONFIG_DEBUG_FS 22 220 extern int dwc3_debugfs_init(struct dwc3 *); ··· 225 27 static inline void dwc3_debugfs_exit(struct dwc3 *d) 226 28 { } 227 29 #endif 228 - 30 + #endif /* __DWC3_DEBUG_H */
+1 -3
drivers/usb/dwc3/dwc3-exynos.c
··· 113 113 int ret; 114 114 115 115 exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); 116 - if (!exynos) { 117 - dev_err(dev, "not enough memory\n"); 116 + if (!exynos) 118 117 return -ENOMEM; 119 - } 120 118 121 119 /* 122 120 * Right now device-tree probed devices don't get dma_mask set.
+1 -3
drivers/usb/dwc3/dwc3-omap.c
··· 481 481 } 482 482 483 483 omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL); 484 - if (!omap) { 485 - dev_err(dev, "not enough memory\n"); 484 + if (!omap) 486 485 return -ENOMEM; 487 - } 488 486 489 487 platform_set_drvdata(pdev, omap); 490 488
+1 -3
drivers/usb/dwc3/dwc3-pci.c
··· 103 103 struct device *dev = &pci->dev; 104 104 105 105 glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL); 106 - if (!glue) { 107 - dev_err(dev, "not enough memory\n"); 106 + if (!glue) 108 107 return -ENOMEM; 109 - } 110 108 111 109 glue->dev = dev; 112 110
+131
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_dbg(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_dbg(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 + .owner = THIS_MODULE, 122 + .of_match_table = of_dwc3_match, 123 + }, 124 + }; 125 + 126 + module_platform_driver(dwc3_qcom_driver); 127 + 128 + MODULE_ALIAS("platform:qcom-dwc3"); 129 + MODULE_LICENSE("GPL v2"); 130 + MODULE_DESCRIPTION("DesignWare USB3 QCOM Glue Layer"); 131 + MODULE_AUTHOR("Ivan T. Ivanov <iivanov@mm-sol.com>");
+367
drivers/usb/dwc3/dwc3-st.c
··· 1 + /** 2 + * dwc3-st.c Support for dwc3 platform devices on ST Microelectronics platforms 3 + * 4 + * This is a small driver for the dwc3 to provide the glue logic 5 + * to configure the controller. Tested on STi platforms. 6 + * 7 + * Copyright (C) 2014 Stmicroelectronics 8 + * 9 + * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com> 10 + * Contributors: Aymen Bouattay <aymen.bouattay@st.com> 11 + * Peter Griffin <peter.griffin@linaro.org> 12 + * 13 + * This program is free software; you can redistribute it and/or modify 14 + * it under the terms of the GNU General Public License as published by 15 + * the Free Software Foundation; either version 2 of the License, or 16 + * (at your option) any later version. 17 + * 18 + * Inspired by dwc3-omap.c and dwc3-exynos.c. 19 + */ 20 + 21 + #include <linux/delay.h> 22 + #include <linux/interrupt.h> 23 + #include <linux/io.h> 24 + #include <linux/ioport.h> 25 + #include <linux/kernel.h> 26 + #include <linux/mfd/syscon.h> 27 + #include <linux/module.h> 28 + #include <linux/of.h> 29 + #include <linux/of_platform.h> 30 + #include <linux/platform_device.h> 31 + #include <linux/slab.h> 32 + #include <linux/regmap.h> 33 + #include <linux/reset.h> 34 + #include <linux/usb/of.h> 35 + 36 + #include "core.h" 37 + #include "io.h" 38 + 39 + /* glue registers */ 40 + #define CLKRST_CTRL 0x00 41 + #define AUX_CLK_EN BIT(0) 42 + #define SW_PIPEW_RESET_N BIT(4) 43 + #define EXT_CFG_RESET_N BIT(8) 44 + /* 45 + * 1'b0 : The host controller complies with the xHCI revision 0.96 46 + * 1'b1 : The host controller complies with the xHCI revision 1.0 47 + */ 48 + #define XHCI_REVISION BIT(12) 49 + 50 + #define USB2_VBUS_MNGMNT_SEL1 0x2C 51 + /* 52 + * For all fields in USB2_VBUS_MNGMNT_SEL1 53 + * 2’b00 : Override value from Reg 0x30 is selected 54 + * 2’b01 : utmiotg_<signal_name> from usb3_top is selected 55 + * 2’b10 : pipew_<signal_name> from PIPEW instance is selected 56 + * 2’b11 : value is 1'b0 57 + */ 58 + #define USB2_VBUS_REG30 0x0 59 + #define USB2_VBUS_UTMIOTG 0x1 60 + #define USB2_VBUS_PIPEW 0x2 61 + #define USB2_VBUS_ZERO 0x3 62 + 63 + #define SEL_OVERRIDE_VBUSVALID(n) (n << 0) 64 + #define SEL_OVERRIDE_POWERPRESENT(n) (n << 4) 65 + #define SEL_OVERRIDE_BVALID(n) (n << 8) 66 + 67 + /* Static DRD configuration */ 68 + #define USB3_CONTROL_MASK 0xf77 69 + 70 + #define USB3_DEVICE_NOT_HOST BIT(0) 71 + #define USB3_FORCE_VBUSVALID BIT(1) 72 + #define USB3_DELAY_VBUSVALID BIT(2) 73 + #define USB3_SEL_FORCE_OPMODE BIT(4) 74 + #define USB3_FORCE_OPMODE(n) (n << 5) 75 + #define USB3_SEL_FORCE_DPPULLDOWN2 BIT(8) 76 + #define USB3_FORCE_DPPULLDOWN2 BIT(9) 77 + #define USB3_SEL_FORCE_DMPULLDOWN2 BIT(10) 78 + #define USB3_FORCE_DMPULLDOWN2 BIT(11) 79 + 80 + /** 81 + * struct st_dwc3 - dwc3-st driver private structure 82 + * @dev: device pointer 83 + * @glue_base: ioaddr for the glue registers 84 + * @regmap: regmap pointer for getting syscfg 85 + * @syscfg_reg_off: usb syscfg control offset 86 + * @dr_mode: drd static host/device config 87 + * @rstc_pwrdn: rest controller for powerdown signal 88 + * @rstc_rst: reset controller for softreset signal 89 + */ 90 + 91 + struct st_dwc3 { 92 + struct device *dev; 93 + void __iomem *glue_base; 94 + struct regmap *regmap; 95 + int syscfg_reg_off; 96 + enum usb_dr_mode dr_mode; 97 + struct reset_control *rstc_pwrdn; 98 + struct reset_control *rstc_rst; 99 + }; 100 + 101 + static inline u32 st_dwc3_readl(void __iomem *base, u32 offset) 102 + { 103 + return readl_relaxed(base + offset); 104 + } 105 + 106 + static inline void st_dwc3_writel(void __iomem *base, u32 offset, u32 value) 107 + { 108 + writel_relaxed(value, base + offset); 109 + } 110 + 111 + /** 112 + * st_dwc3_drd_init: program the port 113 + * @dwc3_data: driver private structure 114 + * Description: this function is to program the port as either host or device 115 + * according to the static configuration passed from devicetree. 116 + * OTG and dual role are not yet supported! 117 + */ 118 + static int st_dwc3_drd_init(struct st_dwc3 *dwc3_data) 119 + { 120 + u32 val; 121 + int err; 122 + 123 + err = regmap_read(dwc3_data->regmap, dwc3_data->syscfg_reg_off, &val); 124 + if (err) 125 + return err; 126 + 127 + val &= USB3_CONTROL_MASK; 128 + 129 + switch (dwc3_data->dr_mode) { 130 + case USB_DR_MODE_PERIPHERAL: 131 + 132 + val &= ~(USB3_FORCE_VBUSVALID | USB3_DELAY_VBUSVALID 133 + | USB3_SEL_FORCE_OPMODE | USB3_FORCE_OPMODE(0x3) 134 + | USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2 135 + | USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2); 136 + 137 + val |= USB3_DEVICE_NOT_HOST; 138 + 139 + dev_dbg(dwc3_data->dev, "Configuring as Device\n"); 140 + break; 141 + 142 + case USB_DR_MODE_HOST: 143 + 144 + val &= ~(USB3_DEVICE_NOT_HOST | USB3_FORCE_VBUSVALID 145 + | USB3_SEL_FORCE_OPMODE | USB3_FORCE_OPMODE(0x3) 146 + | USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2 147 + | USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2); 148 + 149 + /* 150 + * USB3_DELAY_VBUSVALID is ANDed with USB_C_VBUSVALID. Thus, 151 + * when set to ‘0‘, it can delay the arrival of VBUSVALID 152 + * information to VBUSVLDEXT2 input of the pico PHY. 153 + * We don't want to do that so we set the bit to '1'. 154 + */ 155 + 156 + val |= USB3_DELAY_VBUSVALID; 157 + 158 + dev_dbg(dwc3_data->dev, "Configuring as Host\n"); 159 + break; 160 + 161 + default: 162 + dev_err(dwc3_data->dev, "Unsupported mode of operation %d\n", 163 + dwc3_data->dr_mode); 164 + return -EINVAL; 165 + } 166 + 167 + return regmap_write(dwc3_data->regmap, dwc3_data->syscfg_reg_off, val); 168 + } 169 + 170 + /** 171 + * st_dwc3_init: init the controller via glue logic 172 + * @dwc3_data: driver private structure 173 + */ 174 + static void st_dwc3_init(struct st_dwc3 *dwc3_data) 175 + { 176 + u32 reg = st_dwc3_readl(dwc3_data->glue_base, CLKRST_CTRL); 177 + 178 + reg |= AUX_CLK_EN | EXT_CFG_RESET_N | XHCI_REVISION; 179 + reg &= ~SW_PIPEW_RESET_N; 180 + st_dwc3_writel(dwc3_data->glue_base, CLKRST_CTRL, reg); 181 + 182 + /* configure mux for vbus, powerpresent and bvalid signals */ 183 + reg = st_dwc3_readl(dwc3_data->glue_base, USB2_VBUS_MNGMNT_SEL1); 184 + 185 + reg |= SEL_OVERRIDE_VBUSVALID(USB2_VBUS_UTMIOTG) | 186 + SEL_OVERRIDE_POWERPRESENT(USB2_VBUS_UTMIOTG) | 187 + SEL_OVERRIDE_BVALID(USB2_VBUS_UTMIOTG); 188 + 189 + st_dwc3_writel(dwc3_data->glue_base, USB2_VBUS_MNGMNT_SEL1, reg); 190 + 191 + reg = st_dwc3_readl(dwc3_data->glue_base, CLKRST_CTRL); 192 + reg |= SW_PIPEW_RESET_N; 193 + st_dwc3_writel(dwc3_data->glue_base, CLKRST_CTRL, reg); 194 + } 195 + 196 + static int st_dwc3_probe(struct platform_device *pdev) 197 + { 198 + struct st_dwc3 *dwc3_data; 199 + struct resource *res; 200 + struct device *dev = &pdev->dev; 201 + struct device_node *node = dev->of_node, *child; 202 + struct regmap *regmap; 203 + int ret; 204 + 205 + dwc3_data = devm_kzalloc(dev, sizeof(*dwc3_data), GFP_KERNEL); 206 + if (!dwc3_data) 207 + return -ENOMEM; 208 + 209 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "reg-glue"); 210 + dwc3_data->glue_base = devm_ioremap_resource(dev, res); 211 + if (IS_ERR(dwc3_data->glue_base)) 212 + return PTR_ERR(dwc3_data->glue_base); 213 + 214 + regmap = syscon_regmap_lookup_by_phandle(node, "st,syscfg"); 215 + if (IS_ERR(regmap)) 216 + return PTR_ERR(regmap); 217 + 218 + dma_set_coherent_mask(dev, dev->coherent_dma_mask); 219 + dwc3_data->dev = dev; 220 + dwc3_data->regmap = regmap; 221 + 222 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "syscfg-reg"); 223 + if (!res) { 224 + ret = -ENXIO; 225 + goto undo_platform_dev_alloc; 226 + } 227 + 228 + dwc3_data->syscfg_reg_off = res->start; 229 + 230 + dev_vdbg(&pdev->dev, "glue-logic addr 0x%p, syscfg-reg offset 0x%x\n", 231 + dwc3_data->glue_base, dwc3_data->syscfg_reg_off); 232 + 233 + dwc3_data->rstc_pwrdn = devm_reset_control_get(dev, "powerdown"); 234 + if (IS_ERR(dwc3_data->rstc_pwrdn)) { 235 + dev_err(&pdev->dev, "could not get power controller\n"); 236 + ret = PTR_ERR(dwc3_data->rstc_pwrdn); 237 + goto undo_platform_dev_alloc; 238 + } 239 + 240 + /* Manage PowerDown */ 241 + reset_control_deassert(dwc3_data->rstc_pwrdn); 242 + 243 + dwc3_data->rstc_rst = devm_reset_control_get(dev, "softreset"); 244 + if (IS_ERR(dwc3_data->rstc_rst)) { 245 + dev_err(&pdev->dev, "could not get reset controller\n"); 246 + ret = PTR_ERR(dwc3_data->rstc_pwrdn); 247 + goto undo_powerdown; 248 + } 249 + 250 + /* Manage SoftReset */ 251 + reset_control_deassert(dwc3_data->rstc_rst); 252 + 253 + child = of_get_child_by_name(node, "dwc3"); 254 + if (!child) { 255 + dev_err(&pdev->dev, "failed to find dwc3 core node\n"); 256 + ret = -ENODEV; 257 + goto undo_softreset; 258 + } 259 + 260 + dwc3_data->dr_mode = of_usb_get_dr_mode(child); 261 + 262 + /* Allocate and initialize the core */ 263 + ret = of_platform_populate(node, NULL, NULL, dev); 264 + if (ret) { 265 + dev_err(dev, "failed to add dwc3 core\n"); 266 + goto undo_softreset; 267 + } 268 + 269 + /* 270 + * Configure the USB port as device or host according to the static 271 + * configuration passed from DT. 272 + * DRD is the only mode currently supported so this will be enhanced 273 + * as soon as OTG is available. 274 + */ 275 + ret = st_dwc3_drd_init(dwc3_data); 276 + if (ret) { 277 + dev_err(dev, "drd initialisation failed\n"); 278 + goto undo_softreset; 279 + } 280 + 281 + /* ST glue logic init */ 282 + st_dwc3_init(dwc3_data); 283 + 284 + platform_set_drvdata(pdev, dwc3_data); 285 + return 0; 286 + 287 + undo_softreset: 288 + reset_control_assert(dwc3_data->rstc_rst); 289 + undo_powerdown: 290 + reset_control_assert(dwc3_data->rstc_pwrdn); 291 + undo_platform_dev_alloc: 292 + platform_device_put(pdev); 293 + return ret; 294 + } 295 + 296 + static int st_dwc3_remove(struct platform_device *pdev) 297 + { 298 + struct st_dwc3 *dwc3_data = platform_get_drvdata(pdev); 299 + 300 + of_platform_depopulate(&pdev->dev); 301 + 302 + reset_control_assert(dwc3_data->rstc_pwrdn); 303 + reset_control_assert(dwc3_data->rstc_rst); 304 + 305 + return 0; 306 + } 307 + 308 + #ifdef CONFIG_PM_SLEEP 309 + static int st_dwc3_suspend(struct device *dev) 310 + { 311 + struct st_dwc3 *dwc3_data = dev_get_drvdata(dev); 312 + 313 + reset_control_assert(dwc3_data->rstc_pwrdn); 314 + reset_control_assert(dwc3_data->rstc_rst); 315 + 316 + pinctrl_pm_select_sleep_state(dev); 317 + 318 + return 0; 319 + } 320 + 321 + static int st_dwc3_resume(struct device *dev) 322 + { 323 + struct st_dwc3 *dwc3_data = dev_get_drvdata(dev); 324 + int ret; 325 + 326 + pinctrl_pm_select_default_state(dev); 327 + 328 + reset_control_deassert(dwc3_data->rstc_pwrdn); 329 + reset_control_deassert(dwc3_data->rstc_rst); 330 + 331 + ret = st_dwc3_drd_init(dwc3_data); 332 + if (ret) { 333 + dev_err(dev, "drd initialisation failed\n"); 334 + return ret; 335 + } 336 + 337 + /* ST glue logic init */ 338 + st_dwc3_init(dwc3_data); 339 + 340 + return 0; 341 + } 342 + #endif /* CONFIG_PM_SLEEP */ 343 + 344 + static SIMPLE_DEV_PM_OPS(st_dwc3_dev_pm_ops, st_dwc3_suspend, st_dwc3_resume); 345 + 346 + static const struct of_device_id st_dwc3_match[] = { 347 + { .compatible = "st,stih407-dwc3" }, 348 + { /* sentinel */ }, 349 + }; 350 + 351 + MODULE_DEVICE_TABLE(of, st_dwc3_match); 352 + 353 + static struct platform_driver st_dwc3_driver = { 354 + .probe = st_dwc3_probe, 355 + .remove = st_dwc3_remove, 356 + .driver = { 357 + .name = "usb-st-dwc3", 358 + .of_match_table = st_dwc3_match, 359 + .pm = &st_dwc3_dev_pm_ops, 360 + }, 361 + }; 362 + 363 + module_platform_driver(st_dwc3_driver); 364 + 365 + MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>"); 366 + MODULE_DESCRIPTION("DesignWare USB3 STi Glue Layer"); 367 + MODULE_LICENSE("GPL v2");
+37 -28
drivers/usb/dwc3/ep0.c
··· 31 31 #include <linux/usb/composite.h> 32 32 33 33 #include "core.h" 34 + #include "debug.h" 34 35 #include "gadget.h" 35 36 #include "io.h" 36 37 ··· 66 65 67 66 dep = dwc->eps[epnum]; 68 67 if (dep->flags & DWC3_EP_BUSY) { 69 - dev_vdbg(dwc->dev, "%s: still busy\n", dep->name); 68 + dwc3_trace(trace_dwc3_ep0, "%s still busy", dep->name); 70 69 return 0; 71 70 } 72 71 ··· 89 88 ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, 90 89 DWC3_DEPCMD_STARTTRANSFER, &params); 91 90 if (ret < 0) { 92 - dev_dbg(dwc->dev, "failed to send STARTTRANSFER command\n"); 91 + dwc3_trace(trace_dwc3_ep0, "%s STARTTRANSFER failed", 92 + dep->name); 93 93 return ret; 94 94 } 95 95 ··· 155 153 if (dwc->ep0state == EP0_STATUS_PHASE) 156 154 __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]); 157 155 else 158 - dev_dbg(dwc->dev, "too early for delayed status\n"); 156 + dwc3_trace(trace_dwc3_ep0, 157 + "too early for delayed status"); 159 158 160 159 return 0; 161 160 } ··· 220 217 221 218 spin_lock_irqsave(&dwc->lock, flags); 222 219 if (!dep->endpoint.desc) { 223 - dev_dbg(dwc->dev, "trying to queue request %p to disabled %s\n", 220 + dwc3_trace(trace_dwc3_ep0, 221 + "trying to queue request %p to disabled %s", 224 222 request, dep->name); 225 223 ret = -ESHUTDOWN; 226 224 goto out; ··· 233 229 goto out; 234 230 } 235 231 236 - dev_vdbg(dwc->dev, "queueing request %p to %s length %d, state '%s'\n", 232 + dwc3_trace(trace_dwc3_ep0, 233 + "queueing request %p to %s length %d state '%s'", 237 234 request, dep->name, request->length, 238 235 dwc3_ep0_state_string(dwc->ep0state)); 239 236 ··· 490 485 491 486 addr = le16_to_cpu(ctrl->wValue); 492 487 if (addr > 127) { 493 - dev_dbg(dwc->dev, "invalid device address %d\n", addr); 488 + dwc3_trace(trace_dwc3_ep0, "invalid device address %d", addr); 494 489 return -EINVAL; 495 490 } 496 491 497 492 if (state == USB_STATE_CONFIGURED) { 498 - dev_dbg(dwc->dev, "trying to set address when configured\n"); 493 + dwc3_trace(trace_dwc3_ep0, 494 + "trying to set address when configured"); 499 495 return -EINVAL; 500 496 } 501 497 ··· 562 556 dwc3_writel(dwc->regs, DWC3_DCTL, reg); 563 557 564 558 dwc->resize_fifos = true; 565 - dev_dbg(dwc->dev, "resize fifos flag SET\n"); 559 + dwc3_trace(trace_dwc3_ep0, "resize FIFOs flag SET"); 566 560 } 567 561 break; 568 562 ··· 686 680 687 681 switch (ctrl->bRequest) { 688 682 case USB_REQ_GET_STATUS: 689 - dev_vdbg(dwc->dev, "USB_REQ_GET_STATUS\n"); 683 + dwc3_trace(trace_dwc3_ep0, "USB_REQ_GET_STATUS\n"); 690 684 ret = dwc3_ep0_handle_status(dwc, ctrl); 691 685 break; 692 686 case USB_REQ_CLEAR_FEATURE: 693 - dev_vdbg(dwc->dev, "USB_REQ_CLEAR_FEATURE\n"); 687 + dwc3_trace(trace_dwc3_ep0, "USB_REQ_CLEAR_FEATURE\n"); 694 688 ret = dwc3_ep0_handle_feature(dwc, ctrl, 0); 695 689 break; 696 690 case USB_REQ_SET_FEATURE: 697 - dev_vdbg(dwc->dev, "USB_REQ_SET_FEATURE\n"); 691 + dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_FEATURE\n"); 698 692 ret = dwc3_ep0_handle_feature(dwc, ctrl, 1); 699 693 break; 700 694 case USB_REQ_SET_ADDRESS: 701 - dev_vdbg(dwc->dev, "USB_REQ_SET_ADDRESS\n"); 695 + dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_ADDRESS\n"); 702 696 ret = dwc3_ep0_set_address(dwc, ctrl); 703 697 break; 704 698 case USB_REQ_SET_CONFIGURATION: 705 - dev_vdbg(dwc->dev, "USB_REQ_SET_CONFIGURATION\n"); 699 + dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_CONFIGURATION\n"); 706 700 ret = dwc3_ep0_set_config(dwc, ctrl); 707 701 break; 708 702 case USB_REQ_SET_SEL: 709 - dev_vdbg(dwc->dev, "USB_REQ_SET_SEL\n"); 703 + dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_SEL\n"); 710 704 ret = dwc3_ep0_set_sel(dwc, ctrl); 711 705 break; 712 706 case USB_REQ_SET_ISOCH_DELAY: 713 - dev_vdbg(dwc->dev, "USB_REQ_SET_ISOCH_DELAY\n"); 707 + dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_ISOCH_DELAY\n"); 714 708 ret = dwc3_ep0_set_isoch_delay(dwc, ctrl); 715 709 break; 716 710 default: 717 - dev_vdbg(dwc->dev, "Forwarding to gadget driver\n"); 711 + dwc3_trace(trace_dwc3_ep0, "Forwarding to gadget driver\n"); 718 712 ret = dwc3_ep0_delegate_req(dwc, ctrl); 719 713 break; 720 714 } ··· 731 725 732 726 if (!dwc->gadget_driver) 733 727 goto out; 728 + 729 + trace_dwc3_ctrl_req(ctrl); 734 730 735 731 len = le16_to_cpu(ctrl->wLength); 736 732 if (!len) { ··· 782 774 783 775 status = DWC3_TRB_SIZE_TRBSTS(trb->size); 784 776 if (status == DWC3_TRBSTS_SETUP_PENDING) { 785 - dev_dbg(dwc->dev, "Setup Pending received\n"); 777 + dwc3_trace(trace_dwc3_ep0, "Setup Pending received"); 786 778 787 779 if (r) 788 780 dwc3_gadget_giveback(ep0, r, -ECONNRESET); ··· 842 834 843 835 ret = dwc3_gadget_set_test_mode(dwc, dwc->test_mode_nr); 844 836 if (ret < 0) { 845 - dev_dbg(dwc->dev, "Invalid Test #%d\n", 837 + dwc3_trace(trace_dwc3_ep0, "Invalid Test #%d", 846 838 dwc->test_mode_nr); 847 839 dwc3_ep0_stall_and_restart(dwc); 848 840 return; ··· 851 843 852 844 status = DWC3_TRB_SIZE_TRBSTS(trb->size); 853 845 if (status == DWC3_TRBSTS_SETUP_PENDING) 854 - dev_dbg(dwc->dev, "Setup Pending received\n"); 846 + dwc3_trace(trace_dwc3_ep0, "Setup Pending received\n"); 855 847 856 848 dwc->ep0state = EP0_SETUP_PHASE; 857 849 dwc3_ep0_out_start(dwc); ··· 868 860 869 861 switch (dwc->ep0state) { 870 862 case EP0_SETUP_PHASE: 871 - dev_vdbg(dwc->dev, "Inspecting Setup Bytes\n"); 863 + dwc3_trace(trace_dwc3_ep0, "Setup Phase"); 872 864 dwc3_ep0_inspect_setup(dwc, event); 873 865 break; 874 866 875 867 case EP0_DATA_PHASE: 876 - dev_vdbg(dwc->dev, "Data Phase\n"); 868 + dwc3_trace(trace_dwc3_ep0, "Data Phase"); 877 869 dwc3_ep0_complete_data(dwc, event); 878 870 break; 879 871 880 872 case EP0_STATUS_PHASE: 881 - dev_vdbg(dwc->dev, "Status Phase\n"); 873 + dwc3_trace(trace_dwc3_ep0, "Status Phase"); 882 874 dwc3_ep0_complete_status(dwc, event); 883 875 break; 884 876 default: ··· 954 946 static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep) 955 947 { 956 948 if (dwc->resize_fifos) { 957 - dev_dbg(dwc->dev, "starting to resize fifos\n"); 949 + dwc3_trace(trace_dwc3_ep0, "Resizing FIFOs"); 958 950 dwc3_gadget_resize_tx_fifos(dwc); 959 951 dwc->resize_fifos = 0; 960 952 } ··· 995 987 996 988 switch (event->status) { 997 989 case DEPEVT_STATUS_CONTROL_DATA: 998 - dev_vdbg(dwc->dev, "Control Data\n"); 990 + dwc3_trace(trace_dwc3_ep0, "Control Data"); 999 991 1000 992 /* 1001 993 * We already have a DATA transfer in the controller's cache, ··· 1009 1001 if (dwc->ep0_expect_in != event->endpoint_number) { 1010 1002 struct dwc3_ep *dep = dwc->eps[dwc->ep0_expect_in]; 1011 1003 1012 - dev_vdbg(dwc->dev, "Wrong direction for Data phase\n"); 1004 + dwc3_trace(trace_dwc3_ep0, 1005 + "Wrong direction for Data phase"); 1013 1006 dwc3_ep0_end_control_data(dwc, dep); 1014 1007 dwc3_ep0_stall_and_restart(dwc); 1015 1008 return; ··· 1022 1013 if (dwc->ep0_next_event != DWC3_EP0_NRDY_STATUS) 1023 1014 return; 1024 1015 1025 - dev_vdbg(dwc->dev, "Control Status\n"); 1016 + dwc3_trace(trace_dwc3_ep0, "Control Status"); 1026 1017 1027 1018 dwc->ep0state = EP0_STATUS_PHASE; 1028 1019 1029 1020 if (dwc->delayed_status) { 1030 1021 WARN_ON_ONCE(event->endpoint_number != 1); 1031 - dev_vdbg(dwc->dev, "Mass Storage delayed status\n"); 1022 + dwc3_trace(trace_dwc3_ep0, "Delayed Status"); 1032 1023 return; 1033 1024 } 1034 1025 ··· 1041 1032 { 1042 1033 u8 epnum = event->endpoint_number; 1043 1034 1044 - dev_dbg(dwc->dev, "%s while ep%d%s in state '%s'\n", 1035 + dwc3_trace(trace_dwc3_ep0, "%s while ep%d%s in state '%s'", 1045 1036 dwc3_ep_event_string(event->endpoint_event), 1046 1037 epnum >> 1, (epnum & 1) ? "in" : "out", 1047 1038 dwc3_ep0_state_string(dwc->ep0state));
+19 -119
drivers/usb/dwc3/gadget.c
··· 30 30 #include <linux/usb/ch9.h> 31 31 #include <linux/usb/gadget.h> 32 32 33 + #include "debug.h" 33 34 #include "core.h" 34 35 #include "gadget.h" 35 36 #include "io.h" ··· 267 266 dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n", 268 267 req, dep->name, req->request.actual, 269 268 req->request.length, status); 269 + trace_dwc3_gadget_giveback(req); 270 270 271 271 spin_unlock(&dwc->lock); 272 272 req->request.complete(&dep->endpoint, &req->request); 273 273 spin_lock(&dwc->lock); 274 274 } 275 275 276 - static const char *dwc3_gadget_ep_cmd_string(u8 cmd) 277 - { 278 - switch (cmd) { 279 - case DWC3_DEPCMD_DEPSTARTCFG: 280 - return "Start New Configuration"; 281 - case DWC3_DEPCMD_ENDTRANSFER: 282 - return "End Transfer"; 283 - case DWC3_DEPCMD_UPDATETRANSFER: 284 - return "Update Transfer"; 285 - case DWC3_DEPCMD_STARTTRANSFER: 286 - return "Start Transfer"; 287 - case DWC3_DEPCMD_CLEARSTALL: 288 - return "Clear Stall"; 289 - case DWC3_DEPCMD_SETSTALL: 290 - return "Set Stall"; 291 - case DWC3_DEPCMD_GETEPSTATE: 292 - return "Get Endpoint State"; 293 - case DWC3_DEPCMD_SETTRANSFRESOURCE: 294 - return "Set Endpoint Transfer Resource"; 295 - case DWC3_DEPCMD_SETEPCONFIG: 296 - return "Set Endpoint Configuration"; 297 - default: 298 - return "UNKNOWN command"; 299 - } 300 - } 301 - 302 - static const char *dwc3_gadget_generic_cmd_string(u8 cmd) 303 - { 304 - switch (cmd) { 305 - case DWC3_DGCMD_SET_LMP: 306 - return "Set LMP"; 307 - case DWC3_DGCMD_SET_PERIODIC_PAR: 308 - return "Set Periodic Parameters"; 309 - case DWC3_DGCMD_XMIT_FUNCTION: 310 - return "Transmit Function Wake Device Notification"; 311 - case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO: 312 - return "Set Scratchpad Buffer Array Address Lo"; 313 - case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI: 314 - return "Set Scratchpad Buffer Array Address Hi"; 315 - case DWC3_DGCMD_SELECTED_FIFO_FLUSH: 316 - return "Selected FIFO Flush"; 317 - case DWC3_DGCMD_ALL_FIFO_FLUSH: 318 - return "All FIFO Flush"; 319 - case DWC3_DGCMD_SET_ENDPOINT_NRDY: 320 - return "Set Endpoint NRDY"; 321 - case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK: 322 - return "Run SoC Bus Loopback Test"; 323 - default: 324 - return "UNKNOWN"; 325 - } 326 - } 327 - 328 - static const char *dwc3_gadget_link_string(enum dwc3_link_state link_state) 329 - { 330 - switch (link_state) { 331 - case DWC3_LINK_STATE_U0: 332 - return "U0"; 333 - case DWC3_LINK_STATE_U1: 334 - return "U1"; 335 - case DWC3_LINK_STATE_U2: 336 - return "U2"; 337 - case DWC3_LINK_STATE_U3: 338 - return "U3"; 339 - case DWC3_LINK_STATE_SS_DIS: 340 - return "SS.Disabled"; 341 - case DWC3_LINK_STATE_RX_DET: 342 - return "RX.Detect"; 343 - case DWC3_LINK_STATE_SS_INACT: 344 - return "SS.Inactive"; 345 - case DWC3_LINK_STATE_POLL: 346 - return "Polling"; 347 - case DWC3_LINK_STATE_RECOV: 348 - return "Recovery"; 349 - case DWC3_LINK_STATE_HRESET: 350 - return "Hot Reset"; 351 - case DWC3_LINK_STATE_CMPLY: 352 - return "Compliance"; 353 - case DWC3_LINK_STATE_LPBK: 354 - return "Loopback"; 355 - case DWC3_LINK_STATE_RESET: 356 - return "Reset"; 357 - case DWC3_LINK_STATE_RESUME: 358 - return "Resume"; 359 - default: 360 - return "UNKNOWN link state\n"; 361 - } 362 - } 363 - 364 - int dwc3_send_gadget_generic_command(struct dwc3 *dwc, int cmd, u32 param) 276 + int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param) 365 277 { 366 278 u32 timeout = 500; 367 279 u32 reg; 368 280 369 - dev_vdbg(dwc->dev, "generic cmd '%s' [%d] param %08x\n", 370 - dwc3_gadget_generic_cmd_string(cmd), cmd, param); 281 + trace_dwc3_gadget_generic_cmd(cmd, param); 371 282 372 283 dwc3_writel(dwc->regs, DWC3_DGCMDPAR, param); 373 284 dwc3_writel(dwc->regs, DWC3_DGCMD, cmd | DWC3_DGCMD_CMDACT); ··· 310 397 u32 timeout = 500; 311 398 u32 reg; 312 399 313 - dev_vdbg(dwc->dev, "%s: cmd '%s' [%d] params %08x %08x %08x\n", 314 - dep->name, 315 - dwc3_gadget_ep_cmd_string(cmd), cmd, params->param0, 316 - params->param1, params->param2); 400 + trace_dwc3_gadget_ep_cmd(dep, cmd, params); 317 401 318 402 dwc3_writel(dwc->regs, DWC3_DEPCMDPAR0(ep), params->param0); 319 403 dwc3_writel(dwc->regs, DWC3_DEPCMDPAR1(ep), params->param1); ··· 699 789 { 700 790 struct dwc3_request *req; 701 791 struct dwc3_ep *dep = to_dwc3_ep(ep); 702 - struct dwc3 *dwc = dep->dwc; 703 792 704 793 req = kzalloc(sizeof(*req), gfp_flags); 705 - if (!req) { 706 - dev_err(dwc->dev, "not enough memory\n"); 794 + if (!req) 707 795 return NULL; 708 - } 709 796 710 797 req->epnum = dep->number; 711 798 req->dep = dep; 799 + 800 + trace_dwc3_alloc_request(req); 712 801 713 802 return &req->request; 714 803 } ··· 717 808 { 718 809 struct dwc3_request *req = to_dwc3_request(request); 719 810 811 + trace_dwc3_free_request(req); 720 812 kfree(req); 721 813 } 722 814 ··· 799 889 trb->ctrl |= DWC3_TRB_CTRL_SID_SOFN(req->request.stream_id); 800 890 801 891 trb->ctrl |= DWC3_TRB_CTRL_HWO; 892 + 893 + trace_dwc3_prepare_trb(dep, trb); 802 894 } 803 895 804 896 /* ··· 1147 1235 1148 1236 dev_vdbg(dwc->dev, "queing request %p to %s length %d\n", 1149 1237 request, ep->name, request->length); 1238 + trace_dwc3_ep_queue(req); 1150 1239 1151 1240 ret = __dwc3_gadget_ep_queue(dep, req); 1152 1241 spin_unlock_irqrestore(&dwc->lock, flags); ··· 1166 1253 1167 1254 unsigned long flags; 1168 1255 int ret = 0; 1256 + 1257 + trace_dwc3_ep_dequeue(req); 1169 1258 1170 1259 spin_lock_irqsave(&dwc->lock, flags); 1171 1260 ··· 1659 1744 u8 epnum = (i << 1) | (!!direction); 1660 1745 1661 1746 dep = kzalloc(sizeof(*dep), GFP_KERNEL); 1662 - if (!dep) { 1663 - dev_err(dwc->dev, "can't allocate endpoint %d\n", 1664 - epnum); 1747 + if (!dep) 1665 1748 return -ENOMEM; 1666 - } 1667 1749 1668 1750 dep->dwc = dwc; 1669 1751 dep->number = epnum; ··· 1758 1846 unsigned int count; 1759 1847 unsigned int s_pkt = 0; 1760 1848 unsigned int trb_status; 1849 + 1850 + trace_dwc3_complete_trb(dep, trb); 1761 1851 1762 1852 if ((trb->ctrl & DWC3_TRB_CTRL_HWO) && status != -ESHUTDOWN) 1763 1853 /* ··· 1934 2020 1935 2021 if (!(dep->flags & DWC3_EP_ENABLED)) 1936 2022 return; 1937 - 1938 - dev_vdbg(dwc->dev, "%s: %s\n", dep->name, 1939 - dwc3_ep_event_string(event->endpoint_event)); 1940 2023 1941 2024 if (epnum == 0 || epnum == 1) { 1942 2025 dwc3_ep0_interrupt(dwc, event); ··· 2121 2210 { 2122 2211 int reg; 2123 2212 2124 - dev_vdbg(dwc->dev, "%s\n", __func__); 2125 - 2126 2213 reg = dwc3_readl(dwc->regs, DWC3_DCTL); 2127 2214 reg &= ~DWC3_DCTL_INITU1ENA; 2128 2215 dwc3_writel(dwc->regs, DWC3_DCTL, reg); ··· 2138 2229 static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) 2139 2230 { 2140 2231 u32 reg; 2141 - 2142 - dev_vdbg(dwc->dev, "%s\n", __func__); 2143 2232 2144 2233 /* 2145 2234 * WORKAROUND: DWC3 revisions <1.88a have an issue which ··· 2222 2315 int ret; 2223 2316 u32 reg; 2224 2317 u8 speed; 2225 - 2226 - dev_vdbg(dwc->dev, "%s\n", __func__); 2227 2318 2228 2319 reg = dwc3_readl(dwc->regs, DWC3_DSTS); 2229 2320 speed = reg & DWC3_DSTS_CONNECTSPD; ··· 2320 2415 2321 2416 static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc) 2322 2417 { 2323 - dev_vdbg(dwc->dev, "%s\n", __func__); 2324 - 2325 2418 /* 2326 2419 * TODO take core out of low power mode when that's 2327 2420 * implemented. ··· 2424 2521 break; 2425 2522 } 2426 2523 2427 - dev_vdbg(dwc->dev, "link change: %s [%d] -> %s [%d]\n", 2428 - dwc3_gadget_link_string(dwc->link_state), 2429 - dwc->link_state, dwc3_gadget_link_string(next), next); 2430 - 2431 2524 dwc->link_state = next; 2432 2525 } 2433 2526 ··· 2500 2601 static void dwc3_process_event_entry(struct dwc3 *dwc, 2501 2602 const union dwc3_event *event) 2502 2603 { 2604 + trace_dwc3_event(event->raw); 2605 + 2503 2606 /* Endpoint IRQ, handle it and return early */ 2504 2607 if (event->type.is_devspec == 0) { 2505 2608 /* depevt */ ··· 2655 2754 2656 2755 dwc->setup_buf = kzalloc(DWC3_EP0_BOUNCE_SIZE, GFP_KERNEL); 2657 2756 if (!dwc->setup_buf) { 2658 - dev_err(dwc->dev, "failed to allocate setup buffer\n"); 2659 2757 ret = -ENOMEM; 2660 2758 goto err2; 2661 2759 }
-56
drivers/usb/dwc3/gadget.h
··· 103 103 return DWC3_DEPCMD_GET_RSC_IDX(res_id); 104 104 } 105 105 106 - /** 107 - * dwc3_gadget_event_string - returns event name 108 - * @event: the event code 109 - */ 110 - static inline const char *dwc3_gadget_event_string(u8 event) 111 - { 112 - switch (event) { 113 - case DWC3_DEVICE_EVENT_DISCONNECT: 114 - return "Disconnect"; 115 - case DWC3_DEVICE_EVENT_RESET: 116 - return "Reset"; 117 - case DWC3_DEVICE_EVENT_CONNECT_DONE: 118 - return "Connection Done"; 119 - case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE: 120 - return "Link Status Change"; 121 - case DWC3_DEVICE_EVENT_WAKEUP: 122 - return "WakeUp"; 123 - case DWC3_DEVICE_EVENT_EOPF: 124 - return "End-Of-Frame"; 125 - case DWC3_DEVICE_EVENT_SOF: 126 - return "Start-Of-Frame"; 127 - case DWC3_DEVICE_EVENT_ERRATIC_ERROR: 128 - return "Erratic Error"; 129 - case DWC3_DEVICE_EVENT_CMD_CMPL: 130 - return "Command Complete"; 131 - case DWC3_DEVICE_EVENT_OVERFLOW: 132 - return "Overflow"; 133 - } 134 - 135 - return "UNKNOWN"; 136 - } 137 - 138 - /** 139 - * dwc3_ep_event_string - returns event name 140 - * @event: then event code 141 - */ 142 - static inline const char *dwc3_ep_event_string(u8 event) 143 - { 144 - switch (event) { 145 - case DWC3_DEPEVT_XFERCOMPLETE: 146 - return "Transfer Complete"; 147 - case DWC3_DEPEVT_XFERINPROGRESS: 148 - return "Transfer In-Progress"; 149 - case DWC3_DEPEVT_XFERNOTREADY: 150 - return "Transfer Not Ready"; 151 - case DWC3_DEPEVT_RXTXFIFOEVT: 152 - return "FIFO"; 153 - case DWC3_DEPEVT_STREAMEVT: 154 - return "Stream"; 155 - case DWC3_DEPEVT_EPCMDCMPLT: 156 - return "Endpoint Command Complete"; 157 - } 158 - 159 - return "UNKNOWN"; 160 - } 161 - 162 106 #endif /* __DRIVERS_USB_DWC3_GADGET_H */
+27 -3
drivers/usb/dwc3/io.h
··· 20 20 #define __DRIVERS_USB_DWC3_IO_H 21 21 22 22 #include <linux/io.h> 23 - 23 + #include "trace.h" 24 + #include "debug.h" 24 25 #include "core.h" 25 26 26 27 static inline u32 dwc3_readl(void __iomem *base, u32 offset) 27 28 { 29 + u32 offs = offset - DWC3_GLOBALS_REGS_START; 30 + u32 value; 31 + 28 32 /* 29 33 * We requested the mem region starting from the Globals address 30 34 * space, see dwc3_probe in core.c. 31 35 * However, the offsets are given starting from xHCI address space. 32 36 */ 33 - return readl(base + (offset - DWC3_GLOBALS_REGS_START)); 37 + value = readl(base + offs); 38 + 39 + /* 40 + * When tracing we want to make it easy to find the correct address on 41 + * documentation, so we revert it back to the proper addresses, the 42 + * same way they are described on SNPS documentation 43 + */ 44 + dwc3_trace(trace_dwc3_readl, "addr %p value %08x", 45 + base - DWC3_GLOBALS_REGS_START + offset, value); 46 + 47 + return value; 34 48 } 35 49 36 50 static inline void dwc3_writel(void __iomem *base, u32 offset, u32 value) 37 51 { 52 + u32 offs = offset - DWC3_GLOBALS_REGS_START; 53 + 38 54 /* 39 55 * We requested the mem region starting from the Globals address 40 56 * space, see dwc3_probe in core.c. 41 57 * However, the offsets are given starting from xHCI address space. 42 58 */ 43 - writel(value, base + (offset - DWC3_GLOBALS_REGS_START)); 59 + writel(value, base + offs); 60 + 61 + /* 62 + * When tracing we want to make it easy to find the correct address on 63 + * documentation, so we revert it back to the proper addresses, the 64 + * same way they are described on SNPS documentation 65 + */ 66 + dwc3_trace(trace_dwc3_writel, "addr %p value %08x", 67 + base - DWC3_GLOBALS_REGS_START + offset, value); 44 68 } 45 69 46 70 #endif /* __DRIVERS_USB_DWC3_IO_H */
+19
drivers/usb/dwc3/trace.c
··· 1 + /** 2 + * trace.c - DesignWare USB3 DRD Controller Trace Support 3 + * 4 + * Copyright (C) 2014 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 + 18 + #define CREATE_TRACE_POINTS 19 + #include "trace.h"
+220
drivers/usb/dwc3/trace.h
··· 1 + /** 2 + * trace.h - DesignWare USB3 DRD Controller Trace Support 3 + * 4 + * Copyright (C) 2014 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 + 18 + #undef TRACE_SYSTEM 19 + #define TRACE_SYSTEM dwc3 20 + 21 + #if !defined(__DWC3_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) 22 + #define __DWC3_TRACE_H 23 + 24 + #include <linux/types.h> 25 + #include <linux/tracepoint.h> 26 + #include <asm/byteorder.h> 27 + #include "core.h" 28 + #include "debug.h" 29 + 30 + DECLARE_EVENT_CLASS(dwc3_log_msg, 31 + TP_PROTO(struct va_format *vaf), 32 + TP_ARGS(vaf), 33 + TP_STRUCT__entry(__dynamic_array(char, msg, DWC3_MSG_MAX)), 34 + TP_fast_assign( 35 + vsnprintf(__get_str(msg), DWC3_MSG_MAX, vaf->fmt, *vaf->va); 36 + ), 37 + TP_printk("%s", __get_str(msg)) 38 + ); 39 + 40 + DEFINE_EVENT(dwc3_log_msg, dwc3_readl, 41 + TP_PROTO(struct va_format *vaf), 42 + TP_ARGS(vaf) 43 + ); 44 + 45 + DEFINE_EVENT(dwc3_log_msg, dwc3_writel, 46 + TP_PROTO(struct va_format *vaf), 47 + TP_ARGS(vaf) 48 + ); 49 + 50 + DEFINE_EVENT(dwc3_log_msg, dwc3_ep0, 51 + TP_PROTO(struct va_format *vaf), 52 + TP_ARGS(vaf) 53 + ); 54 + 55 + DECLARE_EVENT_CLASS(dwc3_log_event, 56 + TP_PROTO(u32 event), 57 + TP_ARGS(event), 58 + TP_STRUCT__entry( 59 + __field(u32, event) 60 + ), 61 + TP_fast_assign( 62 + __entry->event = event; 63 + ), 64 + TP_printk("event %08x\n", __entry->event) 65 + ); 66 + 67 + DEFINE_EVENT(dwc3_log_event, dwc3_event, 68 + TP_PROTO(u32 event), 69 + TP_ARGS(event) 70 + ); 71 + 72 + DECLARE_EVENT_CLASS(dwc3_log_ctrl, 73 + TP_PROTO(struct usb_ctrlrequest *ctrl), 74 + TP_ARGS(ctrl), 75 + TP_STRUCT__entry( 76 + __field(struct usb_ctrlrequest *, ctrl) 77 + ), 78 + TP_fast_assign( 79 + __entry->ctrl = ctrl; 80 + ), 81 + TP_printk("bRequestType %02x bRequest %02x wValue %04x wIndex %04x wLength %d", 82 + __entry->ctrl->bRequestType, __entry->ctrl->bRequest, 83 + le16_to_cpu(__entry->ctrl->wValue), le16_to_cpu(__entry->ctrl->wIndex), 84 + le16_to_cpu(__entry->ctrl->wLength) 85 + ) 86 + ); 87 + 88 + DEFINE_EVENT(dwc3_log_ctrl, dwc3_ctrl_req, 89 + TP_PROTO(struct usb_ctrlrequest *ctrl), 90 + TP_ARGS(ctrl) 91 + ); 92 + 93 + DECLARE_EVENT_CLASS(dwc3_log_request, 94 + TP_PROTO(struct dwc3_request *req), 95 + TP_ARGS(req), 96 + TP_STRUCT__entry( 97 + __field(struct dwc3_request *, req) 98 + ), 99 + TP_fast_assign( 100 + __entry->req = req; 101 + ), 102 + TP_printk("%s: req %p length %u/%u ==> %d", 103 + __entry->req->dep->name, __entry->req, 104 + __entry->req->request.actual, __entry->req->request.length, 105 + __entry->req->request.status 106 + ) 107 + ); 108 + 109 + DEFINE_EVENT(dwc3_log_request, dwc3_alloc_request, 110 + TP_PROTO(struct dwc3_request *req), 111 + TP_ARGS(req) 112 + ); 113 + 114 + DEFINE_EVENT(dwc3_log_request, dwc3_free_request, 115 + TP_PROTO(struct dwc3_request *req), 116 + TP_ARGS(req) 117 + ); 118 + 119 + DEFINE_EVENT(dwc3_log_request, dwc3_ep_queue, 120 + TP_PROTO(struct dwc3_request *req), 121 + TP_ARGS(req) 122 + ); 123 + 124 + DEFINE_EVENT(dwc3_log_request, dwc3_ep_dequeue, 125 + TP_PROTO(struct dwc3_request *req), 126 + TP_ARGS(req) 127 + ); 128 + 129 + DEFINE_EVENT(dwc3_log_request, dwc3_gadget_giveback, 130 + TP_PROTO(struct dwc3_request *req), 131 + TP_ARGS(req) 132 + ); 133 + 134 + DECLARE_EVENT_CLASS(dwc3_log_generic_cmd, 135 + TP_PROTO(unsigned int cmd, u32 param), 136 + TP_ARGS(cmd, param), 137 + TP_STRUCT__entry( 138 + __field(unsigned int, cmd) 139 + __field(u32, param) 140 + ), 141 + TP_fast_assign( 142 + __entry->cmd = cmd; 143 + __entry->param = param; 144 + ), 145 + TP_printk("cmd '%s' [%d] param %08x\n", 146 + dwc3_gadget_generic_cmd_string(__entry->cmd), 147 + __entry->cmd, __entry->param 148 + ) 149 + ); 150 + 151 + DEFINE_EVENT(dwc3_log_generic_cmd, dwc3_gadget_generic_cmd, 152 + TP_PROTO(unsigned int cmd, u32 param), 153 + TP_ARGS(cmd, param) 154 + ); 155 + 156 + DECLARE_EVENT_CLASS(dwc3_log_gadget_ep_cmd, 157 + TP_PROTO(struct dwc3_ep *dep, unsigned int cmd, 158 + struct dwc3_gadget_ep_cmd_params *params), 159 + TP_ARGS(dep, cmd, params), 160 + TP_STRUCT__entry( 161 + __field(struct dwc3_ep *, dep) 162 + __field(unsigned int, cmd) 163 + __field(struct dwc3_gadget_ep_cmd_params *, params) 164 + ), 165 + TP_fast_assign( 166 + __entry->dep = dep; 167 + __entry->cmd = cmd; 168 + __entry->params = params; 169 + ), 170 + TP_printk("%s: cmd '%s' [%d] params %08x %08x %08x\n", 171 + __entry->dep->name, dwc3_gadget_ep_cmd_string(__entry->cmd), 172 + __entry->cmd, __entry->params->param0, 173 + __entry->params->param1, __entry->params->param2 174 + ) 175 + ); 176 + 177 + DEFINE_EVENT(dwc3_log_gadget_ep_cmd, dwc3_gadget_ep_cmd, 178 + TP_PROTO(struct dwc3_ep *dep, unsigned int cmd, 179 + struct dwc3_gadget_ep_cmd_params *params), 180 + TP_ARGS(dep, cmd, params) 181 + ); 182 + 183 + DECLARE_EVENT_CLASS(dwc3_log_trb, 184 + TP_PROTO(struct dwc3_ep *dep, struct dwc3_trb *trb), 185 + TP_ARGS(dep, trb), 186 + TP_STRUCT__entry( 187 + __field(struct dwc3_ep *, dep) 188 + __field(struct dwc3_trb *, trb) 189 + ), 190 + TP_fast_assign( 191 + __entry->dep = dep; 192 + __entry->trb = trb; 193 + ), 194 + TP_printk("%s: trb %p bph %08x bpl %08x size %08x ctrl %08x\n", 195 + __entry->dep->name, __entry->trb, __entry->trb->bph, 196 + __entry->trb->bpl, __entry->trb->size, __entry->trb->ctrl 197 + ) 198 + ); 199 + 200 + DEFINE_EVENT(dwc3_log_trb, dwc3_prepare_trb, 201 + TP_PROTO(struct dwc3_ep *dep, struct dwc3_trb *trb), 202 + TP_ARGS(dep, trb) 203 + ); 204 + 205 + DEFINE_EVENT(dwc3_log_trb, dwc3_complete_trb, 206 + TP_PROTO(struct dwc3_ep *dep, struct dwc3_trb *trb), 207 + TP_ARGS(dep, trb) 208 + ); 209 + 210 + #endif /* __DWC3_TRACE_H */ 211 + 212 + /* this part has to be here */ 213 + 214 + #undef TRACE_INCLUDE_PATH 215 + #define TRACE_INCLUDE_PATH . 216 + 217 + #undef TRACE_INCLUDE_FILE 218 + #define TRACE_INCLUDE_FILE trace 219 + 220 + #include <trace/define_trace.h>
+9
drivers/usb/gadget/Kconfig
··· 181 181 config USB_F_FS 182 182 tristate 183 183 184 + config USB_F_UAC1 185 + tristate 186 + 187 + config USB_F_UAC2 188 + tristate 189 + 190 + config USB_F_UVC 191 + tristate 192 + 184 193 choice 185 194 tristate "USB Gadget Drivers" 186 195 default USB_ETH
+1 -1
drivers/usb/gadget/Makefile
··· 3 3 # 4 4 subdir-ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG 5 5 subdir-ccflags-$(CONFIG_USB_GADGET_VERBOSE) += -DVERBOSE_DEBUG 6 - ccflags-y += -Idrivers/usb/gadget/udc 6 + ccflags-y += -I$(srctree)/drivers/usb/gadget/udc 7 7 8 8 obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o 9 9 libcomposite-y := usbstring.o config.o epautoconf.o
+1
drivers/usb/gadget/composite.c
··· 2073 2073 .unbind = composite_unbind, 2074 2074 2075 2075 .setup = composite_setup, 2076 + .reset = composite_disconnect, 2076 2077 .disconnect = composite_disconnect, 2077 2078 2078 2079 .suspend = composite_suspend,
+1
drivers/usb/gadget/configfs.c
··· 1450 1450 .unbind = configfs_composite_unbind, 1451 1451 1452 1452 .setup = composite_setup, 1453 + .reset = composite_disconnect, 1453 1454 .disconnect = composite_disconnect, 1454 1455 1455 1456 .max_speed = USB_SPEED_SUPER,
+8 -2
drivers/usb/gadget/function/Makefile
··· 2 2 # USB peripheral controller drivers 3 3 # 4 4 5 - ccflags-y := -Idrivers/usb/gadget/ 6 - ccflags-y += -Idrivers/usb/gadget/udc/ 5 + ccflags-y := -I$(srctree)/drivers/usb/gadget/ 6 + ccflags-y += -I$(srctree)/drivers/usb/gadget/udc/ 7 7 8 8 # USB Functions 9 9 usb_f_acm-y := f_acm.o ··· 32 32 obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o 33 33 usb_f_fs-y := f_fs.o 34 34 obj-$(CONFIG_USB_F_FS) += usb_f_fs.o 35 + usb_f_uac1-y := f_uac1.o u_uac1.o 36 + obj-$(CONFIG_USB_F_UAC1) += usb_f_uac1.o 37 + usb_f_uac2-y := f_uac2.o 38 + obj-$(CONFIG_USB_F_UAC2) += usb_f_uac2.o 39 + usb_f_uvc-y := f_uvc.o uvc_queue.o uvc_v4l2.o uvc_video.o 40 + obj-$(CONFIG_USB_F_UVC) += usb_f_uvc.o
+28 -21
drivers/usb/gadget/function/f_acm.c
··· 313 313 struct usb_composite_dev *cdev = acm->port.func.config->cdev; 314 314 315 315 if (req->status != 0) { 316 - DBG(cdev, "acm ttyGS%d completion, err %d\n", 317 - acm->port_num, req->status); 316 + dev_dbg(&cdev->gadget->dev, "acm ttyGS%d completion, err %d\n", 317 + acm->port_num, req->status); 318 318 return; 319 319 } 320 320 321 321 /* normal completion */ 322 322 if (req->actual != sizeof(acm->port_line_coding)) { 323 - DBG(cdev, "acm ttyGS%d short resp, len %d\n", 324 - acm->port_num, req->actual); 323 + dev_dbg(&cdev->gadget->dev, "acm ttyGS%d short resp, len %d\n", 324 + acm->port_num, req->actual); 325 325 usb_ep_set_halt(ep); 326 326 } else { 327 327 struct usb_cdc_line_coding *value = req->buf; ··· 397 397 398 398 default: 399 399 invalid: 400 - VDBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n", 401 - ctrl->bRequestType, ctrl->bRequest, 402 - w_value, w_index, w_length); 400 + dev_vdbg(&cdev->gadget->dev, 401 + "invalid control req%02x.%02x v%04x i%04x l%d\n", 402 + ctrl->bRequestType, ctrl->bRequest, 403 + w_value, w_index, w_length); 403 404 } 404 405 405 406 /* respond with data transfer or status phase? */ 406 407 if (value >= 0) { 407 - DBG(cdev, "acm ttyGS%d req%02x.%02x v%04x i%04x l%d\n", 408 + dev_dbg(&cdev->gadget->dev, 409 + "acm ttyGS%d req%02x.%02x v%04x i%04x l%d\n", 408 410 acm->port_num, ctrl->bRequestType, ctrl->bRequest, 409 411 w_value, w_index, w_length); 410 412 req->zero = 0; ··· 430 428 431 429 if (intf == acm->ctrl_id) { 432 430 if (acm->notify->driver_data) { 433 - VDBG(cdev, "reset acm control interface %d\n", intf); 431 + dev_vdbg(&cdev->gadget->dev, 432 + "reset acm control interface %d\n", intf); 434 433 usb_ep_disable(acm->notify); 435 434 } else { 436 - VDBG(cdev, "init acm ctrl interface %d\n", intf); 435 + dev_vdbg(&cdev->gadget->dev, 436 + "init acm ctrl interface %d\n", intf); 437 437 if (config_ep_by_speed(cdev->gadget, f, acm->notify)) 438 438 return -EINVAL; 439 439 } ··· 444 440 445 441 } else if (intf == acm->data_id) { 446 442 if (acm->port.in->driver_data) { 447 - DBG(cdev, "reset acm ttyGS%d\n", acm->port_num); 443 + dev_dbg(&cdev->gadget->dev, 444 + "reset acm ttyGS%d\n", acm->port_num); 448 445 gserial_disconnect(&acm->port); 449 446 } 450 447 if (!acm->port.in->desc || !acm->port.out->desc) { 451 - DBG(cdev, "activate acm ttyGS%d\n", acm->port_num); 448 + dev_dbg(&cdev->gadget->dev, 449 + "activate acm ttyGS%d\n", acm->port_num); 452 450 if (config_ep_by_speed(cdev->gadget, f, 453 451 acm->port.in) || 454 452 config_ep_by_speed(cdev->gadget, f, ··· 473 467 struct f_acm *acm = func_to_acm(f); 474 468 struct usb_composite_dev *cdev = f->config->cdev; 475 469 476 - DBG(cdev, "acm ttyGS%d deactivated\n", acm->port_num); 470 + dev_dbg(&cdev->gadget->dev, "acm ttyGS%d deactivated\n", acm->port_num); 477 471 gserial_disconnect(&acm->port); 478 472 usb_ep_disable(acm->notify); 479 473 acm->notify->driver_data = NULL; ··· 543 537 544 538 spin_lock(&acm->lock); 545 539 if (acm->notify_req) { 546 - DBG(cdev, "acm ttyGS%d serial state %04x\n", 547 - acm->port_num, acm->serial_state); 540 + dev_dbg(&cdev->gadget->dev, "acm ttyGS%d serial state %04x\n", 541 + acm->port_num, acm->serial_state); 548 542 status = acm_cdc_notify(acm, USB_CDC_NOTIFY_SERIAL_STATE, 549 543 0, &acm->serial_state, sizeof(acm->serial_state)); 550 544 } else { ··· 697 691 if (status) 698 692 goto fail; 699 693 700 - DBG(cdev, "acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n", 701 - acm->port_num, 702 - gadget_is_superspeed(c->cdev->gadget) ? "super" : 703 - gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 704 - acm->port.in->name, acm->port.out->name, 705 - acm->notify->name); 694 + dev_dbg(&cdev->gadget->dev, 695 + "acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n", 696 + acm->port_num, 697 + gadget_is_superspeed(c->cdev->gadget) ? "super" : 698 + gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 699 + acm->port.in->name, acm->port.out->name, 700 + acm->notify->name); 706 701 return 0; 707 702 708 703 fail:
+48 -4
drivers/usb/gadget/function/f_fs.c
··· 1032 1032 case FUNCTIONFS_ENDPOINT_REVMAP: 1033 1033 ret = epfile->ep->num; 1034 1034 break; 1035 + case FUNCTIONFS_ENDPOINT_DESC: 1036 + { 1037 + int desc_idx; 1038 + struct usb_endpoint_descriptor *desc; 1039 + 1040 + switch (epfile->ffs->gadget->speed) { 1041 + case USB_SPEED_SUPER: 1042 + desc_idx = 2; 1043 + break; 1044 + case USB_SPEED_HIGH: 1045 + desc_idx = 1; 1046 + break; 1047 + default: 1048 + desc_idx = 0; 1049 + } 1050 + desc = epfile->ep->descs[desc_idx]; 1051 + 1052 + spin_unlock_irq(&epfile->ffs->eps_lock); 1053 + ret = copy_to_user((void *)value, desc, sizeof(*desc)); 1054 + if (ret) 1055 + ret = -EFAULT; 1056 + return ret; 1057 + } 1035 1058 default: 1036 1059 ret = -ENOTTY; 1037 1060 } ··· 1557 1534 epfile->ffs = ffs; 1558 1535 mutex_init(&epfile->mutex); 1559 1536 init_waitqueue_head(&epfile->wait); 1560 - sprintf(epfiles->name, "ep%u", i); 1537 + if (ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) 1538 + sprintf(epfiles->name, "ep%02x", ffs->eps_addrmap[i]); 1539 + else 1540 + sprintf(epfiles->name, "ep%u", i); 1561 1541 if (!unlikely(ffs_sb_create_file(ffs->sb, epfiles->name, epfile, 1562 1542 &ffs_epfile_operations, 1563 1543 &epfile->dentry))) { ··· 2109 2083 break; 2110 2084 case FUNCTIONFS_DESCRIPTORS_MAGIC_V2: 2111 2085 flags = get_unaligned_le32(data + 8); 2086 + ffs->user_flags = flags; 2112 2087 if (flags & ~(FUNCTIONFS_HAS_FS_DESC | 2113 2088 FUNCTIONFS_HAS_HS_DESC | 2114 2089 FUNCTIONFS_HAS_SS_DESC | 2115 - FUNCTIONFS_HAS_MS_OS_DESC)) { 2090 + FUNCTIONFS_HAS_MS_OS_DESC | 2091 + FUNCTIONFS_VIRTUAL_ADDR)) { 2116 2092 ret = -ENOSYS; 2117 2093 goto error; 2118 2094 } ··· 2374 2346 break; 2375 2347 2376 2348 default: 2377 - BUG(); 2349 + WARN(1, "%d: unknown event, this should not happen\n", type); 2350 + return; 2378 2351 } 2379 2352 2380 2353 { ··· 2422 2393 struct usb_endpoint_descriptor *ds = (void *)desc; 2423 2394 struct ffs_function *func = priv; 2424 2395 struct ffs_ep *ffs_ep; 2425 - unsigned ep_desc_id, idx; 2396 + unsigned ep_desc_id; 2397 + int idx; 2426 2398 static const char *speed_names[] = { "full", "high", "super" }; 2427 2399 2428 2400 if (type != FFS_DESCRIPTOR) ··· 2471 2441 } else { 2472 2442 struct usb_request *req; 2473 2443 struct usb_ep *ep; 2444 + u8 bEndpointAddress; 2474 2445 2446 + /* 2447 + * We back up bEndpointAddress because autoconfig overwrites 2448 + * it with physical endpoint address. 2449 + */ 2450 + bEndpointAddress = ds->bEndpointAddress; 2475 2451 pr_vdebug("autoconfig\n"); 2476 2452 ep = usb_ep_autoconfig(func->gadget, ds); 2477 2453 if (unlikely(!ep)) ··· 2492 2456 ffs_ep->req = req; 2493 2457 func->eps_revmap[ds->bEndpointAddress & 2494 2458 USB_ENDPOINT_NUMBER_MASK] = idx + 1; 2459 + /* 2460 + * If we use virtual address mapping, we restore 2461 + * original bEndpointAddress value. 2462 + */ 2463 + if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) 2464 + ds->bEndpointAddress = bEndpointAddress; 2495 2465 } 2496 2466 ffs_dump_mem(": Rewritten ep desc", ds, ds->bLength); 2497 2467 ··· 2942 2900 ret = ffs_func_revmap_ep(func, le16_to_cpu(creq->wIndex)); 2943 2901 if (unlikely(ret < 0)) 2944 2902 return ret; 2903 + if (func->ffs->user_flags & FUNCTIONFS_VIRTUAL_ADDR) 2904 + ret = func->ffs->eps_addrmap[ret]; 2945 2905 break; 2946 2906 2947 2907 default:
+2 -1
drivers/usb/gadget/function/f_loopback.c
··· 298 298 struct usb_composite_dev *cdev; 299 299 300 300 cdev = loop->function.config->cdev; 301 - disable_endpoints(cdev, loop->in_ep, loop->out_ep, NULL, NULL); 301 + disable_endpoints(cdev, loop->in_ep, loop->out_ep, NULL, NULL, NULL, 302 + NULL); 302 303 VDBG(cdev, "%s disabled\n", loop->function.name); 303 304 } 304 305
+13 -14
drivers/usb/gadget/function/f_mass_storage.c
··· 566 566 *pbusy = 1; 567 567 *state = BUF_STATE_BUSY; 568 568 spin_unlock_irq(&fsg->common->lock); 569 + 569 570 rc = usb_ep_queue(ep, req, GFP_KERNEL); 570 - if (rc != 0) { 571 - *pbusy = 0; 572 - *state = BUF_STATE_EMPTY; 571 + if (rc == 0) 572 + return; /* All good, we're done */ 573 573 574 - /* We can't do much more than wait for a reset */ 574 + *pbusy = 0; 575 + *state = BUF_STATE_EMPTY; 575 576 576 - /* 577 - * Note: currently the net2280 driver fails zero-length 578 - * submissions if DMA is enabled. 579 - */ 580 - if (rc != -ESHUTDOWN && 581 - !(rc == -EOPNOTSUPP && req->length == 0)) 582 - WARNING(fsg, "error in submission: %s --> %d\n", 583 - ep->name, rc); 584 - } 577 + /* We can't do much more than wait for a reset */ 578 + 579 + /* 580 + * Note: currently the net2280 driver fails zero-length 581 + * submissions if DMA is enabled. 582 + */ 583 + if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP && req->length == 0)) 584 + WARNING(fsg, "error in submission: %s --> %d\n", ep->name, rc); 585 585 } 586 586 587 587 static bool start_in_transfer(struct fsg_common *common, struct fsg_buffhd *bh) ··· 3665 3665 cfg->fsg_num_buffers = fsg_num_buffers; 3666 3666 } 3667 3667 EXPORT_SYMBOL_GPL(fsg_config_from_params); 3668 -
+17 -11
drivers/usb/gadget/function/f_obex.c
··· 200 200 if (alt != 0) 201 201 goto fail; 202 202 /* NOP */ 203 - DBG(cdev, "reset obex ttyGS%d control\n", obex->port_num); 203 + dev_dbg(&cdev->gadget->dev, 204 + "reset obex ttyGS%d control\n", obex->port_num); 204 205 205 206 } else if (intf == obex->data_id) { 206 207 if (alt > 1) 207 208 goto fail; 208 209 209 210 if (obex->port.in->driver_data) { 210 - DBG(cdev, "reset obex ttyGS%d\n", obex->port_num); 211 + dev_dbg(&cdev->gadget->dev, 212 + "reset obex ttyGS%d\n", obex->port_num); 211 213 gserial_disconnect(&obex->port); 212 214 } 213 215 214 216 if (!obex->port.in->desc || !obex->port.out->desc) { 215 - DBG(cdev, "init obex ttyGS%d\n", obex->port_num); 217 + dev_dbg(&cdev->gadget->dev, 218 + "init obex ttyGS%d\n", obex->port_num); 216 219 if (config_ep_by_speed(cdev->gadget, f, 217 220 obex->port.in) || 218 221 config_ep_by_speed(cdev->gadget, f, ··· 227 224 } 228 225 229 226 if (alt == 1) { 230 - DBG(cdev, "activate obex ttyGS%d\n", obex->port_num); 227 + dev_dbg(&cdev->gadget->dev, 228 + "activate obex ttyGS%d\n", obex->port_num); 231 229 gserial_connect(&obex->port, obex->port_num); 232 230 } 233 231 ··· 256 252 struct f_obex *obex = func_to_obex(f); 257 253 struct usb_composite_dev *cdev = f->config->cdev; 258 254 259 - DBG(cdev, "obex ttyGS%d disable\n", obex->port_num); 255 + dev_dbg(&cdev->gadget->dev, "obex ttyGS%d disable\n", obex->port_num); 260 256 gserial_disconnect(&obex->port); 261 257 } 262 258 ··· 273 269 274 270 status = usb_function_activate(&g->func); 275 271 if (status) 276 - DBG(cdev, "obex ttyGS%d function activate --> %d\n", 272 + dev_dbg(&cdev->gadget->dev, 273 + "obex ttyGS%d function activate --> %d\n", 277 274 obex->port_num, status); 278 275 } 279 276 ··· 289 284 290 285 status = usb_function_deactivate(&g->func); 291 286 if (status) 292 - DBG(cdev, "obex ttyGS%d function deactivate --> %d\n", 287 + dev_dbg(&cdev->gadget->dev, 288 + "obex ttyGS%d function deactivate --> %d\n", 293 289 obex->port_num, status); 294 290 } 295 291 ··· 389 383 obex->can_activate = true; 390 384 391 385 392 - DBG(cdev, "obex ttyGS%d: %s speed IN/%s OUT/%s\n", 393 - obex->port_num, 394 - gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 395 - obex->port.in->name, obex->port.out->name); 386 + dev_dbg(&cdev->gadget->dev, "obex ttyGS%d: %s speed IN/%s OUT/%s\n", 387 + obex->port_num, 388 + gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 389 + obex->port.in->name, obex->port.out->name); 396 390 397 391 return 0; 398 392
+11 -8
drivers/usb/gadget/function/f_serial.c
··· 155 155 /* we know alt == 0, so this is an activation or a reset */ 156 156 157 157 if (gser->port.in->driver_data) { 158 - DBG(cdev, "reset generic ttyGS%d\n", gser->port_num); 158 + dev_dbg(&cdev->gadget->dev, 159 + "reset generic ttyGS%d\n", gser->port_num); 159 160 gserial_disconnect(&gser->port); 160 161 } 161 162 if (!gser->port.in->desc || !gser->port.out->desc) { 162 - DBG(cdev, "activate generic ttyGS%d\n", gser->port_num); 163 + dev_dbg(&cdev->gadget->dev, 164 + "activate generic ttyGS%d\n", gser->port_num); 163 165 if (config_ep_by_speed(cdev->gadget, f, gser->port.in) || 164 166 config_ep_by_speed(cdev->gadget, f, gser->port.out)) { 165 167 gser->port.in->desc = NULL; ··· 178 176 struct f_gser *gser = func_to_gser(f); 179 177 struct usb_composite_dev *cdev = f->config->cdev; 180 178 181 - DBG(cdev, "generic ttyGS%d deactivated\n", gser->port_num); 179 + dev_dbg(&cdev->gadget->dev, 180 + "generic ttyGS%d deactivated\n", gser->port_num); 182 181 gserial_disconnect(&gser->port); 183 182 } 184 183 ··· 242 239 gser_ss_function); 243 240 if (status) 244 241 goto fail; 245 - DBG(cdev, "generic ttyGS%d: %s speed IN/%s OUT/%s\n", 246 - gser->port_num, 247 - gadget_is_superspeed(c->cdev->gadget) ? "super" : 248 - gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 249 - gser->port.in->name, gser->port.out->name); 242 + dev_dbg(&cdev->gadget->dev, "generic ttyGS%d: %s speed IN/%s OUT/%s\n", 243 + gser->port_num, 244 + gadget_is_superspeed(c->cdev->gadget) ? "super" : 245 + gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full", 246 + gser->port.in->name, gser->port.out->name); 250 247 return 0; 251 248 252 249 fail:
+491 -20
drivers/usb/gadget/function/f_sourcesink.c
··· 23 23 #include "gadget_chips.h" 24 24 #include "u_f.h" 25 25 26 + #define USB_MS_TO_SS_INTERVAL(x) USB_MS_TO_HS_INTERVAL(x) 27 + 28 + enum eptype { 29 + EP_CONTROL = 0, 30 + EP_BULK, 31 + EP_ISOC, 32 + EP_INTERRUPT, 33 + }; 34 + 26 35 /* 27 36 * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral 28 37 * controller drivers. ··· 64 55 struct usb_ep *out_ep; 65 56 struct usb_ep *iso_in_ep; 66 57 struct usb_ep *iso_out_ep; 58 + struct usb_ep *int_in_ep; 59 + struct usb_ep *int_out_ep; 67 60 int cur_alt; 68 61 }; 69 62 ··· 79 68 static unsigned isoc_maxpacket; 80 69 static unsigned isoc_mult; 81 70 static unsigned isoc_maxburst; 71 + static unsigned int_interval; /* In ms */ 72 + static unsigned int_maxpacket; 73 + static unsigned int_mult; 74 + static unsigned int_maxburst; 82 75 static unsigned buflen; 83 76 84 77 /*-------------------------------------------------------------------------*/ ··· 103 88 104 89 .bAlternateSetting = 1, 105 90 .bNumEndpoints = 4, 91 + .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 92 + /* .iInterface = DYNAMIC */ 93 + }; 94 + 95 + static struct usb_interface_descriptor source_sink_intf_alt2 = { 96 + .bLength = USB_DT_INTERFACE_SIZE, 97 + .bDescriptorType = USB_DT_INTERFACE, 98 + 99 + .bAlternateSetting = 2, 100 + .bNumEndpoints = 2, 106 101 .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 107 102 /* .iInterface = DYNAMIC */ 108 103 }; ··· 155 130 .bInterval = 4, 156 131 }; 157 132 133 + static struct usb_endpoint_descriptor fs_int_source_desc = { 134 + .bLength = USB_DT_ENDPOINT_SIZE, 135 + .bDescriptorType = USB_DT_ENDPOINT, 136 + 137 + .bEndpointAddress = USB_DIR_IN, 138 + .bmAttributes = USB_ENDPOINT_XFER_INT, 139 + .wMaxPacketSize = cpu_to_le16(64), 140 + .bInterval = GZERO_INT_INTERVAL, 141 + }; 142 + 143 + static struct usb_endpoint_descriptor fs_int_sink_desc = { 144 + .bLength = USB_DT_ENDPOINT_SIZE, 145 + .bDescriptorType = USB_DT_ENDPOINT, 146 + 147 + .bEndpointAddress = USB_DIR_OUT, 148 + .bmAttributes = USB_ENDPOINT_XFER_INT, 149 + .wMaxPacketSize = cpu_to_le16(64), 150 + .bInterval = GZERO_INT_INTERVAL, 151 + }; 152 + 158 153 static struct usb_descriptor_header *fs_source_sink_descs[] = { 159 154 (struct usb_descriptor_header *) &source_sink_intf_alt0, 160 155 (struct usb_descriptor_header *) &fs_sink_desc, ··· 185 140 (struct usb_descriptor_header *) &fs_source_desc, 186 141 (struct usb_descriptor_header *) &fs_iso_sink_desc, 187 142 (struct usb_descriptor_header *) &fs_iso_source_desc, 143 + (struct usb_descriptor_header *) &source_sink_intf_alt2, 144 + #define FS_ALT_IFC_2_OFFSET 8 145 + (struct usb_descriptor_header *) &fs_int_sink_desc, 146 + (struct usb_descriptor_header *) &fs_int_source_desc, 188 147 NULL, 189 148 }; 190 149 ··· 228 179 .bInterval = 4, 229 180 }; 230 181 182 + static struct usb_endpoint_descriptor hs_int_source_desc = { 183 + .bLength = USB_DT_ENDPOINT_SIZE, 184 + .bDescriptorType = USB_DT_ENDPOINT, 185 + 186 + .bmAttributes = USB_ENDPOINT_XFER_INT, 187 + .wMaxPacketSize = cpu_to_le16(1024), 188 + .bInterval = USB_MS_TO_HS_INTERVAL(GZERO_INT_INTERVAL), 189 + }; 190 + 191 + static struct usb_endpoint_descriptor hs_int_sink_desc = { 192 + .bLength = USB_DT_ENDPOINT_SIZE, 193 + .bDescriptorType = USB_DT_ENDPOINT, 194 + 195 + .bmAttributes = USB_ENDPOINT_XFER_INT, 196 + .wMaxPacketSize = cpu_to_le16(1024), 197 + .bInterval = USB_MS_TO_HS_INTERVAL(GZERO_INT_INTERVAL), 198 + }; 199 + 231 200 static struct usb_descriptor_header *hs_source_sink_descs[] = { 232 201 (struct usb_descriptor_header *) &source_sink_intf_alt0, 233 202 (struct usb_descriptor_header *) &hs_source_desc, ··· 256 189 (struct usb_descriptor_header *) &hs_sink_desc, 257 190 (struct usb_descriptor_header *) &hs_iso_source_desc, 258 191 (struct usb_descriptor_header *) &hs_iso_sink_desc, 192 + (struct usb_descriptor_header *) &source_sink_intf_alt2, 193 + #define HS_ALT_IFC_2_OFFSET 8 194 + (struct usb_descriptor_header *) &hs_int_source_desc, 195 + (struct usb_descriptor_header *) &hs_int_sink_desc, 259 196 NULL, 260 197 }; 261 198 ··· 335 264 .wBytesPerInterval = cpu_to_le16(1024), 336 265 }; 337 266 267 + static struct usb_endpoint_descriptor ss_int_source_desc = { 268 + .bLength = USB_DT_ENDPOINT_SIZE, 269 + .bDescriptorType = USB_DT_ENDPOINT, 270 + 271 + .bmAttributes = USB_ENDPOINT_XFER_INT, 272 + .wMaxPacketSize = cpu_to_le16(1024), 273 + .bInterval = USB_MS_TO_SS_INTERVAL(GZERO_INT_INTERVAL), 274 + }; 275 + 276 + struct usb_ss_ep_comp_descriptor ss_int_source_comp_desc = { 277 + .bLength = USB_DT_SS_EP_COMP_SIZE, 278 + .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 279 + 280 + .bMaxBurst = 0, 281 + .bmAttributes = 0, 282 + .wBytesPerInterval = cpu_to_le16(1024), 283 + }; 284 + 285 + static struct usb_endpoint_descriptor ss_int_sink_desc = { 286 + .bLength = USB_DT_ENDPOINT_SIZE, 287 + .bDescriptorType = USB_DT_ENDPOINT, 288 + 289 + .bmAttributes = USB_ENDPOINT_XFER_INT, 290 + .wMaxPacketSize = cpu_to_le16(1024), 291 + .bInterval = USB_MS_TO_SS_INTERVAL(GZERO_INT_INTERVAL), 292 + }; 293 + 294 + struct usb_ss_ep_comp_descriptor ss_int_sink_comp_desc = { 295 + .bLength = USB_DT_SS_EP_COMP_SIZE, 296 + .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 297 + 298 + .bMaxBurst = 0, 299 + .bmAttributes = 0, 300 + .wBytesPerInterval = cpu_to_le16(1024), 301 + }; 302 + 338 303 static struct usb_descriptor_header *ss_source_sink_descs[] = { 339 304 (struct usb_descriptor_header *) &source_sink_intf_alt0, 340 305 (struct usb_descriptor_header *) &ss_source_desc, ··· 387 280 (struct usb_descriptor_header *) &ss_iso_source_comp_desc, 388 281 (struct usb_descriptor_header *) &ss_iso_sink_desc, 389 282 (struct usb_descriptor_header *) &ss_iso_sink_comp_desc, 283 + (struct usb_descriptor_header *) &source_sink_intf_alt2, 284 + #define SS_ALT_IFC_2_OFFSET 14 285 + (struct usb_descriptor_header *) &ss_int_source_desc, 286 + (struct usb_descriptor_header *) &ss_int_source_comp_desc, 287 + (struct usb_descriptor_header *) &ss_int_sink_desc, 288 + (struct usb_descriptor_header *) &ss_int_sink_comp_desc, 390 289 NULL, 391 290 }; 392 291 ··· 414 301 }; 415 302 416 303 /*-------------------------------------------------------------------------*/ 304 + static const char *get_ep_string(enum eptype ep_type) 305 + { 306 + switch (ep_type) { 307 + case EP_ISOC: 308 + return "ISOC-"; 309 + case EP_INTERRUPT: 310 + return "INTERRUPT-"; 311 + case EP_CONTROL: 312 + return "CTRL-"; 313 + case EP_BULK: 314 + return "BULK-"; 315 + default: 316 + return "UNKNOWN-"; 317 + } 318 + } 417 319 418 320 static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len) 419 321 { ··· 456 328 457 329 void disable_endpoints(struct usb_composite_dev *cdev, 458 330 struct usb_ep *in, struct usb_ep *out, 459 - struct usb_ep *iso_in, struct usb_ep *iso_out) 331 + struct usb_ep *iso_in, struct usb_ep *iso_out, 332 + struct usb_ep *int_in, struct usb_ep *int_out) 460 333 { 461 334 disable_ep(cdev, in); 462 335 disable_ep(cdev, out); ··· 465 336 disable_ep(cdev, iso_in); 466 337 if (iso_out) 467 338 disable_ep(cdev, iso_out); 339 + if (int_in) 340 + disable_ep(cdev, int_in); 341 + if (int_out) 342 + disable_ep(cdev, int_out); 468 343 } 469 344 470 345 static int ··· 485 352 return id; 486 353 source_sink_intf_alt0.bInterfaceNumber = id; 487 354 source_sink_intf_alt1.bInterfaceNumber = id; 355 + source_sink_intf_alt2.bInterfaceNumber = id; 488 356 489 357 /* allocate bulk endpoints */ 490 358 ss->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_source_desc); ··· 546 412 if (isoc_maxpacket > 1024) 547 413 isoc_maxpacket = 1024; 548 414 415 + /* sanity check the interrupt module parameters */ 416 + if (int_interval < 1) 417 + int_interval = 1; 418 + if (int_interval > 4096) 419 + int_interval = 4096; 420 + if (int_mult > 2) 421 + int_mult = 2; 422 + if (int_maxburst > 15) 423 + int_maxburst = 15; 424 + 425 + /* fill in the FS interrupt descriptors from the module parameters */ 426 + fs_int_source_desc.wMaxPacketSize = int_maxpacket > 64 ? 427 + 64 : int_maxpacket; 428 + fs_int_source_desc.bInterval = int_interval > 255 ? 429 + 255 : int_interval; 430 + fs_int_sink_desc.wMaxPacketSize = int_maxpacket > 64 ? 431 + 64 : int_maxpacket; 432 + fs_int_sink_desc.bInterval = int_interval > 255 ? 433 + 255 : int_interval; 434 + 435 + /* allocate int endpoints */ 436 + ss->int_in_ep = usb_ep_autoconfig(cdev->gadget, &fs_int_source_desc); 437 + if (!ss->int_in_ep) 438 + goto no_int; 439 + ss->int_in_ep->driver_data = cdev; /* claim */ 440 + 441 + ss->int_out_ep = usb_ep_autoconfig(cdev->gadget, &fs_int_sink_desc); 442 + if (ss->int_out_ep) { 443 + ss->int_out_ep->driver_data = cdev; /* claim */ 444 + } else { 445 + ss->int_in_ep->driver_data = NULL; 446 + ss->int_in_ep = NULL; 447 + no_int: 448 + fs_source_sink_descs[FS_ALT_IFC_2_OFFSET] = NULL; 449 + hs_source_sink_descs[HS_ALT_IFC_2_OFFSET] = NULL; 450 + ss_source_sink_descs[SS_ALT_IFC_2_OFFSET] = NULL; 451 + } 452 + 453 + if (int_maxpacket > 1024) 454 + int_maxpacket = 1024; 455 + 549 456 /* support high speed hardware */ 550 457 hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress; 551 458 hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress; 552 459 553 460 /* 554 - * Fill in the HS isoc descriptors from the module parameters. 555 - * We assume that the user knows what they are doing and won't 556 - * give parameters that their UDC doesn't support. 461 + * Fill in the HS isoc and interrupt descriptors from the module 462 + * parameters. We assume that the user knows what they are doing and 463 + * won't give parameters that their UDC doesn't support. 557 464 */ 558 465 hs_iso_source_desc.wMaxPacketSize = isoc_maxpacket; 559 466 hs_iso_source_desc.wMaxPacketSize |= isoc_mult << 11; ··· 607 432 hs_iso_sink_desc.bInterval = isoc_interval; 608 433 hs_iso_sink_desc.bEndpointAddress = fs_iso_sink_desc.bEndpointAddress; 609 434 435 + hs_int_source_desc.wMaxPacketSize = int_maxpacket; 436 + hs_int_source_desc.wMaxPacketSize |= int_mult << 11; 437 + hs_int_source_desc.bInterval = USB_MS_TO_HS_INTERVAL(int_interval); 438 + hs_int_source_desc.bEndpointAddress = 439 + fs_int_source_desc.bEndpointAddress; 440 + 441 + hs_int_sink_desc.wMaxPacketSize = int_maxpacket; 442 + hs_int_sink_desc.wMaxPacketSize |= int_mult << 11; 443 + hs_int_sink_desc.bInterval = USB_MS_TO_HS_INTERVAL(int_interval); 444 + hs_int_sink_desc.bEndpointAddress = fs_int_sink_desc.bEndpointAddress; 445 + 610 446 /* support super speed hardware */ 611 447 ss_source_desc.bEndpointAddress = 612 448 fs_source_desc.bEndpointAddress; ··· 625 439 fs_sink_desc.bEndpointAddress; 626 440 627 441 /* 628 - * Fill in the SS isoc descriptors from the module parameters. 629 - * We assume that the user knows what they are doing and won't 630 - * give parameters that their UDC doesn't support. 442 + * Fill in the SS isoc and interrupt descriptors from the module 443 + * parameters. We assume that the user knows what they are doing and 444 + * won't give parameters that their UDC doesn't support. 631 445 */ 632 446 ss_iso_source_desc.wMaxPacketSize = isoc_maxpacket; 633 447 ss_iso_source_desc.bInterval = isoc_interval; ··· 646 460 isoc_maxpacket * (isoc_mult + 1) * (isoc_maxburst + 1); 647 461 ss_iso_sink_desc.bEndpointAddress = fs_iso_sink_desc.bEndpointAddress; 648 462 463 + ss_int_source_desc.wMaxPacketSize = int_maxpacket; 464 + ss_int_source_desc.bInterval = USB_MS_TO_SS_INTERVAL(int_interval); 465 + ss_int_source_comp_desc.bmAttributes = int_mult; 466 + ss_int_source_comp_desc.bMaxBurst = int_maxburst; 467 + ss_int_source_comp_desc.wBytesPerInterval = 468 + int_maxpacket * (int_mult + 1) * (int_maxburst + 1); 469 + ss_int_source_desc.bEndpointAddress = 470 + fs_int_source_desc.bEndpointAddress; 471 + 472 + ss_int_sink_desc.wMaxPacketSize = int_maxpacket; 473 + ss_int_sink_desc.bInterval = USB_MS_TO_SS_INTERVAL(int_interval); 474 + ss_int_sink_comp_desc.bmAttributes = int_mult; 475 + ss_int_sink_comp_desc.bMaxBurst = int_maxburst; 476 + ss_int_sink_comp_desc.wBytesPerInterval = 477 + int_maxpacket * (int_mult + 1) * (int_maxburst + 1); 478 + ss_int_sink_desc.bEndpointAddress = fs_int_sink_desc.bEndpointAddress; 479 + 649 480 ret = usb_assign_descriptors(f, fs_source_sink_descs, 650 481 hs_source_sink_descs, ss_source_sink_descs); 651 482 if (ret) 652 483 return ret; 653 484 654 - DBG(cdev, "%s speed %s: IN/%s, OUT/%s, ISO-IN/%s, ISO-OUT/%s\n", 485 + DBG(cdev, "%s speed %s: IN/%s, OUT/%s, ISO-IN/%s, ISO-OUT/%s, " 486 + "INT-IN/%s, INT-OUT/%s\n", 655 487 (gadget_is_superspeed(c->cdev->gadget) ? "super" : 656 488 (gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full")), 657 489 f->name, ss->in_ep->name, ss->out_ep->name, 658 490 ss->iso_in_ep ? ss->iso_in_ep->name : "<none>", 659 - ss->iso_out_ep ? ss->iso_out_ep->name : "<none>"); 491 + ss->iso_out_ep ? ss->iso_out_ep->name : "<none>", 492 + ss->int_in_ep ? ss->int_in_ep->name : "<none>", 493 + ss->int_out_ep ? ss->int_out_ep->name : "<none>"); 660 494 return 0; 661 495 } 662 496 ··· 807 601 } 808 602 809 603 static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in, 810 - bool is_iso, int speed) 604 + enum eptype ep_type, int speed) 811 605 { 812 606 struct usb_ep *ep; 813 607 struct usb_request *req; 814 608 int i, size, status; 815 609 816 610 for (i = 0; i < 8; i++) { 817 - if (is_iso) { 611 + switch (ep_type) { 612 + case EP_ISOC: 818 613 switch (speed) { 819 614 case USB_SPEED_SUPER: 820 615 size = isoc_maxpacket * (isoc_mult + 1) * ··· 831 624 } 832 625 ep = is_in ? ss->iso_in_ep : ss->iso_out_ep; 833 626 req = ss_alloc_ep_req(ep, size); 834 - } else { 627 + break; 628 + case EP_INTERRUPT: 629 + switch (speed) { 630 + case USB_SPEED_SUPER: 631 + size = int_maxpacket * (int_mult + 1) * 632 + (int_maxburst + 1); 633 + break; 634 + case USB_SPEED_HIGH: 635 + size = int_maxpacket * (int_mult + 1); 636 + break; 637 + default: 638 + size = int_maxpacket > 1023 ? 639 + 1023 : int_maxpacket; 640 + break; 641 + } 642 + ep = is_in ? ss->int_in_ep : ss->int_out_ep; 643 + req = ss_alloc_ep_req(ep, size); 644 + break; 645 + default: 835 646 ep = is_in ? ss->in_ep : ss->out_ep; 836 647 req = ss_alloc_ep_req(ep, 0); 648 + break; 837 649 } 838 650 839 651 if (!req) ··· 870 644 871 645 cdev = ss->function.config->cdev; 872 646 ERROR(cdev, "start %s%s %s --> %d\n", 873 - is_iso ? "ISO-" : "", is_in ? "IN" : "OUT", 874 - ep->name, status); 647 + get_ep_string(ep_type), is_in ? "IN" : "OUT", 648 + ep->name, status); 875 649 free_ep_req(ep, req); 876 650 } 877 651 878 - if (!is_iso) 652 + if (!(ep_type == EP_ISOC)) 879 653 break; 880 654 } 881 655 ··· 888 662 889 663 cdev = ss->function.config->cdev; 890 664 disable_endpoints(cdev, ss->in_ep, ss->out_ep, ss->iso_in_ep, 891 - ss->iso_out_ep); 665 + ss->iso_out_ep, ss->int_in_ep, ss->int_out_ep); 892 666 VDBG(cdev, "%s disabled\n", ss->function.name); 893 667 } 894 668 ··· 900 674 int speed = cdev->gadget->speed; 901 675 struct usb_ep *ep; 902 676 677 + if (alt == 2) { 678 + /* Configure for periodic interrupt endpoint */ 679 + ep = ss->int_in_ep; 680 + if (ep) { 681 + result = config_ep_by_speed(cdev->gadget, 682 + &(ss->function), ep); 683 + if (result) 684 + return result; 685 + 686 + result = usb_ep_enable(ep); 687 + if (result < 0) 688 + return result; 689 + 690 + ep->driver_data = ss; 691 + result = source_sink_start_ep(ss, true, EP_INTERRUPT, 692 + speed); 693 + if (result < 0) { 694 + fail1: 695 + ep = ss->int_in_ep; 696 + if (ep) { 697 + usb_ep_disable(ep); 698 + ep->driver_data = NULL; 699 + } 700 + return result; 701 + } 702 + } 703 + 704 + /* 705 + * one interrupt endpoint reads (sinks) anything OUT (from the 706 + * host) 707 + */ 708 + ep = ss->int_out_ep; 709 + if (ep) { 710 + result = config_ep_by_speed(cdev->gadget, 711 + &(ss->function), ep); 712 + if (result) 713 + goto fail1; 714 + 715 + result = usb_ep_enable(ep); 716 + if (result < 0) 717 + goto fail1; 718 + 719 + ep->driver_data = ss; 720 + result = source_sink_start_ep(ss, false, EP_INTERRUPT, 721 + speed); 722 + if (result < 0) { 723 + ep = ss->int_out_ep; 724 + usb_ep_disable(ep); 725 + ep->driver_data = NULL; 726 + goto fail1; 727 + } 728 + } 729 + 730 + goto out; 731 + } 732 + 903 733 /* one bulk endpoint writes (sources) zeroes IN (to the host) */ 904 734 ep = ss->in_ep; 905 735 result = config_ep_by_speed(cdev->gadget, &(ss->function), ep); ··· 966 684 return result; 967 685 ep->driver_data = ss; 968 686 969 - result = source_sink_start_ep(ss, true, false, speed); 687 + result = source_sink_start_ep(ss, true, EP_BULK, speed); 970 688 if (result < 0) { 971 689 fail: 972 690 ep = ss->in_ep; ··· 985 703 goto fail; 986 704 ep->driver_data = ss; 987 705 988 - result = source_sink_start_ep(ss, false, false, speed); 706 + result = source_sink_start_ep(ss, false, EP_BULK, speed); 989 707 if (result < 0) { 990 708 fail2: 991 709 ep = ss->out_ep; ··· 1008 726 goto fail2; 1009 727 ep->driver_data = ss; 1010 728 1011 - result = source_sink_start_ep(ss, true, true, speed); 729 + result = source_sink_start_ep(ss, true, EP_ISOC, speed); 1012 730 if (result < 0) { 1013 731 fail3: 1014 732 ep = ss->iso_in_ep; ··· 1031 749 goto fail3; 1032 750 ep->driver_data = ss; 1033 751 1034 - result = source_sink_start_ep(ss, false, true, speed); 752 + result = source_sink_start_ep(ss, false, EP_ISOC, speed); 1035 753 if (result < 0) { 1036 754 usb_ep_disable(ep); 1037 755 ep->driver_data = NULL; 1038 756 goto fail3; 1039 757 } 1040 758 } 759 + 1041 760 out: 1042 761 ss->cur_alt = alt; 1043 762 ··· 1053 770 struct usb_composite_dev *cdev = f->config->cdev; 1054 771 1055 772 if (ss->in_ep->driver_data) 773 + disable_source_sink(ss); 774 + else if (alt == 2 && ss->int_in_ep->driver_data) 1056 775 disable_source_sink(ss); 1057 776 return enable_source_sink(cdev, ss, alt); 1058 777 } ··· 1168 883 isoc_maxpacket = ss_opts->isoc_maxpacket; 1169 884 isoc_mult = ss_opts->isoc_mult; 1170 885 isoc_maxburst = ss_opts->isoc_maxburst; 886 + int_interval = ss_opts->int_interval; 887 + int_maxpacket = ss_opts->int_maxpacket; 888 + int_mult = ss_opts->int_mult; 889 + int_maxburst = ss_opts->int_maxburst; 1171 890 buflen = ss_opts->bulk_buflen; 1172 891 1173 892 ss->function.name = "source/sink"; ··· 1468 1179 f_ss_opts_bulk_buflen_show, 1469 1180 f_ss_opts_bulk_buflen_store); 1470 1181 1182 + static ssize_t f_ss_opts_int_interval_show(struct f_ss_opts *opts, char *page) 1183 + { 1184 + int result; 1185 + 1186 + mutex_lock(&opts->lock); 1187 + result = sprintf(page, "%d", opts->int_interval); 1188 + mutex_unlock(&opts->lock); 1189 + 1190 + return result; 1191 + } 1192 + 1193 + static ssize_t f_ss_opts_int_interval_store(struct f_ss_opts *opts, 1194 + const char *page, size_t len) 1195 + { 1196 + int ret; 1197 + u32 num; 1198 + 1199 + mutex_lock(&opts->lock); 1200 + if (opts->refcnt) { 1201 + ret = -EBUSY; 1202 + goto end; 1203 + } 1204 + 1205 + ret = kstrtou32(page, 0, &num); 1206 + if (ret) 1207 + goto end; 1208 + 1209 + if (num > 4096) { 1210 + ret = -EINVAL; 1211 + goto end; 1212 + } 1213 + 1214 + opts->int_interval = num; 1215 + ret = len; 1216 + end: 1217 + mutex_unlock(&opts->lock); 1218 + return ret; 1219 + } 1220 + 1221 + static struct f_ss_opts_attribute f_ss_opts_int_interval = 1222 + __CONFIGFS_ATTR(int_interval, S_IRUGO | S_IWUSR, 1223 + f_ss_opts_int_interval_show, 1224 + f_ss_opts_int_interval_store); 1225 + 1226 + static ssize_t f_ss_opts_int_maxpacket_show(struct f_ss_opts *opts, char *page) 1227 + { 1228 + int result; 1229 + 1230 + mutex_lock(&opts->lock); 1231 + result = sprintf(page, "%d", opts->int_maxpacket); 1232 + mutex_unlock(&opts->lock); 1233 + 1234 + return result; 1235 + } 1236 + 1237 + static ssize_t f_ss_opts_int_maxpacket_store(struct f_ss_opts *opts, 1238 + const char *page, size_t len) 1239 + { 1240 + int ret; 1241 + u16 num; 1242 + 1243 + mutex_lock(&opts->lock); 1244 + if (opts->refcnt) { 1245 + ret = -EBUSY; 1246 + goto end; 1247 + } 1248 + 1249 + ret = kstrtou16(page, 0, &num); 1250 + if (ret) 1251 + goto end; 1252 + 1253 + if (num > 1024) { 1254 + ret = -EINVAL; 1255 + goto end; 1256 + } 1257 + 1258 + opts->int_maxpacket = num; 1259 + ret = len; 1260 + end: 1261 + mutex_unlock(&opts->lock); 1262 + return ret; 1263 + } 1264 + 1265 + static struct f_ss_opts_attribute f_ss_opts_int_maxpacket = 1266 + __CONFIGFS_ATTR(int_maxpacket, S_IRUGO | S_IWUSR, 1267 + f_ss_opts_int_maxpacket_show, 1268 + f_ss_opts_int_maxpacket_store); 1269 + 1270 + static ssize_t f_ss_opts_int_mult_show(struct f_ss_opts *opts, char *page) 1271 + { 1272 + int result; 1273 + 1274 + mutex_lock(&opts->lock); 1275 + result = sprintf(page, "%d", opts->int_mult); 1276 + mutex_unlock(&opts->lock); 1277 + 1278 + return result; 1279 + } 1280 + 1281 + static ssize_t f_ss_opts_int_mult_store(struct f_ss_opts *opts, 1282 + const char *page, size_t len) 1283 + { 1284 + int ret; 1285 + u8 num; 1286 + 1287 + mutex_lock(&opts->lock); 1288 + if (opts->refcnt) { 1289 + ret = -EBUSY; 1290 + goto end; 1291 + } 1292 + 1293 + ret = kstrtou8(page, 0, &num); 1294 + if (ret) 1295 + goto end; 1296 + 1297 + if (num > 2) { 1298 + ret = -EINVAL; 1299 + goto end; 1300 + } 1301 + 1302 + opts->int_mult = num; 1303 + ret = len; 1304 + end: 1305 + mutex_unlock(&opts->lock); 1306 + return ret; 1307 + } 1308 + 1309 + static struct f_ss_opts_attribute f_ss_opts_int_mult = 1310 + __CONFIGFS_ATTR(int_mult, S_IRUGO | S_IWUSR, 1311 + f_ss_opts_int_mult_show, 1312 + f_ss_opts_int_mult_store); 1313 + 1314 + static ssize_t f_ss_opts_int_maxburst_show(struct f_ss_opts *opts, char *page) 1315 + { 1316 + int result; 1317 + 1318 + mutex_lock(&opts->lock); 1319 + result = sprintf(page, "%d", opts->int_maxburst); 1320 + mutex_unlock(&opts->lock); 1321 + 1322 + return result; 1323 + } 1324 + 1325 + static ssize_t f_ss_opts_int_maxburst_store(struct f_ss_opts *opts, 1326 + const char *page, size_t len) 1327 + { 1328 + int ret; 1329 + u8 num; 1330 + 1331 + mutex_lock(&opts->lock); 1332 + if (opts->refcnt) { 1333 + ret = -EBUSY; 1334 + goto end; 1335 + } 1336 + 1337 + ret = kstrtou8(page, 0, &num); 1338 + if (ret) 1339 + goto end; 1340 + 1341 + if (num > 15) { 1342 + ret = -EINVAL; 1343 + goto end; 1344 + } 1345 + 1346 + opts->int_maxburst = num; 1347 + ret = len; 1348 + end: 1349 + mutex_unlock(&opts->lock); 1350 + return ret; 1351 + } 1352 + 1353 + static struct f_ss_opts_attribute f_ss_opts_int_maxburst = 1354 + __CONFIGFS_ATTR(int_maxburst, S_IRUGO | S_IWUSR, 1355 + f_ss_opts_int_maxburst_show, 1356 + f_ss_opts_int_maxburst_store); 1357 + 1471 1358 static struct configfs_attribute *ss_attrs[] = { 1472 1359 &f_ss_opts_pattern.attr, 1473 1360 &f_ss_opts_isoc_interval.attr, ··· 1651 1186 &f_ss_opts_isoc_mult.attr, 1652 1187 &f_ss_opts_isoc_maxburst.attr, 1653 1188 &f_ss_opts_bulk_buflen.attr, 1189 + &f_ss_opts_int_interval.attr, 1190 + &f_ss_opts_int_maxpacket.attr, 1191 + &f_ss_opts_int_mult.attr, 1192 + &f_ss_opts_int_maxburst.attr, 1654 1193 NULL, 1655 1194 }; 1656 1195 ··· 1684 1215 ss_opts->isoc_interval = GZERO_ISOC_INTERVAL; 1685 1216 ss_opts->isoc_maxpacket = GZERO_ISOC_MAXPACKET; 1686 1217 ss_opts->bulk_buflen = GZERO_BULK_BUFLEN; 1218 + ss_opts->int_interval = GZERO_INT_INTERVAL; 1219 + ss_opts->int_maxpacket = GZERO_INT_MAXPACKET; 1687 1220 1688 1221 config_group_init_type_name(&ss_opts->func_inst.group, "", 1689 1222 &ss_func_type);
+277 -60
drivers/usb/gadget/function/f_uac1.c
··· 11 11 12 12 #include <linux/slab.h> 13 13 #include <linux/kernel.h> 14 + #include <linux/module.h> 14 15 #include <linux/device.h> 15 16 #include <linux/atomic.h> 16 17 17 18 #include "u_uac1.h" 18 - 19 - #define OUT_EP_MAX_PACKET_SIZE 200 20 - static int req_buf_size = OUT_EP_MAX_PACKET_SIZE; 21 - module_param(req_buf_size, int, S_IRUGO); 22 - MODULE_PARM_DESC(req_buf_size, "ISO OUT endpoint request buffer size"); 23 - 24 - static int req_count = 256; 25 - module_param(req_count, int, S_IRUGO); 26 - MODULE_PARM_DESC(req_count, "ISO OUT endpoint request count"); 27 - 28 - static int audio_buf_size = 48000; 29 - module_param(audio_buf_size, int, S_IRUGO); 30 - MODULE_PARM_DESC(audio_buf_size, "Audio buffer size"); 31 19 32 20 static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value); 33 21 static int generic_get_cmd(struct usb_audio_control *con, u8 cmd); ··· 34 46 #define F_AUDIO_NUM_INTERFACES 2 35 47 36 48 /* B.3.1 Standard AC Interface Descriptor */ 37 - static struct usb_interface_descriptor ac_interface_desc __initdata = { 49 + static struct usb_interface_descriptor ac_interface_desc = { 38 50 .bLength = USB_DT_INTERFACE_SIZE, 39 51 .bDescriptorType = USB_DT_INTERFACE, 40 52 .bNumEndpoints = 0, ··· 171 183 .bEndpointAddress = USB_DIR_OUT, 172 184 .bmAttributes = USB_ENDPOINT_SYNC_ADAPTIVE 173 185 | USB_ENDPOINT_XFER_ISOC, 174 - .wMaxPacketSize = __constant_cpu_to_le16(OUT_EP_MAX_PACKET_SIZE), 186 + .wMaxPacketSize = cpu_to_le16(UAC1_OUT_EP_MAX_PACKET_SIZE), 175 187 .bInterval = 4, 176 188 }; 177 189 178 190 /* Class-specific AS ISO OUT Endpoint Descriptor */ 179 - static struct uac_iso_endpoint_descriptor as_iso_out_desc __initdata = { 191 + static struct uac_iso_endpoint_descriptor as_iso_out_desc = { 180 192 .bLength = UAC_ISO_ENDPOINT_DESC_SIZE, 181 193 .bDescriptorType = USB_DT_CS_ENDPOINT, 182 194 .bDescriptorSubtype = UAC_EP_GENERAL, ··· 185 197 .wLockDelay = __constant_cpu_to_le16(1), 186 198 }; 187 199 188 - static struct usb_descriptor_header *f_audio_desc[] __initdata = { 200 + static struct usb_descriptor_header *f_audio_desc[] = { 189 201 (struct usb_descriptor_header *)&ac_interface_desc, 190 202 (struct usb_descriptor_header *)&ac_header_desc, 191 203 ··· 201 213 202 214 (struct usb_descriptor_header *)&as_out_ep_desc, 203 215 (struct usb_descriptor_header *)&as_iso_out_desc, 216 + NULL, 217 + }; 218 + 219 + enum { 220 + STR_AC_IF, 221 + STR_INPUT_TERMINAL, 222 + STR_INPUT_TERMINAL_CH_NAMES, 223 + STR_FEAT_DESC_0, 224 + STR_OUTPUT_TERMINAL, 225 + STR_AS_IF_ALT0, 226 + STR_AS_IF_ALT1, 227 + }; 228 + 229 + static struct usb_string strings_uac1[] = { 230 + [STR_AC_IF].s = "AC Interface", 231 + [STR_INPUT_TERMINAL].s = "Input terminal", 232 + [STR_INPUT_TERMINAL_CH_NAMES].s = "Channels", 233 + [STR_FEAT_DESC_0].s = "Volume control & mute", 234 + [STR_OUTPUT_TERMINAL].s = "Output terminal", 235 + [STR_AS_IF_ALT0].s = "AS Interface", 236 + [STR_AS_IF_ALT1].s = "AS Interface", 237 + { }, 238 + }; 239 + 240 + static struct usb_gadget_strings str_uac1 = { 241 + .language = 0x0409, /* en-us */ 242 + .strings = strings_uac1, 243 + }; 244 + 245 + static struct usb_gadget_strings *uac1_strings[] = { 246 + &str_uac1, 204 247 NULL, 205 248 }; 206 249 ··· 319 300 struct f_audio *audio = req->context; 320 301 struct usb_composite_dev *cdev = audio->card.func.config->cdev; 321 302 struct f_audio_buf *copy_buf = audio->copy_buf; 303 + struct f_uac1_opts *opts; 304 + int audio_buf_size; 322 305 int err; 306 + 307 + opts = container_of(audio->card.func.fi, struct f_uac1_opts, 308 + func_inst); 309 + audio_buf_size = opts->audio_buf_size; 323 310 324 311 if (!copy_buf) 325 312 return -EINVAL; ··· 571 546 struct usb_composite_dev *cdev = f->config->cdev; 572 547 struct usb_ep *out_ep = audio->out_ep; 573 548 struct usb_request *req; 549 + struct f_uac1_opts *opts; 550 + int req_buf_size, req_count, audio_buf_size; 574 551 int i = 0, err = 0; 575 552 576 553 DBG(cdev, "intf %d, alt %d\n", intf, alt); 554 + 555 + opts = container_of(f->fi, struct f_uac1_opts, func_inst); 556 + req_buf_size = opts->req_buf_size; 557 + req_count = opts->req_count; 558 + audio_buf_size = opts->audio_buf_size; 577 559 578 560 if (intf == 1) { 579 561 if (alt == 1) { ··· 657 625 } 658 626 659 627 /* audio function driver setup/binding */ 660 - static int __init 628 + static int 661 629 f_audio_bind(struct usb_configuration *c, struct usb_function *f) 662 630 { 663 631 struct usb_composite_dev *cdev = c->cdev; 664 632 struct f_audio *audio = func_to_audio(f); 633 + struct usb_string *us; 665 634 int status; 666 635 struct usb_ep *ep = NULL; 636 + struct f_uac1_opts *audio_opts; 637 + 638 + audio_opts = container_of(f->fi, struct f_uac1_opts, func_inst); 639 + audio->card.gadget = c->cdev->gadget; 640 + audio_opts->card = &audio->card; 641 + /* set up ASLA audio devices */ 642 + if (!audio_opts->bound) { 643 + status = gaudio_setup(&audio->card); 644 + if (status < 0) 645 + return status; 646 + audio_opts->bound = true; 647 + } 648 + us = usb_gstrings_attach(cdev, uac1_strings, ARRAY_SIZE(strings_uac1)); 649 + if (IS_ERR(us)) 650 + return PTR_ERR(us); 651 + ac_interface_desc.iInterface = us[STR_AC_IF].id; 652 + input_terminal_desc.iTerminal = us[STR_INPUT_TERMINAL].id; 653 + input_terminal_desc.iChannelNames = us[STR_INPUT_TERMINAL_CH_NAMES].id; 654 + feature_unit_desc.iFeature = us[STR_FEAT_DESC_0].id; 655 + output_terminal_desc.iTerminal = us[STR_OUTPUT_TERMINAL].id; 656 + as_interface_alt_0_desc.iInterface = us[STR_AS_IF_ALT0].id; 657 + as_interface_alt_1_desc.iInterface = us[STR_AS_IF_ALT1].id; 658 + 667 659 668 660 f_audio_build_desc(audio); 669 661 ··· 722 666 return 0; 723 667 724 668 fail: 669 + gaudio_cleanup(&audio->card); 725 670 if (ep) 726 671 ep->driver_data = NULL; 727 672 return status; 728 - } 729 - 730 - static void 731 - f_audio_unbind(struct usb_configuration *c, struct usb_function *f) 732 - { 733 - struct f_audio *audio = func_to_audio(f); 734 - 735 - usb_free_all_descriptors(f); 736 - kfree(audio); 737 673 } 738 674 739 675 /*-------------------------------------------------------------------------*/ ··· 743 695 } 744 696 745 697 /* Todo: add more control selecotor dynamically */ 746 - static int __init control_selector_init(struct f_audio *audio) 698 + static int control_selector_init(struct f_audio *audio) 747 699 { 748 700 INIT_LIST_HEAD(&audio->cs); 749 701 list_add(&feature_unit.list, &audio->cs); ··· 760 712 return 0; 761 713 } 762 714 763 - /** 764 - * audio_bind_config - add USB audio function to a configuration 765 - * @c: the configuration to supcard the USB audio function 766 - * Context: single threaded during gadget setup 767 - * 768 - * Returns zero on success, else negative errno. 769 - */ 770 - static int __init audio_bind_config(struct usb_configuration *c) 715 + static inline struct f_uac1_opts *to_f_uac1_opts(struct config_item *item) 716 + { 717 + return container_of(to_config_group(item), struct f_uac1_opts, 718 + func_inst.group); 719 + } 720 + 721 + CONFIGFS_ATTR_STRUCT(f_uac1_opts); 722 + CONFIGFS_ATTR_OPS(f_uac1_opts); 723 + 724 + static void f_uac1_attr_release(struct config_item *item) 725 + { 726 + struct f_uac1_opts *opts = to_f_uac1_opts(item); 727 + 728 + usb_put_function_instance(&opts->func_inst); 729 + } 730 + 731 + static struct configfs_item_operations f_uac1_item_ops = { 732 + .release = f_uac1_attr_release, 733 + .show_attribute = f_uac1_opts_attr_show, 734 + .store_attribute = f_uac1_opts_attr_store, 735 + }; 736 + 737 + #define UAC1_INT_ATTRIBUTE(name) \ 738 + static ssize_t f_uac1_opts_##name##_show(struct f_uac1_opts *opts, \ 739 + char *page) \ 740 + { \ 741 + int result; \ 742 + \ 743 + mutex_lock(&opts->lock); \ 744 + result = sprintf(page, "%u\n", opts->name); \ 745 + mutex_unlock(&opts->lock); \ 746 + \ 747 + return result; \ 748 + } \ 749 + \ 750 + static ssize_t f_uac1_opts_##name##_store(struct f_uac1_opts *opts, \ 751 + const char *page, size_t len) \ 752 + { \ 753 + int ret; \ 754 + u32 num; \ 755 + \ 756 + mutex_lock(&opts->lock); \ 757 + if (opts->refcnt) { \ 758 + ret = -EBUSY; \ 759 + goto end; \ 760 + } \ 761 + \ 762 + ret = kstrtou32(page, 0, &num); \ 763 + if (ret) \ 764 + goto end; \ 765 + \ 766 + opts->name = num; \ 767 + ret = len; \ 768 + \ 769 + end: \ 770 + mutex_unlock(&opts->lock); \ 771 + return ret; \ 772 + } \ 773 + \ 774 + static struct f_uac1_opts_attribute f_uac1_opts_##name = \ 775 + __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ 776 + f_uac1_opts_##name##_show, \ 777 + f_uac1_opts_##name##_store) 778 + 779 + UAC1_INT_ATTRIBUTE(req_buf_size); 780 + UAC1_INT_ATTRIBUTE(req_count); 781 + UAC1_INT_ATTRIBUTE(audio_buf_size); 782 + 783 + #define UAC1_STR_ATTRIBUTE(name) \ 784 + static ssize_t f_uac1_opts_##name##_show(struct f_uac1_opts *opts, \ 785 + char *page) \ 786 + { \ 787 + int result; \ 788 + \ 789 + mutex_lock(&opts->lock); \ 790 + result = sprintf(page, "%s\n", opts->name); \ 791 + mutex_unlock(&opts->lock); \ 792 + \ 793 + return result; \ 794 + } \ 795 + \ 796 + static ssize_t f_uac1_opts_##name##_store(struct f_uac1_opts *opts, \ 797 + const char *page, size_t len) \ 798 + { \ 799 + int ret = -EBUSY; \ 800 + char *tmp; \ 801 + \ 802 + mutex_lock(&opts->lock); \ 803 + if (opts->refcnt) \ 804 + goto end; \ 805 + \ 806 + tmp = kstrndup(page, len, GFP_KERNEL); \ 807 + if (tmp) { \ 808 + ret = -ENOMEM; \ 809 + goto end; \ 810 + } \ 811 + if (opts->name##_alloc) \ 812 + kfree(opts->name); \ 813 + opts->name##_alloc = true; \ 814 + opts->name = tmp; \ 815 + ret = len; \ 816 + \ 817 + end: \ 818 + mutex_unlock(&opts->lock); \ 819 + return ret; \ 820 + } \ 821 + \ 822 + static struct f_uac1_opts_attribute f_uac1_opts_##name = \ 823 + __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ 824 + f_uac1_opts_##name##_show, \ 825 + f_uac1_opts_##name##_store) 826 + 827 + UAC1_STR_ATTRIBUTE(fn_play); 828 + UAC1_STR_ATTRIBUTE(fn_cap); 829 + UAC1_STR_ATTRIBUTE(fn_cntl); 830 + 831 + static struct configfs_attribute *f_uac1_attrs[] = { 832 + &f_uac1_opts_req_buf_size.attr, 833 + &f_uac1_opts_req_count.attr, 834 + &f_uac1_opts_audio_buf_size.attr, 835 + &f_uac1_opts_fn_play.attr, 836 + &f_uac1_opts_fn_cap.attr, 837 + &f_uac1_opts_fn_cntl.attr, 838 + NULL, 839 + }; 840 + 841 + static struct config_item_type f_uac1_func_type = { 842 + .ct_item_ops = &f_uac1_item_ops, 843 + .ct_attrs = f_uac1_attrs, 844 + .ct_owner = THIS_MODULE, 845 + }; 846 + 847 + static void f_audio_free_inst(struct usb_function_instance *f) 848 + { 849 + struct f_uac1_opts *opts; 850 + 851 + opts = container_of(f, struct f_uac1_opts, func_inst); 852 + gaudio_cleanup(opts->card); 853 + if (opts->fn_play_alloc) 854 + kfree(opts->fn_play); 855 + if (opts->fn_cap_alloc) 856 + kfree(opts->fn_cap); 857 + if (opts->fn_cntl_alloc) 858 + kfree(opts->fn_cntl); 859 + kfree(opts); 860 + } 861 + 862 + static struct usb_function_instance *f_audio_alloc_inst(void) 863 + { 864 + struct f_uac1_opts *opts; 865 + 866 + opts = kzalloc(sizeof(*opts), GFP_KERNEL); 867 + if (!opts) 868 + return ERR_PTR(-ENOMEM); 869 + 870 + mutex_init(&opts->lock); 871 + opts->func_inst.free_func_inst = f_audio_free_inst; 872 + 873 + config_group_init_type_name(&opts->func_inst.group, "", 874 + &f_uac1_func_type); 875 + 876 + opts->req_buf_size = UAC1_OUT_EP_MAX_PACKET_SIZE; 877 + opts->req_count = UAC1_REQ_COUNT; 878 + opts->audio_buf_size = UAC1_AUDIO_BUF_SIZE; 879 + opts->fn_play = FILE_PCM_PLAYBACK; 880 + opts->fn_cap = FILE_PCM_CAPTURE; 881 + opts->fn_cntl = FILE_CONTROL; 882 + return &opts->func_inst; 883 + } 884 + 885 + static void f_audio_free(struct usb_function *f) 886 + { 887 + struct f_audio *audio = func_to_audio(f); 888 + struct f_uac1_opts *opts; 889 + 890 + opts = container_of(f->fi, struct f_uac1_opts, func_inst); 891 + kfree(audio); 892 + mutex_lock(&opts->lock); 893 + --opts->refcnt; 894 + mutex_unlock(&opts->lock); 895 + } 896 + 897 + static void f_audio_unbind(struct usb_configuration *c, struct usb_function *f) 898 + { 899 + usb_free_all_descriptors(f); 900 + } 901 + 902 + static struct usb_function *f_audio_alloc(struct usb_function_instance *fi) 771 903 { 772 904 struct f_audio *audio; 773 - int status; 905 + struct f_uac1_opts *opts; 774 906 775 907 /* allocate and initialize one new instance */ 776 - audio = kzalloc(sizeof *audio, GFP_KERNEL); 908 + audio = kzalloc(sizeof(*audio), GFP_KERNEL); 777 909 if (!audio) 778 - return -ENOMEM; 910 + return ERR_PTR(-ENOMEM); 779 911 780 912 audio->card.func.name = "g_audio"; 781 - audio->card.gadget = c->cdev->gadget; 782 913 914 + opts = container_of(fi, struct f_uac1_opts, func_inst); 915 + mutex_lock(&opts->lock); 916 + ++opts->refcnt; 917 + mutex_unlock(&opts->lock); 783 918 INIT_LIST_HEAD(&audio->play_queue); 784 919 spin_lock_init(&audio->lock); 785 920 786 - /* set up ASLA audio devices */ 787 - status = gaudio_setup(&audio->card); 788 - if (status < 0) 789 - goto setup_fail; 790 - 791 - audio->card.func.strings = audio_strings; 792 921 audio->card.func.bind = f_audio_bind; 793 922 audio->card.func.unbind = f_audio_unbind; 794 923 audio->card.func.set_alt = f_audio_set_alt; 795 924 audio->card.func.setup = f_audio_setup; 796 925 audio->card.func.disable = f_audio_disable; 926 + audio->card.func.free_func = f_audio_free; 797 927 798 928 control_selector_init(audio); 799 929 800 930 INIT_WORK(&audio->playback_work, f_audio_playback_work); 801 931 802 - status = usb_add_function(c, &audio->card.func); 803 - if (status) 804 - goto add_fail; 805 - 806 - INFO(c->cdev, "audio_buf_size %d, req_buf_size %d, req_count %d\n", 807 - audio_buf_size, req_buf_size, req_count); 808 - 809 - return status; 810 - 811 - add_fail: 812 - gaudio_cleanup(); 813 - setup_fail: 814 - kfree(audio); 815 - return status; 932 + return &audio->card.func; 816 933 } 934 + 935 + DECLARE_USB_FUNCTION_INIT(uac1, f_audio_alloc_inst, f_audio_alloc); 936 + MODULE_LICENSE("GPL"); 937 + MODULE_AUTHOR("Bryan Wu");
+364 -158
drivers/usb/gadget/function/f_uac2.c
··· 20 20 #include <sound/pcm.h> 21 21 #include <sound/pcm_params.h> 22 22 23 - /* Playback(USB-IN) Default Stereo - Fl/Fr */ 24 - static int p_chmask = 0x3; 25 - module_param(p_chmask, uint, S_IRUGO); 26 - MODULE_PARM_DESC(p_chmask, "Playback Channel Mask"); 27 - 28 - /* Playback Default 48 KHz */ 29 - static int p_srate = 48000; 30 - module_param(p_srate, uint, S_IRUGO); 31 - MODULE_PARM_DESC(p_srate, "Playback Sampling Rate"); 32 - 33 - /* Playback Default 16bits/sample */ 34 - static int p_ssize = 2; 35 - module_param(p_ssize, uint, S_IRUGO); 36 - MODULE_PARM_DESC(p_ssize, "Playback Sample Size(bytes)"); 37 - 38 - /* Capture(USB-OUT) Default Stereo - Fl/Fr */ 39 - static int c_chmask = 0x3; 40 - module_param(c_chmask, uint, S_IRUGO); 41 - MODULE_PARM_DESC(c_chmask, "Capture Channel Mask"); 42 - 43 - /* Capture Default 64 KHz */ 44 - static int c_srate = 64000; 45 - module_param(c_srate, uint, S_IRUGO); 46 - MODULE_PARM_DESC(c_srate, "Capture Sampling Rate"); 47 - 48 - /* Capture Default 16bits/sample */ 49 - static int c_ssize = 2; 50 - module_param(c_ssize, uint, S_IRUGO); 51 - MODULE_PARM_DESC(c_ssize, "Capture Sample Size(bytes)"); 23 + #include "u_uac2.h" 52 24 53 25 /* Keep everyone on toes */ 54 26 #define USB_XFERS 2 ··· 92 120 93 121 struct snd_card *card; 94 122 struct snd_pcm *pcm; 123 + 124 + /* timekeeping for the playback endpoint */ 125 + unsigned int p_interval; 126 + unsigned int p_residue; 127 + 128 + /* pre-calculated values for playback iso completion */ 129 + unsigned int p_pktsize; 130 + unsigned int p_pktsize_residue; 131 + unsigned int p_framesize; 95 132 }; 96 133 97 134 #define BUFF_SIZE_MAX (PAGE_SIZE * 16) ··· 130 149 struct snd_uac2_chip uac2; 131 150 }; 132 151 133 - static struct audio_dev *agdev_g; 134 - 135 152 static inline 136 153 struct audio_dev *func_to_agdev(struct usb_function *f) 137 154 { ··· 146 167 struct snd_uac2_chip *pdev_to_uac2(struct platform_device *p) 147 168 { 148 169 return container_of(p, struct snd_uac2_chip, pdev); 170 + } 171 + 172 + static inline 173 + struct f_uac2_opts *agdev_to_uac2_opts(struct audio_dev *agdev) 174 + { 175 + return container_of(agdev->func.fi, struct f_uac2_opts, func_inst); 149 176 } 150 177 151 178 static inline ··· 172 187 { 173 188 unsigned pending; 174 189 unsigned long flags; 190 + unsigned int hw_ptr; 175 191 bool update_alsa = false; 176 - unsigned char *src, *dst; 177 192 int status = req->status; 178 193 struct uac2_req *ur = req->context; 179 194 struct snd_pcm_substream *substream; ··· 201 216 spin_lock_irqsave(&prm->lock, flags); 202 217 203 218 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 204 - src = prm->dma_area + prm->hw_ptr; 219 + /* 220 + * For each IN packet, take the quotient of the current data 221 + * rate and the endpoint's interval as the base packet size. 222 + * If there is a residue from this division, add it to the 223 + * residue accumulator. 224 + */ 225 + req->length = uac2->p_pktsize; 226 + uac2->p_residue += uac2->p_pktsize_residue; 227 + 228 + /* 229 + * Whenever there are more bytes in the accumulator than we 230 + * need to add one more sample frame, increase this packet's 231 + * size and decrease the accumulator. 232 + */ 233 + if (uac2->p_residue / uac2->p_interval >= uac2->p_framesize) { 234 + req->length += uac2->p_framesize; 235 + uac2->p_residue -= uac2->p_framesize * 236 + uac2->p_interval; 237 + } 238 + 205 239 req->actual = req->length; 206 - dst = req->buf; 207 - } else { 208 - dst = prm->dma_area + prm->hw_ptr; 209 - src = req->buf; 210 240 } 211 241 212 242 pending = prm->hw_ptr % prm->period_size; ··· 229 229 if (pending >= prm->period_size) 230 230 update_alsa = true; 231 231 232 + hw_ptr = prm->hw_ptr; 232 233 prm->hw_ptr = (prm->hw_ptr + req->actual) % prm->dma_bytes; 233 234 234 235 spin_unlock_irqrestore(&prm->lock, flags); 235 236 236 237 /* Pack USB load in ALSA ring buffer */ 237 - memcpy(dst, src, req->actual); 238 + pending = prm->dma_bytes - hw_ptr; 239 + 240 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 241 + if (unlikely(pending < req->actual)) { 242 + memcpy(req->buf, prm->dma_area + hw_ptr, pending); 243 + memcpy(req->buf + pending, prm->dma_area, 244 + req->actual - pending); 245 + } else { 246 + memcpy(req->buf, prm->dma_area + hw_ptr, req->actual); 247 + } 248 + } else { 249 + if (unlikely(pending < req->actual)) { 250 + memcpy(prm->dma_area + hw_ptr, req->buf, pending); 251 + memcpy(prm->dma_area, req->buf + pending, 252 + req->actual - pending); 253 + } else { 254 + memcpy(prm->dma_area + hw_ptr, req->buf, req->actual); 255 + } 256 + } 257 + 238 258 exit: 239 259 if (usb_ep_queue(ep, req, GFP_ATOMIC)) 240 260 dev_err(&uac2->pdev.dev, "%d Error!\n", __LINE__); ··· 362 342 { 363 343 struct snd_uac2_chip *uac2 = snd_pcm_substream_chip(substream); 364 344 struct snd_pcm_runtime *runtime = substream->runtime; 345 + struct audio_dev *audio_dev; 346 + struct f_uac2_opts *opts; 347 + int p_ssize, c_ssize; 348 + int p_srate, c_srate; 349 + int p_chmask, c_chmask; 350 + 351 + audio_dev = uac2_to_agdev(uac2); 352 + opts = container_of(audio_dev->func.fi, struct f_uac2_opts, func_inst); 353 + p_ssize = opts->p_ssize; 354 + c_ssize = opts->c_ssize; 355 + p_srate = opts->p_srate; 356 + c_srate = opts->c_srate; 357 + p_chmask = opts->p_chmask; 358 + c_chmask = opts->c_chmask; 359 + uac2->p_residue = 0; 365 360 366 361 runtime->hw = uac2_pcm_hardware; 367 362 ··· 446 411 struct snd_uac2_chip *uac2 = pdev_to_uac2(pdev); 447 412 struct snd_card *card; 448 413 struct snd_pcm *pcm; 414 + struct audio_dev *audio_dev; 415 + struct f_uac2_opts *opts; 449 416 int err; 417 + int p_chmask, c_chmask; 418 + 419 + audio_dev = uac2_to_agdev(uac2); 420 + opts = container_of(audio_dev->func.fi, struct f_uac2_opts, func_inst); 421 + p_chmask = opts->p_chmask; 422 + c_chmask = opts->c_chmask; 450 423 451 424 /* Choose any slot, with no id */ 452 425 err = snd_card_new(&pdev->dev, -1, NULL, THIS_MODULE, 0, &card); ··· 962 919 "%s:%d Error!\n", __func__, __LINE__); 963 920 } 964 921 965 - static int __init 922 + static int 966 923 afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) 967 924 { 968 925 struct audio_dev *agdev = func_to_agdev(fn); 969 926 struct snd_uac2_chip *uac2 = &agdev->uac2; 970 927 struct usb_composite_dev *cdev = cfg->cdev; 971 928 struct usb_gadget *gadget = cdev->gadget; 929 + struct device *dev = &uac2->pdev.dev; 972 930 struct uac2_rtd_params *prm; 931 + struct f_uac2_opts *uac2_opts; 932 + struct usb_string *us; 973 933 int ret; 934 + 935 + uac2_opts = container_of(fn->fi, struct f_uac2_opts, func_inst); 936 + 937 + us = usb_gstrings_attach(cdev, fn_strings, ARRAY_SIZE(strings_fn)); 938 + if (IS_ERR(us)) 939 + return PTR_ERR(us); 940 + iad_desc.iFunction = us[STR_ASSOC].id; 941 + std_ac_if_desc.iInterface = us[STR_IF_CTRL].id; 942 + in_clk_src_desc.iClockSource = us[STR_CLKSRC_IN].id; 943 + out_clk_src_desc.iClockSource = us[STR_CLKSRC_OUT].id; 944 + usb_out_it_desc.iTerminal = us[STR_USB_IT].id; 945 + io_in_it_desc.iTerminal = us[STR_IO_IT].id; 946 + usb_in_ot_desc.iTerminal = us[STR_USB_OT].id; 947 + io_out_ot_desc.iTerminal = us[STR_IO_OT].id; 948 + std_as_out_if0_desc.iInterface = us[STR_AS_OUT_ALT0].id; 949 + std_as_out_if1_desc.iInterface = us[STR_AS_OUT_ALT1].id; 950 + std_as_in_if0_desc.iInterface = us[STR_AS_IN_ALT0].id; 951 + std_as_in_if1_desc.iInterface = us[STR_AS_IN_ALT1].id; 952 + 953 + 954 + /* Initialize the configurable parameters */ 955 + usb_out_it_desc.bNrChannels = num_channels(uac2_opts->c_chmask); 956 + usb_out_it_desc.bmChannelConfig = cpu_to_le32(uac2_opts->c_chmask); 957 + io_in_it_desc.bNrChannels = num_channels(uac2_opts->p_chmask); 958 + io_in_it_desc.bmChannelConfig = cpu_to_le32(uac2_opts->p_chmask); 959 + as_out_hdr_desc.bNrChannels = num_channels(uac2_opts->c_chmask); 960 + as_out_hdr_desc.bmChannelConfig = cpu_to_le32(uac2_opts->c_chmask); 961 + as_in_hdr_desc.bNrChannels = num_channels(uac2_opts->p_chmask); 962 + as_in_hdr_desc.bmChannelConfig = cpu_to_le32(uac2_opts->p_chmask); 963 + as_out_fmt1_desc.bSubslotSize = uac2_opts->c_ssize; 964 + as_out_fmt1_desc.bBitResolution = uac2_opts->c_ssize * 8; 965 + as_in_fmt1_desc.bSubslotSize = uac2_opts->p_ssize; 966 + as_in_fmt1_desc.bBitResolution = uac2_opts->p_ssize * 8; 967 + 968 + snprintf(clksrc_in, sizeof(clksrc_in), "%uHz", uac2_opts->p_srate); 969 + snprintf(clksrc_out, sizeof(clksrc_out), "%uHz", uac2_opts->c_srate); 974 970 975 971 ret = usb_interface_id(cfg, fn); 976 972 if (ret < 0) { 977 - dev_err(&uac2->pdev.dev, 978 - "%s:%d Error!\n", __func__, __LINE__); 973 + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 979 974 return ret; 980 975 } 981 976 std_ac_if_desc.bInterfaceNumber = ret; ··· 1022 941 1023 942 ret = usb_interface_id(cfg, fn); 1024 943 if (ret < 0) { 1025 - dev_err(&uac2->pdev.dev, 1026 - "%s:%d Error!\n", __func__, __LINE__); 944 + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 1027 945 return ret; 1028 946 } 1029 947 std_as_out_if0_desc.bInterfaceNumber = ret; ··· 1032 952 1033 953 ret = usb_interface_id(cfg, fn); 1034 954 if (ret < 0) { 1035 - dev_err(&uac2->pdev.dev, 1036 - "%s:%d Error!\n", __func__, __LINE__); 955 + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 1037 956 return ret; 1038 957 } 1039 958 std_as_in_if0_desc.bInterfaceNumber = ret; ··· 1042 963 1043 964 agdev->out_ep = usb_ep_autoconfig(gadget, &fs_epout_desc); 1044 965 if (!agdev->out_ep) { 1045 - dev_err(&uac2->pdev.dev, 1046 - "%s:%d Error!\n", __func__, __LINE__); 966 + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 1047 967 goto err; 1048 968 } 1049 969 agdev->out_ep->driver_data = agdev; 1050 970 1051 971 agdev->in_ep = usb_ep_autoconfig(gadget, &fs_epin_desc); 1052 972 if (!agdev->in_ep) { 1053 - dev_err(&uac2->pdev.dev, 1054 - "%s:%d Error!\n", __func__, __LINE__); 973 + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 1055 974 goto err; 1056 975 } 1057 976 agdev->in_ep->driver_data = agdev; ··· 1097 1020 return -EINVAL; 1098 1021 } 1099 1022 1100 - static void 1101 - afunc_unbind(struct usb_configuration *cfg, struct usb_function *fn) 1102 - { 1103 - struct audio_dev *agdev = func_to_agdev(fn); 1104 - struct uac2_rtd_params *prm; 1105 - 1106 - alsa_uac2_exit(agdev); 1107 - 1108 - prm = &agdev->uac2.p_prm; 1109 - kfree(prm->rbuf); 1110 - 1111 - prm = &agdev->uac2.c_prm; 1112 - kfree(prm->rbuf); 1113 - usb_free_all_descriptors(fn); 1114 - 1115 - if (agdev->in_ep) 1116 - agdev->in_ep->driver_data = NULL; 1117 - if (agdev->out_ep) 1118 - agdev->out_ep->driver_data = NULL; 1119 - } 1120 - 1121 1023 static int 1122 1024 afunc_set_alt(struct usb_function *fn, unsigned intf, unsigned alt) 1123 1025 { ··· 1104 1048 struct audio_dev *agdev = func_to_agdev(fn); 1105 1049 struct snd_uac2_chip *uac2 = &agdev->uac2; 1106 1050 struct usb_gadget *gadget = cdev->gadget; 1051 + struct device *dev = &uac2->pdev.dev; 1107 1052 struct usb_request *req; 1108 1053 struct usb_ep *ep; 1109 1054 struct uac2_rtd_params *prm; 1110 - int i; 1055 + int req_len, i; 1111 1056 1112 1057 /* No i/f has more than 2 alt settings */ 1113 1058 if (alt > 1) { 1114 - dev_err(&uac2->pdev.dev, 1115 - "%s:%d Error!\n", __func__, __LINE__); 1059 + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 1116 1060 return -EINVAL; 1117 1061 } 1118 1062 1119 1063 if (intf == agdev->ac_intf) { 1120 1064 /* Control I/f has only 1 AltSetting - 0 */ 1121 1065 if (alt) { 1122 - dev_err(&uac2->pdev.dev, 1123 - "%s:%d Error!\n", __func__, __LINE__); 1066 + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 1124 1067 return -EINVAL; 1125 1068 } 1126 1069 return 0; ··· 1130 1075 prm = &uac2->c_prm; 1131 1076 config_ep_by_speed(gadget, fn, ep); 1132 1077 agdev->as_out_alt = alt; 1078 + req_len = prm->max_psize; 1133 1079 } else if (intf == agdev->as_in_intf) { 1080 + struct f_uac2_opts *opts = agdev_to_uac2_opts(agdev); 1081 + unsigned int factor, rate; 1082 + struct usb_endpoint_descriptor *ep_desc; 1083 + 1134 1084 ep = agdev->in_ep; 1135 1085 prm = &uac2->p_prm; 1136 1086 config_ep_by_speed(gadget, fn, ep); 1137 1087 agdev->as_in_alt = alt; 1088 + 1089 + /* pre-calculate the playback endpoint's interval */ 1090 + if (gadget->speed == USB_SPEED_FULL) { 1091 + ep_desc = &fs_epin_desc; 1092 + factor = 1000; 1093 + } else { 1094 + ep_desc = &hs_epin_desc; 1095 + factor = 125; 1096 + } 1097 + 1098 + /* pre-compute some values for iso_complete() */ 1099 + uac2->p_framesize = opts->p_ssize * 1100 + num_channels(opts->p_chmask); 1101 + rate = opts->p_srate * uac2->p_framesize; 1102 + uac2->p_interval = (1 << (ep_desc->bInterval - 1)) * factor; 1103 + uac2->p_pktsize = min_t(unsigned int, rate / uac2->p_interval, 1104 + prm->max_psize); 1105 + 1106 + if (uac2->p_pktsize < prm->max_psize) 1107 + uac2->p_pktsize_residue = rate % uac2->p_interval; 1108 + else 1109 + uac2->p_pktsize_residue = 0; 1110 + 1111 + req_len = uac2->p_pktsize; 1112 + uac2->p_residue = 0; 1138 1113 } else { 1139 - dev_err(&uac2->pdev.dev, 1140 - "%s:%d Error!\n", __func__, __LINE__); 1114 + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 1141 1115 return -EINVAL; 1142 1116 } 1143 1117 ··· 1179 1095 usb_ep_enable(ep); 1180 1096 1181 1097 for (i = 0; i < USB_XFERS; i++) { 1182 - if (prm->ureq[i].req) { 1183 - if (usb_ep_queue(ep, prm->ureq[i].req, GFP_ATOMIC)) 1184 - dev_err(&uac2->pdev.dev, "%d Error!\n", 1185 - __LINE__); 1186 - continue; 1098 + if (!prm->ureq[i].req) { 1099 + req = usb_ep_alloc_request(ep, GFP_ATOMIC); 1100 + if (req == NULL) 1101 + return -ENOMEM; 1102 + 1103 + prm->ureq[i].req = req; 1104 + prm->ureq[i].pp = prm; 1105 + 1106 + req->zero = 0; 1107 + req->context = &prm->ureq[i]; 1108 + req->length = req_len; 1109 + req->complete = agdev_iso_complete; 1110 + req->buf = prm->rbuf + i * prm->max_psize; 1187 1111 } 1188 1112 1189 - req = usb_ep_alloc_request(ep, GFP_ATOMIC); 1190 - if (req == NULL) { 1191 - dev_err(&uac2->pdev.dev, 1192 - "%s:%d Error!\n", __func__, __LINE__); 1193 - return -EINVAL; 1194 - } 1195 - 1196 - prm->ureq[i].req = req; 1197 - prm->ureq[i].pp = prm; 1198 - 1199 - req->zero = 0; 1200 - req->context = &prm->ureq[i]; 1201 - req->length = prm->max_psize; 1202 - req->complete = agdev_iso_complete; 1203 - req->buf = prm->rbuf + i * req->length; 1204 - 1205 - if (usb_ep_queue(ep, req, GFP_ATOMIC)) 1206 - dev_err(&uac2->pdev.dev, "%d Error!\n", __LINE__); 1113 + if (usb_ep_queue(ep, prm->ureq[i].req, GFP_ATOMIC)) 1114 + dev_err(dev, "%s:%d Error!\n", __func__, __LINE__); 1207 1115 } 1208 1116 1209 1117 return 0; ··· 1240 1164 struct usb_request *req = fn->config->cdev->req; 1241 1165 struct audio_dev *agdev = func_to_agdev(fn); 1242 1166 struct snd_uac2_chip *uac2 = &agdev->uac2; 1167 + struct f_uac2_opts *opts; 1243 1168 u16 w_length = le16_to_cpu(cr->wLength); 1244 1169 u16 w_index = le16_to_cpu(cr->wIndex); 1245 1170 u16 w_value = le16_to_cpu(cr->wValue); 1246 1171 u8 entity_id = (w_index >> 8) & 0xff; 1247 1172 u8 control_selector = w_value >> 8; 1248 1173 int value = -EOPNOTSUPP; 1174 + int p_srate, c_srate; 1175 + 1176 + opts = agdev_to_uac2_opts(agdev); 1177 + p_srate = opts->p_srate; 1178 + c_srate = opts->c_srate; 1249 1179 1250 1180 if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) { 1251 1181 struct cntrl_cur_lay3 c; ··· 1281 1199 struct usb_request *req = fn->config->cdev->req; 1282 1200 struct audio_dev *agdev = func_to_agdev(fn); 1283 1201 struct snd_uac2_chip *uac2 = &agdev->uac2; 1202 + struct f_uac2_opts *opts; 1284 1203 u16 w_length = le16_to_cpu(cr->wLength); 1285 1204 u16 w_index = le16_to_cpu(cr->wIndex); 1286 1205 u16 w_value = le16_to_cpu(cr->wValue); ··· 1289 1206 u8 control_selector = w_value >> 8; 1290 1207 struct cntrl_range_lay3 r; 1291 1208 int value = -EOPNOTSUPP; 1209 + int p_srate, c_srate; 1210 + 1211 + opts = agdev_to_uac2_opts(agdev); 1212 + p_srate = opts->p_srate; 1213 + c_srate = opts->c_srate; 1292 1214 1293 1215 if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) { 1294 1216 if (entity_id == USB_IN_CLK_ID) ··· 1397 1309 return value; 1398 1310 } 1399 1311 1400 - static int audio_bind_config(struct usb_configuration *cfg) 1312 + static inline struct f_uac2_opts *to_f_uac2_opts(struct config_item *item) 1401 1313 { 1402 - int res; 1403 - 1404 - agdev_g = kzalloc(sizeof *agdev_g, GFP_KERNEL); 1405 - if (agdev_g == NULL) 1406 - return -ENOMEM; 1407 - 1408 - res = usb_string_ids_tab(cfg->cdev, strings_fn); 1409 - if (res) 1410 - return res; 1411 - iad_desc.iFunction = strings_fn[STR_ASSOC].id; 1412 - std_ac_if_desc.iInterface = strings_fn[STR_IF_CTRL].id; 1413 - in_clk_src_desc.iClockSource = strings_fn[STR_CLKSRC_IN].id; 1414 - out_clk_src_desc.iClockSource = strings_fn[STR_CLKSRC_OUT].id; 1415 - usb_out_it_desc.iTerminal = strings_fn[STR_USB_IT].id; 1416 - io_in_it_desc.iTerminal = strings_fn[STR_IO_IT].id; 1417 - usb_in_ot_desc.iTerminal = strings_fn[STR_USB_OT].id; 1418 - io_out_ot_desc.iTerminal = strings_fn[STR_IO_OT].id; 1419 - std_as_out_if0_desc.iInterface = strings_fn[STR_AS_OUT_ALT0].id; 1420 - std_as_out_if1_desc.iInterface = strings_fn[STR_AS_OUT_ALT1].id; 1421 - std_as_in_if0_desc.iInterface = strings_fn[STR_AS_IN_ALT0].id; 1422 - std_as_in_if1_desc.iInterface = strings_fn[STR_AS_IN_ALT1].id; 1423 - 1424 - agdev_g->func.name = "uac2_func"; 1425 - agdev_g->func.strings = fn_strings; 1426 - agdev_g->func.bind = afunc_bind; 1427 - agdev_g->func.unbind = afunc_unbind; 1428 - agdev_g->func.set_alt = afunc_set_alt; 1429 - agdev_g->func.get_alt = afunc_get_alt; 1430 - agdev_g->func.disable = afunc_disable; 1431 - agdev_g->func.setup = afunc_setup; 1432 - 1433 - /* Initialize the configurable parameters */ 1434 - usb_out_it_desc.bNrChannels = num_channels(c_chmask); 1435 - usb_out_it_desc.bmChannelConfig = cpu_to_le32(c_chmask); 1436 - io_in_it_desc.bNrChannels = num_channels(p_chmask); 1437 - io_in_it_desc.bmChannelConfig = cpu_to_le32(p_chmask); 1438 - as_out_hdr_desc.bNrChannels = num_channels(c_chmask); 1439 - as_out_hdr_desc.bmChannelConfig = cpu_to_le32(c_chmask); 1440 - as_in_hdr_desc.bNrChannels = num_channels(p_chmask); 1441 - as_in_hdr_desc.bmChannelConfig = cpu_to_le32(p_chmask); 1442 - as_out_fmt1_desc.bSubslotSize = c_ssize; 1443 - as_out_fmt1_desc.bBitResolution = c_ssize * 8; 1444 - as_in_fmt1_desc.bSubslotSize = p_ssize; 1445 - as_in_fmt1_desc.bBitResolution = p_ssize * 8; 1446 - 1447 - snprintf(clksrc_in, sizeof(clksrc_in), "%uHz", p_srate); 1448 - snprintf(clksrc_out, sizeof(clksrc_out), "%uHz", c_srate); 1449 - 1450 - res = usb_add_function(cfg, &agdev_g->func); 1451 - if (res < 0) 1452 - kfree(agdev_g); 1453 - 1454 - return res; 1314 + return container_of(to_config_group(item), struct f_uac2_opts, 1315 + func_inst.group); 1455 1316 } 1456 1317 1457 - static void 1458 - uac2_unbind_config(struct usb_configuration *cfg) 1318 + CONFIGFS_ATTR_STRUCT(f_uac2_opts); 1319 + CONFIGFS_ATTR_OPS(f_uac2_opts); 1320 + 1321 + static void f_uac2_attr_release(struct config_item *item) 1459 1322 { 1460 - kfree(agdev_g); 1461 - agdev_g = NULL; 1323 + struct f_uac2_opts *opts = to_f_uac2_opts(item); 1324 + 1325 + usb_put_function_instance(&opts->func_inst); 1462 1326 } 1327 + 1328 + static struct configfs_item_operations f_uac2_item_ops = { 1329 + .release = f_uac2_attr_release, 1330 + .show_attribute = f_uac2_opts_attr_show, 1331 + .store_attribute = f_uac2_opts_attr_store, 1332 + }; 1333 + 1334 + #define UAC2_ATTRIBUTE(name) \ 1335 + static ssize_t f_uac2_opts_##name##_show(struct f_uac2_opts *opts, \ 1336 + char *page) \ 1337 + { \ 1338 + int result; \ 1339 + \ 1340 + mutex_lock(&opts->lock); \ 1341 + result = sprintf(page, "%u\n", opts->name); \ 1342 + mutex_unlock(&opts->lock); \ 1343 + \ 1344 + return result; \ 1345 + } \ 1346 + \ 1347 + static ssize_t f_uac2_opts_##name##_store(struct f_uac2_opts *opts, \ 1348 + const char *page, size_t len) \ 1349 + { \ 1350 + int ret; \ 1351 + u32 num; \ 1352 + \ 1353 + mutex_lock(&opts->lock); \ 1354 + if (opts->refcnt) { \ 1355 + ret = -EBUSY; \ 1356 + goto end; \ 1357 + } \ 1358 + \ 1359 + ret = kstrtou32(page, 0, &num); \ 1360 + if (ret) \ 1361 + goto end; \ 1362 + \ 1363 + opts->name = num; \ 1364 + ret = len; \ 1365 + \ 1366 + end: \ 1367 + mutex_unlock(&opts->lock); \ 1368 + return ret; \ 1369 + } \ 1370 + \ 1371 + static struct f_uac2_opts_attribute f_uac2_opts_##name = \ 1372 + __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \ 1373 + f_uac2_opts_##name##_show, \ 1374 + f_uac2_opts_##name##_store) 1375 + 1376 + UAC2_ATTRIBUTE(p_chmask); 1377 + UAC2_ATTRIBUTE(p_srate); 1378 + UAC2_ATTRIBUTE(p_ssize); 1379 + UAC2_ATTRIBUTE(c_chmask); 1380 + UAC2_ATTRIBUTE(c_srate); 1381 + UAC2_ATTRIBUTE(c_ssize); 1382 + 1383 + static struct configfs_attribute *f_uac2_attrs[] = { 1384 + &f_uac2_opts_p_chmask.attr, 1385 + &f_uac2_opts_p_srate.attr, 1386 + &f_uac2_opts_p_ssize.attr, 1387 + &f_uac2_opts_c_chmask.attr, 1388 + &f_uac2_opts_c_srate.attr, 1389 + &f_uac2_opts_c_ssize.attr, 1390 + NULL, 1391 + }; 1392 + 1393 + static struct config_item_type f_uac2_func_type = { 1394 + .ct_item_ops = &f_uac2_item_ops, 1395 + .ct_attrs = f_uac2_attrs, 1396 + .ct_owner = THIS_MODULE, 1397 + }; 1398 + 1399 + static void afunc_free_inst(struct usb_function_instance *f) 1400 + { 1401 + struct f_uac2_opts *opts; 1402 + 1403 + opts = container_of(f, struct f_uac2_opts, func_inst); 1404 + kfree(opts); 1405 + } 1406 + 1407 + static struct usb_function_instance *afunc_alloc_inst(void) 1408 + { 1409 + struct f_uac2_opts *opts; 1410 + 1411 + opts = kzalloc(sizeof(*opts), GFP_KERNEL); 1412 + if (!opts) 1413 + return ERR_PTR(-ENOMEM); 1414 + 1415 + mutex_init(&opts->lock); 1416 + opts->func_inst.free_func_inst = afunc_free_inst; 1417 + 1418 + config_group_init_type_name(&opts->func_inst.group, "", 1419 + &f_uac2_func_type); 1420 + 1421 + opts->p_chmask = UAC2_DEF_PCHMASK; 1422 + opts->p_srate = UAC2_DEF_PSRATE; 1423 + opts->p_ssize = UAC2_DEF_PSSIZE; 1424 + opts->c_chmask = UAC2_DEF_CCHMASK; 1425 + opts->c_srate = UAC2_DEF_CSRATE; 1426 + opts->c_ssize = UAC2_DEF_CSSIZE; 1427 + return &opts->func_inst; 1428 + } 1429 + 1430 + static void afunc_free(struct usb_function *f) 1431 + { 1432 + struct audio_dev *agdev; 1433 + struct f_uac2_opts *opts; 1434 + 1435 + agdev = func_to_agdev(f); 1436 + opts = container_of(f->fi, struct f_uac2_opts, func_inst); 1437 + kfree(agdev); 1438 + mutex_lock(&opts->lock); 1439 + --opts->refcnt; 1440 + mutex_unlock(&opts->lock); 1441 + } 1442 + 1443 + static void afunc_unbind(struct usb_configuration *c, struct usb_function *f) 1444 + { 1445 + struct audio_dev *agdev = func_to_agdev(f); 1446 + struct uac2_rtd_params *prm; 1447 + 1448 + alsa_uac2_exit(agdev); 1449 + 1450 + prm = &agdev->uac2.p_prm; 1451 + kfree(prm->rbuf); 1452 + 1453 + prm = &agdev->uac2.c_prm; 1454 + kfree(prm->rbuf); 1455 + usb_free_all_descriptors(f); 1456 + 1457 + if (agdev->in_ep) 1458 + agdev->in_ep->driver_data = NULL; 1459 + if (agdev->out_ep) 1460 + agdev->out_ep->driver_data = NULL; 1461 + } 1462 + 1463 + struct usb_function *afunc_alloc(struct usb_function_instance *fi) 1464 + { 1465 + struct audio_dev *agdev; 1466 + struct f_uac2_opts *opts; 1467 + 1468 + agdev = kzalloc(sizeof(*agdev), GFP_KERNEL); 1469 + if (agdev == NULL) 1470 + return ERR_PTR(-ENOMEM); 1471 + 1472 + opts = container_of(fi, struct f_uac2_opts, func_inst); 1473 + mutex_lock(&opts->lock); 1474 + ++opts->refcnt; 1475 + mutex_unlock(&opts->lock); 1476 + 1477 + agdev->func.name = "uac2_func"; 1478 + agdev->func.bind = afunc_bind; 1479 + agdev->func.unbind = afunc_unbind; 1480 + agdev->func.set_alt = afunc_set_alt; 1481 + agdev->func.get_alt = afunc_get_alt; 1482 + agdev->func.disable = afunc_disable; 1483 + agdev->func.setup = afunc_setup; 1484 + agdev->func.free_func = afunc_free; 1485 + 1486 + return &agdev->func; 1487 + } 1488 + 1489 + DECLARE_USB_FUNCTION_INIT(uac2, afunc_alloc_inst, afunc_alloc); 1490 + MODULE_LICENSE("GPL"); 1491 + MODULE_AUTHOR("Yadwinder Singh"); 1492 + MODULE_AUTHOR("Jaswinder Singh");
+127 -153
drivers/usb/gadget/function/f_uvc.c
··· 11 11 */ 12 12 13 13 #include <linux/kernel.h> 14 + #include <linux/module.h> 14 15 #include <linux/device.h> 15 16 #include <linux/errno.h> 16 17 #include <linux/fs.h> ··· 28 27 #include <media/v4l2-event.h> 29 28 30 29 #include "uvc.h" 30 + #include "uvc_v4l2.h" 31 + #include "uvc_video.h" 32 + #include "u_uvc.h" 31 33 32 34 unsigned int uvc_gadget_trace_param; 33 - 34 - /*-------------------------------------------------------------------------*/ 35 - 36 - /* module parameters specific to the Video streaming endpoint */ 37 - static unsigned int streaming_interval = 1; 38 - module_param(streaming_interval, uint, S_IRUGO|S_IWUSR); 39 - MODULE_PARM_DESC(streaming_interval, "1 - 16"); 40 - 41 - static unsigned int streaming_maxpacket = 1024; 42 - module_param(streaming_maxpacket, uint, S_IRUGO|S_IWUSR); 43 - MODULE_PARM_DESC(streaming_maxpacket, "1 - 1023 (FS), 1 - 3072 (hs/ss)"); 44 - 45 - static unsigned int streaming_maxburst; 46 - module_param(streaming_maxburst, uint, S_IRUGO|S_IWUSR); 47 - MODULE_PARM_DESC(streaming_maxburst, "0 - 15 (ss only)"); 48 35 49 36 /* -------------------------------------------------------------------------- 50 37 * Function descriptors ··· 64 75 65 76 #define UVC_STATUS_MAX_PACKET_SIZE 16 /* 16 bytes status */ 66 77 67 - static struct usb_interface_assoc_descriptor uvc_iad __initdata = { 78 + static struct usb_interface_assoc_descriptor uvc_iad = { 68 79 .bLength = sizeof(uvc_iad), 69 80 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, 70 81 .bFirstInterface = 0, ··· 75 86 .iFunction = 0, 76 87 }; 77 88 78 - static struct usb_interface_descriptor uvc_control_intf __initdata = { 89 + static struct usb_interface_descriptor uvc_control_intf = { 79 90 .bLength = USB_DT_INTERFACE_SIZE, 80 91 .bDescriptorType = USB_DT_INTERFACE, 81 92 .bInterfaceNumber = UVC_INTF_VIDEO_CONTROL, ··· 87 98 .iInterface = 0, 88 99 }; 89 100 90 - static struct usb_endpoint_descriptor uvc_control_ep __initdata = { 101 + static struct usb_endpoint_descriptor uvc_control_ep = { 91 102 .bLength = USB_DT_ENDPOINT_SIZE, 92 103 .bDescriptorType = USB_DT_ENDPOINT, 93 104 .bEndpointAddress = USB_DIR_IN, ··· 96 107 .bInterval = 8, 97 108 }; 98 109 99 - static struct usb_ss_ep_comp_descriptor uvc_ss_control_comp __initdata = { 110 + static struct usb_ss_ep_comp_descriptor uvc_ss_control_comp = { 100 111 .bLength = sizeof(uvc_ss_control_comp), 101 112 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 102 113 /* The following 3 values can be tweaked if necessary. */ ··· 105 116 .wBytesPerInterval = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE), 106 117 }; 107 118 108 - static struct uvc_control_endpoint_descriptor uvc_control_cs_ep __initdata = { 119 + static struct uvc_control_endpoint_descriptor uvc_control_cs_ep = { 109 120 .bLength = UVC_DT_CONTROL_ENDPOINT_SIZE, 110 121 .bDescriptorType = USB_DT_CS_ENDPOINT, 111 122 .bDescriptorSubType = UVC_EP_INTERRUPT, 112 123 .wMaxTransferSize = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE), 113 124 }; 114 125 115 - static struct usb_interface_descriptor uvc_streaming_intf_alt0 __initdata = { 126 + static struct usb_interface_descriptor uvc_streaming_intf_alt0 = { 116 127 .bLength = USB_DT_INTERFACE_SIZE, 117 128 .bDescriptorType = USB_DT_INTERFACE, 118 129 .bInterfaceNumber = UVC_INTF_VIDEO_STREAMING, ··· 124 135 .iInterface = 0, 125 136 }; 126 137 127 - static struct usb_interface_descriptor uvc_streaming_intf_alt1 __initdata = { 138 + static struct usb_interface_descriptor uvc_streaming_intf_alt1 = { 128 139 .bLength = USB_DT_INTERFACE_SIZE, 129 140 .bDescriptorType = USB_DT_INTERFACE, 130 141 .bInterfaceNumber = UVC_INTF_VIDEO_STREAMING, ··· 136 147 .iInterface = 0, 137 148 }; 138 149 139 - static struct usb_endpoint_descriptor uvc_fs_streaming_ep __initdata = { 150 + static struct usb_endpoint_descriptor uvc_fs_streaming_ep = { 140 151 .bLength = USB_DT_ENDPOINT_SIZE, 141 152 .bDescriptorType = USB_DT_ENDPOINT, 142 153 .bEndpointAddress = USB_DIR_IN, ··· 147 158 */ 148 159 }; 149 160 150 - static struct usb_endpoint_descriptor uvc_hs_streaming_ep __initdata = { 161 + static struct usb_endpoint_descriptor uvc_hs_streaming_ep = { 151 162 .bLength = USB_DT_ENDPOINT_SIZE, 152 163 .bDescriptorType = USB_DT_ENDPOINT, 153 164 .bEndpointAddress = USB_DIR_IN, ··· 158 169 */ 159 170 }; 160 171 161 - static struct usb_endpoint_descriptor uvc_ss_streaming_ep __initdata = { 172 + static struct usb_endpoint_descriptor uvc_ss_streaming_ep = { 162 173 .bLength = USB_DT_ENDPOINT_SIZE, 163 174 .bDescriptorType = USB_DT_ENDPOINT, 164 175 ··· 170 181 */ 171 182 }; 172 183 173 - static struct usb_ss_ep_comp_descriptor uvc_ss_streaming_comp __initdata = { 184 + static struct usb_ss_ep_comp_descriptor uvc_ss_streaming_comp = { 174 185 .bLength = sizeof(uvc_ss_streaming_comp), 175 186 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 176 187 /* The bMaxBurst, bmAttributes and wBytesPerInterval values will be ··· 196 207 (struct usb_descriptor_header *) &uvc_ss_streaming_comp, 197 208 NULL, 198 209 }; 210 + 211 + void uvc_set_trace_param(unsigned int trace) 212 + { 213 + uvc_gadget_trace_param = trace; 214 + } 215 + EXPORT_SYMBOL(uvc_set_trace_param); 199 216 200 217 /* -------------------------------------------------------------------------- 201 218 * Control requests ··· 245 250 /* Stall too big requests. */ 246 251 if (le16_to_cpu(ctrl->wLength) > UVC_MAX_REQUEST_SIZE) 247 252 return -EINVAL; 253 + 254 + /* Tell the complete callback to generate an event for the next request 255 + * that will be enqueued by UVCIOC_SEND_RESPONSE. 256 + */ 257 + uvc->event_setup_out = !(ctrl->bRequestType & USB_DIR_IN); 258 + uvc->event_length = le16_to_cpu(ctrl->wLength); 248 259 249 260 memset(&v4l2_event, 0, sizeof(v4l2_event)); 250 261 v4l2_event.type = UVC_EVENT_SETUP; ··· 409 408 410 409 video->v4l2_dev = &uvc->v4l2_dev; 411 410 video->fops = &uvc_v4l2_fops; 411 + video->ioctl_ops = &uvc_v4l2_ioctl_ops; 412 412 video->release = video_device_release; 413 + video->vfl_dir = VFL_DIR_TX; 413 414 strlcpy(video->name, cdev->gadget->name, sizeof(video->name)); 414 415 415 416 uvc->vdev = video; ··· 437 434 } \ 438 435 } while (0) 439 436 440 - static struct usb_descriptor_header ** __init 437 + static struct usb_descriptor_header ** 441 438 uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed) 442 439 { 443 440 struct uvc_input_header_descriptor *uvc_streaming_header; ··· 557 554 return hdr; 558 555 } 559 556 560 - static void 561 - uvc_function_unbind(struct usb_configuration *c, struct usb_function *f) 562 - { 563 - struct usb_composite_dev *cdev = c->cdev; 564 - struct uvc_device *uvc = to_uvc(f); 565 - 566 - INFO(cdev, "uvc_function_unbind\n"); 567 - 568 - video_unregister_device(uvc->vdev); 569 - v4l2_device_unregister(&uvc->v4l2_dev); 570 - uvc->control_ep->driver_data = NULL; 571 - uvc->video.ep->driver_data = NULL; 572 - 573 - uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id = 0; 574 - usb_ep_free_request(cdev->gadget->ep0, uvc->control_req); 575 - kfree(uvc->control_buf); 576 - 577 - usb_free_all_descriptors(f); 578 - 579 - kfree(uvc); 580 - } 581 - 582 - static int __init 557 + static int 583 558 uvc_function_bind(struct usb_configuration *c, struct usb_function *f) 584 559 { 585 560 struct usb_composite_dev *cdev = c->cdev; 586 561 struct uvc_device *uvc = to_uvc(f); 562 + struct usb_string *us; 587 563 unsigned int max_packet_mult; 588 564 unsigned int max_packet_size; 589 565 struct usb_ep *ep; 566 + struct f_uvc_opts *opts; 590 567 int ret = -EINVAL; 591 568 592 569 INFO(cdev, "uvc_function_bind\n"); 593 570 571 + opts = to_f_uvc_opts(f->fi); 594 572 /* Sanity check the streaming endpoint module parameters. 595 573 */ 596 - streaming_interval = clamp(streaming_interval, 1U, 16U); 597 - streaming_maxpacket = clamp(streaming_maxpacket, 1U, 3072U); 598 - streaming_maxburst = min(streaming_maxburst, 15U); 574 + opts->streaming_interval = clamp(opts->streaming_interval, 1U, 16U); 575 + opts->streaming_maxpacket = clamp(opts->streaming_maxpacket, 1U, 3072U); 576 + opts->streaming_maxburst = min(opts->streaming_maxburst, 15U); 599 577 600 578 /* Fill in the FS/HS/SS Video Streaming specific descriptors from the 601 579 * module parameters. ··· 584 600 * NOTE: We assume that the user knows what they are doing and won't 585 601 * give parameters that their UDC doesn't support. 586 602 */ 587 - if (streaming_maxpacket <= 1024) { 603 + if (opts->streaming_maxpacket <= 1024) { 588 604 max_packet_mult = 1; 589 - max_packet_size = streaming_maxpacket; 590 - } else if (streaming_maxpacket <= 2048) { 605 + max_packet_size = opts->streaming_maxpacket; 606 + } else if (opts->streaming_maxpacket <= 2048) { 591 607 max_packet_mult = 2; 592 - max_packet_size = streaming_maxpacket / 2; 608 + max_packet_size = opts->streaming_maxpacket / 2; 593 609 } else { 594 610 max_packet_mult = 3; 595 - max_packet_size = streaming_maxpacket / 3; 611 + max_packet_size = opts->streaming_maxpacket / 3; 596 612 } 597 613 598 - uvc_fs_streaming_ep.wMaxPacketSize = min(streaming_maxpacket, 1023U); 599 - uvc_fs_streaming_ep.bInterval = streaming_interval; 614 + uvc_fs_streaming_ep.wMaxPacketSize = 615 + cpu_to_le16(min(opts->streaming_maxpacket, 1023U)); 616 + uvc_fs_streaming_ep.bInterval = opts->streaming_interval; 600 617 601 - uvc_hs_streaming_ep.wMaxPacketSize = max_packet_size; 602 - uvc_hs_streaming_ep.wMaxPacketSize |= ((max_packet_mult - 1) << 11); 603 - uvc_hs_streaming_ep.bInterval = streaming_interval; 618 + uvc_hs_streaming_ep.wMaxPacketSize = 619 + cpu_to_le16(max_packet_size | ((max_packet_mult - 1) << 11)); 620 + uvc_hs_streaming_ep.bInterval = opts->streaming_interval; 604 621 605 - uvc_ss_streaming_ep.wMaxPacketSize = max_packet_size; 606 - uvc_ss_streaming_ep.bInterval = streaming_interval; 622 + uvc_ss_streaming_ep.wMaxPacketSize = cpu_to_le16(max_packet_size); 623 + uvc_ss_streaming_ep.bInterval = opts->streaming_interval; 607 624 uvc_ss_streaming_comp.bmAttributes = max_packet_mult - 1; 608 - uvc_ss_streaming_comp.bMaxBurst = streaming_maxburst; 625 + uvc_ss_streaming_comp.bMaxBurst = opts->streaming_maxburst; 609 626 uvc_ss_streaming_comp.wBytesPerInterval = 610 - max_packet_size * max_packet_mult * streaming_maxburst; 627 + cpu_to_le16(max_packet_size * max_packet_mult * 628 + opts->streaming_maxburst); 611 629 612 630 /* Allocate endpoints. */ 613 631 ep = usb_ep_autoconfig(cdev->gadget, &uvc_control_ep); ··· 638 652 uvc_fs_streaming_ep.bEndpointAddress = uvc->video.ep->address; 639 653 uvc_hs_streaming_ep.bEndpointAddress = uvc->video.ep->address; 640 654 uvc_ss_streaming_ep.bEndpointAddress = uvc->video.ep->address; 655 + 656 + us = usb_gstrings_attach(cdev, uvc_function_strings, 657 + ARRAY_SIZE(uvc_en_us_strings)); 658 + if (IS_ERR(us)) { 659 + ret = PTR_ERR(us); 660 + goto error; 661 + } 662 + uvc_iad.iFunction = us[UVC_STRING_CONTROL_IDX].id; 663 + uvc_control_intf.iInterface = us[UVC_STRING_CONTROL_IDX].id; 664 + ret = us[UVC_STRING_STREAMING_IDX].id; 665 + uvc_streaming_intf_alt0.iInterface = ret; 666 + uvc_streaming_intf_alt1.iInterface = ret; 641 667 642 668 /* Allocate interface IDs. */ 643 669 if ((ret = usb_interface_id(c, f)) < 0) ··· 695 697 } 696 698 697 699 /* Initialise video. */ 698 - ret = uvc_video_init(&uvc->video); 700 + ret = uvcg_video_init(&uvc->video); 699 701 if (ret < 0) 700 702 goto error; 701 703 ··· 718 720 if (uvc->video.ep) 719 721 uvc->video.ep->driver_data = NULL; 720 722 721 - if (uvc->control_req) { 723 + if (uvc->control_req) 722 724 usb_ep_free_request(cdev->gadget->ep0, uvc->control_req); 723 - kfree(uvc->control_buf); 724 - } 725 + kfree(uvc->control_buf); 725 726 726 727 usb_free_all_descriptors(f); 727 728 return ret; ··· 730 733 * USB gadget function 731 734 */ 732 735 733 - /** 734 - * uvc_bind_config - add a UVC function to a configuration 735 - * @c: the configuration to support the UVC instance 736 - * Context: single threaded during gadget setup 737 - * 738 - * Returns zero on success, else negative errno. 739 - * 740 - * Caller must have called @uvc_setup(). Caller is also responsible for 741 - * calling @uvc_cleanup() before module unload. 742 - */ 743 - int __init 744 - uvc_bind_config(struct usb_configuration *c, 745 - const struct uvc_descriptor_header * const *fs_control, 746 - const struct uvc_descriptor_header * const *ss_control, 747 - const struct uvc_descriptor_header * const *fs_streaming, 748 - const struct uvc_descriptor_header * const *hs_streaming, 749 - const struct uvc_descriptor_header * const *ss_streaming) 736 + static void uvc_free_inst(struct usb_function_instance *f) 737 + { 738 + struct f_uvc_opts *opts = to_f_uvc_opts(f); 739 + 740 + kfree(opts); 741 + } 742 + 743 + static struct usb_function_instance *uvc_alloc_inst(void) 744 + { 745 + struct f_uvc_opts *opts; 746 + 747 + opts = kzalloc(sizeof(*opts), GFP_KERNEL); 748 + if (!opts) 749 + return ERR_PTR(-ENOMEM); 750 + opts->func_inst.free_func_inst = uvc_free_inst; 751 + 752 + return &opts->func_inst; 753 + } 754 + 755 + static void uvc_free(struct usb_function *f) 756 + { 757 + struct uvc_device *uvc = to_uvc(f); 758 + 759 + kfree(uvc); 760 + } 761 + 762 + static void uvc_unbind(struct usb_configuration *c, struct usb_function *f) 763 + { 764 + struct usb_composite_dev *cdev = c->cdev; 765 + struct uvc_device *uvc = to_uvc(f); 766 + 767 + INFO(cdev, "%s\n", __func__); 768 + 769 + video_unregister_device(uvc->vdev); 770 + v4l2_device_unregister(&uvc->v4l2_dev); 771 + uvc->control_ep->driver_data = NULL; 772 + uvc->video.ep->driver_data = NULL; 773 + 774 + usb_ep_free_request(cdev->gadget->ep0, uvc->control_req); 775 + kfree(uvc->control_buf); 776 + 777 + usb_free_all_descriptors(f); 778 + } 779 + 780 + static struct usb_function *uvc_alloc(struct usb_function_instance *fi) 750 781 { 751 782 struct uvc_device *uvc; 752 - int ret = 0; 753 - 754 - /* TODO Check if the USB device controller supports the required 755 - * features. 756 - */ 757 - if (!gadget_is_dualspeed(c->cdev->gadget)) 758 - return -EINVAL; 783 + struct f_uvc_opts *opts; 759 784 760 785 uvc = kzalloc(sizeof(*uvc), GFP_KERNEL); 761 786 if (uvc == NULL) 762 - return -ENOMEM; 787 + return ERR_PTR(-ENOMEM); 763 788 764 789 uvc->state = UVC_STATE_DISCONNECTED; 790 + opts = to_f_uvc_opts(fi); 765 791 766 - /* Validate the descriptors. */ 767 - if (fs_control == NULL || fs_control[0] == NULL || 768 - fs_control[0]->bDescriptorSubType != UVC_VC_HEADER) 769 - goto error; 770 - 771 - if (ss_control == NULL || ss_control[0] == NULL || 772 - ss_control[0]->bDescriptorSubType != UVC_VC_HEADER) 773 - goto error; 774 - 775 - if (fs_streaming == NULL || fs_streaming[0] == NULL || 776 - fs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) 777 - goto error; 778 - 779 - if (hs_streaming == NULL || hs_streaming[0] == NULL || 780 - hs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) 781 - goto error; 782 - 783 - if (ss_streaming == NULL || ss_streaming[0] == NULL || 784 - ss_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) 785 - goto error; 786 - 787 - uvc->desc.fs_control = fs_control; 788 - uvc->desc.ss_control = ss_control; 789 - uvc->desc.fs_streaming = fs_streaming; 790 - uvc->desc.hs_streaming = hs_streaming; 791 - uvc->desc.ss_streaming = ss_streaming; 792 - 793 - /* String descriptors are global, we only need to allocate string IDs 794 - * for the first UVC function. UVC functions beyond the first (if any) 795 - * will reuse the same IDs. 796 - */ 797 - if (uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id == 0) { 798 - ret = usb_string_ids_tab(c->cdev, uvc_en_us_strings); 799 - if (ret) 800 - goto error; 801 - uvc_iad.iFunction = 802 - uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id; 803 - uvc_control_intf.iInterface = 804 - uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id; 805 - ret = uvc_en_us_strings[UVC_STRING_STREAMING_IDX].id; 806 - uvc_streaming_intf_alt0.iInterface = ret; 807 - uvc_streaming_intf_alt1.iInterface = ret; 808 - } 792 + uvc->desc.fs_control = opts->fs_control; 793 + uvc->desc.ss_control = opts->ss_control; 794 + uvc->desc.fs_streaming = opts->fs_streaming; 795 + uvc->desc.hs_streaming = opts->hs_streaming; 796 + uvc->desc.ss_streaming = opts->ss_streaming; 809 797 810 798 /* Register the function. */ 811 799 uvc->func.name = "uvc"; 812 - uvc->func.strings = uvc_function_strings; 813 800 uvc->func.bind = uvc_function_bind; 814 - uvc->func.unbind = uvc_function_unbind; 801 + uvc->func.unbind = uvc_unbind; 815 802 uvc->func.get_alt = uvc_function_get_alt; 816 803 uvc->func.set_alt = uvc_function_set_alt; 817 804 uvc->func.disable = uvc_function_disable; 818 805 uvc->func.setup = uvc_function_setup; 806 + uvc->func.free_func = uvc_free; 819 807 820 - ret = usb_add_function(c, &uvc->func); 821 - if (ret) 822 - kfree(uvc); 823 - 824 - return ret; 825 - 826 - error: 827 - kfree(uvc); 828 - return ret; 808 + return &uvc->func; 829 809 } 830 810 831 - module_param_named(trace, uvc_gadget_trace_param, uint, S_IRUGO|S_IWUSR); 832 - MODULE_PARM_DESC(trace, "Trace level bitmask"); 833 - 811 + DECLARE_USB_FUNCTION_INIT(uvc, uvc_alloc_inst, uvc_alloc); 812 + MODULE_LICENSE("GPL"); 813 + MODULE_AUTHOR("Laurent Pinchart");
+7 -6
drivers/usb/gadget/function/f_uvc.h
··· 16 16 #include <linux/usb/composite.h> 17 17 #include <linux/usb/video.h> 18 18 19 - int uvc_bind_config(struct usb_configuration *c, 20 - const struct uvc_descriptor_header * const *fs_control, 21 - const struct uvc_descriptor_header * const *hs_control, 22 - const struct uvc_descriptor_header * const *fs_streaming, 23 - const struct uvc_descriptor_header * const *hs_streaming, 24 - const struct uvc_descriptor_header * const *ss_streaming); 19 + #include "uvc.h" 20 + 21 + void uvc_function_setup_continue(struct uvc_device *uvc); 22 + 23 + void uvc_function_connect(struct uvc_device *uvc); 24 + 25 + void uvc_function_disconnect(struct uvc_device *uvc); 25 26 26 27 #endif /* _F_UVC_H_ */ 27 28
+12 -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_INT_INTERVAL 1 /* Default interrupt interval = 1 ms */ 14 + #define GZERO_INT_MAXPACKET 1024 13 15 14 16 struct usb_zero_options { 15 17 unsigned pattern; ··· 19 17 unsigned isoc_maxpacket; 20 18 unsigned isoc_mult; 21 19 unsigned isoc_maxburst; 20 + unsigned int_interval; /* In ms */ 21 + unsigned int_maxpacket; 22 + unsigned int_mult; 23 + unsigned int_maxburst; 22 24 unsigned bulk_buflen; 23 25 unsigned qlen; 24 26 }; ··· 34 28 unsigned isoc_maxpacket; 35 29 unsigned isoc_mult; 36 30 unsigned isoc_maxburst; 31 + unsigned int_interval; /* In ms */ 32 + unsigned int_maxpacket; 33 + unsigned int_mult; 34 + unsigned int_maxburst; 37 35 unsigned bulk_buflen; 38 36 39 37 /* ··· 72 62 void free_ep_req(struct usb_ep *ep, struct usb_request *req); 73 63 void disable_endpoints(struct usb_composite_dev *cdev, 74 64 struct usb_ep *in, struct usb_ep *out, 75 - struct usb_ep *iso_in, struct usb_ep *iso_out); 65 + struct usb_ep *iso_in, struct usb_ep *iso_out, 66 + struct usb_ep *int_in, struct usb_ep *int_out); 76 67 77 68 #endif /* __G_ZERO_H */
+2
drivers/usb/gadget/function/u_fs.h
··· 224 224 void *ms_os_descs_ext_prop_name_avail; 225 225 void *ms_os_descs_ext_prop_data_avail; 226 226 227 + unsigned user_flags; 228 + 227 229 u8 eps_addrmap[15]; 228 230 229 231 unsigned short strings_count;
+13 -17
drivers/usb/gadget/function/u_serial.c
··· 55 55 * for a telephone or fax link. And ttyGS2 might be something that just 56 56 * needs a simple byte stream interface for some messaging protocol that 57 57 * is managed in userspace ... OBEX, PTP, and MTP have been mentioned. 58 - */ 59 - 60 - #define PREFIX "ttyGS" 61 - 62 - /* 58 + * 59 + * 63 60 * gserial is the lifecycle interface, used by USB functions 64 61 * gs_port is the I/O nexus, used by the tty driver 65 62 * tty_struct links to the tty/filesystem framework ··· 382 385 list_del(&req->list); 383 386 req->zero = (gs_buf_data_avail(&port->port_write_buf) == 0); 384 387 385 - pr_vdebug(PREFIX "%d: tx len=%d, 0x%02x 0x%02x 0x%02x ...\n", 386 - port->port_num, len, *((u8 *)req->buf), 387 - *((u8 *)req->buf+1), *((u8 *)req->buf+2)); 388 + pr_vdebug("ttyGS%d: tx len=%d, 0x%02x 0x%02x 0x%02x ...\n", 389 + port->port_num, len, *((u8 *)req->buf), 390 + *((u8 *)req->buf+1), *((u8 *)req->buf+2)); 388 391 389 392 /* Drop lock while we call out of driver; completions 390 393 * could be issued while we do so. Disconnection may ··· 500 503 switch (req->status) { 501 504 case -ESHUTDOWN: 502 505 disconnect = true; 503 - pr_vdebug(PREFIX "%d: shutdown\n", port->port_num); 506 + pr_vdebug("ttyGS%d: shutdown\n", port->port_num); 504 507 break; 505 508 506 509 default: 507 510 /* presumably a transient fault */ 508 - pr_warning(PREFIX "%d: unexpected RX status %d\n", 509 - port->port_num, req->status); 511 + pr_warn("ttyGS%d: unexpected RX status %d\n", 512 + port->port_num, req->status); 510 513 /* FALLTHROUGH */ 511 514 case 0: 512 515 /* normal completion */ ··· 534 537 if (count != size) { 535 538 /* stop pushing; TTY layer can't handle more */ 536 539 port->n_read += count; 537 - pr_vdebug(PREFIX "%d: rx block %d/%d\n", 538 - port->port_num, 539 - count, req->actual); 540 + pr_vdebug("ttyGS%d: rx block %d/%d\n", 541 + port->port_num, count, req->actual); 540 542 break; 541 543 } 542 544 port->n_read = 0; ··· 565 569 if (do_push) 566 570 tasklet_schedule(&port->push); 567 571 else 568 - pr_warning(PREFIX "%d: RX not scheduled?\n", 572 + pr_warn("ttyGS%d: RX not scheduled?\n", 569 573 port->port_num); 570 574 } 571 575 } ··· 981 985 * read queue backs up enough we'll be NAKing OUT packets. 982 986 */ 983 987 tasklet_schedule(&port->push); 984 - pr_vdebug(PREFIX "%d: unthrottle\n", port->port_num); 988 + pr_vdebug("ttyGS%d: unthrottle\n", port->port_num); 985 989 } 986 990 spin_unlock_irqrestore(&port->port_lock, flags); 987 991 } ··· 1291 1295 return -ENOMEM; 1292 1296 1293 1297 gs_tty_driver->driver_name = "g_serial"; 1294 - gs_tty_driver->name = PREFIX; 1298 + gs_tty_driver->name = "ttyGS"; 1295 1299 /* uses dynamically assigned dev_t values */ 1296 1300 1297 1301 gs_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
+13 -25
drivers/usb/gadget/function/u_uac1.c
··· 10 10 */ 11 11 12 12 #include <linux/kernel.h> 13 + #include <linux/module.h> 13 14 #include <linux/slab.h> 14 15 #include <linux/device.h> 15 16 #include <linux/delay.h> ··· 23 22 /* 24 23 * This component encapsulates the ALSA devices for USB audio gadget 25 24 */ 26 - 27 - #define FILE_PCM_PLAYBACK "/dev/snd/pcmC0D0p" 28 - #define FILE_PCM_CAPTURE "/dev/snd/pcmC0D0c" 29 - #define FILE_CONTROL "/dev/snd/controlC0" 30 - 31 - static char *fn_play = FILE_PCM_PLAYBACK; 32 - module_param(fn_play, charp, S_IRUGO); 33 - MODULE_PARM_DESC(fn_play, "Playback PCM device file name"); 34 - 35 - static char *fn_cap = FILE_PCM_CAPTURE; 36 - module_param(fn_cap, charp, S_IRUGO); 37 - MODULE_PARM_DESC(fn_cap, "Capture PCM device file name"); 38 - 39 - static char *fn_cntl = FILE_CONTROL; 40 - module_param(fn_cntl, charp, S_IRUGO); 41 - MODULE_PARM_DESC(fn_cntl, "Control device file name"); 42 25 43 26 /*-------------------------------------------------------------------------*/ 44 27 ··· 152 167 /** 153 168 * Playback audio buffer data by ALSA PCM device 154 169 */ 155 - static size_t u_audio_playback(struct gaudio *card, void *buf, size_t count) 170 + size_t u_audio_playback(struct gaudio *card, void *buf, size_t count) 156 171 { 157 172 struct gaudio_snd_dev *snd = &card->playback; 158 173 struct snd_pcm_substream *substream = snd->substream; ··· 187 202 return 0; 188 203 } 189 204 190 - static int u_audio_get_playback_channels(struct gaudio *card) 205 + int u_audio_get_playback_channels(struct gaudio *card) 191 206 { 192 207 return card->playback.channels; 193 208 } 194 209 195 - static int u_audio_get_playback_rate(struct gaudio *card) 210 + int u_audio_get_playback_rate(struct gaudio *card) 196 211 { 197 212 return card->playback.rate; 198 213 } ··· 205 220 { 206 221 struct snd_pcm_file *pcm_file; 207 222 struct gaudio_snd_dev *snd; 223 + struct f_uac1_opts *opts; 224 + char *fn_play, *fn_cap, *fn_cntl; 225 + 226 + opts = container_of(card->func.fi, struct f_uac1_opts, func_inst); 227 + fn_play = opts->fn_play; 228 + fn_cap = opts->fn_cap; 229 + fn_cntl = opts->fn_cntl; 208 230 209 231 if (!card) 210 232 return -ENODEV; ··· 285 293 return 0; 286 294 } 287 295 288 - static struct gaudio *the_card; 289 296 /** 290 297 * gaudio_setup - setup ALSA interface and preparing for USB transfer 291 298 * ··· 292 301 * 293 302 * Returns negative errno, or zero on success 294 303 */ 295 - int __init gaudio_setup(struct gaudio *card) 304 + int gaudio_setup(struct gaudio *card) 296 305 { 297 306 int ret; 298 307 299 308 ret = gaudio_open_snd_dev(card); 300 309 if (ret) 301 310 ERROR(card, "we need at least one control device\n"); 302 - else if (!the_card) 303 - the_card = card; 304 311 305 312 return ret; 306 313 ··· 309 320 * 310 321 * This is called to free all resources allocated by @gaudio_setup(). 311 322 */ 312 - void gaudio_cleanup(void) 323 + void gaudio_cleanup(struct gaudio *the_card) 313 324 { 314 325 if (the_card) { 315 326 gaudio_close_snd_dev(the_card); 316 - the_card = NULL; 317 327 } 318 328 } 319 329
+30 -1
drivers/usb/gadget/function/u_uac1.h
··· 23 23 24 24 #include "gadget_chips.h" 25 25 26 + #define FILE_PCM_PLAYBACK "/dev/snd/pcmC0D0p" 27 + #define FILE_PCM_CAPTURE "/dev/snd/pcmC0D0c" 28 + #define FILE_CONTROL "/dev/snd/controlC0" 29 + 30 + #define UAC1_OUT_EP_MAX_PACKET_SIZE 200 31 + #define UAC1_REQ_COUNT 256 32 + #define UAC1_AUDIO_BUF_SIZE 48000 33 + 26 34 /* 27 35 * This represents the USB side of an audio card device, managed by a USB 28 36 * function which provides control and stream interfaces. ··· 58 50 /* TODO */ 59 51 }; 60 52 53 + struct f_uac1_opts { 54 + struct usb_function_instance func_inst; 55 + int req_buf_size; 56 + int req_count; 57 + int audio_buf_size; 58 + char *fn_play; 59 + char *fn_cap; 60 + char *fn_cntl; 61 + unsigned bound:1; 62 + unsigned fn_play_alloc:1; 63 + unsigned fn_cap_alloc:1; 64 + unsigned fn_cntl_alloc:1; 65 + struct gaudio *card; 66 + struct mutex lock; 67 + int refcnt; 68 + }; 69 + 61 70 int gaudio_setup(struct gaudio *card); 62 - void gaudio_cleanup(void); 71 + void gaudio_cleanup(struct gaudio *the_card); 72 + 73 + size_t u_audio_playback(struct gaudio *card, void *buf, size_t count); 74 + int u_audio_get_playback_channels(struct gaudio *card); 75 + int u_audio_get_playback_rate(struct gaudio *card); 63 76 64 77 #endif /* __U_AUDIO_H */
+42
drivers/usb/gadget/function/u_uac2.h
··· 1 + /* 2 + * u_uac2.h 3 + * 4 + * Utility definitions for UAC2 function 5 + * 6 + * Copyright (c) 2014 Samsung Electronics Co., Ltd. 7 + * http://www.samsung.com 8 + * 9 + * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + */ 15 + 16 + #ifndef U_UAC2_H 17 + #define U_UAC2_H 18 + 19 + #include <linux/usb/composite.h> 20 + 21 + #define UAC2_DEF_PCHMASK 0x3 22 + #define UAC2_DEF_PSRATE 48000 23 + #define UAC2_DEF_PSSIZE 2 24 + #define UAC2_DEF_CCHMASK 0x3 25 + #define UAC2_DEF_CSRATE 64000 26 + #define UAC2_DEF_CSSIZE 2 27 + 28 + struct f_uac2_opts { 29 + struct usb_function_instance func_inst; 30 + int p_chmask; 31 + int p_srate; 32 + int p_ssize; 33 + int c_chmask; 34 + int c_srate; 35 + int c_ssize; 36 + bool bound; 37 + 38 + struct mutex lock; 39 + int refcnt; 40 + }; 41 + 42 + #endif
+39
drivers/usb/gadget/function/u_uvc.h
··· 1 + /* 2 + * u_uvc.h 3 + * 4 + * Utility definitions for the uvc function 5 + * 6 + * Copyright (c) 2013-2014 Samsung Electronics Co., Ltd. 7 + * http://www.samsung.com 8 + * 9 + * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + */ 15 + 16 + #ifndef U_UVC_H 17 + #define U_UVC_H 18 + 19 + #include <linux/usb/composite.h> 20 + 21 + #define to_f_uvc_opts(f) container_of(f, struct f_uvc_opts, func_inst) 22 + 23 + struct f_uvc_opts { 24 + struct usb_function_instance func_inst; 25 + unsigned int uvc_gadget_trace_param; 26 + unsigned int streaming_interval; 27 + unsigned int streaming_maxpacket; 28 + unsigned int streaming_maxburst; 29 + const struct uvc_descriptor_header * const *fs_control; 30 + const struct uvc_descriptor_header * const *ss_control; 31 + const struct uvc_descriptor_header * const *fs_streaming; 32 + const struct uvc_descriptor_header * const *hs_streaming; 33 + const struct uvc_descriptor_header * const *ss_streaming; 34 + }; 35 + 36 + void uvc_set_trace_param(unsigned int trace); 37 + 38 + #endif /* U_UVC_H */ 39 +
+1 -3
drivers/usb/gadget/function/uvc.h
··· 53 53 #ifdef __KERNEL__ 54 54 55 55 #include <linux/usb.h> /* For usb_endpoint_* */ 56 + #include <linux/usb/composite.h> 56 57 #include <linux/usb/gadget.h> 57 58 #include <linux/videodev2.h> 58 59 #include <linux/version.h> ··· 96 95 /* ------------------------------------------------------------------------ 97 96 * Driver specific constants 98 97 */ 99 - 100 - #define DRIVER_VERSION "0.1.0" 101 - #define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0) 102 98 103 99 #define UVC_NUM_REQUESTS 4 104 100 #define UVC_MAX_REQUEST_SIZE 64
+21 -25
drivers/usb/gadget/function/uvc_queue.c
··· 28 28 /* ------------------------------------------------------------------------ 29 29 * Video buffers queue management. 30 30 * 31 - * Video queues is initialized by uvc_queue_init(). The function performs 31 + * Video queues is initialized by uvcg_queue_init(). The function performs 32 32 * basic initialization of the uvc_video_queue struct and never fails. 33 33 * 34 34 * Video buffers are managed by videobuf2. The driver uses a mutex to protect ··· 126 126 .wait_finish = uvc_wait_finish, 127 127 }; 128 128 129 - static int uvc_queue_init(struct uvc_video_queue *queue, 130 - enum v4l2_buf_type type) 129 + int uvcg_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) 131 130 { 132 131 int ret; 133 132 134 133 queue->queue.type = type; 135 - queue->queue.io_modes = VB2_MMAP | VB2_USERPTR; 134 + queue->queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; 136 135 queue->queue.drv_priv = queue; 137 136 queue->queue.buf_struct_size = sizeof(struct uvc_buffer); 138 137 queue->queue.ops = &uvc_queue_qops; ··· 153 154 /* 154 155 * Free the video buffers. 155 156 */ 156 - static void uvc_free_buffers(struct uvc_video_queue *queue) 157 + void uvcg_free_buffers(struct uvc_video_queue *queue) 157 158 { 158 159 mutex_lock(&queue->mutex); 159 160 vb2_queue_release(&queue->queue); ··· 163 164 /* 164 165 * Allocate the video buffers. 165 166 */ 166 - static int uvc_alloc_buffers(struct uvc_video_queue *queue, 167 - struct v4l2_requestbuffers *rb) 167 + int uvcg_alloc_buffers(struct uvc_video_queue *queue, 168 + struct v4l2_requestbuffers *rb) 168 169 { 169 170 int ret; 170 171 ··· 175 176 return ret ? ret : rb->count; 176 177 } 177 178 178 - static int uvc_query_buffer(struct uvc_video_queue *queue, 179 - struct v4l2_buffer *buf) 179 + int uvcg_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf) 180 180 { 181 181 int ret; 182 182 ··· 186 188 return ret; 187 189 } 188 190 189 - static int uvc_queue_buffer(struct uvc_video_queue *queue, 190 - struct v4l2_buffer *buf) 191 + int uvcg_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf) 191 192 { 192 193 unsigned long flags; 193 194 int ret; ··· 210 213 * Dequeue a video buffer. If nonblocking is false, block until a buffer is 211 214 * available. 212 215 */ 213 - static int uvc_dequeue_buffer(struct uvc_video_queue *queue, 214 - struct v4l2_buffer *buf, int nonblocking) 216 + int uvcg_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf, 217 + int nonblocking) 215 218 { 216 219 int ret; 217 220 ··· 228 231 * This function implements video queue polling and is intended to be used by 229 232 * the device poll handler. 230 233 */ 231 - static unsigned int uvc_queue_poll(struct uvc_video_queue *queue, 232 - struct file *file, poll_table *wait) 234 + unsigned int uvcg_queue_poll(struct uvc_video_queue *queue, struct file *file, 235 + poll_table *wait) 233 236 { 234 237 unsigned int ret; 235 238 ··· 240 243 return ret; 241 244 } 242 245 243 - static int uvc_queue_mmap(struct uvc_video_queue *queue, 244 - struct vm_area_struct *vma) 246 + int uvcg_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma) 245 247 { 246 248 int ret; 247 249 ··· 257 261 * 258 262 * NO-MMU arch need this function to make mmap() work correctly. 259 263 */ 260 - static unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, 261 - unsigned long pgoff) 264 + unsigned long uvcg_queue_get_unmapped_area(struct uvc_video_queue *queue, 265 + unsigned long pgoff) 262 266 { 263 267 unsigned long ret; 264 268 ··· 281 285 * This function acquires the irq spinlock and can be called from interrupt 282 286 * context. 283 287 */ 284 - static void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect) 288 + void uvcg_queue_cancel(struct uvc_video_queue *queue, int disconnect) 285 289 { 286 290 struct uvc_buffer *buf; 287 291 unsigned long flags; ··· 320 324 * the main queue. 321 325 * 322 326 * This function can't be called from interrupt context. Use 323 - * uvc_queue_cancel() instead. 327 + * uvcg_queue_cancel() instead. 324 328 */ 325 - static int uvc_queue_enable(struct uvc_video_queue *queue, int enable) 329 + int uvcg_queue_enable(struct uvc_video_queue *queue, int enable) 326 330 { 327 331 unsigned long flags; 328 332 int ret = 0; ··· 359 363 } 360 364 361 365 /* called with &queue_irqlock held.. */ 362 - static struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, 363 - struct uvc_buffer *buf) 366 + struct uvc_buffer *uvcg_queue_next_buffer(struct uvc_video_queue *queue, 367 + struct uvc_buffer *buf) 364 368 { 365 369 struct uvc_buffer *nextbuf; 366 370 ··· 388 392 return nextbuf; 389 393 } 390 394 391 - static struct uvc_buffer *uvc_queue_head(struct uvc_video_queue *queue) 395 + struct uvc_buffer *uvcg_queue_head(struct uvc_video_queue *queue) 392 396 { 393 397 struct uvc_buffer *buf = NULL; 394 398
+33
drivers/usb/gadget/function/uvc_queue.h
··· 57 57 return vb2_is_streaming(&queue->queue); 58 58 } 59 59 60 + int uvcg_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type); 61 + 62 + void uvcg_free_buffers(struct uvc_video_queue *queue); 63 + 64 + int uvcg_alloc_buffers(struct uvc_video_queue *queue, 65 + struct v4l2_requestbuffers *rb); 66 + 67 + int uvcg_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf); 68 + 69 + int uvcg_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *buf); 70 + 71 + int uvcg_dequeue_buffer(struct uvc_video_queue *queue, 72 + struct v4l2_buffer *buf, int nonblocking); 73 + 74 + unsigned int uvcg_queue_poll(struct uvc_video_queue *queue, 75 + struct file *file, poll_table *wait); 76 + 77 + int uvcg_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma); 78 + 79 + #ifndef CONFIG_MMU 80 + unsigned long uvcg_queue_get_unmapped_area(struct uvc_video_queue *queue, 81 + unsigned long pgoff); 82 + #endif /* CONFIG_MMU */ 83 + 84 + void uvcg_queue_cancel(struct uvc_video_queue *queue, int disconnect); 85 + 86 + int uvcg_queue_enable(struct uvc_video_queue *queue, int enable); 87 + 88 + struct uvc_buffer *uvcg_queue_next_buffer(struct uvc_video_queue *queue, 89 + struct uvc_buffer *buf); 90 + 91 + struct uvc_buffer *uvcg_queue_head(struct uvc_video_queue *queue); 92 + 60 93 #endif /* __KERNEL__ */ 61 94 62 95 #endif /* _UVC_QUEUE_H_ */
+176 -175
drivers/usb/gadget/function/uvc_v4l2.c
··· 23 23 #include <media/v4l2-event.h> 24 24 #include <media/v4l2-ioctl.h> 25 25 26 + #include "f_uvc.h" 26 27 #include "uvc.h" 27 28 #include "uvc_queue.h" 29 + #include "uvc_video.h" 28 30 29 31 /* -------------------------------------------------------------------------- 30 32 * Requests handling ··· 50 48 } 51 49 52 50 /* -------------------------------------------------------------------------- 53 - * V4L2 51 + * V4L2 ioctls 54 52 */ 55 53 56 54 struct uvc_format ··· 65 63 }; 66 64 67 65 static int 68 - uvc_v4l2_get_format(struct uvc_video *video, struct v4l2_format *fmt) 66 + uvc_v4l2_querycap(struct file *file, void *fh, struct v4l2_capability *cap) 69 67 { 68 + struct video_device *vdev = video_devdata(file); 69 + struct uvc_device *uvc = video_get_drvdata(vdev); 70 + struct usb_composite_dev *cdev = uvc->func.config->cdev; 71 + 72 + strlcpy(cap->driver, "g_uvc", sizeof(cap->driver)); 73 + strlcpy(cap->card, cdev->gadget->name, sizeof(cap->card)); 74 + strlcpy(cap->bus_info, dev_name(&cdev->gadget->dev), 75 + sizeof(cap->bus_info)); 76 + 77 + cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; 78 + 79 + return 0; 80 + } 81 + 82 + static int 83 + uvc_v4l2_get_format(struct file *file, void *fh, struct v4l2_format *fmt) 84 + { 85 + struct video_device *vdev = video_devdata(file); 86 + struct uvc_device *uvc = video_get_drvdata(vdev); 87 + struct uvc_video *video = &uvc->video; 88 + 70 89 fmt->fmt.pix.pixelformat = video->fcc; 71 90 fmt->fmt.pix.width = video->width; 72 91 fmt->fmt.pix.height = video->height; ··· 101 78 } 102 79 103 80 static int 104 - uvc_v4l2_set_format(struct uvc_video *video, struct v4l2_format *fmt) 81 + uvc_v4l2_set_format(struct file *file, void *fh, struct v4l2_format *fmt) 105 82 { 83 + struct video_device *vdev = video_devdata(file); 84 + struct uvc_device *uvc = video_get_drvdata(vdev); 85 + struct uvc_video *video = &uvc->video; 106 86 struct uvc_format *format; 107 87 unsigned int imagesize; 108 88 unsigned int bpl; ··· 142 116 } 143 117 144 118 static int 119 + uvc_v4l2_reqbufs(struct file *file, void *fh, struct v4l2_requestbuffers *b) 120 + { 121 + struct video_device *vdev = video_devdata(file); 122 + struct uvc_device *uvc = video_get_drvdata(vdev); 123 + struct uvc_video *video = &uvc->video; 124 + 125 + if (b->type != video->queue.queue.type) 126 + return -EINVAL; 127 + 128 + return uvcg_alloc_buffers(&video->queue, b); 129 + } 130 + 131 + static int 132 + uvc_v4l2_querybuf(struct file *file, void *fh, struct v4l2_buffer *b) 133 + { 134 + struct video_device *vdev = video_devdata(file); 135 + struct uvc_device *uvc = video_get_drvdata(vdev); 136 + struct uvc_video *video = &uvc->video; 137 + 138 + return uvcg_query_buffer(&video->queue, b); 139 + } 140 + 141 + static int 142 + uvc_v4l2_qbuf(struct file *file, void *fh, struct v4l2_buffer *b) 143 + { 144 + struct video_device *vdev = video_devdata(file); 145 + struct uvc_device *uvc = video_get_drvdata(vdev); 146 + struct uvc_video *video = &uvc->video; 147 + int ret; 148 + 149 + ret = uvcg_queue_buffer(&video->queue, b); 150 + if (ret < 0) 151 + return ret; 152 + 153 + return uvcg_video_pump(video); 154 + } 155 + 156 + static int 157 + uvc_v4l2_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b) 158 + { 159 + struct video_device *vdev = video_devdata(file); 160 + struct uvc_device *uvc = video_get_drvdata(vdev); 161 + struct uvc_video *video = &uvc->video; 162 + 163 + return uvcg_dequeue_buffer(&video->queue, b, file->f_flags & O_NONBLOCK); 164 + } 165 + 166 + static int 167 + uvc_v4l2_streamon(struct file *file, void *fh, enum v4l2_buf_type type) 168 + { 169 + struct video_device *vdev = video_devdata(file); 170 + struct uvc_device *uvc = video_get_drvdata(vdev); 171 + struct uvc_video *video = &uvc->video; 172 + int ret; 173 + 174 + if (type != video->queue.queue.type) 175 + return -EINVAL; 176 + 177 + /* Enable UVC video. */ 178 + ret = uvcg_video_enable(video, 1); 179 + if (ret < 0) 180 + return ret; 181 + 182 + /* 183 + * Complete the alternate setting selection setup phase now that 184 + * userspace is ready to provide video frames. 185 + */ 186 + uvc_function_setup_continue(uvc); 187 + uvc->state = UVC_STATE_STREAMING; 188 + 189 + return 0; 190 + } 191 + 192 + static int 193 + uvc_v4l2_streamoff(struct file *file, void *fh, enum v4l2_buf_type type) 194 + { 195 + struct video_device *vdev = video_devdata(file); 196 + struct uvc_device *uvc = video_get_drvdata(vdev); 197 + struct uvc_video *video = &uvc->video; 198 + 199 + if (type != video->queue.queue.type) 200 + return -EINVAL; 201 + 202 + return uvcg_video_enable(video, 0); 203 + } 204 + 205 + static int 206 + uvc_v4l2_subscribe_event(struct v4l2_fh *fh, 207 + const struct v4l2_event_subscription *sub) 208 + { 209 + if (sub->type < UVC_EVENT_FIRST || sub->type > UVC_EVENT_LAST) 210 + return -EINVAL; 211 + 212 + return v4l2_event_subscribe(fh, sub, 2, NULL); 213 + } 214 + 215 + static int 216 + uvc_v4l2_unsubscribe_event(struct v4l2_fh *fh, 217 + const struct v4l2_event_subscription *sub) 218 + { 219 + return v4l2_event_unsubscribe(fh, sub); 220 + } 221 + 222 + static long 223 + uvc_v4l2_ioctl_default(struct file *file, void *fh, bool valid_prio, 224 + unsigned int cmd, void *arg) 225 + { 226 + struct video_device *vdev = video_devdata(file); 227 + struct uvc_device *uvc = video_get_drvdata(vdev); 228 + 229 + switch (cmd) { 230 + case UVCIOC_SEND_RESPONSE: 231 + return uvc_send_response(uvc, arg); 232 + 233 + default: 234 + return -ENOIOCTLCMD; 235 + } 236 + } 237 + 238 + const struct v4l2_ioctl_ops uvc_v4l2_ioctl_ops = { 239 + .vidioc_querycap = uvc_v4l2_querycap, 240 + .vidioc_g_fmt_vid_out = uvc_v4l2_get_format, 241 + .vidioc_s_fmt_vid_out = uvc_v4l2_set_format, 242 + .vidioc_reqbufs = uvc_v4l2_reqbufs, 243 + .vidioc_querybuf = uvc_v4l2_querybuf, 244 + .vidioc_qbuf = uvc_v4l2_qbuf, 245 + .vidioc_dqbuf = uvc_v4l2_dqbuf, 246 + .vidioc_streamon = uvc_v4l2_streamon, 247 + .vidioc_streamoff = uvc_v4l2_streamoff, 248 + .vidioc_subscribe_event = uvc_v4l2_subscribe_event, 249 + .vidioc_unsubscribe_event = uvc_v4l2_unsubscribe_event, 250 + .vidioc_default = uvc_v4l2_ioctl_default, 251 + }; 252 + 253 + /* -------------------------------------------------------------------------- 254 + * V4L2 255 + */ 256 + 257 + static int 145 258 uvc_v4l2_open(struct file *file) 146 259 { 147 260 struct video_device *vdev = video_devdata(file); ··· 311 146 312 147 uvc_function_disconnect(uvc); 313 148 314 - uvc_video_enable(video, 0); 315 - uvc_free_buffers(&video->queue); 149 + uvcg_video_enable(video, 0); 150 + uvcg_free_buffers(&video->queue); 316 151 317 152 file->private_data = NULL; 318 153 v4l2_fh_del(&handle->vfh); ··· 322 157 return 0; 323 158 } 324 159 325 - static long 326 - uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) 327 - { 328 - struct video_device *vdev = video_devdata(file); 329 - struct uvc_device *uvc = video_get_drvdata(vdev); 330 - struct uvc_file_handle *handle = to_uvc_file_handle(file->private_data); 331 - struct usb_composite_dev *cdev = uvc->func.config->cdev; 332 - struct uvc_video *video = &uvc->video; 333 - int ret = 0; 334 - 335 - switch (cmd) { 336 - /* Query capabilities */ 337 - case VIDIOC_QUERYCAP: 338 - { 339 - struct v4l2_capability *cap = arg; 340 - 341 - memset(cap, 0, sizeof *cap); 342 - strlcpy(cap->driver, "g_uvc", sizeof(cap->driver)); 343 - strlcpy(cap->card, cdev->gadget->name, sizeof(cap->card)); 344 - strlcpy(cap->bus_info, dev_name(&cdev->gadget->dev), 345 - sizeof cap->bus_info); 346 - cap->version = DRIVER_VERSION_NUMBER; 347 - cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; 348 - break; 349 - } 350 - 351 - /* Get & Set format */ 352 - case VIDIOC_G_FMT: 353 - { 354 - struct v4l2_format *fmt = arg; 355 - 356 - if (fmt->type != video->queue.queue.type) 357 - return -EINVAL; 358 - 359 - return uvc_v4l2_get_format(video, fmt); 360 - } 361 - 362 - case VIDIOC_S_FMT: 363 - { 364 - struct v4l2_format *fmt = arg; 365 - 366 - if (fmt->type != video->queue.queue.type) 367 - return -EINVAL; 368 - 369 - return uvc_v4l2_set_format(video, fmt); 370 - } 371 - 372 - /* Buffers & streaming */ 373 - case VIDIOC_REQBUFS: 374 - { 375 - struct v4l2_requestbuffers *rb = arg; 376 - 377 - if (rb->type != video->queue.queue.type) 378 - return -EINVAL; 379 - 380 - ret = uvc_alloc_buffers(&video->queue, rb); 381 - if (ret < 0) 382 - return ret; 383 - 384 - ret = 0; 385 - break; 386 - } 387 - 388 - case VIDIOC_QUERYBUF: 389 - { 390 - struct v4l2_buffer *buf = arg; 391 - 392 - return uvc_query_buffer(&video->queue, buf); 393 - } 394 - 395 - case VIDIOC_QBUF: 396 - if ((ret = uvc_queue_buffer(&video->queue, arg)) < 0) 397 - return ret; 398 - 399 - return uvc_video_pump(video); 400 - 401 - case VIDIOC_DQBUF: 402 - return uvc_dequeue_buffer(&video->queue, arg, 403 - file->f_flags & O_NONBLOCK); 404 - 405 - case VIDIOC_STREAMON: 406 - { 407 - int *type = arg; 408 - 409 - if (*type != video->queue.queue.type) 410 - return -EINVAL; 411 - 412 - /* Enable UVC video. */ 413 - ret = uvc_video_enable(video, 1); 414 - if (ret < 0) 415 - return ret; 416 - 417 - /* 418 - * Complete the alternate setting selection setup phase now that 419 - * userspace is ready to provide video frames. 420 - */ 421 - uvc_function_setup_continue(uvc); 422 - uvc->state = UVC_STATE_STREAMING; 423 - 424 - return 0; 425 - } 426 - 427 - case VIDIOC_STREAMOFF: 428 - { 429 - int *type = arg; 430 - 431 - if (*type != video->queue.queue.type) 432 - return -EINVAL; 433 - 434 - return uvc_video_enable(video, 0); 435 - } 436 - 437 - /* Events */ 438 - case VIDIOC_DQEVENT: 439 - { 440 - struct v4l2_event *event = arg; 441 - 442 - ret = v4l2_event_dequeue(&handle->vfh, event, 443 - file->f_flags & O_NONBLOCK); 444 - if (ret == 0 && event->type == UVC_EVENT_SETUP) { 445 - struct uvc_event *uvc_event = (void *)&event->u.data; 446 - 447 - /* Tell the complete callback to generate an event for 448 - * the next request that will be enqueued by 449 - * uvc_event_write. 450 - */ 451 - uvc->event_setup_out = 452 - !(uvc_event->req.bRequestType & USB_DIR_IN); 453 - uvc->event_length = uvc_event->req.wLength; 454 - } 455 - 456 - return ret; 457 - } 458 - 459 - case VIDIOC_SUBSCRIBE_EVENT: 460 - { 461 - struct v4l2_event_subscription *sub = arg; 462 - 463 - if (sub->type < UVC_EVENT_FIRST || sub->type > UVC_EVENT_LAST) 464 - return -EINVAL; 465 - 466 - return v4l2_event_subscribe(&handle->vfh, arg, 2, NULL); 467 - } 468 - 469 - case VIDIOC_UNSUBSCRIBE_EVENT: 470 - return v4l2_event_unsubscribe(&handle->vfh, arg); 471 - 472 - case UVCIOC_SEND_RESPONSE: 473 - ret = uvc_send_response(uvc, arg); 474 - break; 475 - 476 - default: 477 - return -ENOIOCTLCMD; 478 - } 479 - 480 - return ret; 481 - } 482 - 483 - static long 484 - uvc_v4l2_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 485 - { 486 - return video_usercopy(file, cmd, arg, uvc_v4l2_do_ioctl); 487 - } 488 - 489 160 static int 490 161 uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma) 491 162 { 492 163 struct video_device *vdev = video_devdata(file); 493 164 struct uvc_device *uvc = video_get_drvdata(vdev); 494 165 495 - return uvc_queue_mmap(&uvc->video.queue, vma); 166 + return uvcg_queue_mmap(&uvc->video.queue, vma); 496 167 } 497 168 498 169 static unsigned int ··· 337 336 struct video_device *vdev = video_devdata(file); 338 337 struct uvc_device *uvc = video_get_drvdata(vdev); 339 338 340 - return uvc_queue_poll(&uvc->video.queue, file, wait); 339 + return uvcg_queue_poll(&uvc->video.queue, file, wait); 341 340 } 342 341 343 342 #ifndef CONFIG_MMU ··· 348 347 struct video_device *vdev = video_devdata(file); 349 348 struct uvc_device *uvc = video_get_drvdata(vdev); 350 349 351 - return uvc_queue_get_unmapped_area(&uvc->video.queue, pgoff); 350 + return uvcg_queue_get_unmapped_area(&uvc->video.queue, pgoff); 352 351 } 353 352 #endif 354 353 355 - static struct v4l2_file_operations uvc_v4l2_fops = { 354 + struct v4l2_file_operations uvc_v4l2_fops = { 356 355 .owner = THIS_MODULE, 357 356 .open = uvc_v4l2_open, 358 357 .release = uvc_v4l2_release, 359 - .ioctl = uvc_v4l2_ioctl, 358 + .ioctl = video_ioctl2, 360 359 .mmap = uvc_v4l2_mmap, 361 360 .poll = uvc_v4l2_poll, 362 361 #ifndef CONFIG_MMU 363 - .get_unmapped_area = uvc_v4l2_get_unmapped_area, 362 + .get_unmapped_area = uvcg_v4l2_get_unmapped_area, 364 363 #endif 365 364 }; 366 365
+22
drivers/usb/gadget/function/uvc_v4l2.h
··· 1 + /* 2 + * uvc_v4l2.h -- USB Video Class Gadget driver 3 + * 4 + * Copyright (C) 2009-2010 5 + * Laurent Pinchart (laurent.pinchart@ideasonboard.com) 6 + * 7 + * Copyright (c) 2013 Samsung Electronics Co., Ltd. 8 + * http://www.samsung.com 9 + * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + */ 15 + 16 + #ifndef __UVC_V4L2_H__ 17 + #define __UVC_V4L2_H__ 18 + 19 + extern const struct v4l2_ioctl_ops uvc_v4l2_ioctl_ops; 20 + extern struct v4l2_file_operations uvc_v4l2_fops; 21 + 22 + #endif /* __UVC_V4L2_H__ */
+23 -25
drivers/usb/gadget/function/uvc_video.c
··· 15 15 #include <linux/errno.h> 16 16 #include <linux/usb/ch9.h> 17 17 #include <linux/usb/gadget.h> 18 + #include <linux/usb/video.h> 18 19 19 20 #include <media/v4l2-dev.h> 20 21 ··· 86 85 if (buf->bytesused == video->queue.buf_used) { 87 86 video->queue.buf_used = 0; 88 87 buf->state = UVC_BUF_STATE_DONE; 89 - uvc_queue_next_buffer(&video->queue, buf); 88 + uvcg_queue_next_buffer(&video->queue, buf); 90 89 video->fid ^= UVC_STREAM_FID; 91 90 92 91 video->payload_size = 0; ··· 119 118 if (buf->bytesused == video->queue.buf_used) { 120 119 video->queue.buf_used = 0; 121 120 buf->state = UVC_BUF_STATE_DONE; 122 - uvc_queue_next_buffer(&video->queue, buf); 121 + uvcg_queue_next_buffer(&video->queue, buf); 123 122 video->fid ^= UVC_STREAM_FID; 124 123 } 125 124 } ··· 172 171 break; 173 172 174 173 case -ESHUTDOWN: /* disconnect from host. */ 175 - printk(KERN_INFO "VS request cancelled.\n"); 176 - uvc_queue_cancel(queue, 1); 174 + printk(KERN_DEBUG "VS request cancelled.\n"); 175 + uvcg_queue_cancel(queue, 1); 177 176 goto requeue; 178 177 179 178 default: 180 179 printk(KERN_INFO "VS request completed with status %d.\n", 181 180 req->status); 182 - uvc_queue_cancel(queue, 0); 181 + uvcg_queue_cancel(queue, 0); 183 182 goto requeue; 184 183 } 185 184 186 185 spin_lock_irqsave(&video->queue.irqlock, flags); 187 - buf = uvc_queue_head(&video->queue); 186 + buf = uvcg_queue_head(&video->queue); 188 187 if (buf == NULL) { 189 188 spin_unlock_irqrestore(&video->queue.irqlock, flags); 190 189 goto requeue; ··· 196 195 printk(KERN_INFO "Failed to queue request (%d).\n", ret); 197 196 usb_ep_set_halt(ep); 198 197 spin_unlock_irqrestore(&video->queue.irqlock, flags); 199 - uvc_queue_cancel(queue, 0); 198 + uvcg_queue_cancel(queue, 0); 200 199 goto requeue; 201 200 } 202 201 spin_unlock_irqrestore(&video->queue.irqlock, flags); ··· 275 274 */ 276 275 277 276 /* 278 - * uvc_video_pump - Pump video data into the USB requests 277 + * uvcg_video_pump - Pump video data into the USB requests 279 278 * 280 279 * This function fills the available USB requests (listed in req_free) with 281 280 * video data from the queued buffers. 282 281 */ 283 - static int 284 - uvc_video_pump(struct uvc_video *video) 282 + int uvcg_video_pump(struct uvc_video *video) 285 283 { 286 284 struct uvc_video_queue *queue = &video->queue; 287 285 struct usb_request *req; ··· 288 288 unsigned long flags; 289 289 int ret; 290 290 291 - /* FIXME TODO Race between uvc_video_pump and requests completion 291 + /* FIXME TODO Race between uvcg_video_pump and requests completion 292 292 * handler ??? 293 293 */ 294 294 ··· 309 309 /* Retrieve the first available video buffer and fill the 310 310 * request, protected by the video queue irqlock. 311 311 */ 312 - spin_lock_irqsave(&video->queue.irqlock, flags); 313 - buf = uvc_queue_head(&video->queue); 312 + spin_lock_irqsave(&queue->irqlock, flags); 313 + buf = uvcg_queue_head(queue); 314 314 if (buf == NULL) { 315 - spin_unlock_irqrestore(&video->queue.irqlock, flags); 315 + spin_unlock_irqrestore(&queue->irqlock, flags); 316 316 break; 317 317 } 318 318 ··· 323 323 if (ret < 0) { 324 324 printk(KERN_INFO "Failed to queue request (%d)\n", ret); 325 325 usb_ep_set_halt(video->ep); 326 - spin_unlock_irqrestore(&video->queue.irqlock, flags); 327 - uvc_queue_cancel(queue, 0); 326 + spin_unlock_irqrestore(&queue->irqlock, flags); 327 + uvcg_queue_cancel(queue, 0); 328 328 break; 329 329 } 330 - spin_unlock_irqrestore(&video->queue.irqlock, flags); 330 + spin_unlock_irqrestore(&queue->irqlock, flags); 331 331 } 332 332 333 333 spin_lock_irqsave(&video->req_lock, flags); ··· 339 339 /* 340 340 * Enable or disable the video stream. 341 341 */ 342 - static int 343 - uvc_video_enable(struct uvc_video *video, int enable) 342 + int uvcg_video_enable(struct uvc_video *video, int enable) 344 343 { 345 344 unsigned int i; 346 345 int ret; ··· 355 356 usb_ep_dequeue(video->ep, video->req[i]); 356 357 357 358 uvc_video_free_requests(video); 358 - uvc_queue_enable(&video->queue, 0); 359 + uvcg_queue_enable(&video->queue, 0); 359 360 return 0; 360 361 } 361 362 362 - if ((ret = uvc_queue_enable(&video->queue, 1)) < 0) 363 + if ((ret = uvcg_queue_enable(&video->queue, 1)) < 0) 363 364 return ret; 364 365 365 366 if ((ret = uvc_video_alloc_requests(video)) < 0) ··· 371 372 } else 372 373 video->encode = uvc_video_encode_isoc; 373 374 374 - return uvc_video_pump(video); 375 + return uvcg_video_pump(video); 375 376 } 376 377 377 378 /* 378 379 * Initialize the UVC video stream. 379 380 */ 380 - static int 381 - uvc_video_init(struct uvc_video *video) 381 + int uvcg_video_init(struct uvc_video *video) 382 382 { 383 383 INIT_LIST_HEAD(&video->req_free); 384 384 spin_lock_init(&video->req_lock); ··· 389 391 video->imagesize = 320 * 240 * 2; 390 392 391 393 /* Initialize the video buffers queue. */ 392 - uvc_queue_init(&video->queue, V4L2_BUF_TYPE_VIDEO_OUTPUT); 394 + uvcg_queue_init(&video->queue, V4L2_BUF_TYPE_VIDEO_OUTPUT); 393 395 return 0; 394 396 } 395 397
+24
drivers/usb/gadget/function/uvc_video.h
··· 1 + /* 2 + * uvc_video.h -- USB Video Class Gadget driver 3 + * 4 + * Copyright (C) 2009-2010 5 + * Laurent Pinchart (laurent.pinchart@ideasonboard.com) 6 + * 7 + * Copyright (c) 2013 Samsung Electronics Co., Ltd. 8 + * http://www.samsung.com 9 + * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com> 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + */ 15 + #ifndef __UVC_VIDEO_H__ 16 + #define __UVC_VIDEO_H__ 17 + 18 + int uvcg_video_pump(struct uvc_video *video); 19 + 20 + int uvcg_video_enable(struct uvc_video *video, int enable); 21 + 22 + int uvcg_video_init(struct uvc_video *video); 23 + 24 + #endif /* __UVC_VIDEO_H__ */
+3
drivers/usb/gadget/legacy/Kconfig
··· 54 54 depends on SND 55 55 select USB_LIBCOMPOSITE 56 56 select SND_PCM 57 + select USB_F_UAC1 if GADGET_UAC1 58 + select USB_F_UAC2 if !GADGET_UAC1 57 59 help 58 60 This Gadget Audio driver is compatible with USB Audio Class 59 61 specification 2.0. It implements 1 AudioControl interface, ··· 468 466 depends on VIDEO_DEV 469 467 select USB_LIBCOMPOSITE 470 468 select VIDEOBUF2_VMALLOC 469 + select USB_F_UVC 471 470 help 472 471 The Webcam Gadget acts as a composite USB Audio and Video Class 473 472 device. It provides a userspace API to process UVC control requests
+3 -3
drivers/usb/gadget/legacy/Makefile
··· 2 2 # USB gadget drivers 3 3 # 4 4 5 - ccflags-y := -Idrivers/usb/gadget/ 6 - ccflags-y += -Idrivers/usb/gadget/udc/ 7 - ccflags-y += -Idrivers/usb/gadget/function/ 5 + ccflags-y := -I$(srctree)/drivers/usb/gadget/ 6 + ccflags-y += -I$(srctree)/drivers/usb/gadget/udc/ 7 + ccflags-y += -I$(srctree)/drivers/usb/gadget/function/ 8 8 9 9 g_zero-y := zero.o 10 10 g_audio-y := audio.o
+139 -10
drivers/usb/gadget/legacy/audio.c
··· 21 21 22 22 USB_GADGET_COMPOSITE_OPTIONS(); 23 23 24 + #ifndef CONFIG_GADGET_UAC1 25 + #include "u_uac2.h" 26 + 27 + /* Playback(USB-IN) Default Stereo - Fl/Fr */ 28 + static int p_chmask = UAC2_DEF_PCHMASK; 29 + module_param(p_chmask, uint, S_IRUGO); 30 + MODULE_PARM_DESC(p_chmask, "Playback Channel Mask"); 31 + 32 + /* Playback Default 48 KHz */ 33 + static int p_srate = UAC2_DEF_PSRATE; 34 + module_param(p_srate, uint, S_IRUGO); 35 + MODULE_PARM_DESC(p_srate, "Playback Sampling Rate"); 36 + 37 + /* Playback Default 16bits/sample */ 38 + static int p_ssize = UAC2_DEF_PSSIZE; 39 + module_param(p_ssize, uint, S_IRUGO); 40 + MODULE_PARM_DESC(p_ssize, "Playback Sample Size(bytes)"); 41 + 42 + /* Capture(USB-OUT) Default Stereo - Fl/Fr */ 43 + static int c_chmask = UAC2_DEF_CCHMASK; 44 + module_param(c_chmask, uint, S_IRUGO); 45 + MODULE_PARM_DESC(c_chmask, "Capture Channel Mask"); 46 + 47 + /* Capture Default 64 KHz */ 48 + static int c_srate = UAC2_DEF_CSRATE; 49 + module_param(c_srate, uint, S_IRUGO); 50 + MODULE_PARM_DESC(c_srate, "Capture Sampling Rate"); 51 + 52 + /* Capture Default 16bits/sample */ 53 + static int c_ssize = UAC2_DEF_CSSIZE; 54 + module_param(c_ssize, uint, S_IRUGO); 55 + MODULE_PARM_DESC(c_ssize, "Capture Sample Size(bytes)"); 56 + #else 57 + #include "u_uac1.h" 58 + 59 + static char *fn_play = FILE_PCM_PLAYBACK; 60 + module_param(fn_play, charp, S_IRUGO); 61 + MODULE_PARM_DESC(fn_play, "Playback PCM device file name"); 62 + 63 + static char *fn_cap = FILE_PCM_CAPTURE; 64 + module_param(fn_cap, charp, S_IRUGO); 65 + MODULE_PARM_DESC(fn_cap, "Capture PCM device file name"); 66 + 67 + static char *fn_cntl = FILE_CONTROL; 68 + module_param(fn_cntl, charp, S_IRUGO); 69 + MODULE_PARM_DESC(fn_cntl, "Control device file name"); 70 + 71 + static int req_buf_size = UAC1_OUT_EP_MAX_PACKET_SIZE; 72 + module_param(req_buf_size, int, S_IRUGO); 73 + MODULE_PARM_DESC(req_buf_size, "ISO OUT endpoint request buffer size"); 74 + 75 + static int req_count = UAC1_REQ_COUNT; 76 + module_param(req_count, int, S_IRUGO); 77 + MODULE_PARM_DESC(req_count, "ISO OUT endpoint request count"); 78 + 79 + static int audio_buf_size = UAC1_AUDIO_BUF_SIZE; 80 + module_param(audio_buf_size, int, S_IRUGO); 81 + MODULE_PARM_DESC(audio_buf_size, "Audio buffer size"); 82 + #endif 83 + 24 84 /* string IDs are assigned dynamically */ 25 85 26 86 static struct usb_string strings_dev[] = { ··· 100 40 NULL, 101 41 }; 102 42 103 - #ifdef CONFIG_GADGET_UAC1 104 - #include "u_uac1.h" 105 - #include "u_uac1.c" 106 - #include "f_uac1.c" 43 + #ifndef CONFIG_GADGET_UAC1 44 + static struct usb_function_instance *fi_uac2; 45 + static struct usb_function *f_uac2; 107 46 #else 108 - #include "f_uac2.c" 47 + static struct usb_function_instance *fi_uac1; 48 + static struct usb_function *f_uac1; 109 49 #endif 110 50 111 51 /*-------------------------------------------------------------------------*/ ··· 169 109 170 110 static int __init audio_do_config(struct usb_configuration *c) 171 111 { 112 + int status; 113 + 172 114 /* FIXME alloc iConfiguration string, set it in c->strings */ 173 115 174 116 if (gadget_is_otg(c->cdev->gadget)) { ··· 178 116 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 179 117 } 180 118 181 - audio_bind_config(c); 119 + #ifdef CONFIG_GADGET_UAC1 120 + f_uac1 = usb_get_function(fi_uac1); 121 + if (IS_ERR(f_uac1)) { 122 + status = PTR_ERR(f_uac1); 123 + return status; 124 + } 125 + 126 + status = usb_add_function(c, f_uac1); 127 + if (status < 0) { 128 + usb_put_function(f_uac1); 129 + return status; 130 + } 131 + #else 132 + f_uac2 = usb_get_function(fi_uac2); 133 + if (IS_ERR(f_uac2)) { 134 + status = PTR_ERR(f_uac2); 135 + return status; 136 + } 137 + 138 + status = usb_add_function(c, f_uac2); 139 + if (status < 0) { 140 + usb_put_function(f_uac2); 141 + return status; 142 + } 143 + #endif 182 144 183 145 return 0; 184 146 } ··· 212 126 .bConfigurationValue = 1, 213 127 /* .iConfiguration = DYNAMIC */ 214 128 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 215 - #ifndef CONFIG_GADGET_UAC1 216 - .unbind = uac2_unbind_config, 217 - #endif 218 129 }; 219 130 220 131 /*-------------------------------------------------------------------------*/ 221 132 222 133 static int __init audio_bind(struct usb_composite_dev *cdev) 223 134 { 135 + #ifndef CONFIG_GADGET_UAC1 136 + struct f_uac2_opts *uac2_opts; 137 + #else 138 + struct f_uac1_opts *uac1_opts; 139 + #endif 224 140 int status; 141 + 142 + #ifndef CONFIG_GADGET_UAC1 143 + fi_uac2 = usb_get_function_instance("uac2"); 144 + if (IS_ERR(fi_uac2)) 145 + return PTR_ERR(fi_uac2); 146 + #else 147 + fi_uac1 = usb_get_function_instance("uac1"); 148 + if (IS_ERR(fi_uac1)) 149 + return PTR_ERR(fi_uac1); 150 + #endif 151 + 152 + #ifndef CONFIG_GADGET_UAC1 153 + uac2_opts = container_of(fi_uac2, struct f_uac2_opts, func_inst); 154 + uac2_opts->p_chmask = p_chmask; 155 + uac2_opts->p_srate = p_srate; 156 + uac2_opts->p_ssize = p_ssize; 157 + uac2_opts->c_chmask = c_chmask; 158 + uac2_opts->c_srate = c_srate; 159 + uac2_opts->c_ssize = c_ssize; 160 + #else 161 + uac1_opts = container_of(fi_uac1, struct f_uac1_opts, func_inst); 162 + uac1_opts->fn_play = fn_play; 163 + uac1_opts->fn_cap = fn_cap; 164 + uac1_opts->fn_cntl = fn_cntl; 165 + uac1_opts->req_buf_size = req_buf_size; 166 + uac1_opts->req_count = req_count; 167 + uac1_opts->audio_buf_size = audio_buf_size; 168 + #endif 225 169 226 170 status = usb_string_ids_tab(cdev, strings_dev); 227 171 if (status < 0) ··· 268 152 return 0; 269 153 270 154 fail: 155 + #ifndef CONFIG_GADGET_UAC1 156 + usb_put_function_instance(fi_uac2); 157 + #else 158 + usb_put_function_instance(fi_uac1); 159 + #endif 271 160 return status; 272 161 } 273 162 274 163 static int __exit audio_unbind(struct usb_composite_dev *cdev) 275 164 { 276 165 #ifdef CONFIG_GADGET_UAC1 277 - gaudio_cleanup(); 166 + if (!IS_ERR_OR_NULL(f_uac1)) 167 + usb_put_function(f_uac1); 168 + if (!IS_ERR_OR_NULL(fi_uac1)) 169 + usb_put_function_instance(fi_uac1); 170 + #else 171 + if (!IS_ERR_OR_NULL(f_uac2)) 172 + usb_put_function(f_uac2); 173 + if (!IS_ERR_OR_NULL(fi_uac2)) 174 + usb_put_function_instance(fi_uac2); 278 175 #endif 279 176 return 0; 280 177 }
+1
drivers/usb/gadget/legacy/dbgp.c
··· 410 410 .bind = dbgp_bind, 411 411 .unbind = dbgp_unbind, 412 412 .setup = dbgp_setup, 413 + .reset = dbgp_disconnect, 413 414 .disconnect = dbgp_disconnect, 414 415 .driver = { 415 416 .owner = THIS_MODULE,
+1
drivers/usb/gadget/legacy/inode.c
··· 1775 1775 .bind = gadgetfs_bind, 1776 1776 .unbind = gadgetfs_unbind, 1777 1777 .setup = gadgetfs_setup, 1778 + .reset = gadgetfs_disconnect, 1778 1779 .disconnect = gadgetfs_disconnect, 1779 1780 .suspend = gadgetfs_suspend, 1780 1781
+58 -17
drivers/usb/gadget/legacy/webcam.c
··· 12 12 13 13 #include <linux/kernel.h> 14 14 #include <linux/device.h> 15 + #include <linux/module.h> 15 16 #include <linux/usb/video.h> 16 17 17 - #include "f_uvc.h" 18 - 19 - /* 20 - * Kbuild is not very cooperative with respect to linking separately 21 - * compiled library objects into one module. So for now we won't use 22 - * separate compilation ... ensuring init/exit sections work to shrink 23 - * the runtime footprint, and giving us at least some parts of what 24 - * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 25 - */ 26 - #include "uvc_queue.c" 27 - #include "uvc_video.c" 28 - #include "uvc_v4l2.c" 29 - #include "f_uvc.c" 18 + #include "u_uvc.h" 30 19 31 20 USB_GADGET_COMPOSITE_OPTIONS(); 21 + 22 + /*-------------------------------------------------------------------------*/ 23 + 24 + /* module parameters specific to the Video streaming endpoint */ 25 + static unsigned int streaming_interval = 1; 26 + module_param(streaming_interval, uint, S_IRUGO|S_IWUSR); 27 + MODULE_PARM_DESC(streaming_interval, "1 - 16"); 28 + 29 + static unsigned int streaming_maxpacket = 1024; 30 + module_param(streaming_maxpacket, uint, S_IRUGO|S_IWUSR); 31 + MODULE_PARM_DESC(streaming_maxpacket, "1 - 1023 (FS), 1 - 3072 (hs/ss)"); 32 + 33 + static unsigned int streaming_maxburst; 34 + module_param(streaming_maxburst, uint, S_IRUGO|S_IWUSR); 35 + MODULE_PARM_DESC(streaming_maxburst, "0 - 15 (ss only)"); 36 + 37 + static unsigned int trace; 38 + module_param(trace, uint, S_IRUGO|S_IWUSR); 39 + MODULE_PARM_DESC(trace, "Trace level bitmask"); 32 40 /* -------------------------------------------------------------------------- 33 41 * Device descriptor 34 42 */ ··· 70 62 &webcam_stringtab, 71 63 NULL, 72 64 }; 65 + 66 + static struct usb_function_instance *fi_uvc; 67 + static struct usb_function *f_uvc; 73 68 74 69 static struct usb_device_descriptor webcam_device_descriptor = { 75 70 .bLength = USB_DT_DEVICE_SIZE, ··· 337 326 static int __init 338 327 webcam_config_bind(struct usb_configuration *c) 339 328 { 340 - return uvc_bind_config(c, uvc_fs_control_cls, uvc_ss_control_cls, 341 - uvc_fs_streaming_cls, uvc_hs_streaming_cls, 342 - uvc_ss_streaming_cls); 329 + int status = 0; 330 + 331 + f_uvc = usb_get_function(fi_uvc); 332 + if (IS_ERR(f_uvc)) 333 + return PTR_ERR(f_uvc); 334 + 335 + status = usb_add_function(c, f_uvc); 336 + if (status < 0) 337 + usb_put_function(f_uvc); 338 + 339 + return status; 343 340 } 344 341 345 342 static struct usb_configuration webcam_config_driver = { ··· 361 342 static int /* __init_or_exit */ 362 343 webcam_unbind(struct usb_composite_dev *cdev) 363 344 { 345 + if (!IS_ERR_OR_NULL(f_uvc)) 346 + usb_put_function(f_uvc); 347 + if (!IS_ERR_OR_NULL(fi_uvc)) 348 + usb_put_function_instance(fi_uvc); 364 349 return 0; 365 350 } 366 351 367 352 static int __init 368 353 webcam_bind(struct usb_composite_dev *cdev) 369 354 { 355 + struct f_uvc_opts *uvc_opts; 370 356 int ret; 357 + 358 + fi_uvc = usb_get_function_instance("uvc"); 359 + if (IS_ERR(fi_uvc)) 360 + return PTR_ERR(fi_uvc); 361 + 362 + uvc_opts = container_of(fi_uvc, struct f_uvc_opts, func_inst); 363 + 364 + uvc_opts->streaming_interval = streaming_interval; 365 + uvc_opts->streaming_maxpacket = streaming_maxpacket; 366 + uvc_opts->streaming_maxburst = streaming_maxburst; 367 + uvc_set_trace_param(trace); 368 + 369 + uvc_opts->fs_control = uvc_fs_control_cls; 370 + uvc_opts->ss_control = uvc_ss_control_cls; 371 + uvc_opts->fs_streaming = uvc_fs_streaming_cls; 372 + uvc_opts->hs_streaming = uvc_hs_streaming_cls; 373 + uvc_opts->ss_streaming = uvc_ss_streaming_cls; 371 374 372 375 /* Allocate string descriptor numbers ... note that string contents 373 376 * can be overridden by the composite_dev glue. ··· 414 373 return 0; 415 374 416 375 error: 417 - webcam_unbind(cdev); 376 + usb_put_function_instance(fi_uvc); 418 377 return ret; 419 378 } 420 379
+21
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 + .int_interval = GZERO_INT_INTERVAL, 72 + .int_maxpacket = GZERO_INT_MAXPACKET, 71 73 }; 72 74 73 75 /*-------------------------------------------------------------------------*/ ··· 268 266 S_IRUGO|S_IWUSR); 269 267 MODULE_PARM_DESC(isoc_maxburst, "0 - 15 (ss only)"); 270 268 269 + module_param_named(int_interval, gzero_options.int_interval, uint, 270 + S_IRUGO|S_IWUSR); 271 + MODULE_PARM_DESC(int_interval, "1 - 16"); 272 + 273 + module_param_named(int_maxpacket, gzero_options.int_maxpacket, uint, 274 + S_IRUGO|S_IWUSR); 275 + MODULE_PARM_DESC(int_maxpacket, "0 - 1023 (fs), 0 - 1024 (hs/ss)"); 276 + 277 + module_param_named(int_mult, gzero_options.int_mult, uint, S_IRUGO|S_IWUSR); 278 + MODULE_PARM_DESC(int_mult, "0 - 2 (hs/ss only)"); 279 + 280 + module_param_named(int_maxburst, gzero_options.int_maxburst, uint, 281 + S_IRUGO|S_IWUSR); 282 + MODULE_PARM_DESC(int_maxburst, "0 - 15 (ss only)"); 283 + 271 284 static struct usb_function *func_lb; 272 285 static struct usb_function_instance *func_inst_lb; 273 286 ··· 318 301 ss_opts->isoc_maxpacket = gzero_options.isoc_maxpacket; 319 302 ss_opts->isoc_mult = gzero_options.isoc_mult; 320 303 ss_opts->isoc_maxburst = gzero_options.isoc_maxburst; 304 + ss_opts->int_interval = gzero_options.int_interval; 305 + ss_opts->int_maxpacket = gzero_options.int_maxpacket; 306 + ss_opts->int_mult = gzero_options.int_mult; 307 + ss_opts->int_maxburst = gzero_options.int_maxburst; 321 308 ss_opts->bulk_buflen = gzero_options.bulk_buflen; 322 309 323 310 func_ss = usb_get_function(func_inst_ss);
+16 -1
drivers/usb/gadget/udc/Kconfig
··· 163 163 164 164 config USB_RENESAS_USBHS_UDC 165 165 tristate 'Renesas USBHS controller' 166 - depends on USB_RENESAS_USBHS 166 + depends on USB_RENESAS_USBHS && HAS_DMA 167 167 help 168 168 Renesas USBHS is a discrete USB host and peripheral controller chip 169 169 that supports both full and high speed USB 2.0 data transfers. ··· 354 354 ML7213/ML7831 is completely compatible for Intel EG20T PCH. 355 355 356 356 This driver can be used with Intel's Quark X1000 SOC platform 357 + 358 + config USB_GADGET_XILINX 359 + tristate "Xilinx USB Driver" 360 + depends on OF || COMPILE_TEST 361 + help 362 + USB peripheral controller driver for Xilinx USB2 device. 363 + Xilinx USB2 device is a soft IP which supports both full 364 + and high speed USB 2.0 data transfers. It has seven configurable 365 + endpoints(bulk or interrupt or isochronous), as well as 366 + endpoint zero(for control transfers). 367 + 368 + Say "y" to link the driver statically, or "m" to build a 369 + dynamically linked module called "udc-xilinx" and force all 370 + gadget drivers to also be dynamically linked. 371 + 357 372 # 358 373 # LAST -- dummy/emulated controller 359 374 #
+1
drivers/usb/gadget/udc/Makefile
··· 29 29 obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o 30 30 obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o 31 31 obj-$(CONFIG_USB_GR_UDC) += gr_udc.o 32 + obj-$(CONFIG_USB_GADGET_XILINX) += udc-xilinx.o
+60 -21
drivers/usb/gadget/udc/gr_udc.c
··· 318 318 usb_gadget_unmap_request(&dev->gadget, &req->req, ep->is_in); 319 319 gr_free_dma_desc_chain(dev, req); 320 320 321 - if (ep->is_in) /* For OUT, actual gets updated bit by bit */ 321 + if (ep->is_in) { /* For OUT, req->req.actual gets updated bit by bit */ 322 322 req->req.actual = req->req.length; 323 + } else if (req->oddlen && req->req.actual > req->evenlen) { 324 + /* 325 + * Copy to user buffer in this case where length was not evenly 326 + * divisible by ep->ep.maxpacket and the last descriptor was 327 + * actually used. 328 + */ 329 + char *buftail = ((char *)req->req.buf + req->evenlen); 330 + 331 + memcpy(buftail, ep->tailbuf, req->oddlen); 332 + 333 + if (req->req.actual > req->req.length) { 334 + /* We got more data than was requested */ 335 + dev_dbg(ep->dev->dev, "Overflow for ep %s\n", 336 + ep->ep.name); 337 + gr_dbgprint_request("OVFL", ep, req); 338 + req->req.status = -EOVERFLOW; 339 + } 340 + } 323 341 324 342 if (!status) { 325 343 if (ep->is_in) ··· 396 378 397 379 /* A descriptor should already have been allocated */ 398 380 BUG_ON(!req->curr_desc); 381 + 382 + /* 383 + * The DMA controller can not handle smaller OUT buffers than 384 + * ep->ep.maxpacket. It could lead to buffer overruns if an unexpectedly 385 + * long packet are received. Therefore an internal bounce buffer gets 386 + * used when such a request gets enabled. 387 + */ 388 + if (!ep->is_in && req->oddlen) 389 + req->last_desc->data = ep->tailbuf_paddr; 399 390 400 391 wmb(); /* Make sure all is settled before handing it over to DMA */ 401 392 ··· 507 480 dma_addr_t start = req->req.dma + bytes_used; 508 481 u16 size = min(bytes_left, ep->bytes_per_buffer); 509 482 510 - /* Should not happen however - gr_queue stops such lengths */ 511 - if (size < ep->bytes_per_buffer) 512 - dev_warn(ep->dev->dev, 513 - "Buffer overrun risk: %u < %u bytes/buffer\n", 514 - size, ep->bytes_per_buffer); 483 + if (size < ep->bytes_per_buffer) { 484 + /* Prepare using bounce buffer */ 485 + req->evenlen = req->req.length - bytes_left; 486 + req->oddlen = size; 487 + } 515 488 516 489 ret = gr_add_dma_desc(ep, req, start, size, gfp_flags); 517 490 if (ret) ··· 609 582 "Invalid request for %s: buf=%p list_empty=%d\n", 610 583 ep->ep.name, req->req.buf, list_empty(&req->queue)); 611 584 return -EINVAL; 612 - } 613 - 614 - /* 615 - * The DMA controller can not handle smaller OUT buffers than 616 - * maxpacket. It could lead to buffer overruns if unexpectedly long 617 - * packet are received. 618 - */ 619 - if (!ep->is_in && (req->req.length % ep->ep.maxpacket) != 0) { 620 - dev_err(dev->dev, 621 - "OUT request length %d is not multiple of maxpacket\n", 622 - req->req.length); 623 - return -EMSGSIZE; 624 585 } 625 586 626 587 if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) { ··· 1301 1286 if (ctrl & GR_DESC_OUT_CTRL_SE) 1302 1287 req->setup = 1; 1303 1288 1304 - if (len < ep->ep.maxpacket || req->req.actual == req->req.length) { 1305 - /* Short packet or the expected size - we are done */ 1289 + if (len < ep->ep.maxpacket || req->req.actual >= req->req.length) { 1290 + /* Short packet or >= expected size - we are done */ 1306 1291 1307 1292 if ((ep == &dev->epo[0]) && (dev->ep0state == GR_EP0_OSTATUS)) { 1308 1293 /* ··· 2030 2015 } 2031 2016 list_add_tail(&ep->ep_list, &dev->ep_list); 2032 2017 2018 + ep->tailbuf = dma_alloc_coherent(dev->dev, ep->ep.maxpacket_limit, 2019 + &ep->tailbuf_paddr, GFP_ATOMIC); 2020 + if (!ep->tailbuf) 2021 + return -ENOMEM; 2022 + 2033 2023 return 0; 2034 2024 } 2035 2025 ··· 2087 2067 return 0; 2088 2068 } 2089 2069 2070 + static void gr_ep_remove(struct gr_udc *dev, int num, int is_in) 2071 + { 2072 + struct gr_ep *ep; 2073 + 2074 + if (is_in) 2075 + ep = &dev->epi[num]; 2076 + else 2077 + ep = &dev->epo[num]; 2078 + 2079 + if (ep->tailbuf) 2080 + dma_free_coherent(dev->dev, ep->ep.maxpacket_limit, 2081 + ep->tailbuf, ep->tailbuf_paddr); 2082 + } 2083 + 2090 2084 static int gr_remove(struct platform_device *pdev) 2091 2085 { 2092 2086 struct gr_udc *dev = platform_get_drvdata(pdev); 2087 + int i; 2093 2088 2094 2089 if (dev->added) 2095 2090 usb_del_gadget_udc(&dev->gadget); /* Shuts everything down */ ··· 2118 2083 2119 2084 gr_free_request(&dev->epi[0].ep, &dev->ep0reqi->req); 2120 2085 gr_free_request(&dev->epo[0].ep, &dev->ep0reqo->req); 2086 + 2087 + for (i = 0; i < dev->nepo; i++) 2088 + gr_ep_remove(dev, i, 0); 2089 + for (i = 0; i < dev->nepi; i++) 2090 + gr_ep_remove(dev, i, 1); 2121 2091 2122 2092 return 0; 2123 2093 } ··· 2171 2131 dev->gadget.name = driver_name; 2172 2132 dev->gadget.max_speed = USB_SPEED_HIGH; 2173 2133 dev->gadget.ops = &gr_ops; 2174 - dev->gadget.quirk_ep_out_aligned_size = true; 2175 2134 2176 2135 spin_lock_init(&dev->lock); 2177 2136 dev->regs = regs;
+7
drivers/usb/gadget/udc/gr_udc.h
··· 156 156 struct list_head queue; 157 157 158 158 struct list_head ep_list; 159 + 160 + /* Bounce buffer for end of "odd" sized OUT requests */ 161 + void *tailbuf; 162 + dma_addr_t tailbuf_paddr; 159 163 }; 160 164 161 165 struct gr_request { ··· 170 166 struct gr_dma_desc *first_desc; /* First in the chain */ 171 167 struct gr_dma_desc *curr_desc; /* Current descriptor */ 172 168 struct gr_dma_desc *last_desc; /* Last in the chain */ 169 + 170 + u16 evenlen; /* Size of even length head (if oddlen != 0) */ 171 + u16 oddlen; /* Size of odd length tail if buffer length is "odd" */ 173 172 174 173 u8 setup; /* Setup packet */ 175 174 };
+4 -6
drivers/usb/gadget/udc/r8a66597-udc.c
··· 430 430 ep->pipenum = pipenum; 431 431 ep->ep.maxpacket = usb_endpoint_maxp(desc); 432 432 r8a66597->pipenum2ep[pipenum] = ep; 433 - r8a66597->epaddr2ep[desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK] 433 + r8a66597->epaddr2ep[usb_endpoint_num(desc)] 434 434 = ep; 435 435 INIT_LIST_HEAD(&ep->queue); 436 436 } ··· 464 464 if (ep->pipenum) /* already allocated pipe */ 465 465 return 0; 466 466 467 - switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { 467 + switch (usb_endpoint_type(desc)) { 468 468 case USB_ENDPOINT_XFER_BULK: 469 469 if (r8a66597->bulk >= R8A66597_MAX_NUM_BULK) { 470 470 if (r8a66597->isochronous >= R8A66597_MAX_NUM_ISOC) { ··· 509 509 } 510 510 ep->type = info.type; 511 511 512 - info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; 512 + info.epnum = usb_endpoint_num(desc); 513 513 info.maxpacket = usb_endpoint_maxp(desc); 514 514 info.interval = desc->bInterval; 515 515 if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ··· 1846 1846 1847 1847 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sudmac"); 1848 1848 r8a66597->sudmac_reg = devm_ioremap_resource(&pdev->dev, res); 1849 - if (IS_ERR(r8a66597->sudmac_reg)) { 1850 - dev_err(&pdev->dev, "ioremap error(sudmac).\n"); 1849 + if (IS_ERR(r8a66597->sudmac_reg)) 1851 1850 return PTR_ERR(r8a66597->sudmac_reg); 1852 - } 1853 1851 1854 1852 return 0; 1855 1853 }
+30 -1
drivers/usb/gadget/udc/udc-core.c
··· 109 109 static void usb_gadget_state_work(struct work_struct *work) 110 110 { 111 111 struct usb_gadget *gadget = work_to_gadget(work); 112 + struct usb_udc *udc = NULL; 112 113 113 - sysfs_notify(&gadget->dev.kobj, NULL, "state"); 114 + mutex_lock(&udc_lock); 115 + list_for_each_entry(udc, &udc_list, list) 116 + if (udc->gadget == gadget) 117 + goto found; 118 + mutex_unlock(&udc_lock); 119 + 120 + return; 121 + 122 + found: 123 + mutex_unlock(&udc_lock); 124 + 125 + sysfs_notify(&udc->dev.kobj, NULL, "state"); 114 126 } 115 127 116 128 void usb_gadget_set_state(struct usb_gadget *gadget, ··· 134 122 EXPORT_SYMBOL_GPL(usb_gadget_set_state); 135 123 136 124 /* ------------------------------------------------------------------------- */ 125 + 126 + /** 127 + * usb_gadget_udc_reset - notifies the udc core that bus reset occurs 128 + * @gadget: The gadget which bus reset occurs 129 + * @driver: The gadget driver we want to notify 130 + * 131 + * If the udc driver has bus reset handler, it needs to call this when the bus 132 + * reset occurs, it notifies the gadget driver that the bus reset occurs as 133 + * well as updates gadget state. 134 + */ 135 + void usb_gadget_udc_reset(struct usb_gadget *gadget, 136 + struct usb_gadget_driver *driver) 137 + { 138 + driver->reset(gadget); 139 + usb_gadget_set_state(gadget, USB_STATE_DEFAULT); 140 + } 141 + EXPORT_SYMBOL_GPL(usb_gadget_udc_reset); 137 142 138 143 /** 139 144 * usb_gadget_udc_start - tells usb device controller to start up
+2180
drivers/usb/gadget/udc/udc-xilinx.c
··· 1 + /* 2 + * Xilinx USB peripheral controller driver 3 + * 4 + * Copyright (C) 2004 by Thomas Rathbone 5 + * Copyright (C) 2005 by HP Labs 6 + * Copyright (C) 2005 by David Brownell 7 + * Copyright (C) 2010 - 2014 Xilinx, Inc. 8 + * 9 + * Some parts of this driver code is based on the driver for at91-series 10 + * USB peripheral controller (at91_udc.c). 11 + * 12 + * This program is free software; you can redistribute it 13 + * and/or modify it under the terms of the GNU General Public 14 + * License as published by the Free Software Foundation; 15 + * either version 2 of the License, or (at your option) any 16 + * later version. 17 + */ 18 + 19 + #include <linux/delay.h> 20 + #include <linux/device.h> 21 + #include <linux/dma-mapping.h> 22 + #include <linux/interrupt.h> 23 + #include <linux/io.h> 24 + #include <linux/module.h> 25 + #include <linux/of_address.h> 26 + #include <linux/of_device.h> 27 + #include <linux/of_platform.h> 28 + #include <linux/of_irq.h> 29 + #include <linux/prefetch.h> 30 + #include <linux/usb/ch9.h> 31 + #include <linux/usb/gadget.h> 32 + 33 + /* Register offsets for the USB device.*/ 34 + #define XUSB_EP0_CONFIG_OFFSET 0x0000 /* EP0 Config Reg Offset */ 35 + #define XUSB_SETUP_PKT_ADDR_OFFSET 0x0080 /* Setup Packet Address */ 36 + #define XUSB_ADDRESS_OFFSET 0x0100 /* Address Register */ 37 + #define XUSB_CONTROL_OFFSET 0x0104 /* Control Register */ 38 + #define XUSB_STATUS_OFFSET 0x0108 /* Status Register */ 39 + #define XUSB_FRAMENUM_OFFSET 0x010C /* Frame Number Register */ 40 + #define XUSB_IER_OFFSET 0x0110 /* Interrupt Enable Register */ 41 + #define XUSB_BUFFREADY_OFFSET 0x0114 /* Buffer Ready Register */ 42 + #define XUSB_TESTMODE_OFFSET 0x0118 /* Test Mode Register */ 43 + #define XUSB_DMA_RESET_OFFSET 0x0200 /* DMA Soft Reset Register */ 44 + #define XUSB_DMA_CONTROL_OFFSET 0x0204 /* DMA Control Register */ 45 + #define XUSB_DMA_DSAR_ADDR_OFFSET 0x0208 /* DMA source Address Reg */ 46 + #define XUSB_DMA_DDAR_ADDR_OFFSET 0x020C /* DMA destination Addr Reg */ 47 + #define XUSB_DMA_LENGTH_OFFSET 0x0210 /* DMA Length Register */ 48 + #define XUSB_DMA_STATUS_OFFSET 0x0214 /* DMA Status Register */ 49 + 50 + /* Endpoint Configuration Space offsets */ 51 + #define XUSB_EP_CFGSTATUS_OFFSET 0x00 /* Endpoint Config Status */ 52 + #define XUSB_EP_BUF0COUNT_OFFSET 0x08 /* Buffer 0 Count */ 53 + #define XUSB_EP_BUF1COUNT_OFFSET 0x0C /* Buffer 1 Count */ 54 + 55 + #define XUSB_CONTROL_USB_READY_MASK 0x80000000 /* USB ready Mask */ 56 + #define XUSB_CONTROL_USB_RMTWAKE_MASK 0x40000000 /* Remote wake up mask */ 57 + 58 + /* Interrupt register related masks.*/ 59 + #define XUSB_STATUS_GLOBAL_INTR_MASK 0x80000000 /* Global Intr Enable */ 60 + #define XUSB_STATUS_DMADONE_MASK 0x04000000 /* DMA done Mask */ 61 + #define XUSB_STATUS_DMAERR_MASK 0x02000000 /* DMA Error Mask */ 62 + #define XUSB_STATUS_DMABUSY_MASK 0x80000000 /* DMA Error Mask */ 63 + #define XUSB_STATUS_RESUME_MASK 0x01000000 /* USB Resume Mask */ 64 + #define XUSB_STATUS_RESET_MASK 0x00800000 /* USB Reset Mask */ 65 + #define XUSB_STATUS_SUSPEND_MASK 0x00400000 /* USB Suspend Mask */ 66 + #define XUSB_STATUS_DISCONNECT_MASK 0x00200000 /* USB Disconnect Mask */ 67 + #define XUSB_STATUS_FIFO_BUFF_RDY_MASK 0x00100000 /* FIFO Buff Ready Mask */ 68 + #define XUSB_STATUS_FIFO_BUFF_FREE_MASK 0x00080000 /* FIFO Buff Free Mask */ 69 + #define XUSB_STATUS_SETUP_PACKET_MASK 0x00040000 /* Setup packet received */ 70 + #define XUSB_STATUS_EP1_BUFF2_COMP_MASK 0x00000200 /* EP 1 Buff 2 Processed */ 71 + #define XUSB_STATUS_EP1_BUFF1_COMP_MASK 0x00000002 /* EP 1 Buff 1 Processed */ 72 + #define XUSB_STATUS_EP0_BUFF2_COMP_MASK 0x00000100 /* EP 0 Buff 2 Processed */ 73 + #define XUSB_STATUS_EP0_BUFF1_COMP_MASK 0x00000001 /* EP 0 Buff 1 Processed */ 74 + #define XUSB_STATUS_HIGH_SPEED_MASK 0x00010000 /* USB Speed Mask */ 75 + /* Suspend,Reset,Suspend and Disconnect Mask */ 76 + #define XUSB_STATUS_INTR_EVENT_MASK 0x01E00000 77 + /* Buffers completion Mask */ 78 + #define XUSB_STATUS_INTR_BUFF_COMP_ALL_MASK 0x0000FEFF 79 + /* Mask for buffer 0 and buffer 1 completion for all Endpoints */ 80 + #define XUSB_STATUS_INTR_BUFF_COMP_SHIFT_MASK 0x00000101 81 + #define XUSB_STATUS_EP_BUFF2_SHIFT 8 /* EP buffer offset */ 82 + 83 + /* Endpoint Configuration Status Register */ 84 + #define XUSB_EP_CFG_VALID_MASK 0x80000000 /* Endpoint Valid bit */ 85 + #define XUSB_EP_CFG_STALL_MASK 0x40000000 /* Endpoint Stall bit */ 86 + #define XUSB_EP_CFG_DATA_TOGGLE_MASK 0x08000000 /* Endpoint Data toggle */ 87 + 88 + /* USB device specific global configuration constants.*/ 89 + #define XUSB_MAX_ENDPOINTS 8 /* Maximum End Points */ 90 + #define XUSB_EP_NUMBER_ZERO 0 /* End point Zero */ 91 + /* DPRAM is the source address for DMA transfer */ 92 + #define XUSB_DMA_READ_FROM_DPRAM 0x80000000 93 + #define XUSB_DMA_DMASR_BUSY 0x80000000 /* DMA busy */ 94 + #define XUSB_DMA_DMASR_ERROR 0x40000000 /* DMA Error */ 95 + /* 96 + * When this bit is set, the DMA buffer ready bit is set by hardware upon 97 + * DMA transfer completion. 98 + */ 99 + #define XUSB_DMA_BRR_CTRL 0x40000000 /* DMA bufready ctrl bit */ 100 + /* Phase States */ 101 + #define SETUP_PHASE 0x0000 /* Setup Phase */ 102 + #define DATA_PHASE 0x0001 /* Data Phase */ 103 + #define STATUS_PHASE 0x0002 /* Status Phase */ 104 + 105 + #define EP0_MAX_PACKET 64 /* Endpoint 0 maximum packet length */ 106 + #define STATUSBUFF_SIZE 2 /* Buffer size for GET_STATUS command */ 107 + #define EPNAME_SIZE 4 /* Buffer size for endpoint name */ 108 + 109 + /* container_of helper macros */ 110 + #define to_udc(g) container_of((g), struct xusb_udc, gadget) 111 + #define to_xusb_ep(ep) container_of((ep), struct xusb_ep, ep_usb) 112 + #define to_xusb_req(req) container_of((req), struct xusb_req, usb_req) 113 + 114 + /** 115 + * struct xusb_req - Xilinx USB device request structure 116 + * @usb_req: Linux usb request structure 117 + * @queue: usb device request queue 118 + * @ep: pointer to xusb_endpoint structure 119 + */ 120 + struct xusb_req { 121 + struct usb_request usb_req; 122 + struct list_head queue; 123 + struct xusb_ep *ep; 124 + }; 125 + 126 + /** 127 + * struct xusb_ep - USB end point structure. 128 + * @ep_usb: usb endpoint instance 129 + * @queue: endpoint message queue 130 + * @udc: xilinx usb peripheral driver instance pointer 131 + * @desc: pointer to the usb endpoint descriptor 132 + * @rambase: the endpoint buffer address 133 + * @offset: the endpoint register offset value 134 + * @name: name of the endpoint 135 + * @epnumber: endpoint number 136 + * @maxpacket: maximum packet size the endpoint can store 137 + * @buffer0count: the size of the packet recieved in the first buffer 138 + * @buffer1count: the size of the packet received in the second buffer 139 + * @curbufnum: current buffer of endpoint that will be processed next 140 + * @buffer0ready: the busy state of first buffer 141 + * @buffer1ready: the busy state of second buffer 142 + * @is_in: endpoint direction (IN or OUT) 143 + * @is_iso: endpoint type(isochronous or non isochronous) 144 + */ 145 + struct xusb_ep { 146 + struct usb_ep ep_usb; 147 + struct list_head queue; 148 + struct xusb_udc *udc; 149 + const struct usb_endpoint_descriptor *desc; 150 + u32 rambase; 151 + u32 offset; 152 + char name[4]; 153 + u16 epnumber; 154 + u16 maxpacket; 155 + u16 buffer0count; 156 + u16 buffer1count; 157 + u8 curbufnum; 158 + bool buffer0ready; 159 + bool buffer1ready; 160 + bool is_in; 161 + bool is_iso; 162 + }; 163 + 164 + /** 165 + * struct xusb_udc - USB peripheral driver structure 166 + * @gadget: USB gadget driver instance 167 + * @ep: an array of endpoint structures 168 + * @driver: pointer to the usb gadget driver instance 169 + * @setup: usb_ctrlrequest structure for control requests 170 + * @req: pointer to dummy request for get status command 171 + * @dev: pointer to device structure in gadget 172 + * @usb_state: device in suspended state or not 173 + * @remote_wkp: remote wakeup enabled by host 174 + * @setupseqtx: tx status 175 + * @setupseqrx: rx status 176 + * @addr: the usb device base address 177 + * @lock: instance of spinlock 178 + * @dma_enabled: flag indicating whether the dma is included in the system 179 + * @read_fn: function pointer to read device registers 180 + * @write_fn: function pointer to write to device registers 181 + */ 182 + struct xusb_udc { 183 + struct usb_gadget gadget; 184 + struct xusb_ep ep[8]; 185 + struct usb_gadget_driver *driver; 186 + struct usb_ctrlrequest setup; 187 + struct xusb_req *req; 188 + struct device *dev; 189 + u32 usb_state; 190 + u32 remote_wkp; 191 + u32 setupseqtx; 192 + u32 setupseqrx; 193 + void __iomem *addr; 194 + spinlock_t lock; 195 + bool dma_enabled; 196 + 197 + unsigned int (*read_fn)(void __iomem *); 198 + void (*write_fn)(void __iomem *, u32, u32); 199 + }; 200 + 201 + /* Endpoint buffer start addresses in the core */ 202 + static u32 rambase[8] = { 0x22, 0x1000, 0x1100, 0x1200, 0x1300, 0x1400, 0x1500, 203 + 0x1600 }; 204 + 205 + static const char driver_name[] = "xilinx-udc"; 206 + static const char ep0name[] = "ep0"; 207 + 208 + /* Control endpoint configuration.*/ 209 + static const struct usb_endpoint_descriptor config_bulk_out_desc = { 210 + .bLength = USB_DT_ENDPOINT_SIZE, 211 + .bDescriptorType = USB_DT_ENDPOINT, 212 + .bEndpointAddress = USB_DIR_OUT, 213 + .bmAttributes = USB_ENDPOINT_XFER_BULK, 214 + .wMaxPacketSize = cpu_to_le16(EP0_MAX_PACKET), 215 + }; 216 + 217 + /** 218 + * xudc_write32 - little endian write to device registers 219 + * @addr: base addr of device registers 220 + * @offset: register offset 221 + * @val: data to be written 222 + */ 223 + static void xudc_write32(void __iomem *addr, u32 offset, u32 val) 224 + { 225 + iowrite32(val, addr + offset); 226 + } 227 + 228 + /** 229 + * xudc_read32 - little endian read from device registers 230 + * @addr: addr of device register 231 + * Return: value at addr 232 + */ 233 + static unsigned int xudc_read32(void __iomem *addr) 234 + { 235 + return ioread32(addr); 236 + } 237 + 238 + /** 239 + * xudc_write32_be - big endian write to device registers 240 + * @addr: base addr of device registers 241 + * @offset: register offset 242 + * @val: data to be written 243 + */ 244 + static void xudc_write32_be(void __iomem *addr, u32 offset, u32 val) 245 + { 246 + iowrite32be(val, addr + offset); 247 + } 248 + 249 + /** 250 + * xudc_read32_be - big endian read from device registers 251 + * @addr: addr of device register 252 + * Return: value at addr 253 + */ 254 + static unsigned int xudc_read32_be(void __iomem *addr) 255 + { 256 + return ioread32be(addr); 257 + } 258 + 259 + /** 260 + * xudc_wrstatus - Sets up the usb device status stages. 261 + * @udc: pointer to the usb device controller structure. 262 + */ 263 + static void xudc_wrstatus(struct xusb_udc *udc) 264 + { 265 + struct xusb_ep *ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO]; 266 + u32 epcfgreg; 267 + 268 + epcfgreg = udc->read_fn(udc->addr + ep0->offset)| 269 + XUSB_EP_CFG_DATA_TOGGLE_MASK; 270 + udc->write_fn(udc->addr, ep0->offset, epcfgreg); 271 + udc->write_fn(udc->addr, ep0->offset + XUSB_EP_BUF0COUNT_OFFSET, 0); 272 + udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); 273 + } 274 + 275 + /** 276 + * xudc_epconfig - Configures the given endpoint. 277 + * @ep: pointer to the usb device endpoint structure. 278 + * @udc: pointer to the usb peripheral controller structure. 279 + * 280 + * This function configures a specific endpoint with the given configuration 281 + * data. 282 + */ 283 + static void xudc_epconfig(struct xusb_ep *ep, struct xusb_udc *udc) 284 + { 285 + u32 epcfgreg; 286 + 287 + /* 288 + * Configure the end point direction, type, Max Packet Size and the 289 + * EP buffer location. 290 + */ 291 + epcfgreg = ((ep->is_in << 29) | (ep->is_iso << 28) | 292 + (ep->ep_usb.maxpacket << 15) | (ep->rambase)); 293 + udc->write_fn(udc->addr, ep->offset, epcfgreg); 294 + 295 + /* Set the Buffer count and the Buffer ready bits.*/ 296 + udc->write_fn(udc->addr, ep->offset + XUSB_EP_BUF0COUNT_OFFSET, 297 + ep->buffer0count); 298 + udc->write_fn(udc->addr, ep->offset + XUSB_EP_BUF1COUNT_OFFSET, 299 + ep->buffer1count); 300 + if (ep->buffer0ready) 301 + udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 302 + 1 << ep->epnumber); 303 + if (ep->buffer1ready) 304 + udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 305 + 1 << (ep->epnumber + XUSB_STATUS_EP_BUFF2_SHIFT)); 306 + } 307 + 308 + /** 309 + * xudc_start_dma - Starts DMA transfer. 310 + * @ep: pointer to the usb device endpoint structure. 311 + * @src: DMA source address. 312 + * @dst: DMA destination address. 313 + * @length: number of bytes to transfer. 314 + * 315 + * Return: 0 on success, error code on failure 316 + * 317 + * This function starts DMA transfer by writing to DMA source, 318 + * destination and lenth registers. 319 + */ 320 + static int xudc_start_dma(struct xusb_ep *ep, dma_addr_t src, 321 + dma_addr_t dst, u32 length) 322 + { 323 + struct xusb_udc *udc = ep->udc; 324 + int rc = 0; 325 + u32 timeout = 500; 326 + u32 reg; 327 + 328 + /* 329 + * Set the addresses in the DMA source and 330 + * destination registers and then set the length 331 + * into the DMA length register. 332 + */ 333 + udc->write_fn(udc->addr, XUSB_DMA_DSAR_ADDR_OFFSET, src); 334 + udc->write_fn(udc->addr, XUSB_DMA_DDAR_ADDR_OFFSET, dst); 335 + udc->write_fn(udc->addr, XUSB_DMA_LENGTH_OFFSET, length); 336 + 337 + /* 338 + * Wait till DMA transaction is complete and 339 + * check whether the DMA transaction was 340 + * successful. 341 + */ 342 + do { 343 + reg = udc->read_fn(udc->addr + XUSB_DMA_STATUS_OFFSET); 344 + if (!(reg & XUSB_DMA_DMASR_BUSY)) 345 + break; 346 + 347 + /* 348 + * We can't sleep here, because it's also called from 349 + * interrupt context. 350 + */ 351 + timeout--; 352 + if (!timeout) { 353 + dev_err(udc->dev, "DMA timeout\n"); 354 + return -ETIMEDOUT; 355 + } 356 + udelay(1); 357 + } while (1); 358 + 359 + if ((udc->read_fn(udc->addr + XUSB_DMA_STATUS_OFFSET) & 360 + XUSB_DMA_DMASR_ERROR) == XUSB_DMA_DMASR_ERROR){ 361 + dev_err(udc->dev, "DMA Error\n"); 362 + rc = -EINVAL; 363 + } 364 + 365 + return rc; 366 + } 367 + 368 + /** 369 + * xudc_dma_send - Sends IN data using DMA. 370 + * @ep: pointer to the usb device endpoint structure. 371 + * @req: pointer to the usb request structure. 372 + * @buffer: pointer to data to be sent. 373 + * @length: number of bytes to send. 374 + * 375 + * Return: 0 on success, -EAGAIN if no buffer is free and error 376 + * code on failure. 377 + * 378 + * This function sends data using DMA. 379 + */ 380 + static int xudc_dma_send(struct xusb_ep *ep, struct xusb_req *req, 381 + u8 *buffer, u32 length) 382 + { 383 + u32 *eprambase; 384 + dma_addr_t src; 385 + dma_addr_t dst; 386 + struct xusb_udc *udc = ep->udc; 387 + 388 + src = req->usb_req.dma + req->usb_req.actual; 389 + if (req->usb_req.length) 390 + dma_sync_single_for_device(udc->dev, src, 391 + length, DMA_TO_DEVICE); 392 + if (!ep->curbufnum && !ep->buffer0ready) { 393 + /* Get the Buffer address and copy the transmit data.*/ 394 + eprambase = (u32 __force *)(udc->addr + ep->rambase); 395 + dst = virt_to_phys(eprambase); 396 + udc->write_fn(udc->addr, ep->offset + 397 + XUSB_EP_BUF0COUNT_OFFSET, length); 398 + udc->write_fn(udc->addr, XUSB_DMA_CONTROL_OFFSET, 399 + XUSB_DMA_BRR_CTRL | (1 << ep->epnumber)); 400 + ep->buffer0ready = 1; 401 + ep->curbufnum = 1; 402 + } else if (ep->curbufnum && !ep->buffer1ready) { 403 + /* Get the Buffer address and copy the transmit data.*/ 404 + eprambase = (u32 __force *)(udc->addr + ep->rambase + 405 + ep->ep_usb.maxpacket); 406 + dst = virt_to_phys(eprambase); 407 + udc->write_fn(udc->addr, ep->offset + 408 + XUSB_EP_BUF1COUNT_OFFSET, length); 409 + udc->write_fn(udc->addr, XUSB_DMA_CONTROL_OFFSET, 410 + XUSB_DMA_BRR_CTRL | (1 << (ep->epnumber + 411 + XUSB_STATUS_EP_BUFF2_SHIFT))); 412 + ep->buffer1ready = 1; 413 + ep->curbufnum = 0; 414 + } else { 415 + /* None of ping pong buffers are ready currently .*/ 416 + return -EAGAIN; 417 + } 418 + 419 + return xudc_start_dma(ep, src, dst, length); 420 + } 421 + 422 + /** 423 + * xudc_dma_receive - Receives OUT data using DMA. 424 + * @ep: pointer to the usb device endpoint structure. 425 + * @req: pointer to the usb request structure. 426 + * @buffer: pointer to storage buffer of received data. 427 + * @length: number of bytes to receive. 428 + * 429 + * Return: 0 on success, -EAGAIN if no buffer is free and error 430 + * code on failure. 431 + * 432 + * This function receives data using DMA. 433 + */ 434 + static int xudc_dma_receive(struct xusb_ep *ep, struct xusb_req *req, 435 + u8 *buffer, u32 length) 436 + { 437 + u32 *eprambase; 438 + dma_addr_t src; 439 + dma_addr_t dst; 440 + struct xusb_udc *udc = ep->udc; 441 + 442 + dst = req->usb_req.dma + req->usb_req.actual; 443 + if (!ep->curbufnum && !ep->buffer0ready) { 444 + /* Get the Buffer address and copy the transmit data */ 445 + eprambase = (u32 __force *)(udc->addr + ep->rambase); 446 + src = virt_to_phys(eprambase); 447 + udc->write_fn(udc->addr, XUSB_DMA_CONTROL_OFFSET, 448 + XUSB_DMA_BRR_CTRL | XUSB_DMA_READ_FROM_DPRAM | 449 + (1 << ep->epnumber)); 450 + ep->buffer0ready = 1; 451 + ep->curbufnum = 1; 452 + } else if (ep->curbufnum && !ep->buffer1ready) { 453 + /* Get the Buffer address and copy the transmit data */ 454 + eprambase = (u32 __force *)(udc->addr + 455 + ep->rambase + ep->ep_usb.maxpacket); 456 + src = virt_to_phys(eprambase); 457 + udc->write_fn(udc->addr, XUSB_DMA_CONTROL_OFFSET, 458 + XUSB_DMA_BRR_CTRL | XUSB_DMA_READ_FROM_DPRAM | 459 + (1 << (ep->epnumber + 460 + XUSB_STATUS_EP_BUFF2_SHIFT))); 461 + ep->buffer1ready = 1; 462 + ep->curbufnum = 0; 463 + } else { 464 + /* None of the ping-pong buffers are ready currently */ 465 + return -EAGAIN; 466 + } 467 + 468 + return xudc_start_dma(ep, src, dst, length); 469 + } 470 + 471 + /** 472 + * xudc_eptxrx - Transmits or receives data to or from an endpoint. 473 + * @ep: pointer to the usb endpoint configuration structure. 474 + * @req: pointer to the usb request structure. 475 + * @bufferptr: pointer to buffer containing the data to be sent. 476 + * @bufferlen: The number of data bytes to be sent. 477 + * 478 + * Return: 0 on success, -EAGAIN if no buffer is free. 479 + * 480 + * This function copies the transmit/receive data to/from the end point buffer 481 + * and enables the buffer for transmission/reception. 482 + */ 483 + static int xudc_eptxrx(struct xusb_ep *ep, struct xusb_req *req, 484 + u8 *bufferptr, u32 bufferlen) 485 + { 486 + u32 *eprambase; 487 + u32 bytestosend; 488 + int rc = 0; 489 + struct xusb_udc *udc = ep->udc; 490 + 491 + bytestosend = bufferlen; 492 + if (udc->dma_enabled) { 493 + if (ep->is_in) 494 + rc = xudc_dma_send(ep, req, bufferptr, bufferlen); 495 + else 496 + rc = xudc_dma_receive(ep, req, bufferptr, bufferlen); 497 + return rc; 498 + } 499 + /* Put the transmit buffer into the correct ping-pong buffer.*/ 500 + if (!ep->curbufnum && !ep->buffer0ready) { 501 + /* Get the Buffer address and copy the transmit data.*/ 502 + eprambase = (u32 __force *)(udc->addr + ep->rambase); 503 + if (ep->is_in) { 504 + memcpy(eprambase, bufferptr, bytestosend); 505 + udc->write_fn(udc->addr, ep->offset + 506 + XUSB_EP_BUF0COUNT_OFFSET, bufferlen); 507 + } else { 508 + memcpy(bufferptr, eprambase, bytestosend); 509 + } 510 + /* 511 + * Enable the buffer for transmission. 512 + */ 513 + udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 514 + 1 << ep->epnumber); 515 + ep->buffer0ready = 1; 516 + ep->curbufnum = 1; 517 + } else if (ep->curbufnum && !ep->buffer1ready) { 518 + /* Get the Buffer address and copy the transmit data.*/ 519 + eprambase = (u32 __force *)(udc->addr + ep->rambase + 520 + ep->ep_usb.maxpacket); 521 + if (ep->is_in) { 522 + memcpy(eprambase, bufferptr, bytestosend); 523 + udc->write_fn(udc->addr, ep->offset + 524 + XUSB_EP_BUF1COUNT_OFFSET, bufferlen); 525 + } else { 526 + memcpy(bufferptr, eprambase, bytestosend); 527 + } 528 + /* 529 + * Enable the buffer for transmission. 530 + */ 531 + udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 532 + 1 << (ep->epnumber + XUSB_STATUS_EP_BUFF2_SHIFT)); 533 + ep->buffer1ready = 1; 534 + ep->curbufnum = 0; 535 + } else { 536 + /* None of the ping-pong buffers are ready currently */ 537 + return -EAGAIN; 538 + } 539 + return rc; 540 + } 541 + 542 + /** 543 + * xudc_done - Exeutes the endpoint data transfer completion tasks. 544 + * @ep: pointer to the usb device endpoint structure. 545 + * @req: pointer to the usb request structure. 546 + * @status: Status of the data transfer. 547 + * 548 + * Deletes the message from the queue and updates data transfer completion 549 + * status. 550 + */ 551 + static void xudc_done(struct xusb_ep *ep, struct xusb_req *req, int status) 552 + { 553 + struct xusb_udc *udc = ep->udc; 554 + 555 + list_del_init(&req->queue); 556 + 557 + if (req->usb_req.status == -EINPROGRESS) 558 + req->usb_req.status = status; 559 + else 560 + status = req->usb_req.status; 561 + 562 + if (status && status != -ESHUTDOWN) 563 + dev_dbg(udc->dev, "%s done %p, status %d\n", 564 + ep->ep_usb.name, req, status); 565 + /* unmap request if DMA is present*/ 566 + if (udc->dma_enabled && ep->epnumber && req->usb_req.length) 567 + usb_gadget_unmap_request(&udc->gadget, &req->usb_req, 568 + ep->is_in); 569 + 570 + if (req->usb_req.complete) { 571 + spin_unlock(&udc->lock); 572 + req->usb_req.complete(&ep->ep_usb, &req->usb_req); 573 + spin_lock(&udc->lock); 574 + } 575 + } 576 + 577 + /** 578 + * xudc_read_fifo - Reads the data from the given endpoint buffer. 579 + * @ep: pointer to the usb device endpoint structure. 580 + * @req: pointer to the usb request structure. 581 + * 582 + * Return: 0 if request is completed and -EAGAIN if not completed. 583 + * 584 + * Pulls OUT packet data from the endpoint buffer. 585 + */ 586 + static int xudc_read_fifo(struct xusb_ep *ep, struct xusb_req *req) 587 + { 588 + u8 *buf; 589 + u32 is_short, count, bufferspace; 590 + u8 bufoffset; 591 + u8 two_pkts = 0; 592 + int ret; 593 + int retval = -EAGAIN; 594 + struct xusb_udc *udc = ep->udc; 595 + 596 + if (ep->buffer0ready && ep->buffer1ready) { 597 + dev_dbg(udc->dev, "Packet NOT ready!\n"); 598 + return retval; 599 + } 600 + top: 601 + if (ep->curbufnum) 602 + bufoffset = XUSB_EP_BUF1COUNT_OFFSET; 603 + else 604 + bufoffset = XUSB_EP_BUF0COUNT_OFFSET; 605 + 606 + count = udc->read_fn(udc->addr + ep->offset + bufoffset); 607 + 608 + if (!ep->buffer0ready && !ep->buffer1ready) 609 + two_pkts = 1; 610 + 611 + buf = req->usb_req.buf + req->usb_req.actual; 612 + prefetchw(buf); 613 + bufferspace = req->usb_req.length - req->usb_req.actual; 614 + is_short = count < ep->ep_usb.maxpacket; 615 + 616 + if (unlikely(!bufferspace)) { 617 + /* 618 + * This happens when the driver's buffer 619 + * is smaller than what the host sent. 620 + * discard the extra data. 621 + */ 622 + if (req->usb_req.status != -EOVERFLOW) 623 + dev_dbg(udc->dev, "%s overflow %d\n", 624 + ep->ep_usb.name, count); 625 + req->usb_req.status = -EOVERFLOW; 626 + xudc_done(ep, req, -EOVERFLOW); 627 + return 0; 628 + } 629 + 630 + ret = xudc_eptxrx(ep, req, buf, count); 631 + switch (ret) { 632 + case 0: 633 + req->usb_req.actual += min(count, bufferspace); 634 + dev_dbg(udc->dev, "read %s, %d bytes%s req %p %d/%d\n", 635 + ep->ep_usb.name, count, is_short ? "/S" : "", req, 636 + req->usb_req.actual, req->usb_req.length); 637 + bufferspace -= count; 638 + /* Completion */ 639 + if ((req->usb_req.actual == req->usb_req.length) || is_short) { 640 + if (udc->dma_enabled && req->usb_req.length) 641 + dma_sync_single_for_cpu(udc->dev, 642 + req->usb_req.dma, 643 + req->usb_req.actual, 644 + DMA_FROM_DEVICE); 645 + xudc_done(ep, req, 0); 646 + return 0; 647 + } 648 + if (two_pkts) { 649 + two_pkts = 0; 650 + goto top; 651 + } 652 + break; 653 + case -EAGAIN: 654 + dev_dbg(udc->dev, "receive busy\n"); 655 + break; 656 + case -EINVAL: 657 + case -ETIMEDOUT: 658 + /* DMA error, dequeue the request */ 659 + xudc_done(ep, req, -ECONNRESET); 660 + retval = 0; 661 + break; 662 + } 663 + 664 + return retval; 665 + } 666 + 667 + /** 668 + * xudc_write_fifo - Writes data into the given endpoint buffer. 669 + * @ep: pointer to the usb device endpoint structure. 670 + * @req: pointer to the usb request structure. 671 + * 672 + * Return: 0 if request is completed and -EAGAIN if not completed. 673 + * 674 + * Loads endpoint buffer for an IN packet. 675 + */ 676 + static int xudc_write_fifo(struct xusb_ep *ep, struct xusb_req *req) 677 + { 678 + u32 max; 679 + u32 length; 680 + int ret; 681 + int retval = -EAGAIN; 682 + struct xusb_udc *udc = ep->udc; 683 + int is_last, is_short = 0; 684 + u8 *buf; 685 + 686 + max = le16_to_cpu(ep->desc->wMaxPacketSize); 687 + buf = req->usb_req.buf + req->usb_req.actual; 688 + prefetch(buf); 689 + length = req->usb_req.length - req->usb_req.actual; 690 + length = min(length, max); 691 + 692 + ret = xudc_eptxrx(ep, req, buf, length); 693 + switch (ret) { 694 + case 0: 695 + req->usb_req.actual += length; 696 + if (unlikely(length != max)) { 697 + is_last = is_short = 1; 698 + } else { 699 + if (likely(req->usb_req.length != 700 + req->usb_req.actual) || req->usb_req.zero) 701 + is_last = 0; 702 + else 703 + is_last = 1; 704 + } 705 + dev_dbg(udc->dev, "%s: wrote %s %d bytes%s%s %d left %p\n", 706 + __func__, ep->ep_usb.name, length, is_last ? "/L" : "", 707 + is_short ? "/S" : "", 708 + req->usb_req.length - req->usb_req.actual, req); 709 + /* completion */ 710 + if (is_last) { 711 + xudc_done(ep, req, 0); 712 + retval = 0; 713 + } 714 + break; 715 + case -EAGAIN: 716 + dev_dbg(udc->dev, "Send busy\n"); 717 + break; 718 + case -EINVAL: 719 + case -ETIMEDOUT: 720 + /* DMA error, dequeue the request */ 721 + xudc_done(ep, req, -ECONNRESET); 722 + retval = 0; 723 + break; 724 + } 725 + 726 + return retval; 727 + } 728 + 729 + /** 730 + * xudc_nuke - Cleans up the data transfer message list. 731 + * @ep: pointer to the usb device endpoint structure. 732 + * @status: Status of the data transfer. 733 + */ 734 + static void xudc_nuke(struct xusb_ep *ep, int status) 735 + { 736 + struct xusb_req *req; 737 + 738 + while (!list_empty(&ep->queue)) { 739 + req = list_first_entry(&ep->queue, struct xusb_req, queue); 740 + xudc_done(ep, req, status); 741 + } 742 + } 743 + 744 + /** 745 + * xudc_ep_set_halt - Stalls/unstalls the given endpoint. 746 + * @_ep: pointer to the usb device endpoint structure. 747 + * @value: value to indicate stall/unstall. 748 + * 749 + * Return: 0 for success and error value on failure 750 + */ 751 + static int xudc_ep_set_halt(struct usb_ep *_ep, int value) 752 + { 753 + struct xusb_ep *ep = to_xusb_ep(_ep); 754 + struct xusb_udc *udc; 755 + unsigned long flags; 756 + u32 epcfgreg; 757 + 758 + if (!_ep || (!ep->desc && ep->epnumber)) { 759 + pr_debug("%s: bad ep or descriptor\n", __func__); 760 + return -EINVAL; 761 + } 762 + udc = ep->udc; 763 + 764 + if (ep->is_in && (!list_empty(&ep->queue)) && value) { 765 + dev_dbg(udc->dev, "requests pending can't halt\n"); 766 + return -EAGAIN; 767 + } 768 + 769 + if (ep->buffer0ready || ep->buffer1ready) { 770 + dev_dbg(udc->dev, "HW buffers busy can't halt\n"); 771 + return -EAGAIN; 772 + } 773 + 774 + spin_lock_irqsave(&udc->lock, flags); 775 + 776 + if (value) { 777 + /* Stall the device.*/ 778 + epcfgreg = udc->read_fn(udc->addr + ep->offset); 779 + epcfgreg |= XUSB_EP_CFG_STALL_MASK; 780 + udc->write_fn(udc->addr, ep->offset, epcfgreg); 781 + } else { 782 + /* Unstall the device.*/ 783 + epcfgreg = udc->read_fn(udc->addr + ep->offset); 784 + epcfgreg &= ~XUSB_EP_CFG_STALL_MASK; 785 + udc->write_fn(udc->addr, ep->offset, epcfgreg); 786 + if (ep->epnumber) { 787 + /* Reset the toggle bit.*/ 788 + epcfgreg = udc->read_fn(ep->udc->addr + ep->offset); 789 + epcfgreg &= ~XUSB_EP_CFG_DATA_TOGGLE_MASK; 790 + udc->write_fn(udc->addr, ep->offset, epcfgreg); 791 + } 792 + } 793 + 794 + spin_unlock_irqrestore(&udc->lock, flags); 795 + return 0; 796 + } 797 + 798 + /** 799 + * xudc_ep_enable - Enables the given endpoint. 800 + * @ep: pointer to the xusb endpoint structure. 801 + * @desc: pointer to usb endpoint descriptor. 802 + * 803 + * Return: 0 for success and error value on failure 804 + */ 805 + static int __xudc_ep_enable(struct xusb_ep *ep, 806 + const struct usb_endpoint_descriptor *desc) 807 + { 808 + struct xusb_udc *udc = ep->udc; 809 + u32 tmp; 810 + u32 epcfg; 811 + u32 ier; 812 + u16 maxpacket; 813 + 814 + ep->is_in = ((desc->bEndpointAddress & USB_DIR_IN) != 0); 815 + /* Bit 3...0:endpoint number */ 816 + ep->epnumber = (desc->bEndpointAddress & 0x0f); 817 + ep->desc = desc; 818 + ep->ep_usb.desc = desc; 819 + tmp = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; 820 + ep->ep_usb.maxpacket = maxpacket = le16_to_cpu(desc->wMaxPacketSize); 821 + 822 + switch (tmp) { 823 + case USB_ENDPOINT_XFER_CONTROL: 824 + dev_dbg(udc->dev, "only one control endpoint\n"); 825 + /* NON- ISO */ 826 + ep->is_iso = 0; 827 + return -EINVAL; 828 + case USB_ENDPOINT_XFER_INT: 829 + /* NON- ISO */ 830 + ep->is_iso = 0; 831 + if (maxpacket > 64) { 832 + dev_dbg(udc->dev, "bogus maxpacket %d\n", maxpacket); 833 + return -EINVAL; 834 + } 835 + break; 836 + case USB_ENDPOINT_XFER_BULK: 837 + /* NON- ISO */ 838 + ep->is_iso = 0; 839 + if (!(is_power_of_2(maxpacket) && maxpacket >= 8 && 840 + maxpacket <= 512)) { 841 + dev_dbg(udc->dev, "bogus maxpacket %d\n", maxpacket); 842 + return -EINVAL; 843 + } 844 + break; 845 + case USB_ENDPOINT_XFER_ISOC: 846 + /* ISO */ 847 + ep->is_iso = 1; 848 + break; 849 + } 850 + 851 + ep->buffer0ready = 0; 852 + ep->buffer1ready = 0; 853 + ep->curbufnum = 0; 854 + ep->rambase = rambase[ep->epnumber]; 855 + xudc_epconfig(ep, udc); 856 + 857 + dev_dbg(udc->dev, "Enable Endpoint %d max pkt is %d\n", 858 + ep->epnumber, maxpacket); 859 + 860 + /* Enable the End point.*/ 861 + epcfg = udc->read_fn(udc->addr + ep->offset); 862 + epcfg |= XUSB_EP_CFG_VALID_MASK; 863 + udc->write_fn(udc->addr, ep->offset, epcfg); 864 + if (ep->epnumber) 865 + ep->rambase <<= 2; 866 + 867 + /* Enable buffer completion interrupts for endpoint */ 868 + ier = udc->read_fn(udc->addr + XUSB_IER_OFFSET); 869 + ier |= (XUSB_STATUS_INTR_BUFF_COMP_SHIFT_MASK << ep->epnumber); 870 + udc->write_fn(udc->addr, XUSB_IER_OFFSET, ier); 871 + 872 + /* for OUT endpoint set buffers ready to receive */ 873 + if (ep->epnumber && !ep->is_in) { 874 + udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 875 + 1 << ep->epnumber); 876 + ep->buffer0ready = 1; 877 + udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 878 + (1 << (ep->epnumber + 879 + XUSB_STATUS_EP_BUFF2_SHIFT))); 880 + ep->buffer1ready = 1; 881 + } 882 + 883 + return 0; 884 + } 885 + 886 + /** 887 + * xudc_ep_enable - Enables the given endpoint. 888 + * @_ep: pointer to the usb endpoint structure. 889 + * @desc: pointer to usb endpoint descriptor. 890 + * 891 + * Return: 0 for success and error value on failure 892 + */ 893 + static int xudc_ep_enable(struct usb_ep *_ep, 894 + const struct usb_endpoint_descriptor *desc) 895 + { 896 + struct xusb_ep *ep; 897 + struct xusb_udc *udc; 898 + unsigned long flags; 899 + int ret; 900 + 901 + if (!_ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) { 902 + pr_debug("%s: bad ep or descriptor\n", __func__); 903 + return -EINVAL; 904 + } 905 + 906 + ep = to_xusb_ep(_ep); 907 + udc = ep->udc; 908 + 909 + if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { 910 + dev_dbg(udc->dev, "bogus device state\n"); 911 + return -ESHUTDOWN; 912 + } 913 + 914 + spin_lock_irqsave(&udc->lock, flags); 915 + ret = __xudc_ep_enable(ep, desc); 916 + spin_unlock_irqrestore(&udc->lock, flags); 917 + 918 + return ret; 919 + } 920 + 921 + /** 922 + * xudc_ep_disable - Disables the given endpoint. 923 + * @_ep: pointer to the usb endpoint structure. 924 + * 925 + * Return: 0 for success and error value on failure 926 + */ 927 + static int xudc_ep_disable(struct usb_ep *_ep) 928 + { 929 + struct xusb_ep *ep; 930 + unsigned long flags; 931 + u32 epcfg; 932 + struct xusb_udc *udc; 933 + 934 + if (!_ep) { 935 + pr_debug("%s: invalid ep\n", __func__); 936 + return -EINVAL; 937 + } 938 + 939 + ep = to_xusb_ep(_ep); 940 + udc = ep->udc; 941 + 942 + spin_lock_irqsave(&udc->lock, flags); 943 + 944 + xudc_nuke(ep, -ESHUTDOWN); 945 + 946 + /* Restore the endpoint's pristine config */ 947 + ep->desc = NULL; 948 + ep->ep_usb.desc = NULL; 949 + 950 + dev_dbg(udc->dev, "USB Ep %d disable\n ", ep->epnumber); 951 + /* Disable the endpoint.*/ 952 + epcfg = udc->read_fn(udc->addr + ep->offset); 953 + epcfg &= ~XUSB_EP_CFG_VALID_MASK; 954 + udc->write_fn(udc->addr, ep->offset, epcfg); 955 + 956 + spin_unlock_irqrestore(&udc->lock, flags); 957 + return 0; 958 + } 959 + 960 + /** 961 + * xudc_ep_alloc_request - Initializes the request queue. 962 + * @_ep: pointer to the usb endpoint structure. 963 + * @gfp_flags: Flags related to the request call. 964 + * 965 + * Return: pointer to request structure on success and a NULL on failure. 966 + */ 967 + static struct usb_request *xudc_ep_alloc_request(struct usb_ep *_ep, 968 + gfp_t gfp_flags) 969 + { 970 + struct xusb_ep *ep = to_xusb_ep(_ep); 971 + struct xusb_udc *udc; 972 + struct xusb_req *req; 973 + 974 + udc = ep->udc; 975 + req = kzalloc(sizeof(*req), gfp_flags); 976 + if (!req) { 977 + dev_err(udc->dev, "%s:not enough memory", __func__); 978 + return NULL; 979 + } 980 + 981 + req->ep = ep; 982 + INIT_LIST_HEAD(&req->queue); 983 + return &req->usb_req; 984 + } 985 + 986 + /** 987 + * xudc_free_request - Releases the request from queue. 988 + * @_ep: pointer to the usb device endpoint structure. 989 + * @_req: pointer to the usb request structure. 990 + */ 991 + static void xudc_free_request(struct usb_ep *_ep, struct usb_request *_req) 992 + { 993 + struct xusb_req *req = to_xusb_req(_req); 994 + 995 + kfree(req); 996 + } 997 + 998 + /** 999 + * xudc_ep0_queue - Adds the request to endpoint 0 queue. 1000 + * @ep0: pointer to the xusb endpoint 0 structure. 1001 + * @req: pointer to the xusb request structure. 1002 + * 1003 + * Return: 0 for success and error value on failure 1004 + */ 1005 + static int __xudc_ep0_queue(struct xusb_ep *ep0, struct xusb_req *req) 1006 + { 1007 + struct xusb_udc *udc = ep0->udc; 1008 + u32 length; 1009 + u8 *corebuf; 1010 + 1011 + if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { 1012 + dev_dbg(udc->dev, "%s, bogus device state\n", __func__); 1013 + return -EINVAL; 1014 + } 1015 + if (!list_empty(&ep0->queue)) { 1016 + dev_dbg(udc->dev, "%s:ep0 busy\n", __func__); 1017 + return -EBUSY; 1018 + } 1019 + 1020 + req->usb_req.status = -EINPROGRESS; 1021 + req->usb_req.actual = 0; 1022 + 1023 + list_add_tail(&req->queue, &ep0->queue); 1024 + 1025 + if (udc->setup.bRequestType & USB_DIR_IN) { 1026 + prefetch(req->usb_req.buf); 1027 + length = req->usb_req.length; 1028 + corebuf = (void __force *) ((ep0->rambase << 2) + 1029 + udc->addr); 1030 + length = req->usb_req.actual = min_t(u32, length, 1031 + EP0_MAX_PACKET); 1032 + memcpy(corebuf, req->usb_req.buf, length); 1033 + udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, length); 1034 + udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); 1035 + } else { 1036 + if (udc->setup.wLength) { 1037 + /* Enable EP0 buffer to receive data */ 1038 + udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, 0); 1039 + udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); 1040 + } else { 1041 + xudc_wrstatus(udc); 1042 + } 1043 + } 1044 + 1045 + return 0; 1046 + } 1047 + 1048 + /** 1049 + * xudc_ep0_queue - Adds the request to endpoint 0 queue. 1050 + * @_ep: pointer to the usb endpoint 0 structure. 1051 + * @_req: pointer to the usb request structure. 1052 + * @gfp_flags: Flags related to the request call. 1053 + * 1054 + * Return: 0 for success and error value on failure 1055 + */ 1056 + static int xudc_ep0_queue(struct usb_ep *_ep, struct usb_request *_req, 1057 + gfp_t gfp_flags) 1058 + { 1059 + struct xusb_req *req = to_xusb_req(_req); 1060 + struct xusb_ep *ep0 = to_xusb_ep(_ep); 1061 + struct xusb_udc *udc = ep0->udc; 1062 + unsigned long flags; 1063 + int ret; 1064 + 1065 + spin_lock_irqsave(&udc->lock, flags); 1066 + ret = __xudc_ep0_queue(ep0, req); 1067 + spin_unlock_irqrestore(&udc->lock, flags); 1068 + 1069 + return ret; 1070 + } 1071 + 1072 + /** 1073 + * xudc_ep_queue - Adds the request to endpoint queue. 1074 + * @_ep: pointer to the usb endpoint structure. 1075 + * @_req: pointer to the usb request structure. 1076 + * @gfp_flags: Flags related to the request call. 1077 + * 1078 + * Return: 0 for success and error value on failure 1079 + */ 1080 + static int xudc_ep_queue(struct usb_ep *_ep, struct usb_request *_req, 1081 + gfp_t gfp_flags) 1082 + { 1083 + struct xusb_req *req = to_xusb_req(_req); 1084 + struct xusb_ep *ep = to_xusb_ep(_ep); 1085 + struct xusb_udc *udc = ep->udc; 1086 + int ret; 1087 + unsigned long flags; 1088 + 1089 + if (!ep->desc) { 1090 + dev_dbg(udc->dev, "%s:queing request to disabled %s\n", 1091 + __func__, ep->name); 1092 + return -ESHUTDOWN; 1093 + } 1094 + 1095 + if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { 1096 + dev_dbg(udc->dev, "%s, bogus device state\n", __func__); 1097 + return -EINVAL; 1098 + } 1099 + 1100 + spin_lock_irqsave(&udc->lock, flags); 1101 + 1102 + _req->status = -EINPROGRESS; 1103 + _req->actual = 0; 1104 + 1105 + if (udc->dma_enabled) { 1106 + ret = usb_gadget_map_request(&udc->gadget, &req->usb_req, 1107 + ep->is_in); 1108 + if (ret) { 1109 + dev_dbg(udc->dev, "gadget_map failed ep%d\n", 1110 + ep->epnumber); 1111 + spin_unlock_irqrestore(&udc->lock, flags); 1112 + return -EAGAIN; 1113 + } 1114 + } 1115 + 1116 + if (list_empty(&ep->queue)) { 1117 + if (ep->is_in) { 1118 + dev_dbg(udc->dev, "xudc_write_fifo from ep_queue\n"); 1119 + if (!xudc_write_fifo(ep, req)) 1120 + req = NULL; 1121 + } else { 1122 + dev_dbg(udc->dev, "xudc_read_fifo from ep_queue\n"); 1123 + if (!xudc_read_fifo(ep, req)) 1124 + req = NULL; 1125 + } 1126 + } 1127 + 1128 + if (req != NULL) 1129 + list_add_tail(&req->queue, &ep->queue); 1130 + 1131 + spin_unlock_irqrestore(&udc->lock, flags); 1132 + return 0; 1133 + } 1134 + 1135 + /** 1136 + * xudc_ep_dequeue - Removes the request from the queue. 1137 + * @_ep: pointer to the usb device endpoint structure. 1138 + * @_req: pointer to the usb request structure. 1139 + * 1140 + * Return: 0 for success and error value on failure 1141 + */ 1142 + static int xudc_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) 1143 + { 1144 + struct xusb_ep *ep = to_xusb_ep(_ep); 1145 + struct xusb_req *req = to_xusb_req(_req); 1146 + struct xusb_udc *udc = ep->udc; 1147 + unsigned long flags; 1148 + 1149 + spin_lock_irqsave(&udc->lock, flags); 1150 + /* Make sure it's actually queued on this endpoint */ 1151 + list_for_each_entry(req, &ep->queue, queue) { 1152 + if (&req->usb_req == _req) 1153 + break; 1154 + } 1155 + if (&req->usb_req != _req) { 1156 + spin_unlock_irqrestore(&ep->udc->lock, flags); 1157 + return -EINVAL; 1158 + } 1159 + xudc_done(ep, req, -ECONNRESET); 1160 + spin_unlock_irqrestore(&udc->lock, flags); 1161 + 1162 + return 0; 1163 + } 1164 + 1165 + /** 1166 + * xudc_ep0_enable - Enables the given endpoint. 1167 + * @ep: pointer to the usb endpoint structure. 1168 + * @desc: pointer to usb endpoint descriptor. 1169 + * 1170 + * Return: error always. 1171 + * 1172 + * endpoint 0 enable should not be called by gadget layer. 1173 + */ 1174 + static int xudc_ep0_enable(struct usb_ep *ep, 1175 + const struct usb_endpoint_descriptor *desc) 1176 + { 1177 + return -EINVAL; 1178 + } 1179 + 1180 + /** 1181 + * xudc_ep0_disable - Disables the given endpoint. 1182 + * @ep: pointer to the usb endpoint structure. 1183 + * 1184 + * Return: error always. 1185 + * 1186 + * endpoint 0 disable should not be called by gadget layer. 1187 + */ 1188 + static int xudc_ep0_disable(struct usb_ep *ep) 1189 + { 1190 + return -EINVAL; 1191 + } 1192 + 1193 + static const struct usb_ep_ops xusb_ep0_ops = { 1194 + .enable = xudc_ep0_enable, 1195 + .disable = xudc_ep0_disable, 1196 + .alloc_request = xudc_ep_alloc_request, 1197 + .free_request = xudc_free_request, 1198 + .queue = xudc_ep0_queue, 1199 + .dequeue = xudc_ep_dequeue, 1200 + .set_halt = xudc_ep_set_halt, 1201 + }; 1202 + 1203 + static const struct usb_ep_ops xusb_ep_ops = { 1204 + .enable = xudc_ep_enable, 1205 + .disable = xudc_ep_disable, 1206 + .alloc_request = xudc_ep_alloc_request, 1207 + .free_request = xudc_free_request, 1208 + .queue = xudc_ep_queue, 1209 + .dequeue = xudc_ep_dequeue, 1210 + .set_halt = xudc_ep_set_halt, 1211 + }; 1212 + 1213 + /** 1214 + * xudc_get_frame - Reads the current usb frame number. 1215 + * @gadget: pointer to the usb gadget structure. 1216 + * 1217 + * Return: current frame number for success and error value on failure. 1218 + */ 1219 + static int xudc_get_frame(struct usb_gadget *gadget) 1220 + { 1221 + struct xusb_udc *udc; 1222 + int frame; 1223 + 1224 + if (!gadget) 1225 + return -ENODEV; 1226 + 1227 + udc = to_udc(gadget); 1228 + frame = udc->read_fn(udc->addr + XUSB_FRAMENUM_OFFSET); 1229 + return frame; 1230 + } 1231 + 1232 + /** 1233 + * xudc_wakeup - Send remote wakeup signal to host 1234 + * @gadget: pointer to the usb gadget structure. 1235 + * 1236 + * Return: 0 on success and error on failure 1237 + */ 1238 + static int xudc_wakeup(struct usb_gadget *gadget) 1239 + { 1240 + struct xusb_udc *udc = to_udc(gadget); 1241 + u32 crtlreg; 1242 + int status = -EINVAL; 1243 + unsigned long flags; 1244 + 1245 + spin_lock_irqsave(&udc->lock, flags); 1246 + 1247 + /* Remote wake up not enabled by host */ 1248 + if (!udc->remote_wkp) 1249 + goto done; 1250 + 1251 + crtlreg = udc->read_fn(udc->addr + XUSB_CONTROL_OFFSET); 1252 + crtlreg |= XUSB_CONTROL_USB_RMTWAKE_MASK; 1253 + /* set remote wake up bit */ 1254 + udc->write_fn(udc->addr, XUSB_CONTROL_OFFSET, crtlreg); 1255 + /* 1256 + * wait for a while and reset remote wake up bit since this bit 1257 + * is not cleared by HW after sending remote wakeup to host. 1258 + */ 1259 + mdelay(2); 1260 + 1261 + crtlreg &= ~XUSB_CONTROL_USB_RMTWAKE_MASK; 1262 + udc->write_fn(udc->addr, XUSB_CONTROL_OFFSET, crtlreg); 1263 + status = 0; 1264 + done: 1265 + spin_unlock_irqrestore(&udc->lock, flags); 1266 + return status; 1267 + } 1268 + 1269 + /** 1270 + * xudc_pullup - start/stop USB traffic 1271 + * @gadget: pointer to the usb gadget structure. 1272 + * @is_on: flag to start or stop 1273 + * 1274 + * Return: 0 always 1275 + * 1276 + * This function starts/stops SIE engine of IP based on is_on. 1277 + */ 1278 + static int xudc_pullup(struct usb_gadget *gadget, int is_on) 1279 + { 1280 + struct xusb_udc *udc = to_udc(gadget); 1281 + unsigned long flags; 1282 + u32 crtlreg; 1283 + 1284 + spin_lock_irqsave(&udc->lock, flags); 1285 + 1286 + crtlreg = udc->read_fn(udc->addr + XUSB_CONTROL_OFFSET); 1287 + if (is_on) 1288 + crtlreg |= XUSB_CONTROL_USB_READY_MASK; 1289 + else 1290 + crtlreg &= ~XUSB_CONTROL_USB_READY_MASK; 1291 + 1292 + udc->write_fn(udc->addr, XUSB_CONTROL_OFFSET, crtlreg); 1293 + 1294 + spin_unlock_irqrestore(&udc->lock, flags); 1295 + 1296 + return 0; 1297 + } 1298 + 1299 + /** 1300 + * xudc_eps_init - initialize endpoints. 1301 + * @udc: pointer to the usb device controller structure. 1302 + */ 1303 + static void xudc_eps_init(struct xusb_udc *udc) 1304 + { 1305 + u32 ep_number; 1306 + 1307 + INIT_LIST_HEAD(&udc->gadget.ep_list); 1308 + 1309 + for (ep_number = 0; ep_number < XUSB_MAX_ENDPOINTS; ep_number++) { 1310 + struct xusb_ep *ep = &udc->ep[ep_number]; 1311 + 1312 + if (ep_number) { 1313 + list_add_tail(&ep->ep_usb.ep_list, 1314 + &udc->gadget.ep_list); 1315 + usb_ep_set_maxpacket_limit(&ep->ep_usb, 1316 + (unsigned short) ~0); 1317 + snprintf(ep->name, EPNAME_SIZE, "ep%d", ep_number); 1318 + ep->ep_usb.name = ep->name; 1319 + ep->ep_usb.ops = &xusb_ep_ops; 1320 + } else { 1321 + ep->ep_usb.name = ep0name; 1322 + usb_ep_set_maxpacket_limit(&ep->ep_usb, EP0_MAX_PACKET); 1323 + ep->ep_usb.ops = &xusb_ep0_ops; 1324 + } 1325 + 1326 + ep->udc = udc; 1327 + ep->epnumber = ep_number; 1328 + ep->desc = NULL; 1329 + /* 1330 + * The configuration register address offset between 1331 + * each endpoint is 0x10. 1332 + */ 1333 + ep->offset = XUSB_EP0_CONFIG_OFFSET + (ep_number * 0x10); 1334 + ep->is_in = 0; 1335 + ep->is_iso = 0; 1336 + ep->maxpacket = 0; 1337 + xudc_epconfig(ep, udc); 1338 + 1339 + /* Initialize one queue per endpoint */ 1340 + INIT_LIST_HEAD(&ep->queue); 1341 + } 1342 + } 1343 + 1344 + /** 1345 + * xudc_stop_activity - Stops any further activity on the device. 1346 + * @udc: pointer to the usb device controller structure. 1347 + */ 1348 + static void xudc_stop_activity(struct xusb_udc *udc) 1349 + { 1350 + int i; 1351 + struct xusb_ep *ep; 1352 + 1353 + for (i = 0; i < XUSB_MAX_ENDPOINTS; i++) { 1354 + ep = &udc->ep[i]; 1355 + xudc_nuke(ep, -ESHUTDOWN); 1356 + } 1357 + } 1358 + 1359 + /** 1360 + * xudc_start - Starts the device. 1361 + * @gadget: pointer to the usb gadget structure 1362 + * @driver: pointer to gadget driver structure 1363 + * 1364 + * Return: zero on success and error on failure 1365 + */ 1366 + static int xudc_start(struct usb_gadget *gadget, 1367 + struct usb_gadget_driver *driver) 1368 + { 1369 + struct xusb_udc *udc = to_udc(gadget); 1370 + struct xusb_ep *ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO]; 1371 + const struct usb_endpoint_descriptor *desc = &config_bulk_out_desc; 1372 + unsigned long flags; 1373 + int ret = 0; 1374 + 1375 + spin_lock_irqsave(&udc->lock, flags); 1376 + 1377 + if (udc->driver) { 1378 + dev_err(udc->dev, "%s is already bound to %s\n", 1379 + udc->gadget.name, udc->driver->driver.name); 1380 + ret = -EBUSY; 1381 + goto err; 1382 + } 1383 + 1384 + /* hook up the driver */ 1385 + udc->driver = driver; 1386 + udc->gadget.speed = driver->max_speed; 1387 + 1388 + /* Enable the control endpoint. */ 1389 + ret = __xudc_ep_enable(ep0, desc); 1390 + 1391 + /* Set device address and remote wakeup to 0 */ 1392 + udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0); 1393 + udc->remote_wkp = 0; 1394 + err: 1395 + spin_unlock_irqrestore(&udc->lock, flags); 1396 + return ret; 1397 + } 1398 + 1399 + /** 1400 + * xudc_stop - stops the device. 1401 + * @gadget: pointer to the usb gadget structure 1402 + * @driver: pointer to usb gadget driver structure 1403 + * 1404 + * Return: zero always 1405 + */ 1406 + static int xudc_stop(struct usb_gadget *gadget, 1407 + struct usb_gadget_driver *driver) 1408 + { 1409 + struct xusb_udc *udc = to_udc(gadget); 1410 + unsigned long flags; 1411 + 1412 + spin_lock_irqsave(&udc->lock, flags); 1413 + 1414 + udc->gadget.speed = USB_SPEED_UNKNOWN; 1415 + udc->driver = NULL; 1416 + 1417 + /* Set device address and remote wakeup to 0 */ 1418 + udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0); 1419 + udc->remote_wkp = 0; 1420 + 1421 + xudc_stop_activity(udc); 1422 + 1423 + spin_unlock_irqrestore(&udc->lock, flags); 1424 + 1425 + return 0; 1426 + } 1427 + 1428 + static const struct usb_gadget_ops xusb_udc_ops = { 1429 + .get_frame = xudc_get_frame, 1430 + .wakeup = xudc_wakeup, 1431 + .pullup = xudc_pullup, 1432 + .udc_start = xudc_start, 1433 + .udc_stop = xudc_stop, 1434 + }; 1435 + 1436 + /** 1437 + * xudc_clear_stall_all_ep - clears stall of every endpoint. 1438 + * @udc: pointer to the udc structure. 1439 + */ 1440 + static void xudc_clear_stall_all_ep(struct xusb_udc *udc) 1441 + { 1442 + struct xusb_ep *ep; 1443 + u32 epcfgreg; 1444 + int i; 1445 + 1446 + for (i = 0; i < XUSB_MAX_ENDPOINTS; i++) { 1447 + ep = &udc->ep[i]; 1448 + epcfgreg = udc->read_fn(udc->addr + ep->offset); 1449 + epcfgreg &= ~XUSB_EP_CFG_STALL_MASK; 1450 + udc->write_fn(udc->addr, ep->offset, epcfgreg); 1451 + if (ep->epnumber) { 1452 + /* Reset the toggle bit.*/ 1453 + epcfgreg = udc->read_fn(udc->addr + ep->offset); 1454 + epcfgreg &= ~XUSB_EP_CFG_DATA_TOGGLE_MASK; 1455 + udc->write_fn(udc->addr, ep->offset, epcfgreg); 1456 + } 1457 + } 1458 + } 1459 + 1460 + /** 1461 + * xudc_startup_handler - The usb device controller interrupt handler. 1462 + * @udc: pointer to the udc structure. 1463 + * @intrstatus: The mask value containing the interrupt sources. 1464 + * 1465 + * This function handles the RESET,SUSPEND,RESUME and DISCONNECT interrupts. 1466 + */ 1467 + static void xudc_startup_handler(struct xusb_udc *udc, u32 intrstatus) 1468 + { 1469 + u32 intrreg; 1470 + 1471 + if (intrstatus & XUSB_STATUS_RESET_MASK) { 1472 + 1473 + dev_dbg(udc->dev, "Reset\n"); 1474 + 1475 + if (intrstatus & XUSB_STATUS_HIGH_SPEED_MASK) 1476 + udc->gadget.speed = USB_SPEED_HIGH; 1477 + else 1478 + udc->gadget.speed = USB_SPEED_FULL; 1479 + 1480 + xudc_stop_activity(udc); 1481 + xudc_clear_stall_all_ep(udc); 1482 + udc->write_fn(udc->addr, XUSB_TESTMODE_OFFSET, 0); 1483 + 1484 + /* Set device address and remote wakeup to 0 */ 1485 + udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0); 1486 + udc->remote_wkp = 0; 1487 + 1488 + /* Enable the suspend, resume and disconnect */ 1489 + intrreg = udc->read_fn(udc->addr + XUSB_IER_OFFSET); 1490 + intrreg |= XUSB_STATUS_SUSPEND_MASK | XUSB_STATUS_RESUME_MASK | 1491 + XUSB_STATUS_DISCONNECT_MASK; 1492 + udc->write_fn(udc->addr, XUSB_IER_OFFSET, intrreg); 1493 + } 1494 + if (intrstatus & XUSB_STATUS_SUSPEND_MASK) { 1495 + 1496 + dev_dbg(udc->dev, "Suspend\n"); 1497 + 1498 + /* Enable the reset, resume and disconnect */ 1499 + intrreg = udc->read_fn(udc->addr + XUSB_IER_OFFSET); 1500 + intrreg |= XUSB_STATUS_RESET_MASK | XUSB_STATUS_RESUME_MASK | 1501 + XUSB_STATUS_DISCONNECT_MASK; 1502 + udc->write_fn(udc->addr, XUSB_IER_OFFSET, intrreg); 1503 + 1504 + udc->usb_state = USB_STATE_SUSPENDED; 1505 + 1506 + if (udc->driver->suspend) { 1507 + spin_unlock(&udc->lock); 1508 + udc->driver->suspend(&udc->gadget); 1509 + spin_lock(&udc->lock); 1510 + } 1511 + } 1512 + if (intrstatus & XUSB_STATUS_RESUME_MASK) { 1513 + bool condition = (udc->usb_state != USB_STATE_SUSPENDED); 1514 + 1515 + dev_WARN_ONCE(udc->dev, condition, 1516 + "Resume IRQ while not suspended\n"); 1517 + 1518 + dev_dbg(udc->dev, "Resume\n"); 1519 + 1520 + /* Enable the reset, suspend and disconnect */ 1521 + intrreg = udc->read_fn(udc->addr + XUSB_IER_OFFSET); 1522 + intrreg |= XUSB_STATUS_RESET_MASK | XUSB_STATUS_SUSPEND_MASK | 1523 + XUSB_STATUS_DISCONNECT_MASK; 1524 + udc->write_fn(udc->addr, XUSB_IER_OFFSET, intrreg); 1525 + 1526 + udc->usb_state = 0; 1527 + 1528 + if (udc->driver->resume) { 1529 + spin_unlock(&udc->lock); 1530 + udc->driver->resume(&udc->gadget); 1531 + spin_lock(&udc->lock); 1532 + } 1533 + } 1534 + if (intrstatus & XUSB_STATUS_DISCONNECT_MASK) { 1535 + 1536 + dev_dbg(udc->dev, "Disconnect\n"); 1537 + 1538 + /* Enable the reset, resume and suspend */ 1539 + intrreg = udc->read_fn(udc->addr + XUSB_IER_OFFSET); 1540 + intrreg |= XUSB_STATUS_RESET_MASK | XUSB_STATUS_RESUME_MASK | 1541 + XUSB_STATUS_SUSPEND_MASK; 1542 + udc->write_fn(udc->addr, XUSB_IER_OFFSET, intrreg); 1543 + 1544 + if (udc->driver && udc->driver->disconnect) { 1545 + spin_unlock(&udc->lock); 1546 + udc->driver->disconnect(&udc->gadget); 1547 + spin_lock(&udc->lock); 1548 + } 1549 + } 1550 + } 1551 + 1552 + /** 1553 + * xudc_ep0_stall - Stall endpoint zero. 1554 + * @udc: pointer to the udc structure. 1555 + * 1556 + * This function stalls endpoint zero. 1557 + */ 1558 + static void xudc_ep0_stall(struct xusb_udc *udc) 1559 + { 1560 + u32 epcfgreg; 1561 + struct xusb_ep *ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO]; 1562 + 1563 + epcfgreg = udc->read_fn(udc->addr + ep0->offset); 1564 + epcfgreg |= XUSB_EP_CFG_STALL_MASK; 1565 + udc->write_fn(udc->addr, ep0->offset, epcfgreg); 1566 + } 1567 + 1568 + /** 1569 + * xudc_setaddress - executes SET_ADDRESS command 1570 + * @udc: pointer to the udc structure. 1571 + * 1572 + * This function executes USB SET_ADDRESS command 1573 + */ 1574 + static void xudc_setaddress(struct xusb_udc *udc) 1575 + { 1576 + struct xusb_ep *ep0 = &udc->ep[0]; 1577 + struct xusb_req *req = udc->req; 1578 + int ret; 1579 + 1580 + req->usb_req.length = 0; 1581 + ret = __xudc_ep0_queue(ep0, req); 1582 + if (ret == 0) 1583 + return; 1584 + 1585 + dev_err(udc->dev, "Can't respond to SET ADDRESS request\n"); 1586 + xudc_ep0_stall(udc); 1587 + } 1588 + 1589 + /** 1590 + * xudc_getstatus - executes GET_STATUS command 1591 + * @udc: pointer to the udc structure. 1592 + * 1593 + * This function executes USB GET_STATUS command 1594 + */ 1595 + static void xudc_getstatus(struct xusb_udc *udc) 1596 + { 1597 + struct xusb_ep *ep0 = &udc->ep[0]; 1598 + struct xusb_req *req = udc->req; 1599 + struct xusb_ep *target_ep; 1600 + u16 status = 0; 1601 + u32 epcfgreg; 1602 + int epnum; 1603 + u32 halt; 1604 + int ret; 1605 + 1606 + switch (udc->setup.bRequestType & USB_RECIP_MASK) { 1607 + case USB_RECIP_DEVICE: 1608 + /* Get device status */ 1609 + status = 1 << USB_DEVICE_SELF_POWERED; 1610 + if (udc->remote_wkp) 1611 + status |= (1 << USB_DEVICE_REMOTE_WAKEUP); 1612 + break; 1613 + case USB_RECIP_INTERFACE: 1614 + break; 1615 + case USB_RECIP_ENDPOINT: 1616 + epnum = udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK; 1617 + target_ep = &udc->ep[epnum]; 1618 + epcfgreg = udc->read_fn(udc->addr + target_ep->offset); 1619 + halt = epcfgreg & XUSB_EP_CFG_STALL_MASK; 1620 + if (udc->setup.wIndex & USB_DIR_IN) { 1621 + if (!target_ep->is_in) 1622 + goto stall; 1623 + } else { 1624 + if (target_ep->is_in) 1625 + goto stall; 1626 + } 1627 + if (halt) 1628 + status = 1 << USB_ENDPOINT_HALT; 1629 + break; 1630 + default: 1631 + goto stall; 1632 + } 1633 + 1634 + req->usb_req.length = 2; 1635 + *(u16 *)req->usb_req.buf = cpu_to_le16(status); 1636 + ret = __xudc_ep0_queue(ep0, req); 1637 + if (ret == 0) 1638 + return; 1639 + stall: 1640 + dev_err(udc->dev, "Can't respond to getstatus request\n"); 1641 + xudc_ep0_stall(udc); 1642 + } 1643 + 1644 + /** 1645 + * xudc_set_clear_feature - Executes the set feature and clear feature commands. 1646 + * @udc: pointer to the usb device controller structure. 1647 + * 1648 + * Processes the SET_FEATURE and CLEAR_FEATURE commands. 1649 + */ 1650 + static void xudc_set_clear_feature(struct xusb_udc *udc) 1651 + { 1652 + struct xusb_ep *ep0 = &udc->ep[0]; 1653 + struct xusb_req *req = udc->req; 1654 + struct xusb_ep *target_ep; 1655 + u8 endpoint; 1656 + u8 outinbit; 1657 + u32 epcfgreg; 1658 + int flag = (udc->setup.bRequest == USB_REQ_SET_FEATURE ? 1 : 0); 1659 + int ret; 1660 + 1661 + switch (udc->setup.bRequestType) { 1662 + case USB_RECIP_DEVICE: 1663 + switch (udc->setup.wValue) { 1664 + case USB_DEVICE_TEST_MODE: 1665 + /* 1666 + * The Test Mode will be executed 1667 + * after the status phase. 1668 + */ 1669 + break; 1670 + case USB_DEVICE_REMOTE_WAKEUP: 1671 + if (flag) 1672 + udc->remote_wkp = 1; 1673 + else 1674 + udc->remote_wkp = 0; 1675 + break; 1676 + default: 1677 + xudc_ep0_stall(udc); 1678 + break; 1679 + } 1680 + break; 1681 + case USB_RECIP_ENDPOINT: 1682 + if (!udc->setup.wValue) { 1683 + endpoint = udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK; 1684 + target_ep = &udc->ep[endpoint]; 1685 + outinbit = udc->setup.wIndex & USB_ENDPOINT_DIR_MASK; 1686 + outinbit = outinbit >> 7; 1687 + 1688 + /* Make sure direction matches.*/ 1689 + if (outinbit != target_ep->is_in) { 1690 + xudc_ep0_stall(udc); 1691 + return; 1692 + } 1693 + epcfgreg = udc->read_fn(udc->addr + target_ep->offset); 1694 + if (!endpoint) { 1695 + /* Clear the stall.*/ 1696 + epcfgreg &= ~XUSB_EP_CFG_STALL_MASK; 1697 + udc->write_fn(udc->addr, 1698 + target_ep->offset, epcfgreg); 1699 + } else { 1700 + if (flag) { 1701 + epcfgreg |= XUSB_EP_CFG_STALL_MASK; 1702 + udc->write_fn(udc->addr, 1703 + target_ep->offset, 1704 + epcfgreg); 1705 + } else { 1706 + /* Unstall the endpoint.*/ 1707 + epcfgreg &= ~(XUSB_EP_CFG_STALL_MASK | 1708 + XUSB_EP_CFG_DATA_TOGGLE_MASK); 1709 + udc->write_fn(udc->addr, 1710 + target_ep->offset, 1711 + epcfgreg); 1712 + } 1713 + } 1714 + } 1715 + break; 1716 + default: 1717 + xudc_ep0_stall(udc); 1718 + return; 1719 + } 1720 + 1721 + req->usb_req.length = 0; 1722 + ret = __xudc_ep0_queue(ep0, req); 1723 + if (ret == 0) 1724 + return; 1725 + 1726 + dev_err(udc->dev, "Can't respond to SET/CLEAR FEATURE\n"); 1727 + xudc_ep0_stall(udc); 1728 + } 1729 + 1730 + /** 1731 + * xudc_handle_setup - Processes the setup packet. 1732 + * @udc: pointer to the usb device controller structure. 1733 + * 1734 + * Process setup packet and delegate to gadget layer. 1735 + */ 1736 + static void xudc_handle_setup(struct xusb_udc *udc) 1737 + { 1738 + struct xusb_ep *ep0 = &udc->ep[0]; 1739 + struct usb_ctrlrequest setup; 1740 + u32 *ep0rambase; 1741 + 1742 + /* Load up the chapter 9 command buffer.*/ 1743 + ep0rambase = (u32 __force *) (udc->addr + XUSB_SETUP_PKT_ADDR_OFFSET); 1744 + memcpy(&setup, ep0rambase, 8); 1745 + 1746 + udc->setup = setup; 1747 + udc->setup.wValue = cpu_to_le16(setup.wValue); 1748 + udc->setup.wIndex = cpu_to_le16(setup.wIndex); 1749 + udc->setup.wLength = cpu_to_le16(setup.wLength); 1750 + 1751 + /* Clear previous requests */ 1752 + xudc_nuke(ep0, -ECONNRESET); 1753 + 1754 + if (udc->setup.bRequestType & USB_DIR_IN) { 1755 + /* Execute the get command.*/ 1756 + udc->setupseqrx = STATUS_PHASE; 1757 + udc->setupseqtx = DATA_PHASE; 1758 + } else { 1759 + /* Execute the put command.*/ 1760 + udc->setupseqrx = DATA_PHASE; 1761 + udc->setupseqtx = STATUS_PHASE; 1762 + } 1763 + 1764 + switch (udc->setup.bRequest) { 1765 + case USB_REQ_GET_STATUS: 1766 + /* Data+Status phase form udc */ 1767 + if ((udc->setup.bRequestType & 1768 + (USB_DIR_IN | USB_TYPE_MASK)) != 1769 + (USB_DIR_IN | USB_TYPE_STANDARD)) 1770 + break; 1771 + xudc_getstatus(udc); 1772 + return; 1773 + case USB_REQ_SET_ADDRESS: 1774 + /* Status phase from udc */ 1775 + if (udc->setup.bRequestType != (USB_DIR_OUT | 1776 + USB_TYPE_STANDARD | USB_RECIP_DEVICE)) 1777 + break; 1778 + xudc_setaddress(udc); 1779 + return; 1780 + case USB_REQ_CLEAR_FEATURE: 1781 + case USB_REQ_SET_FEATURE: 1782 + /* Requests with no data phase, status phase from udc */ 1783 + if ((udc->setup.bRequestType & USB_TYPE_MASK) 1784 + != USB_TYPE_STANDARD) 1785 + break; 1786 + xudc_set_clear_feature(udc); 1787 + return; 1788 + default: 1789 + break; 1790 + } 1791 + 1792 + spin_unlock(&udc->lock); 1793 + if (udc->driver->setup(&udc->gadget, &setup) < 0) 1794 + xudc_ep0_stall(udc); 1795 + spin_lock(&udc->lock); 1796 + } 1797 + 1798 + /** 1799 + * xudc_ep0_out - Processes the endpoint 0 OUT token. 1800 + * @udc: pointer to the usb device controller structure. 1801 + */ 1802 + static void xudc_ep0_out(struct xusb_udc *udc) 1803 + { 1804 + struct xusb_ep *ep0 = &udc->ep[0]; 1805 + struct xusb_req *req; 1806 + u8 *ep0rambase; 1807 + unsigned int bytes_to_rx; 1808 + void *buffer; 1809 + 1810 + req = list_first_entry(&ep0->queue, struct xusb_req, queue); 1811 + 1812 + switch (udc->setupseqrx) { 1813 + case STATUS_PHASE: 1814 + /* 1815 + * This resets both state machines for the next 1816 + * Setup packet. 1817 + */ 1818 + udc->setupseqrx = SETUP_PHASE; 1819 + udc->setupseqtx = SETUP_PHASE; 1820 + req->usb_req.actual = req->usb_req.length; 1821 + xudc_done(ep0, req, 0); 1822 + break; 1823 + case DATA_PHASE: 1824 + bytes_to_rx = udc->read_fn(udc->addr + 1825 + XUSB_EP_BUF0COUNT_OFFSET); 1826 + /* Copy the data to be received from the DPRAM. */ 1827 + ep0rambase = (u8 __force *) (udc->addr + 1828 + (ep0->rambase << 2)); 1829 + buffer = req->usb_req.buf + req->usb_req.actual; 1830 + req->usb_req.actual = req->usb_req.actual + bytes_to_rx; 1831 + memcpy(buffer, ep0rambase, bytes_to_rx); 1832 + 1833 + if (req->usb_req.length == req->usb_req.actual) { 1834 + /* Data transfer completed get ready for Status stage */ 1835 + xudc_wrstatus(udc); 1836 + } else { 1837 + /* Enable EP0 buffer to receive data */ 1838 + udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, 0); 1839 + udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); 1840 + } 1841 + break; 1842 + default: 1843 + break; 1844 + } 1845 + } 1846 + 1847 + /** 1848 + * xudc_ep0_in - Processes the endpoint 0 IN token. 1849 + * @udc: pointer to the usb device controller structure. 1850 + */ 1851 + static void xudc_ep0_in(struct xusb_udc *udc) 1852 + { 1853 + struct xusb_ep *ep0 = &udc->ep[0]; 1854 + struct xusb_req *req; 1855 + unsigned int bytes_to_tx; 1856 + void *buffer; 1857 + u32 epcfgreg; 1858 + u16 count = 0; 1859 + u16 length; 1860 + u8 *ep0rambase; 1861 + u8 test_mode = udc->setup.wIndex >> 8; 1862 + 1863 + req = list_first_entry(&ep0->queue, struct xusb_req, queue); 1864 + bytes_to_tx = req->usb_req.length - req->usb_req.actual; 1865 + 1866 + switch (udc->setupseqtx) { 1867 + case STATUS_PHASE: 1868 + switch (udc->setup.bRequest) { 1869 + case USB_REQ_SET_ADDRESS: 1870 + /* Set the address of the device.*/ 1871 + udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 1872 + udc->setup.wValue); 1873 + break; 1874 + case USB_REQ_SET_FEATURE: 1875 + if (udc->setup.bRequestType == 1876 + USB_RECIP_DEVICE) { 1877 + if (udc->setup.wValue == 1878 + USB_DEVICE_TEST_MODE) 1879 + udc->write_fn(udc->addr, 1880 + XUSB_TESTMODE_OFFSET, 1881 + test_mode); 1882 + } 1883 + break; 1884 + } 1885 + req->usb_req.actual = req->usb_req.length; 1886 + xudc_done(ep0, req, 0); 1887 + break; 1888 + case DATA_PHASE: 1889 + if (!bytes_to_tx) { 1890 + /* 1891 + * We're done with data transfer, next 1892 + * will be zero length OUT with data toggle of 1893 + * 1. Setup data_toggle. 1894 + */ 1895 + epcfgreg = udc->read_fn(udc->addr + ep0->offset); 1896 + epcfgreg |= XUSB_EP_CFG_DATA_TOGGLE_MASK; 1897 + udc->write_fn(udc->addr, ep0->offset, epcfgreg); 1898 + udc->setupseqtx = STATUS_PHASE; 1899 + } else { 1900 + length = count = min_t(u32, bytes_to_tx, 1901 + EP0_MAX_PACKET); 1902 + /* Copy the data to be transmitted into the DPRAM. */ 1903 + ep0rambase = (u8 __force *) (udc->addr + 1904 + (ep0->rambase << 2)); 1905 + buffer = req->usb_req.buf + req->usb_req.actual; 1906 + req->usb_req.actual = req->usb_req.actual + length; 1907 + memcpy(ep0rambase, buffer, length); 1908 + } 1909 + udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, count); 1910 + udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); 1911 + break; 1912 + default: 1913 + break; 1914 + } 1915 + } 1916 + 1917 + /** 1918 + * xudc_ctrl_ep_handler - Endpoint 0 interrupt handler. 1919 + * @udc: pointer to the udc structure. 1920 + * @intrstatus: It's the mask value for the interrupt sources on endpoint 0. 1921 + * 1922 + * Processes the commands received during enumeration phase. 1923 + */ 1924 + static void xudc_ctrl_ep_handler(struct xusb_udc *udc, u32 intrstatus) 1925 + { 1926 + 1927 + if (intrstatus & XUSB_STATUS_SETUP_PACKET_MASK) { 1928 + xudc_handle_setup(udc); 1929 + } else { 1930 + if (intrstatus & XUSB_STATUS_FIFO_BUFF_RDY_MASK) 1931 + xudc_ep0_out(udc); 1932 + else if (intrstatus & XUSB_STATUS_FIFO_BUFF_FREE_MASK) 1933 + xudc_ep0_in(udc); 1934 + } 1935 + } 1936 + 1937 + /** 1938 + * xudc_nonctrl_ep_handler - Non control endpoint interrupt handler. 1939 + * @udc: pointer to the udc structure. 1940 + * @epnum: End point number for which the interrupt is to be processed 1941 + * @intrstatus: mask value for interrupt sources of endpoints other 1942 + * than endpoint 0. 1943 + * 1944 + * Processes the buffer completion interrupts. 1945 + */ 1946 + static void xudc_nonctrl_ep_handler(struct xusb_udc *udc, u8 epnum, 1947 + u32 intrstatus) 1948 + { 1949 + 1950 + struct xusb_req *req; 1951 + struct xusb_ep *ep; 1952 + 1953 + ep = &udc->ep[epnum]; 1954 + /* Process the End point interrupts.*/ 1955 + if (intrstatus & (XUSB_STATUS_EP0_BUFF1_COMP_MASK << epnum)) 1956 + ep->buffer0ready = 0; 1957 + if (intrstatus & (XUSB_STATUS_EP0_BUFF2_COMP_MASK << epnum)) 1958 + ep->buffer1ready = 0; 1959 + 1960 + if (list_empty(&ep->queue)) 1961 + return; 1962 + 1963 + req = list_first_entry(&ep->queue, struct xusb_req, queue); 1964 + 1965 + if (ep->is_in) 1966 + xudc_write_fifo(ep, req); 1967 + else 1968 + xudc_read_fifo(ep, req); 1969 + } 1970 + 1971 + /** 1972 + * xudc_irq - The main interrupt handler. 1973 + * @irq: The interrupt number. 1974 + * @_udc: pointer to the usb device controller structure. 1975 + * 1976 + * Return: IRQ_HANDLED after the interrupt is handled. 1977 + */ 1978 + static irqreturn_t xudc_irq(int irq, void *_udc) 1979 + { 1980 + struct xusb_udc *udc = _udc; 1981 + u32 intrstatus; 1982 + u32 ier; 1983 + u8 index; 1984 + u32 bufintr; 1985 + unsigned long flags; 1986 + 1987 + spin_lock_irqsave(&udc->lock, flags); 1988 + 1989 + /* 1990 + * Event interrupts are level sensitive hence first disable 1991 + * IER, read ISR and figure out active interrupts. 1992 + */ 1993 + ier = udc->read_fn(udc->addr + XUSB_IER_OFFSET); 1994 + ier &= ~XUSB_STATUS_INTR_EVENT_MASK; 1995 + udc->write_fn(udc->addr, XUSB_IER_OFFSET, ier); 1996 + 1997 + /* Read the Interrupt Status Register.*/ 1998 + intrstatus = udc->read_fn(udc->addr + XUSB_STATUS_OFFSET); 1999 + 2000 + /* Call the handler for the event interrupt.*/ 2001 + if (intrstatus & XUSB_STATUS_INTR_EVENT_MASK) { 2002 + /* 2003 + * Check if there is any action to be done for : 2004 + * - USB Reset received {XUSB_STATUS_RESET_MASK} 2005 + * - USB Suspend received {XUSB_STATUS_SUSPEND_MASK} 2006 + * - USB Resume received {XUSB_STATUS_RESUME_MASK} 2007 + * - USB Disconnect received {XUSB_STATUS_DISCONNECT_MASK} 2008 + */ 2009 + xudc_startup_handler(udc, intrstatus); 2010 + } 2011 + 2012 + /* Check the buffer completion interrupts */ 2013 + if (intrstatus & XUSB_STATUS_INTR_BUFF_COMP_ALL_MASK) { 2014 + /* Enable Reset, Suspend, Resume and Disconnect */ 2015 + ier = udc->read_fn(udc->addr + XUSB_IER_OFFSET); 2016 + ier |= XUSB_STATUS_INTR_EVENT_MASK; 2017 + udc->write_fn(udc->addr, XUSB_IER_OFFSET, ier); 2018 + 2019 + if (intrstatus & XUSB_STATUS_EP0_BUFF1_COMP_MASK) 2020 + xudc_ctrl_ep_handler(udc, intrstatus); 2021 + 2022 + for (index = 1; index < 8; index++) { 2023 + bufintr = ((intrstatus & 2024 + (XUSB_STATUS_EP1_BUFF1_COMP_MASK << 2025 + (index - 1))) || (intrstatus & 2026 + (XUSB_STATUS_EP1_BUFF2_COMP_MASK << 2027 + (index - 1)))); 2028 + if (bufintr) { 2029 + xudc_nonctrl_ep_handler(udc, index, 2030 + intrstatus); 2031 + } 2032 + } 2033 + } 2034 + 2035 + spin_unlock_irqrestore(&udc->lock, flags); 2036 + return IRQ_HANDLED; 2037 + } 2038 + 2039 + /** 2040 + * xudc_probe - The device probe function for driver initialization. 2041 + * @pdev: pointer to the platform device structure. 2042 + * 2043 + * Return: 0 for success and error value on failure 2044 + */ 2045 + static int xudc_probe(struct platform_device *pdev) 2046 + { 2047 + struct device_node *np = pdev->dev.of_node; 2048 + struct resource *res; 2049 + struct xusb_udc *udc; 2050 + struct xusb_ep *ep0; 2051 + int irq; 2052 + int ret; 2053 + u32 ier; 2054 + u8 *buff; 2055 + 2056 + udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL); 2057 + if (!udc) 2058 + return -ENOMEM; 2059 + 2060 + /* Create a dummy request for GET_STATUS, SET_ADDRESS */ 2061 + udc->req = devm_kzalloc(&pdev->dev, sizeof(struct xusb_req), 2062 + GFP_KERNEL); 2063 + if (!udc->req) 2064 + return -ENOMEM; 2065 + 2066 + buff = devm_kzalloc(&pdev->dev, STATUSBUFF_SIZE, GFP_KERNEL); 2067 + if (!buff) 2068 + return -ENOMEM; 2069 + 2070 + udc->req->usb_req.buf = buff; 2071 + 2072 + /* Map the registers */ 2073 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2074 + udc->addr = devm_ioremap_resource(&pdev->dev, res); 2075 + if (!udc->addr) 2076 + return -ENOMEM; 2077 + 2078 + irq = platform_get_irq(pdev, 0); 2079 + if (irq < 0) { 2080 + dev_err(&pdev->dev, "unable to get irq\n"); 2081 + return irq; 2082 + } 2083 + ret = devm_request_irq(&pdev->dev, irq, xudc_irq, 0, 2084 + dev_name(&pdev->dev), udc); 2085 + if (ret < 0) { 2086 + dev_dbg(&pdev->dev, "unable to request irq %d", irq); 2087 + goto fail; 2088 + } 2089 + 2090 + udc->dma_enabled = of_property_read_bool(np, "xlnx,has-builtin-dma"); 2091 + 2092 + /* Setup gadget structure */ 2093 + udc->gadget.ops = &xusb_udc_ops; 2094 + udc->gadget.max_speed = USB_SPEED_HIGH; 2095 + udc->gadget.speed = USB_SPEED_UNKNOWN; 2096 + udc->gadget.ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO].ep_usb; 2097 + udc->gadget.name = driver_name; 2098 + 2099 + spin_lock_init(&udc->lock); 2100 + 2101 + /* Check for IP endianness */ 2102 + udc->write_fn = xudc_write32_be; 2103 + udc->read_fn = xudc_read32_be; 2104 + udc->write_fn(udc->addr, XUSB_TESTMODE_OFFSET, TEST_J); 2105 + if ((udc->read_fn(udc->addr + XUSB_TESTMODE_OFFSET)) 2106 + != TEST_J) { 2107 + udc->write_fn = xudc_write32; 2108 + udc->read_fn = xudc_read32; 2109 + } 2110 + udc->write_fn(udc->addr, XUSB_TESTMODE_OFFSET, 0); 2111 + 2112 + xudc_eps_init(udc); 2113 + 2114 + ep0 = &udc->ep[0]; 2115 + 2116 + /* Set device address to 0.*/ 2117 + udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0); 2118 + 2119 + ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); 2120 + if (ret) 2121 + goto fail; 2122 + 2123 + udc->dev = &udc->gadget.dev; 2124 + 2125 + /* Enable the interrupts.*/ 2126 + ier = XUSB_STATUS_GLOBAL_INTR_MASK | XUSB_STATUS_INTR_EVENT_MASK | 2127 + XUSB_STATUS_FIFO_BUFF_RDY_MASK | XUSB_STATUS_FIFO_BUFF_FREE_MASK | 2128 + XUSB_STATUS_SETUP_PACKET_MASK | 2129 + XUSB_STATUS_INTR_BUFF_COMP_ALL_MASK; 2130 + 2131 + udc->write_fn(udc->addr, XUSB_IER_OFFSET, ier); 2132 + 2133 + platform_set_drvdata(pdev, udc); 2134 + 2135 + dev_vdbg(&pdev->dev, "%s at 0x%08X mapped to 0x%08X %s\n", 2136 + driver_name, (u32)res->start, (u32 __force)udc->addr, 2137 + udc->dma_enabled ? "with DMA" : "without DMA"); 2138 + 2139 + return 0; 2140 + fail: 2141 + dev_err(&pdev->dev, "probe failed, %d\n", ret); 2142 + return ret; 2143 + } 2144 + 2145 + /** 2146 + * xudc_remove - Releases the resources allocated during the initialization. 2147 + * @pdev: pointer to the platform device structure. 2148 + * 2149 + * Return: 0 always 2150 + */ 2151 + static int xudc_remove(struct platform_device *pdev) 2152 + { 2153 + struct xusb_udc *udc = platform_get_drvdata(pdev); 2154 + 2155 + usb_del_gadget_udc(&udc->gadget); 2156 + 2157 + return 0; 2158 + } 2159 + 2160 + /* Match table for of_platform binding */ 2161 + static const struct of_device_id usb_of_match[] = { 2162 + { .compatible = "xlnx,usb2-device-4.00.a", }, 2163 + { /* end of list */ }, 2164 + }; 2165 + MODULE_DEVICE_TABLE(of, usb_of_match); 2166 + 2167 + static struct platform_driver xudc_driver = { 2168 + .driver = { 2169 + .name = driver_name, 2170 + .of_match_table = usb_of_match, 2171 + }, 2172 + .probe = xudc_probe, 2173 + .remove = xudc_remove, 2174 + }; 2175 + 2176 + module_platform_driver(xudc_driver); 2177 + 2178 + MODULE_DESCRIPTION("Xilinx udc driver"); 2179 + MODULE_AUTHOR("Xilinx, Inc"); 2180 + MODULE_LICENSE("GPL");
+98 -15
drivers/usb/misc/usbtest.c
··· 54 54 unsigned autoconf:1; 55 55 unsigned ctrl_out:1; 56 56 unsigned iso:1; /* try iso in/out */ 57 + unsigned intr:1; /* try interrupt in/out */ 57 58 int alt; 58 59 }; 59 60 ··· 71 70 int out_pipe; 72 71 int in_iso_pipe; 73 72 int out_iso_pipe; 73 + int in_int_pipe; 74 + int out_int_pipe; 74 75 struct usb_endpoint_descriptor *iso_in, *iso_out; 76 + struct usb_endpoint_descriptor *int_in, *int_out; 75 77 struct mutex lock; 76 78 77 79 #define TBUF_SIZE 256 ··· 105 101 struct usb_host_interface *alt; 106 102 struct usb_host_endpoint *in, *out; 107 103 struct usb_host_endpoint *iso_in, *iso_out; 104 + struct usb_host_endpoint *int_in, *int_out; 108 105 struct usb_device *udev; 109 106 110 107 for (tmp = 0; tmp < intf->num_altsetting; tmp++) { ··· 113 108 114 109 in = out = NULL; 115 110 iso_in = iso_out = NULL; 111 + int_in = int_out = NULL; 116 112 alt = intf->altsetting + tmp; 117 113 118 114 if (override_alt >= 0 && ··· 130 124 switch (usb_endpoint_type(&e->desc)) { 131 125 case USB_ENDPOINT_XFER_BULK: 132 126 break; 127 + case USB_ENDPOINT_XFER_INT: 128 + if (dev->info->intr) 129 + goto try_intr; 133 130 case USB_ENDPOINT_XFER_ISOC: 134 131 if (dev->info->iso) 135 132 goto try_iso; ··· 148 139 out = e; 149 140 } 150 141 continue; 142 + try_intr: 143 + if (usb_endpoint_dir_in(&e->desc)) { 144 + if (!int_in) 145 + int_in = e; 146 + } else { 147 + if (!int_out) 148 + int_out = e; 149 + } 150 + continue; 151 151 try_iso: 152 152 if (usb_endpoint_dir_in(&e->desc)) { 153 153 if (!iso_in) ··· 166 148 iso_out = e; 167 149 } 168 150 } 169 - if ((in && out) || iso_in || iso_out) 151 + if ((in && out) || iso_in || iso_out || int_in || int_out) 170 152 goto found; 171 153 } 172 154 return -EINVAL; ··· 201 183 iso_out->desc.bEndpointAddress 202 184 & USB_ENDPOINT_NUMBER_MASK); 203 185 } 186 + 187 + if (int_in) { 188 + dev->int_in = &int_in->desc; 189 + dev->in_int_pipe = usb_rcvintpipe(udev, 190 + int_in->desc.bEndpointAddress 191 + & USB_ENDPOINT_NUMBER_MASK); 192 + } 193 + 194 + if (int_out) { 195 + dev->int_out = &int_out->desc; 196 + dev->out_int_pipe = usb_sndintpipe(udev, 197 + int_out->desc.bEndpointAddress 198 + & USB_ENDPOINT_NUMBER_MASK); 199 + } 204 200 return 0; 205 201 } 206 202 ··· 237 205 int pipe, 238 206 unsigned long bytes, 239 207 unsigned transfer_flags, 240 - unsigned offset) 208 + unsigned offset, 209 + u8 bInterval) 241 210 { 242 211 struct urb *urb; 243 212 244 213 urb = usb_alloc_urb(0, GFP_KERNEL); 245 214 if (!urb) 246 215 return urb; 247 - usb_fill_bulk_urb(urb, udev, pipe, NULL, bytes, simple_callback, NULL); 216 + 217 + if (bInterval) 218 + usb_fill_int_urb(urb, udev, pipe, NULL, bytes, simple_callback, 219 + NULL, bInterval); 220 + else 221 + usb_fill_bulk_urb(urb, udev, pipe, NULL, bytes, simple_callback, 222 + NULL); 223 + 248 224 urb->interval = (udev->speed == USB_SPEED_HIGH) 249 225 ? (INTERRUPT_RATE << 3) 250 226 : INTERRUPT_RATE; ··· 291 251 static struct urb *simple_alloc_urb( 292 252 struct usb_device *udev, 293 253 int pipe, 294 - unsigned long bytes) 254 + unsigned long bytes, 255 + u8 bInterval) 295 256 { 296 - return usbtest_alloc_urb(udev, pipe, bytes, URB_NO_TRANSFER_DMA_MAP, 0); 257 + return usbtest_alloc_urb(udev, pipe, bytes, URB_NO_TRANSFER_DMA_MAP, 0, 258 + bInterval); 297 259 } 298 260 299 261 static unsigned pattern; ··· 1297 1255 goto cleanup; 1298 1256 } 1299 1257 req.wLength = cpu_to_le16(len); 1300 - urb[i] = u = simple_alloc_urb(udev, pipe, len); 1258 + urb[i] = u = simple_alloc_urb(udev, pipe, len, 0); 1301 1259 if (!u) 1302 1260 goto cleanup; 1303 1261 ··· 1370 1328 int retval = 0; 1371 1329 1372 1330 init_completion(&completion); 1373 - urb = simple_alloc_urb(testdev_to_usbdev(dev), pipe, size); 1331 + urb = simple_alloc_urb(testdev_to_usbdev(dev), pipe, size, 0); 1374 1332 if (!urb) 1375 1333 return -ENOMEM; 1376 1334 urb->context = &completion; ··· 1658 1616 struct usb_device *udev = testdev_to_usbdev(dev); 1659 1617 1660 1618 if (udev->speed == USB_SPEED_SUPER) 1661 - urb = simple_alloc_urb(udev, 0, 1024); 1619 + urb = simple_alloc_urb(udev, 0, 1024, 0); 1662 1620 else 1663 - urb = simple_alloc_urb(udev, 0, 512); 1621 + urb = simple_alloc_urb(udev, 0, 512, 0); 1664 1622 if (urb == NULL) 1665 1623 return -ENOMEM; 1666 1624 ··· 2004 1962 { 2005 1963 int retval; 2006 1964 struct urb *urb = usbtest_alloc_urb( 2007 - testdev_to_usbdev(tdev), pipe, length, transfer_flags, 1); 1965 + testdev_to_usbdev(tdev), pipe, length, transfer_flags, 1, 0); 2008 1966 2009 1967 if (!urb) 2010 1968 return -ENOMEM; ··· 2110 2068 dev_info(&intf->dev, 2111 2069 "TEST 1: write %d bytes %u times\n", 2112 2070 param->length, param->iterations); 2113 - urb = simple_alloc_urb(udev, dev->out_pipe, param->length); 2071 + urb = simple_alloc_urb(udev, dev->out_pipe, param->length, 0); 2114 2072 if (!urb) { 2115 2073 retval = -ENOMEM; 2116 2074 break; ··· 2125 2083 dev_info(&intf->dev, 2126 2084 "TEST 2: read %d bytes %u times\n", 2127 2085 param->length, param->iterations); 2128 - urb = simple_alloc_urb(udev, dev->in_pipe, param->length); 2086 + urb = simple_alloc_urb(udev, dev->in_pipe, param->length, 0); 2129 2087 if (!urb) { 2130 2088 retval = -ENOMEM; 2131 2089 break; ··· 2140 2098 dev_info(&intf->dev, 2141 2099 "TEST 3: write/%d 0..%d bytes %u times\n", 2142 2100 param->vary, param->length, param->iterations); 2143 - urb = simple_alloc_urb(udev, dev->out_pipe, param->length); 2101 + urb = simple_alloc_urb(udev, dev->out_pipe, param->length, 0); 2144 2102 if (!urb) { 2145 2103 retval = -ENOMEM; 2146 2104 break; ··· 2156 2114 dev_info(&intf->dev, 2157 2115 "TEST 4: read/%d 0..%d bytes %u times\n", 2158 2116 param->vary, param->length, param->iterations); 2159 - urb = simple_alloc_urb(udev, dev->in_pipe, param->length); 2117 + urb = simple_alloc_urb(udev, dev->in_pipe, param->length, 0); 2160 2118 if (!urb) { 2161 2119 retval = -ENOMEM; 2162 2120 break; ··· 2453 2411 } 2454 2412 break; 2455 2413 2414 + /* Simple non-queued interrupt I/O tests */ 2415 + case 25: 2416 + if (dev->out_int_pipe == 0) 2417 + break; 2418 + dev_info(&intf->dev, 2419 + "TEST 25: write %d bytes %u times\n", 2420 + param->length, param->iterations); 2421 + urb = simple_alloc_urb(udev, dev->out_int_pipe, param->length, 2422 + dev->int_out->bInterval); 2423 + if (!urb) { 2424 + retval = -ENOMEM; 2425 + break; 2426 + } 2427 + /* FIRMWARE: interrupt sink (maybe accepts short writes) */ 2428 + retval = simple_io(dev, urb, param->iterations, 0, 0, "test25"); 2429 + simple_free_urb(urb); 2430 + break; 2431 + case 26: 2432 + if (dev->in_int_pipe == 0) 2433 + break; 2434 + dev_info(&intf->dev, 2435 + "TEST 26: read %d bytes %u times\n", 2436 + param->length, param->iterations); 2437 + urb = simple_alloc_urb(udev, dev->in_int_pipe, param->length, 2438 + dev->int_in->bInterval); 2439 + if (!urb) { 2440 + retval = -ENOMEM; 2441 + break; 2442 + } 2443 + /* FIRMWARE: interrupt source (maybe generates short writes) */ 2444 + retval = simple_io(dev, urb, param->iterations, 0, 0, "test26"); 2445 + simple_free_urb(urb); 2446 + break; 2456 2447 } 2457 2448 do_gettimeofday(&param->duration); 2458 2449 param->duration.tv_sec -= start.tv_sec; ··· 2522 2447 struct usbtest_info *info; 2523 2448 char *rtest, *wtest; 2524 2449 char *irtest, *iwtest; 2450 + char *intrtest, *intwtest; 2525 2451 2526 2452 udev = interface_to_usbdev(intf); 2527 2453 ··· 2563 2487 */ 2564 2488 rtest = wtest = ""; 2565 2489 irtest = iwtest = ""; 2490 + intrtest = intwtest = ""; 2566 2491 if (force_interrupt || udev->speed == USB_SPEED_LOW) { 2567 2492 if (info->ep_in) { 2568 2493 dev->in_pipe = usb_rcvintpipe(udev, info->ep_in); ··· 2602 2525 irtest = " iso-in"; 2603 2526 if (dev->out_iso_pipe) 2604 2527 iwtest = " iso-out"; 2528 + if (dev->in_int_pipe) 2529 + intrtest = " int-in"; 2530 + if (dev->out_int_pipe) 2531 + intwtest = " int-out"; 2605 2532 } 2606 2533 2607 2534 usb_set_intfdata(intf, dev); 2608 2535 dev_info(&intf->dev, "%s\n", info->name); 2609 - dev_info(&intf->dev, "%s {control%s%s%s%s%s} tests%s\n", 2536 + dev_info(&intf->dev, "%s {control%s%s%s%s%s%s%s} tests%s\n", 2610 2537 usb_speed_string(udev->speed), 2611 2538 info->ctrl_out ? " in/out" : "", 2612 2539 rtest, wtest, 2613 2540 irtest, iwtest, 2541 + intrtest, intwtest, 2614 2542 info->alt >= 0 ? " (+alt)" : ""); 2615 2543 return 0; 2616 2544 } ··· 2689 2607 .autoconf = 1, 2690 2608 .ctrl_out = 1, 2691 2609 .iso = 1, 2610 + .intr = 1, 2692 2611 .alt = 0, 2693 2612 }; 2694 2613
+2 -2
drivers/usb/musb/musb_cppi41.c
··· 212 212 if (!list_empty(&controller->early_tx_list)) { 213 213 ret = HRTIMER_RESTART; 214 214 hrtimer_forward_now(&controller->early_tx, 215 - ktime_set(0, 50 * NSEC_PER_USEC)); 215 + ktime_set(0, 20 * NSEC_PER_USEC)); 216 216 } 217 217 218 218 spin_unlock_irqrestore(&musb->lock, flags); ··· 290 290 291 291 hrtimer_start_range_ns(&controller->early_tx, 292 292 ktime_set(0, usecs * NSEC_PER_USEC), 293 - 40 * NSEC_PER_USEC, 293 + 20 * NSEC_PER_USEC, 294 294 HRTIMER_MODE_REL); 295 295 } 296 296 }
+2
drivers/usb/musb/musb_dsps.c
··· 870 870 struct musb *musb = platform_get_drvdata(glue->musb); 871 871 void __iomem *mbase = musb->ctrl_base; 872 872 873 + del_timer_sync(&glue->timer); 873 874 glue->context.control = dsps_readl(mbase, wrp->control); 874 875 glue->context.epintr = dsps_readl(mbase, wrp->epintr_set); 875 876 glue->context.coreintr = dsps_readl(mbase, wrp->coreintr_set); ··· 896 895 dsps_writel(mbase, wrp->mode, glue->context.mode); 897 896 dsps_writel(mbase, wrp->tx_mode, glue->context.tx_mode); 898 897 dsps_writel(mbase, wrp->rx_mode, glue->context.rx_mode); 898 + setup_timer(&glue->timer, otg_timer, (unsigned long) musb); 899 899 900 900 return 0; 901 901 }
-16
drivers/usb/phy/Kconfig
··· 78 78 This driver provides common interface to interact, for Samsung USB 2.0 PHY 79 79 driver and later for Samsung USB 3.0 PHY driver. 80 80 81 - config SAMSUNG_USB2PHY 82 - tristate "Samsung USB 2.0 PHY controller Driver" 83 - select SAMSUNG_USBPHY 84 - select USB_PHY 85 - help 86 - Enable this to support Samsung USB 2.0 (High Speed) PHY controller 87 - driver for Samsung SoCs. 88 - 89 - config SAMSUNG_USB3PHY 90 - tristate "Samsung USB 3.0 PHY controller Driver" 91 - select SAMSUNG_USBPHY 92 - select USB_PHY 93 - help 94 - Enable this to support Samsung USB 3.0 (Super Speed) phy controller 95 - for samsung SoCs. 96 - 97 81 config TWL6030_USB 98 82 tristate "TWL6030 USB Transceiver Driver" 99 83 depends on TWL4030_CORE && OMAP_USB2 && USB_MUSB_OMAP2PLUS
-2
drivers/usb/phy/Makefile
··· 15 15 obj-$(CONFIG_AM335X_PHY_USB) += phy-am335x.o 16 16 obj-$(CONFIG_OMAP_OTG) += phy-omap-otg.o 17 17 obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o 18 - obj-$(CONFIG_SAMSUNG_USB2PHY) += phy-samsung-usb2.o 19 - obj-$(CONFIG_SAMSUNG_USB3PHY) += phy-samsung-usb3.o 20 18 obj-$(CONFIG_TWL6030_USB) += phy-twl6030-usb.o 21 19 obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o 22 20 obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o
+9 -6
drivers/usb/phy/phy-msm-usb.c
··· 281 281 { 282 282 int ret = 0; 283 283 284 - if (motg->pdata->phy_clk_reset && motg->phy_reset_clk) 284 + if (motg->pdata->phy_clk_reset) 285 285 ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk); 286 286 else if (motg->phy_rst) 287 287 ret = reset_control_reset(motg->phy_rst); ··· 1394 1394 return status; 1395 1395 } 1396 1396 1397 - const struct file_operations msm_otg_mode_fops = { 1397 + static const struct file_operations msm_otg_mode_fops = { 1398 1398 .open = msm_otg_mode_open, 1399 1399 .read = seq_read, 1400 1400 .write = msm_otg_mode_write, ··· 1554 1554 phy = &motg->phy; 1555 1555 phy->dev = &pdev->dev; 1556 1556 1557 - motg->phy_reset_clk = devm_clk_get(&pdev->dev, 1557 + if (motg->pdata->phy_clk_reset) { 1558 + motg->phy_reset_clk = devm_clk_get(&pdev->dev, 1558 1559 np ? "phy" : "usb_phy_clk"); 1559 - if (IS_ERR(motg->phy_reset_clk)) { 1560 - dev_err(&pdev->dev, "failed to get usb_phy_clk\n"); 1561 - motg->phy_reset_clk = NULL; 1560 + 1561 + if (IS_ERR(motg->phy_reset_clk)) { 1562 + dev_err(&pdev->dev, "failed to get usb_phy_clk\n"); 1563 + return PTR_ERR(motg->phy_reset_clk); 1564 + } 1562 1565 } 1563 1566 1564 1567 motg->clk = devm_clk_get(&pdev->dev, np ? "core" : "usb_hs_clk");
+6
drivers/usb/phy/phy-mxs-usb.c
··· 125 125 MXS_PHY_NEED_IP_FIX, 126 126 }; 127 127 128 + static const struct mxs_phy_data vf610_phy_data = { 129 + .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS | 130 + MXS_PHY_NEED_IP_FIX, 131 + }; 132 + 128 133 static const struct mxs_phy_data imx6sx_phy_data = { 129 134 .flags = MXS_PHY_DISCONNECT_LINE_WITHOUT_VBUS | 130 135 MXS_PHY_NEED_IP_FIX, ··· 140 135 { .compatible = "fsl,imx6sl-usbphy", .data = &imx6sl_phy_data, }, 141 136 { .compatible = "fsl,imx6q-usbphy", .data = &imx6q_phy_data, }, 142 137 { .compatible = "fsl,imx23-usbphy", .data = &imx23_phy_data, }, 138 + { .compatible = "fsl,vf610-usbphy", .data = &vf610_phy_data, }, 143 139 { /* sentinel */ } 144 140 }; 145 141 MODULE_DEVICE_TABLE(of, mxs_phy_dt_ids);
-241
drivers/usb/phy/phy-samsung-usb.c
··· 1 - /* linux/drivers/usb/phy/phy-samsung-usb.c 2 - * 3 - * Copyright (c) 2012 Samsung Electronics Co., Ltd. 4 - * http://www.samsung.com 5 - * 6 - * Author: Praveen Paneri <p.paneri@samsung.com> 7 - * 8 - * Samsung USB-PHY helper driver with common function calls; 9 - * interacts with Samsung USB 2.0 PHY controller driver and later 10 - * with Samsung USB 3.0 PHY driver. 11 - * 12 - * This program is free software; you can redistribute it and/or modify 13 - * it under the terms of the GNU General Public License version 2 as 14 - * published by the Free Software Foundation. 15 - * 16 - * This program is distributed in the hope that it will be useful, 17 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 - * GNU General Public License for more details. 20 - */ 21 - 22 - #include <linux/module.h> 23 - #include <linux/platform_device.h> 24 - #include <linux/clk.h> 25 - #include <linux/device.h> 26 - #include <linux/err.h> 27 - #include <linux/io.h> 28 - #include <linux/of.h> 29 - #include <linux/of_address.h> 30 - #include <linux/usb/samsung_usb_phy.h> 31 - 32 - #include "phy-samsung-usb.h" 33 - 34 - int samsung_usbphy_parse_dt(struct samsung_usbphy *sphy) 35 - { 36 - struct device_node *usbphy_sys; 37 - 38 - /* Getting node for system controller interface for usb-phy */ 39 - usbphy_sys = of_get_child_by_name(sphy->dev->of_node, "usbphy-sys"); 40 - if (!usbphy_sys) { 41 - dev_err(sphy->dev, "No sys-controller interface for usb-phy\n"); 42 - return -ENODEV; 43 - } 44 - 45 - sphy->pmuregs = of_iomap(usbphy_sys, 0); 46 - 47 - if (sphy->pmuregs == NULL) { 48 - dev_err(sphy->dev, "Can't get usb-phy pmu control register\n"); 49 - goto err0; 50 - } 51 - 52 - sphy->sysreg = of_iomap(usbphy_sys, 1); 53 - 54 - /* 55 - * Not returning error code here, since this situation is not fatal. 56 - * Few SoCs may not have this switch available 57 - */ 58 - if (sphy->sysreg == NULL) 59 - dev_warn(sphy->dev, "Can't get usb-phy sysreg cfg register\n"); 60 - 61 - of_node_put(usbphy_sys); 62 - 63 - return 0; 64 - 65 - err0: 66 - of_node_put(usbphy_sys); 67 - return -ENXIO; 68 - } 69 - EXPORT_SYMBOL_GPL(samsung_usbphy_parse_dt); 70 - 71 - /* 72 - * Set isolation here for phy. 73 - * Here 'on = true' would mean USB PHY block is isolated, hence 74 - * de-activated and vice-versa. 75 - */ 76 - void samsung_usbphy_set_isolation_4210(struct samsung_usbphy *sphy, bool on) 77 - { 78 - void __iomem *reg = NULL; 79 - u32 reg_val; 80 - u32 en_mask = 0; 81 - 82 - if (!sphy->pmuregs) { 83 - dev_warn(sphy->dev, "Can't set pmu isolation\n"); 84 - return; 85 - } 86 - 87 - if (sphy->phy_type == USB_PHY_TYPE_DEVICE) { 88 - reg = sphy->pmuregs + sphy->drv_data->devphy_reg_offset; 89 - en_mask = sphy->drv_data->devphy_en_mask; 90 - } else if (sphy->phy_type == USB_PHY_TYPE_HOST) { 91 - reg = sphy->pmuregs + sphy->drv_data->hostphy_reg_offset; 92 - en_mask = sphy->drv_data->hostphy_en_mask; 93 - } 94 - 95 - reg_val = readl(reg); 96 - 97 - if (on) 98 - reg_val &= ~en_mask; 99 - else 100 - reg_val |= en_mask; 101 - 102 - writel(reg_val, reg); 103 - 104 - if (sphy->drv_data->cpu_type == TYPE_EXYNOS4X12) { 105 - writel(reg_val, sphy->pmuregs + EXYNOS4X12_PHY_HSIC_CTRL0); 106 - writel(reg_val, sphy->pmuregs + EXYNOS4X12_PHY_HSIC_CTRL1); 107 - } 108 - } 109 - EXPORT_SYMBOL_GPL(samsung_usbphy_set_isolation_4210); 110 - 111 - /* 112 - * Configure the mode of working of usb-phy here: HOST/DEVICE. 113 - */ 114 - void samsung_usbphy_cfg_sel(struct samsung_usbphy *sphy) 115 - { 116 - u32 reg; 117 - 118 - if (!sphy->sysreg) { 119 - dev_warn(sphy->dev, "Can't configure specified phy mode\n"); 120 - return; 121 - } 122 - 123 - reg = readl(sphy->sysreg); 124 - 125 - if (sphy->phy_type == USB_PHY_TYPE_DEVICE) 126 - reg &= ~EXYNOS_USB20PHY_CFG_HOST_LINK; 127 - else if (sphy->phy_type == USB_PHY_TYPE_HOST) 128 - reg |= EXYNOS_USB20PHY_CFG_HOST_LINK; 129 - 130 - writel(reg, sphy->sysreg); 131 - } 132 - EXPORT_SYMBOL_GPL(samsung_usbphy_cfg_sel); 133 - 134 - /* 135 - * PHYs are different for USB Device and USB Host. 136 - * This make sure that correct PHY type is selected before 137 - * any operation on PHY. 138 - */ 139 - int samsung_usbphy_set_type(struct usb_phy *phy, 140 - enum samsung_usb_phy_type phy_type) 141 - { 142 - struct samsung_usbphy *sphy = phy_to_sphy(phy); 143 - 144 - sphy->phy_type = phy_type; 145 - 146 - return 0; 147 - } 148 - EXPORT_SYMBOL_GPL(samsung_usbphy_set_type); 149 - 150 - int samsung_usbphy_rate_to_clksel_64xx(struct samsung_usbphy *sphy, 151 - unsigned long rate) 152 - { 153 - unsigned int clksel; 154 - 155 - switch (rate) { 156 - case 12 * MHZ: 157 - clksel = PHYCLK_CLKSEL_12M; 158 - break; 159 - case 24 * MHZ: 160 - clksel = PHYCLK_CLKSEL_24M; 161 - break; 162 - case 48 * MHZ: 163 - clksel = PHYCLK_CLKSEL_48M; 164 - break; 165 - default: 166 - dev_err(sphy->dev, 167 - "Invalid reference clock frequency: %lu\n", rate); 168 - return -EINVAL; 169 - } 170 - 171 - return clksel; 172 - } 173 - EXPORT_SYMBOL_GPL(samsung_usbphy_rate_to_clksel_64xx); 174 - 175 - int samsung_usbphy_rate_to_clksel_4x12(struct samsung_usbphy *sphy, 176 - unsigned long rate) 177 - { 178 - unsigned int clksel; 179 - 180 - switch (rate) { 181 - case 9600 * KHZ: 182 - clksel = FSEL_CLKSEL_9600K; 183 - break; 184 - case 10 * MHZ: 185 - clksel = FSEL_CLKSEL_10M; 186 - break; 187 - case 12 * MHZ: 188 - clksel = FSEL_CLKSEL_12M; 189 - break; 190 - case 19200 * KHZ: 191 - clksel = FSEL_CLKSEL_19200K; 192 - break; 193 - case 20 * MHZ: 194 - clksel = FSEL_CLKSEL_20M; 195 - break; 196 - case 24 * MHZ: 197 - clksel = FSEL_CLKSEL_24M; 198 - break; 199 - case 50 * MHZ: 200 - clksel = FSEL_CLKSEL_50M; 201 - break; 202 - default: 203 - dev_err(sphy->dev, 204 - "Invalid reference clock frequency: %lu\n", rate); 205 - return -EINVAL; 206 - } 207 - 208 - return clksel; 209 - } 210 - EXPORT_SYMBOL_GPL(samsung_usbphy_rate_to_clksel_4x12); 211 - 212 - /* 213 - * Returns reference clock frequency selection value 214 - */ 215 - int samsung_usbphy_get_refclk_freq(struct samsung_usbphy *sphy) 216 - { 217 - struct clk *ref_clk; 218 - unsigned long rate; 219 - int refclk_freq; 220 - 221 - /* 222 - * In exynos5250 USB host and device PHY use 223 - * external crystal clock XXTI 224 - */ 225 - if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) 226 - ref_clk = clk_get(sphy->dev, "ext_xtal"); 227 - else 228 - ref_clk = clk_get(sphy->dev, "xusbxti"); 229 - if (IS_ERR(ref_clk)) { 230 - dev_err(sphy->dev, "Failed to get reference clock\n"); 231 - return PTR_ERR(ref_clk); 232 - } 233 - 234 - rate = clk_get_rate(ref_clk); 235 - refclk_freq = sphy->drv_data->rate_to_clksel(sphy, rate); 236 - 237 - clk_put(ref_clk); 238 - 239 - return refclk_freq; 240 - } 241 - EXPORT_SYMBOL_GPL(samsung_usbphy_get_refclk_freq);
-349
drivers/usb/phy/phy-samsung-usb.h
··· 1 - /* linux/drivers/usb/phy/phy-samsung-usb.h 2 - * 3 - * Copyright (c) 2012 Samsung Electronics Co., Ltd. 4 - * http://www.samsung.com 5 - * 6 - * Samsung USB-PHY transceiver; talks to S3C HS OTG controller, EHCI-S5P and 7 - * OHCI-EXYNOS controllers. 8 - * 9 - * This program is free software; you can redistribute it and/or modify 10 - * it under the terms of the GNU General Public License version 2 as 11 - * published by the Free Software Foundation. 12 - * 13 - * This program is distributed in the hope that it will be useful, 14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 - * GNU General Public License for more details. 17 - */ 18 - 19 - #include <linux/usb/phy.h> 20 - 21 - /* Register definitions */ 22 - 23 - #define SAMSUNG_PHYPWR (0x00) 24 - 25 - #define PHYPWR_NORMAL_MASK (0x19 << 0) 26 - #define PHYPWR_OTG_DISABLE (0x1 << 4) 27 - #define PHYPWR_ANALOG_POWERDOWN (0x1 << 3) 28 - #define PHYPWR_FORCE_SUSPEND (0x1 << 1) 29 - /* For Exynos4 */ 30 - #define PHYPWR_NORMAL_MASK_PHY0 (0x39 << 0) 31 - #define PHYPWR_SLEEP_PHY0 (0x1 << 5) 32 - 33 - #define SAMSUNG_PHYCLK (0x04) 34 - 35 - #define PHYCLK_MODE_USB11 (0x1 << 6) 36 - #define PHYCLK_EXT_OSC (0x1 << 5) 37 - #define PHYCLK_COMMON_ON_N (0x1 << 4) 38 - #define PHYCLK_ID_PULL (0x1 << 2) 39 - #define PHYCLK_CLKSEL_MASK (0x3 << 0) 40 - #define PHYCLK_CLKSEL_48M (0x0 << 0) 41 - #define PHYCLK_CLKSEL_12M (0x2 << 0) 42 - #define PHYCLK_CLKSEL_24M (0x3 << 0) 43 - 44 - #define SAMSUNG_RSTCON (0x08) 45 - 46 - #define RSTCON_PHYLINK_SWRST (0x1 << 2) 47 - #define RSTCON_HLINK_SWRST (0x1 << 1) 48 - #define RSTCON_SWRST (0x1 << 0) 49 - 50 - /* EXYNOS4X12 */ 51 - #define EXYNOS4X12_PHY_HSIC_CTRL0 (0x04) 52 - #define EXYNOS4X12_PHY_HSIC_CTRL1 (0x08) 53 - 54 - #define PHYPWR_NORMAL_MASK_HSIC1 (0x7 << 12) 55 - #define PHYPWR_NORMAL_MASK_HSIC0 (0x7 << 9) 56 - #define PHYPWR_NORMAL_MASK_PHY1 (0x7 << 6) 57 - 58 - #define RSTCON_HOSTPHY_SWRST (0xf << 3) 59 - 60 - /* EXYNOS5 */ 61 - #define EXYNOS5_PHY_HOST_CTRL0 (0x00) 62 - 63 - #define HOST_CTRL0_PHYSWRSTALL (0x1 << 31) 64 - 65 - #define HOST_CTRL0_REFCLKSEL_MASK (0x3 << 19) 66 - #define HOST_CTRL0_REFCLKSEL_XTAL (0x0 << 19) 67 - #define HOST_CTRL0_REFCLKSEL_EXTL (0x1 << 19) 68 - #define HOST_CTRL0_REFCLKSEL_CLKCORE (0x2 << 19) 69 - 70 - #define HOST_CTRL0_FSEL_MASK (0x7 << 16) 71 - #define HOST_CTRL0_FSEL(_x) ((_x) << 16) 72 - 73 - #define FSEL_CLKSEL_50M (0x7) 74 - #define FSEL_CLKSEL_24M (0x5) 75 - #define FSEL_CLKSEL_20M (0x4) 76 - #define FSEL_CLKSEL_19200K (0x3) 77 - #define FSEL_CLKSEL_12M (0x2) 78 - #define FSEL_CLKSEL_10M (0x1) 79 - #define FSEL_CLKSEL_9600K (0x0) 80 - 81 - #define HOST_CTRL0_TESTBURNIN (0x1 << 11) 82 - #define HOST_CTRL0_RETENABLE (0x1 << 10) 83 - #define HOST_CTRL0_COMMONON_N (0x1 << 9) 84 - #define HOST_CTRL0_SIDDQ (0x1 << 6) 85 - #define HOST_CTRL0_FORCESLEEP (0x1 << 5) 86 - #define HOST_CTRL0_FORCESUSPEND (0x1 << 4) 87 - #define HOST_CTRL0_WORDINTERFACE (0x1 << 3) 88 - #define HOST_CTRL0_UTMISWRST (0x1 << 2) 89 - #define HOST_CTRL0_LINKSWRST (0x1 << 1) 90 - #define HOST_CTRL0_PHYSWRST (0x1 << 0) 91 - 92 - #define EXYNOS5_PHY_HOST_TUNE0 (0x04) 93 - 94 - #define EXYNOS5_PHY_HSIC_CTRL1 (0x10) 95 - 96 - #define EXYNOS5_PHY_HSIC_TUNE1 (0x14) 97 - 98 - #define EXYNOS5_PHY_HSIC_CTRL2 (0x20) 99 - 100 - #define EXYNOS5_PHY_HSIC_TUNE2 (0x24) 101 - 102 - #define HSIC_CTRL_REFCLKSEL_MASK (0x3 << 23) 103 - #define HSIC_CTRL_REFCLKSEL (0x2 << 23) 104 - 105 - #define HSIC_CTRL_REFCLKDIV_MASK (0x7f << 16) 106 - #define HSIC_CTRL_REFCLKDIV(_x) ((_x) << 16) 107 - #define HSIC_CTRL_REFCLKDIV_12 (0x24 << 16) 108 - #define HSIC_CTRL_REFCLKDIV_15 (0x1c << 16) 109 - #define HSIC_CTRL_REFCLKDIV_16 (0x1a << 16) 110 - #define HSIC_CTRL_REFCLKDIV_19_2 (0x15 << 16) 111 - #define HSIC_CTRL_REFCLKDIV_20 (0x14 << 16) 112 - 113 - #define HSIC_CTRL_SIDDQ (0x1 << 6) 114 - #define HSIC_CTRL_FORCESLEEP (0x1 << 5) 115 - #define HSIC_CTRL_FORCESUSPEND (0x1 << 4) 116 - #define HSIC_CTRL_WORDINTERFACE (0x1 << 3) 117 - #define HSIC_CTRL_UTMISWRST (0x1 << 2) 118 - #define HSIC_CTRL_PHYSWRST (0x1 << 0) 119 - 120 - #define EXYNOS5_PHY_HOST_EHCICTRL (0x30) 121 - 122 - #define HOST_EHCICTRL_ENAINCRXALIGN (0x1 << 29) 123 - #define HOST_EHCICTRL_ENAINCR4 (0x1 << 28) 124 - #define HOST_EHCICTRL_ENAINCR8 (0x1 << 27) 125 - #define HOST_EHCICTRL_ENAINCR16 (0x1 << 26) 126 - 127 - #define EXYNOS5_PHY_HOST_OHCICTRL (0x34) 128 - 129 - #define HOST_OHCICTRL_SUSPLGCY (0x1 << 3) 130 - #define HOST_OHCICTRL_APPSTARTCLK (0x1 << 2) 131 - #define HOST_OHCICTRL_CNTSEL (0x1 << 1) 132 - #define HOST_OHCICTRL_CLKCKTRST (0x1 << 0) 133 - 134 - #define EXYNOS5_PHY_OTG_SYS (0x38) 135 - 136 - #define OTG_SYS_PHYLINK_SWRESET (0x1 << 14) 137 - #define OTG_SYS_LINKSWRST_UOTG (0x1 << 13) 138 - #define OTG_SYS_PHY0_SWRST (0x1 << 12) 139 - 140 - #define OTG_SYS_REFCLKSEL_MASK (0x3 << 9) 141 - #define OTG_SYS_REFCLKSEL_XTAL (0x0 << 9) 142 - #define OTG_SYS_REFCLKSEL_EXTL (0x1 << 9) 143 - #define OTG_SYS_REFCLKSEL_CLKCORE (0x2 << 9) 144 - 145 - #define OTG_SYS_IDPULLUP_UOTG (0x1 << 8) 146 - #define OTG_SYS_COMMON_ON (0x1 << 7) 147 - 148 - #define OTG_SYS_FSEL_MASK (0x7 << 4) 149 - #define OTG_SYS_FSEL(_x) ((_x) << 4) 150 - 151 - #define OTG_SYS_FORCESLEEP (0x1 << 3) 152 - #define OTG_SYS_OTGDISABLE (0x1 << 2) 153 - #define OTG_SYS_SIDDQ_UOTG (0x1 << 1) 154 - #define OTG_SYS_FORCESUSPEND (0x1 << 0) 155 - 156 - #define EXYNOS5_PHY_OTG_TUNE (0x40) 157 - 158 - /* EXYNOS5: USB 3.0 DRD */ 159 - #define EXYNOS5_DRD_LINKSYSTEM (0x04) 160 - 161 - #define LINKSYSTEM_FLADJ_MASK (0x3f << 1) 162 - #define LINKSYSTEM_FLADJ(_x) ((_x) << 1) 163 - #define LINKSYSTEM_XHCI_VERSION_CONTROL (0x1 << 27) 164 - 165 - #define EXYNOS5_DRD_PHYUTMI (0x08) 166 - 167 - #define PHYUTMI_OTGDISABLE (0x1 << 6) 168 - #define PHYUTMI_FORCESUSPEND (0x1 << 1) 169 - #define PHYUTMI_FORCESLEEP (0x1 << 0) 170 - 171 - #define EXYNOS5_DRD_PHYPIPE (0x0c) 172 - 173 - #define EXYNOS5_DRD_PHYCLKRST (0x10) 174 - 175 - #define PHYCLKRST_SSC_REFCLKSEL_MASK (0xff << 23) 176 - #define PHYCLKRST_SSC_REFCLKSEL(_x) ((_x) << 23) 177 - 178 - #define PHYCLKRST_SSC_RANGE_MASK (0x03 << 21) 179 - #define PHYCLKRST_SSC_RANGE(_x) ((_x) << 21) 180 - 181 - #define PHYCLKRST_SSC_EN (0x1 << 20) 182 - #define PHYCLKRST_REF_SSP_EN (0x1 << 19) 183 - #define PHYCLKRST_REF_CLKDIV2 (0x1 << 18) 184 - 185 - #define PHYCLKRST_MPLL_MULTIPLIER_MASK (0x7f << 11) 186 - #define PHYCLKRST_MPLL_MULTIPLIER_100MHZ_REF (0x19 << 11) 187 - #define PHYCLKRST_MPLL_MULTIPLIER_50M_REF (0x02 << 11) 188 - #define PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF (0x68 << 11) 189 - #define PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF (0x7d << 11) 190 - #define PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF (0x02 << 11) 191 - 192 - #define PHYCLKRST_FSEL_MASK (0x3f << 5) 193 - #define PHYCLKRST_FSEL(_x) ((_x) << 5) 194 - #define PHYCLKRST_FSEL_PAD_100MHZ (0x27 << 5) 195 - #define PHYCLKRST_FSEL_PAD_24MHZ (0x2a << 5) 196 - #define PHYCLKRST_FSEL_PAD_20MHZ (0x31 << 5) 197 - #define PHYCLKRST_FSEL_PAD_19_2MHZ (0x38 << 5) 198 - 199 - #define PHYCLKRST_RETENABLEN (0x1 << 4) 200 - 201 - #define PHYCLKRST_REFCLKSEL_MASK (0x03 << 2) 202 - #define PHYCLKRST_REFCLKSEL_PAD_REFCLK (0x2 << 2) 203 - #define PHYCLKRST_REFCLKSEL_EXT_REFCLK (0x3 << 2) 204 - 205 - #define PHYCLKRST_PORTRESET (0x1 << 1) 206 - #define PHYCLKRST_COMMONONN (0x1 << 0) 207 - 208 - #define EXYNOS5_DRD_PHYREG0 (0x14) 209 - #define EXYNOS5_DRD_PHYREG1 (0x18) 210 - 211 - #define EXYNOS5_DRD_PHYPARAM0 (0x1c) 212 - 213 - #define PHYPARAM0_REF_USE_PAD (0x1 << 31) 214 - #define PHYPARAM0_REF_LOSLEVEL_MASK (0x1f << 26) 215 - #define PHYPARAM0_REF_LOSLEVEL (0x9 << 26) 216 - 217 - #define EXYNOS5_DRD_PHYPARAM1 (0x20) 218 - 219 - #define PHYPARAM1_PCS_TXDEEMPH_MASK (0x3f << 0) 220 - #define PHYPARAM1_PCS_TXDEEMPH (0x1c) 221 - 222 - #define EXYNOS5_DRD_PHYTERM (0x24) 223 - 224 - #define EXYNOS5_DRD_PHYTEST (0x28) 225 - 226 - #define PHYTEST_POWERDOWN_SSP (0x1 << 3) 227 - #define PHYTEST_POWERDOWN_HSP (0x1 << 2) 228 - 229 - #define EXYNOS5_DRD_PHYADP (0x2c) 230 - 231 - #define EXYNOS5_DRD_PHYBATCHG (0x30) 232 - 233 - #define PHYBATCHG_UTMI_CLKSEL (0x1 << 2) 234 - 235 - #define EXYNOS5_DRD_PHYRESUME (0x34) 236 - #define EXYNOS5_DRD_LINKPORT (0x44) 237 - 238 - #ifndef MHZ 239 - #define MHZ (1000*1000) 240 - #endif 241 - 242 - #ifndef KHZ 243 - #define KHZ (1000) 244 - #endif 245 - 246 - #define EXYNOS_USBHOST_PHY_CTRL_OFFSET (0x4) 247 - #define S3C64XX_USBPHY_ENABLE (0x1 << 16) 248 - #define EXYNOS_USBPHY_ENABLE (0x1 << 0) 249 - #define EXYNOS_USB20PHY_CFG_HOST_LINK (0x1 << 0) 250 - 251 - enum samsung_cpu_type { 252 - TYPE_S3C64XX, 253 - TYPE_EXYNOS4210, 254 - TYPE_EXYNOS4X12, 255 - TYPE_EXYNOS5250, 256 - }; 257 - 258 - struct samsung_usbphy; 259 - 260 - /* 261 - * struct samsung_usbphy_drvdata - driver data for various SoC variants 262 - * @cpu_type: machine identifier 263 - * @devphy_en_mask: device phy enable mask for PHY CONTROL register 264 - * @hostphy_en_mask: host phy enable mask for PHY CONTROL register 265 - * @devphy_reg_offset: offset to DEVICE PHY CONTROL register from 266 - * mapped address of system controller. 267 - * @hostphy_reg_offset: offset to HOST PHY CONTROL register from 268 - * mapped address of system controller. 269 - * 270 - * Here we have a separate mask for device type phy. 271 - * Having different masks for host and device type phy helps 272 - * in setting independent masks in case of SoCs like S5PV210, 273 - * in which PHY0 and PHY1 enable bits belong to same register 274 - * placed at position 0 and 1 respectively. 275 - * Although for newer SoCs like exynos these bits belong to 276 - * different registers altogether placed at position 0. 277 - */ 278 - struct samsung_usbphy_drvdata { 279 - int cpu_type; 280 - int devphy_en_mask; 281 - int hostphy_en_mask; 282 - u32 devphy_reg_offset; 283 - u32 hostphy_reg_offset; 284 - int (*rate_to_clksel)(struct samsung_usbphy *, unsigned long); 285 - void (*set_isolation)(struct samsung_usbphy *, bool); 286 - void (*phy_enable)(struct samsung_usbphy *); 287 - void (*phy_disable)(struct samsung_usbphy *); 288 - }; 289 - 290 - /* 291 - * struct samsung_usbphy - transceiver driver state 292 - * @phy: transceiver structure 293 - * @plat: platform data 294 - * @dev: The parent device supplied to the probe function 295 - * @clk: usb phy clock 296 - * @regs: usb phy controller registers memory base 297 - * @pmuregs: USB device PHY_CONTROL register memory base 298 - * @sysreg: USB2.0 PHY_CFG register memory base 299 - * @ref_clk_freq: reference clock frequency selection 300 - * @drv_data: driver data available for different SoCs 301 - * @phy_type: Samsung SoCs specific phy types: #HOST 302 - * #DEVICE 303 - * @phy_usage: usage count for phy 304 - * @lock: lock for phy operations 305 - */ 306 - struct samsung_usbphy { 307 - struct usb_phy phy; 308 - struct samsung_usbphy_data *plat; 309 - struct device *dev; 310 - struct clk *clk; 311 - void __iomem *regs; 312 - void __iomem *pmuregs; 313 - void __iomem *sysreg; 314 - int ref_clk_freq; 315 - const struct samsung_usbphy_drvdata *drv_data; 316 - enum samsung_usb_phy_type phy_type; 317 - atomic_t phy_usage; 318 - spinlock_t lock; 319 - }; 320 - 321 - #define phy_to_sphy(x) container_of((x), struct samsung_usbphy, phy) 322 - 323 - static const struct of_device_id samsung_usbphy_dt_match[]; 324 - 325 - static inline const struct samsung_usbphy_drvdata 326 - *samsung_usbphy_get_driver_data(struct platform_device *pdev) 327 - { 328 - if (pdev->dev.of_node) { 329 - const struct of_device_id *match; 330 - match = of_match_node(samsung_usbphy_dt_match, 331 - pdev->dev.of_node); 332 - return match->data; 333 - } 334 - 335 - return (struct samsung_usbphy_drvdata *) 336 - platform_get_device_id(pdev)->driver_data; 337 - } 338 - 339 - extern int samsung_usbphy_parse_dt(struct samsung_usbphy *sphy); 340 - extern void samsung_usbphy_set_isolation_4210(struct samsung_usbphy *sphy, 341 - bool on); 342 - extern void samsung_usbphy_cfg_sel(struct samsung_usbphy *sphy); 343 - extern int samsung_usbphy_set_type(struct usb_phy *phy, 344 - enum samsung_usb_phy_type phy_type); 345 - extern int samsung_usbphy_get_refclk_freq(struct samsung_usbphy *sphy); 346 - extern int samsung_usbphy_rate_to_clksel_64xx(struct samsung_usbphy *sphy, 347 - unsigned long rate); 348 - extern int samsung_usbphy_rate_to_clksel_4x12(struct samsung_usbphy *sphy, 349 - unsigned long rate);
-541
drivers/usb/phy/phy-samsung-usb2.c
··· 1 - /* linux/drivers/usb/phy/phy-samsung-usb2.c 2 - * 3 - * Copyright (c) 2012 Samsung Electronics Co., Ltd. 4 - * http://www.samsung.com 5 - * 6 - * Author: Praveen Paneri <p.paneri@samsung.com> 7 - * 8 - * Samsung USB2.0 PHY transceiver; talks to S3C HS OTG controller, EHCI-S5P and 9 - * OHCI-EXYNOS controllers. 10 - * 11 - * This program is free software; you can redistribute it and/or modify 12 - * it under the terms of the GNU General Public License version 2 as 13 - * published by the Free Software Foundation. 14 - * 15 - * This program is distributed in the hope that it will be useful, 16 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 - * GNU General Public License for more details. 19 - */ 20 - 21 - #include <linux/module.h> 22 - #include <linux/platform_device.h> 23 - #include <linux/clk.h> 24 - #include <linux/delay.h> 25 - #include <linux/device.h> 26 - #include <linux/err.h> 27 - #include <linux/io.h> 28 - #include <linux/of.h> 29 - #include <linux/usb/otg.h> 30 - #include <linux/usb/samsung_usb_phy.h> 31 - #include <linux/platform_data/samsung-usbphy.h> 32 - 33 - #include "phy-samsung-usb.h" 34 - 35 - static int samsung_usbphy_set_host(struct usb_otg *otg, struct usb_bus *host) 36 - { 37 - if (!otg) 38 - return -ENODEV; 39 - 40 - if (!otg->host) 41 - otg->host = host; 42 - 43 - return 0; 44 - } 45 - 46 - static bool exynos5_phyhost_is_on(void __iomem *regs) 47 - { 48 - u32 reg; 49 - 50 - reg = readl(regs + EXYNOS5_PHY_HOST_CTRL0); 51 - 52 - return !(reg & HOST_CTRL0_SIDDQ); 53 - } 54 - 55 - static void samsung_exynos5_usb2phy_enable(struct samsung_usbphy *sphy) 56 - { 57 - void __iomem *regs = sphy->regs; 58 - u32 phyclk = sphy->ref_clk_freq; 59 - u32 phyhost; 60 - u32 phyotg; 61 - u32 phyhsic; 62 - u32 ehcictrl; 63 - u32 ohcictrl; 64 - 65 - /* 66 - * phy_usage helps in keeping usage count for phy 67 - * so that the first consumer enabling the phy is also 68 - * the last consumer to disable it. 69 - */ 70 - 71 - atomic_inc(&sphy->phy_usage); 72 - 73 - if (exynos5_phyhost_is_on(regs)) { 74 - dev_info(sphy->dev, "Already power on PHY\n"); 75 - return; 76 - } 77 - 78 - /* Host configuration */ 79 - phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0); 80 - 81 - /* phy reference clock configuration */ 82 - phyhost &= ~HOST_CTRL0_FSEL_MASK; 83 - phyhost |= HOST_CTRL0_FSEL(phyclk); 84 - 85 - /* host phy reset */ 86 - phyhost &= ~(HOST_CTRL0_PHYSWRST | 87 - HOST_CTRL0_PHYSWRSTALL | 88 - HOST_CTRL0_SIDDQ | 89 - /* Enable normal mode of operation */ 90 - HOST_CTRL0_FORCESUSPEND | 91 - HOST_CTRL0_FORCESLEEP); 92 - 93 - /* Link reset */ 94 - phyhost |= (HOST_CTRL0_LINKSWRST | 95 - HOST_CTRL0_UTMISWRST | 96 - /* COMMON Block configuration during suspend */ 97 - HOST_CTRL0_COMMONON_N); 98 - writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0); 99 - udelay(10); 100 - phyhost &= ~(HOST_CTRL0_LINKSWRST | 101 - HOST_CTRL0_UTMISWRST); 102 - writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0); 103 - 104 - /* OTG configuration */ 105 - phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS); 106 - 107 - /* phy reference clock configuration */ 108 - phyotg &= ~OTG_SYS_FSEL_MASK; 109 - phyotg |= OTG_SYS_FSEL(phyclk); 110 - 111 - /* Enable normal mode of operation */ 112 - phyotg &= ~(OTG_SYS_FORCESUSPEND | 113 - OTG_SYS_SIDDQ_UOTG | 114 - OTG_SYS_FORCESLEEP | 115 - OTG_SYS_REFCLKSEL_MASK | 116 - /* COMMON Block configuration during suspend */ 117 - OTG_SYS_COMMON_ON); 118 - 119 - /* OTG phy & link reset */ 120 - phyotg |= (OTG_SYS_PHY0_SWRST | 121 - OTG_SYS_LINKSWRST_UOTG | 122 - OTG_SYS_PHYLINK_SWRESET | 123 - OTG_SYS_OTGDISABLE | 124 - /* Set phy refclk */ 125 - OTG_SYS_REFCLKSEL_CLKCORE); 126 - 127 - writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS); 128 - udelay(10); 129 - phyotg &= ~(OTG_SYS_PHY0_SWRST | 130 - OTG_SYS_LINKSWRST_UOTG | 131 - OTG_SYS_PHYLINK_SWRESET); 132 - writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS); 133 - 134 - /* HSIC phy configuration */ 135 - phyhsic = (HSIC_CTRL_REFCLKDIV_12 | 136 - HSIC_CTRL_REFCLKSEL | 137 - HSIC_CTRL_PHYSWRST); 138 - writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1); 139 - writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2); 140 - udelay(10); 141 - phyhsic &= ~HSIC_CTRL_PHYSWRST; 142 - writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1); 143 - writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2); 144 - 145 - udelay(80); 146 - 147 - /* enable EHCI DMA burst */ 148 - ehcictrl = readl(regs + EXYNOS5_PHY_HOST_EHCICTRL); 149 - ehcictrl |= (HOST_EHCICTRL_ENAINCRXALIGN | 150 - HOST_EHCICTRL_ENAINCR4 | 151 - HOST_EHCICTRL_ENAINCR8 | 152 - HOST_EHCICTRL_ENAINCR16); 153 - writel(ehcictrl, regs + EXYNOS5_PHY_HOST_EHCICTRL); 154 - 155 - /* set ohci_suspend_on_n */ 156 - ohcictrl = readl(regs + EXYNOS5_PHY_HOST_OHCICTRL); 157 - ohcictrl |= HOST_OHCICTRL_SUSPLGCY; 158 - writel(ohcictrl, regs + EXYNOS5_PHY_HOST_OHCICTRL); 159 - } 160 - 161 - static void samsung_usb2phy_enable(struct samsung_usbphy *sphy) 162 - { 163 - void __iomem *regs = sphy->regs; 164 - u32 phypwr; 165 - u32 phyclk; 166 - u32 rstcon; 167 - 168 - /* set clock frequency for PLL */ 169 - phyclk = sphy->ref_clk_freq; 170 - phypwr = readl(regs + SAMSUNG_PHYPWR); 171 - rstcon = readl(regs + SAMSUNG_RSTCON); 172 - 173 - switch (sphy->drv_data->cpu_type) { 174 - case TYPE_S3C64XX: 175 - phyclk &= ~PHYCLK_COMMON_ON_N; 176 - phypwr &= ~PHYPWR_NORMAL_MASK; 177 - rstcon |= RSTCON_SWRST; 178 - break; 179 - case TYPE_EXYNOS4X12: 180 - phypwr &= ~(PHYPWR_NORMAL_MASK_HSIC0 | 181 - PHYPWR_NORMAL_MASK_HSIC1 | 182 - PHYPWR_NORMAL_MASK_PHY1); 183 - rstcon |= RSTCON_HOSTPHY_SWRST; 184 - case TYPE_EXYNOS4210: 185 - phypwr &= ~PHYPWR_NORMAL_MASK_PHY0; 186 - rstcon |= RSTCON_SWRST; 187 - default: 188 - break; 189 - } 190 - 191 - writel(phyclk, regs + SAMSUNG_PHYCLK); 192 - /* Configure PHY0 for normal operation*/ 193 - writel(phypwr, regs + SAMSUNG_PHYPWR); 194 - /* reset all ports of PHY and Link */ 195 - writel(rstcon, regs + SAMSUNG_RSTCON); 196 - udelay(10); 197 - if (sphy->drv_data->cpu_type == TYPE_EXYNOS4X12) 198 - rstcon &= ~RSTCON_HOSTPHY_SWRST; 199 - rstcon &= ~RSTCON_SWRST; 200 - writel(rstcon, regs + SAMSUNG_RSTCON); 201 - } 202 - 203 - static void samsung_exynos5_usb2phy_disable(struct samsung_usbphy *sphy) 204 - { 205 - void __iomem *regs = sphy->regs; 206 - u32 phyhost; 207 - u32 phyotg; 208 - u32 phyhsic; 209 - 210 - if (atomic_dec_return(&sphy->phy_usage) > 0) { 211 - dev_info(sphy->dev, "still being used\n"); 212 - return; 213 - } 214 - 215 - phyhsic = (HSIC_CTRL_REFCLKDIV_12 | 216 - HSIC_CTRL_REFCLKSEL | 217 - HSIC_CTRL_SIDDQ | 218 - HSIC_CTRL_FORCESLEEP | 219 - HSIC_CTRL_FORCESUSPEND); 220 - writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1); 221 - writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2); 222 - 223 - phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0); 224 - phyhost |= (HOST_CTRL0_SIDDQ | 225 - HOST_CTRL0_FORCESUSPEND | 226 - HOST_CTRL0_FORCESLEEP | 227 - HOST_CTRL0_PHYSWRST | 228 - HOST_CTRL0_PHYSWRSTALL); 229 - writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0); 230 - 231 - phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS); 232 - phyotg |= (OTG_SYS_FORCESUSPEND | 233 - OTG_SYS_SIDDQ_UOTG | 234 - OTG_SYS_FORCESLEEP); 235 - writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS); 236 - } 237 - 238 - static void samsung_usb2phy_disable(struct samsung_usbphy *sphy) 239 - { 240 - void __iomem *regs = sphy->regs; 241 - u32 phypwr; 242 - 243 - phypwr = readl(regs + SAMSUNG_PHYPWR); 244 - 245 - switch (sphy->drv_data->cpu_type) { 246 - case TYPE_S3C64XX: 247 - phypwr |= PHYPWR_NORMAL_MASK; 248 - break; 249 - case TYPE_EXYNOS4X12: 250 - phypwr |= (PHYPWR_NORMAL_MASK_HSIC0 | 251 - PHYPWR_NORMAL_MASK_HSIC1 | 252 - PHYPWR_NORMAL_MASK_PHY1); 253 - case TYPE_EXYNOS4210: 254 - phypwr |= PHYPWR_NORMAL_MASK_PHY0; 255 - default: 256 - break; 257 - } 258 - 259 - /* Disable analog and otg block power */ 260 - writel(phypwr, regs + SAMSUNG_PHYPWR); 261 - } 262 - 263 - /* 264 - * The function passed to the usb driver for phy initialization 265 - */ 266 - static int samsung_usb2phy_init(struct usb_phy *phy) 267 - { 268 - struct samsung_usbphy *sphy; 269 - struct usb_bus *host = NULL; 270 - unsigned long flags; 271 - int ret = 0; 272 - 273 - sphy = phy_to_sphy(phy); 274 - 275 - host = phy->otg->host; 276 - 277 - /* Enable the phy clock */ 278 - ret = clk_prepare_enable(sphy->clk); 279 - if (ret) { 280 - dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__); 281 - return ret; 282 - } 283 - 284 - spin_lock_irqsave(&sphy->lock, flags); 285 - 286 - if (host) { 287 - /* setting default phy-type for USB 2.0 */ 288 - if (!strstr(dev_name(host->controller), "ehci") || 289 - !strstr(dev_name(host->controller), "ohci")) 290 - samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST); 291 - } else { 292 - samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); 293 - } 294 - 295 - /* Disable phy isolation */ 296 - if (sphy->plat && sphy->plat->pmu_isolation) 297 - sphy->plat->pmu_isolation(false); 298 - else if (sphy->drv_data->set_isolation) 299 - sphy->drv_data->set_isolation(sphy, false); 300 - 301 - /* Selecting Host/OTG mode; After reset USB2.0PHY_CFG: HOST */ 302 - samsung_usbphy_cfg_sel(sphy); 303 - 304 - /* Initialize usb phy registers */ 305 - sphy->drv_data->phy_enable(sphy); 306 - 307 - spin_unlock_irqrestore(&sphy->lock, flags); 308 - 309 - /* Disable the phy clock */ 310 - clk_disable_unprepare(sphy->clk); 311 - 312 - return ret; 313 - } 314 - 315 - /* 316 - * The function passed to the usb driver for phy shutdown 317 - */ 318 - static void samsung_usb2phy_shutdown(struct usb_phy *phy) 319 - { 320 - struct samsung_usbphy *sphy; 321 - struct usb_bus *host = NULL; 322 - unsigned long flags; 323 - 324 - sphy = phy_to_sphy(phy); 325 - 326 - host = phy->otg->host; 327 - 328 - if (clk_prepare_enable(sphy->clk)) { 329 - dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__); 330 - return; 331 - } 332 - 333 - spin_lock_irqsave(&sphy->lock, flags); 334 - 335 - if (host) { 336 - /* setting default phy-type for USB 2.0 */ 337 - if (!strstr(dev_name(host->controller), "ehci") || 338 - !strstr(dev_name(host->controller), "ohci")) 339 - samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST); 340 - } else { 341 - samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); 342 - } 343 - 344 - /* De-initialize usb phy registers */ 345 - sphy->drv_data->phy_disable(sphy); 346 - 347 - /* Enable phy isolation */ 348 - if (sphy->plat && sphy->plat->pmu_isolation) 349 - sphy->plat->pmu_isolation(true); 350 - else if (sphy->drv_data->set_isolation) 351 - sphy->drv_data->set_isolation(sphy, true); 352 - 353 - spin_unlock_irqrestore(&sphy->lock, flags); 354 - 355 - clk_disable_unprepare(sphy->clk); 356 - } 357 - 358 - static int samsung_usb2phy_probe(struct platform_device *pdev) 359 - { 360 - struct samsung_usbphy *sphy; 361 - struct usb_otg *otg; 362 - struct samsung_usbphy_data *pdata = dev_get_platdata(&pdev->dev); 363 - const struct samsung_usbphy_drvdata *drv_data; 364 - struct device *dev = &pdev->dev; 365 - struct resource *phy_mem; 366 - void __iomem *phy_base; 367 - struct clk *clk; 368 - int ret; 369 - 370 - phy_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 371 - phy_base = devm_ioremap_resource(dev, phy_mem); 372 - if (IS_ERR(phy_base)) 373 - return PTR_ERR(phy_base); 374 - 375 - sphy = devm_kzalloc(dev, sizeof(*sphy), GFP_KERNEL); 376 - if (!sphy) 377 - return -ENOMEM; 378 - 379 - otg = devm_kzalloc(dev, sizeof(*otg), GFP_KERNEL); 380 - if (!otg) 381 - return -ENOMEM; 382 - 383 - drv_data = samsung_usbphy_get_driver_data(pdev); 384 - 385 - if (drv_data->cpu_type == TYPE_EXYNOS5250) 386 - clk = devm_clk_get(dev, "usbhost"); 387 - else 388 - clk = devm_clk_get(dev, "otg"); 389 - 390 - if (IS_ERR(clk)) { 391 - dev_err(dev, "Failed to get usbhost/otg clock\n"); 392 - return PTR_ERR(clk); 393 - } 394 - 395 - sphy->dev = dev; 396 - 397 - if (dev->of_node) { 398 - ret = samsung_usbphy_parse_dt(sphy); 399 - if (ret < 0) 400 - return ret; 401 - } else { 402 - if (!pdata) { 403 - dev_err(dev, "no platform data specified\n"); 404 - return -EINVAL; 405 - } 406 - } 407 - 408 - sphy->plat = pdata; 409 - sphy->regs = phy_base; 410 - sphy->clk = clk; 411 - sphy->drv_data = drv_data; 412 - sphy->phy.dev = sphy->dev; 413 - sphy->phy.label = "samsung-usb2phy"; 414 - sphy->phy.type = USB_PHY_TYPE_USB2; 415 - sphy->phy.init = samsung_usb2phy_init; 416 - sphy->phy.shutdown = samsung_usb2phy_shutdown; 417 - 418 - sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy); 419 - if (sphy->ref_clk_freq < 0) 420 - return -EINVAL; 421 - 422 - sphy->phy.otg = otg; 423 - sphy->phy.otg->phy = &sphy->phy; 424 - sphy->phy.otg->set_host = samsung_usbphy_set_host; 425 - 426 - spin_lock_init(&sphy->lock); 427 - 428 - platform_set_drvdata(pdev, sphy); 429 - 430 - return usb_add_phy_dev(&sphy->phy); 431 - } 432 - 433 - static int samsung_usb2phy_remove(struct platform_device *pdev) 434 - { 435 - struct samsung_usbphy *sphy = platform_get_drvdata(pdev); 436 - 437 - usb_remove_phy(&sphy->phy); 438 - 439 - if (sphy->pmuregs) 440 - iounmap(sphy->pmuregs); 441 - if (sphy->sysreg) 442 - iounmap(sphy->sysreg); 443 - 444 - return 0; 445 - } 446 - 447 - static const struct samsung_usbphy_drvdata usb2phy_s3c64xx = { 448 - .cpu_type = TYPE_S3C64XX, 449 - .devphy_en_mask = S3C64XX_USBPHY_ENABLE, 450 - .rate_to_clksel = samsung_usbphy_rate_to_clksel_64xx, 451 - .set_isolation = NULL, /* TODO */ 452 - .phy_enable = samsung_usb2phy_enable, 453 - .phy_disable = samsung_usb2phy_disable, 454 - }; 455 - 456 - static const struct samsung_usbphy_drvdata usb2phy_exynos4 = { 457 - .cpu_type = TYPE_EXYNOS4210, 458 - .devphy_en_mask = EXYNOS_USBPHY_ENABLE, 459 - .hostphy_en_mask = EXYNOS_USBPHY_ENABLE, 460 - .rate_to_clksel = samsung_usbphy_rate_to_clksel_64xx, 461 - .set_isolation = samsung_usbphy_set_isolation_4210, 462 - .phy_enable = samsung_usb2phy_enable, 463 - .phy_disable = samsung_usb2phy_disable, 464 - }; 465 - 466 - static const struct samsung_usbphy_drvdata usb2phy_exynos4x12 = { 467 - .cpu_type = TYPE_EXYNOS4X12, 468 - .devphy_en_mask = EXYNOS_USBPHY_ENABLE, 469 - .hostphy_en_mask = EXYNOS_USBPHY_ENABLE, 470 - .rate_to_clksel = samsung_usbphy_rate_to_clksel_4x12, 471 - .set_isolation = samsung_usbphy_set_isolation_4210, 472 - .phy_enable = samsung_usb2phy_enable, 473 - .phy_disable = samsung_usb2phy_disable, 474 - }; 475 - 476 - static struct samsung_usbphy_drvdata usb2phy_exynos5 = { 477 - .cpu_type = TYPE_EXYNOS5250, 478 - .hostphy_en_mask = EXYNOS_USBPHY_ENABLE, 479 - .hostphy_reg_offset = EXYNOS_USBHOST_PHY_CTRL_OFFSET, 480 - .rate_to_clksel = samsung_usbphy_rate_to_clksel_4x12, 481 - .set_isolation = samsung_usbphy_set_isolation_4210, 482 - .phy_enable = samsung_exynos5_usb2phy_enable, 483 - .phy_disable = samsung_exynos5_usb2phy_disable, 484 - }; 485 - 486 - #ifdef CONFIG_OF 487 - static const struct of_device_id samsung_usbphy_dt_match[] = { 488 - { 489 - .compatible = "samsung,s3c64xx-usb2phy", 490 - .data = &usb2phy_s3c64xx, 491 - }, { 492 - .compatible = "samsung,exynos4210-usb2phy", 493 - .data = &usb2phy_exynos4, 494 - }, { 495 - .compatible = "samsung,exynos4x12-usb2phy", 496 - .data = &usb2phy_exynos4x12, 497 - }, { 498 - .compatible = "samsung,exynos5250-usb2phy", 499 - .data = &usb2phy_exynos5 500 - }, 501 - {}, 502 - }; 503 - MODULE_DEVICE_TABLE(of, samsung_usbphy_dt_match); 504 - #endif 505 - 506 - static struct platform_device_id samsung_usbphy_driver_ids[] = { 507 - { 508 - .name = "s3c64xx-usb2phy", 509 - .driver_data = (unsigned long)&usb2phy_s3c64xx, 510 - }, { 511 - .name = "exynos4210-usb2phy", 512 - .driver_data = (unsigned long)&usb2phy_exynos4, 513 - }, { 514 - .name = "exynos4x12-usb2phy", 515 - .driver_data = (unsigned long)&usb2phy_exynos4x12, 516 - }, { 517 - .name = "exynos5250-usb2phy", 518 - .driver_data = (unsigned long)&usb2phy_exynos5, 519 - }, 520 - {}, 521 - }; 522 - 523 - MODULE_DEVICE_TABLE(platform, samsung_usbphy_driver_ids); 524 - 525 - static struct platform_driver samsung_usb2phy_driver = { 526 - .probe = samsung_usb2phy_probe, 527 - .remove = samsung_usb2phy_remove, 528 - .id_table = samsung_usbphy_driver_ids, 529 - .driver = { 530 - .name = "samsung-usb2phy", 531 - .owner = THIS_MODULE, 532 - .of_match_table = of_match_ptr(samsung_usbphy_dt_match), 533 - }, 534 - }; 535 - 536 - module_platform_driver(samsung_usb2phy_driver); 537 - 538 - MODULE_DESCRIPTION("Samsung USB 2.0 phy controller"); 539 - MODULE_AUTHOR("Praveen Paneri <p.paneri@samsung.com>"); 540 - MODULE_LICENSE("GPL"); 541 - MODULE_ALIAS("platform:samsung-usb2phy");
-350
drivers/usb/phy/phy-samsung-usb3.c
··· 1 - /* linux/drivers/usb/phy/phy-samsung-usb3.c 2 - * 3 - * Copyright (c) 2013 Samsung Electronics Co., Ltd. 4 - * http://www.samsung.com 5 - * 6 - * Author: Vivek Gautam <gautam.vivek@samsung.com> 7 - * 8 - * Samsung USB 3.0 PHY transceiver; talks to DWC3 controller. 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 - * This program is distributed in the hope that it will be useful, 15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 - * GNU General Public License for more details. 18 - */ 19 - 20 - #include <linux/module.h> 21 - #include <linux/platform_device.h> 22 - #include <linux/clk.h> 23 - #include <linux/delay.h> 24 - #include <linux/err.h> 25 - #include <linux/io.h> 26 - #include <linux/of.h> 27 - #include <linux/usb/samsung_usb_phy.h> 28 - #include <linux/platform_data/samsung-usbphy.h> 29 - 30 - #include "phy-samsung-usb.h" 31 - 32 - /* 33 - * Sets the phy clk as EXTREFCLK (XXTI) which is internal clock from clock core. 34 - */ 35 - static u32 samsung_usb3phy_set_refclk(struct samsung_usbphy *sphy) 36 - { 37 - u32 reg; 38 - u32 refclk; 39 - 40 - refclk = sphy->ref_clk_freq; 41 - 42 - reg = PHYCLKRST_REFCLKSEL_EXT_REFCLK | 43 - PHYCLKRST_FSEL(refclk); 44 - 45 - switch (refclk) { 46 - case FSEL_CLKSEL_50M: 47 - reg |= (PHYCLKRST_MPLL_MULTIPLIER_50M_REF | 48 - PHYCLKRST_SSC_REFCLKSEL(0x00)); 49 - break; 50 - case FSEL_CLKSEL_20M: 51 - reg |= (PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF | 52 - PHYCLKRST_SSC_REFCLKSEL(0x00)); 53 - break; 54 - case FSEL_CLKSEL_19200K: 55 - reg |= (PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF | 56 - PHYCLKRST_SSC_REFCLKSEL(0x88)); 57 - break; 58 - case FSEL_CLKSEL_24M: 59 - default: 60 - reg |= (PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF | 61 - PHYCLKRST_SSC_REFCLKSEL(0x88)); 62 - break; 63 - } 64 - 65 - return reg; 66 - } 67 - 68 - static void samsung_exynos5_usb3phy_enable(struct samsung_usbphy *sphy) 69 - { 70 - void __iomem *regs = sphy->regs; 71 - u32 phyparam0; 72 - u32 phyparam1; 73 - u32 linksystem; 74 - u32 phybatchg; 75 - u32 phytest; 76 - u32 phyclkrst; 77 - 78 - /* Reset USB 3.0 PHY */ 79 - writel(0x0, regs + EXYNOS5_DRD_PHYREG0); 80 - 81 - phyparam0 = readl(regs + EXYNOS5_DRD_PHYPARAM0); 82 - /* Select PHY CLK source */ 83 - phyparam0 &= ~PHYPARAM0_REF_USE_PAD; 84 - /* Set Loss-of-Signal Detector sensitivity */ 85 - phyparam0 &= ~PHYPARAM0_REF_LOSLEVEL_MASK; 86 - phyparam0 |= PHYPARAM0_REF_LOSLEVEL; 87 - writel(phyparam0, regs + EXYNOS5_DRD_PHYPARAM0); 88 - 89 - writel(0x0, regs + EXYNOS5_DRD_PHYRESUME); 90 - 91 - /* 92 - * Setting the Frame length Adj value[6:1] to default 0x20 93 - * See xHCI 1.0 spec, 5.2.4 94 - */ 95 - linksystem = LINKSYSTEM_XHCI_VERSION_CONTROL | 96 - LINKSYSTEM_FLADJ(0x20); 97 - writel(linksystem, regs + EXYNOS5_DRD_LINKSYSTEM); 98 - 99 - phyparam1 = readl(regs + EXYNOS5_DRD_PHYPARAM1); 100 - /* Set Tx De-Emphasis level */ 101 - phyparam1 &= ~PHYPARAM1_PCS_TXDEEMPH_MASK; 102 - phyparam1 |= PHYPARAM1_PCS_TXDEEMPH; 103 - writel(phyparam1, regs + EXYNOS5_DRD_PHYPARAM1); 104 - 105 - phybatchg = readl(regs + EXYNOS5_DRD_PHYBATCHG); 106 - phybatchg |= PHYBATCHG_UTMI_CLKSEL; 107 - writel(phybatchg, regs + EXYNOS5_DRD_PHYBATCHG); 108 - 109 - /* PHYTEST POWERDOWN Control */ 110 - phytest = readl(regs + EXYNOS5_DRD_PHYTEST); 111 - phytest &= ~(PHYTEST_POWERDOWN_SSP | 112 - PHYTEST_POWERDOWN_HSP); 113 - writel(phytest, regs + EXYNOS5_DRD_PHYTEST); 114 - 115 - /* UTMI Power Control */ 116 - writel(PHYUTMI_OTGDISABLE, regs + EXYNOS5_DRD_PHYUTMI); 117 - 118 - phyclkrst = samsung_usb3phy_set_refclk(sphy); 119 - 120 - phyclkrst |= PHYCLKRST_PORTRESET | 121 - /* Digital power supply in normal operating mode */ 122 - PHYCLKRST_RETENABLEN | 123 - /* Enable ref clock for SS function */ 124 - PHYCLKRST_REF_SSP_EN | 125 - /* Enable spread spectrum */ 126 - PHYCLKRST_SSC_EN | 127 - /* Power down HS Bias and PLL blocks in suspend mode */ 128 - PHYCLKRST_COMMONONN; 129 - 130 - writel(phyclkrst, regs + EXYNOS5_DRD_PHYCLKRST); 131 - 132 - udelay(10); 133 - 134 - phyclkrst &= ~(PHYCLKRST_PORTRESET); 135 - writel(phyclkrst, regs + EXYNOS5_DRD_PHYCLKRST); 136 - } 137 - 138 - static void samsung_exynos5_usb3phy_disable(struct samsung_usbphy *sphy) 139 - { 140 - u32 phyutmi; 141 - u32 phyclkrst; 142 - u32 phytest; 143 - void __iomem *regs = sphy->regs; 144 - 145 - phyutmi = PHYUTMI_OTGDISABLE | 146 - PHYUTMI_FORCESUSPEND | 147 - PHYUTMI_FORCESLEEP; 148 - writel(phyutmi, regs + EXYNOS5_DRD_PHYUTMI); 149 - 150 - /* Resetting the PHYCLKRST enable bits to reduce leakage current */ 151 - phyclkrst = readl(regs + EXYNOS5_DRD_PHYCLKRST); 152 - phyclkrst &= ~(PHYCLKRST_REF_SSP_EN | 153 - PHYCLKRST_SSC_EN | 154 - PHYCLKRST_COMMONONN); 155 - writel(phyclkrst, regs + EXYNOS5_DRD_PHYCLKRST); 156 - 157 - /* Control PHYTEST to remove leakage current */ 158 - phytest = readl(regs + EXYNOS5_DRD_PHYTEST); 159 - phytest |= (PHYTEST_POWERDOWN_SSP | 160 - PHYTEST_POWERDOWN_HSP); 161 - writel(phytest, regs + EXYNOS5_DRD_PHYTEST); 162 - } 163 - 164 - static int samsung_usb3phy_init(struct usb_phy *phy) 165 - { 166 - struct samsung_usbphy *sphy; 167 - unsigned long flags; 168 - int ret = 0; 169 - 170 - sphy = phy_to_sphy(phy); 171 - 172 - /* Enable the phy clock */ 173 - ret = clk_prepare_enable(sphy->clk); 174 - if (ret) { 175 - dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__); 176 - return ret; 177 - } 178 - 179 - spin_lock_irqsave(&sphy->lock, flags); 180 - 181 - /* setting default phy-type for USB 3.0 */ 182 - samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); 183 - 184 - /* Disable phy isolation */ 185 - if (sphy->drv_data->set_isolation) 186 - sphy->drv_data->set_isolation(sphy, false); 187 - 188 - /* Initialize usb phy registers */ 189 - sphy->drv_data->phy_enable(sphy); 190 - 191 - spin_unlock_irqrestore(&sphy->lock, flags); 192 - 193 - /* Disable the phy clock */ 194 - clk_disable_unprepare(sphy->clk); 195 - 196 - return ret; 197 - } 198 - 199 - /* 200 - * The function passed to the usb driver for phy shutdown 201 - */ 202 - static void samsung_usb3phy_shutdown(struct usb_phy *phy) 203 - { 204 - struct samsung_usbphy *sphy; 205 - unsigned long flags; 206 - 207 - sphy = phy_to_sphy(phy); 208 - 209 - if (clk_prepare_enable(sphy->clk)) { 210 - dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__); 211 - return; 212 - } 213 - 214 - spin_lock_irqsave(&sphy->lock, flags); 215 - 216 - /* setting default phy-type for USB 3.0 */ 217 - samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE); 218 - 219 - /* De-initialize usb phy registers */ 220 - sphy->drv_data->phy_disable(sphy); 221 - 222 - /* Enable phy isolation */ 223 - if (sphy->drv_data->set_isolation) 224 - sphy->drv_data->set_isolation(sphy, true); 225 - 226 - spin_unlock_irqrestore(&sphy->lock, flags); 227 - 228 - clk_disable_unprepare(sphy->clk); 229 - } 230 - 231 - static int samsung_usb3phy_probe(struct platform_device *pdev) 232 - { 233 - struct samsung_usbphy *sphy; 234 - struct samsung_usbphy_data *pdata = dev_get_platdata(&pdev->dev); 235 - struct device *dev = &pdev->dev; 236 - struct resource *phy_mem; 237 - void __iomem *phy_base; 238 - struct clk *clk; 239 - int ret; 240 - 241 - phy_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 242 - phy_base = devm_ioremap_resource(dev, phy_mem); 243 - if (IS_ERR(phy_base)) 244 - return PTR_ERR(phy_base); 245 - 246 - sphy = devm_kzalloc(dev, sizeof(*sphy), GFP_KERNEL); 247 - if (!sphy) 248 - return -ENOMEM; 249 - 250 - clk = devm_clk_get(dev, "usbdrd30"); 251 - if (IS_ERR(clk)) { 252 - dev_err(dev, "Failed to get device clock\n"); 253 - return PTR_ERR(clk); 254 - } 255 - 256 - sphy->dev = dev; 257 - 258 - if (dev->of_node) { 259 - ret = samsung_usbphy_parse_dt(sphy); 260 - if (ret < 0) 261 - return ret; 262 - } else { 263 - if (!pdata) { 264 - dev_err(dev, "no platform data specified\n"); 265 - return -EINVAL; 266 - } 267 - } 268 - 269 - sphy->plat = pdata; 270 - sphy->regs = phy_base; 271 - sphy->clk = clk; 272 - sphy->phy.dev = sphy->dev; 273 - sphy->phy.label = "samsung-usb3phy"; 274 - sphy->phy.type = USB_PHY_TYPE_USB3; 275 - sphy->phy.init = samsung_usb3phy_init; 276 - sphy->phy.shutdown = samsung_usb3phy_shutdown; 277 - sphy->drv_data = samsung_usbphy_get_driver_data(pdev); 278 - 279 - sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy); 280 - if (sphy->ref_clk_freq < 0) 281 - return -EINVAL; 282 - 283 - spin_lock_init(&sphy->lock); 284 - 285 - platform_set_drvdata(pdev, sphy); 286 - 287 - return usb_add_phy_dev(&sphy->phy); 288 - } 289 - 290 - static int samsung_usb3phy_remove(struct platform_device *pdev) 291 - { 292 - struct samsung_usbphy *sphy = platform_get_drvdata(pdev); 293 - 294 - usb_remove_phy(&sphy->phy); 295 - 296 - if (sphy->pmuregs) 297 - iounmap(sphy->pmuregs); 298 - if (sphy->sysreg) 299 - iounmap(sphy->sysreg); 300 - 301 - return 0; 302 - } 303 - 304 - static struct samsung_usbphy_drvdata usb3phy_exynos5 = { 305 - .cpu_type = TYPE_EXYNOS5250, 306 - .devphy_en_mask = EXYNOS_USBPHY_ENABLE, 307 - .rate_to_clksel = samsung_usbphy_rate_to_clksel_4x12, 308 - .set_isolation = samsung_usbphy_set_isolation_4210, 309 - .phy_enable = samsung_exynos5_usb3phy_enable, 310 - .phy_disable = samsung_exynos5_usb3phy_disable, 311 - }; 312 - 313 - #ifdef CONFIG_OF 314 - static const struct of_device_id samsung_usbphy_dt_match[] = { 315 - { 316 - .compatible = "samsung,exynos5250-usb3phy", 317 - .data = &usb3phy_exynos5 318 - }, 319 - {}, 320 - }; 321 - MODULE_DEVICE_TABLE(of, samsung_usbphy_dt_match); 322 - #endif 323 - 324 - static struct platform_device_id samsung_usbphy_driver_ids[] = { 325 - { 326 - .name = "exynos5250-usb3phy", 327 - .driver_data = (unsigned long)&usb3phy_exynos5, 328 - }, 329 - {}, 330 - }; 331 - 332 - MODULE_DEVICE_TABLE(platform, samsung_usbphy_driver_ids); 333 - 334 - static struct platform_driver samsung_usb3phy_driver = { 335 - .probe = samsung_usb3phy_probe, 336 - .remove = samsung_usb3phy_remove, 337 - .id_table = samsung_usbphy_driver_ids, 338 - .driver = { 339 - .name = "samsung-usb3phy", 340 - .owner = THIS_MODULE, 341 - .of_match_table = of_match_ptr(samsung_usbphy_dt_match), 342 - }, 343 - }; 344 - 345 - module_platform_driver(samsung_usb3phy_driver); 346 - 347 - MODULE_DESCRIPTION("Samsung USB 3.0 phy controller"); 348 - MODULE_AUTHOR("Vivek Gautam <gautam.vivek@samsung.com>"); 349 - MODULE_LICENSE("GPL"); 350 - MODULE_ALIAS("platform:samsung-usb3phy");
-2
drivers/usb/phy/phy-twl6030-usb.c
··· 104 104 int irq2; 105 105 enum omap_musb_vbus_id_status linkstat; 106 106 u8 asleep; 107 - bool irq_enabled; 108 107 bool vbus_enable; 109 108 const char *regulator; 110 109 }; ··· 372 373 373 374 INIT_WORK(&twl->set_vbus_work, otg_set_vbus_work); 374 375 375 - twl->irq_enabled = true; 376 376 status = request_threaded_irq(twl->irq1, NULL, twl6030_usbotg_irq, 377 377 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT, 378 378 "twl6030_usb", twl);
+44
drivers/usb/renesas_usbhs/common.c
··· 18 18 #include <linux/gpio.h> 19 19 #include <linux/io.h> 20 20 #include <linux/module.h> 21 + #include <linux/of_device.h> 22 + #include <linux/of_gpio.h> 21 23 #include <linux/pm_runtime.h> 22 24 #include <linux/slab.h> 23 25 #include <linux/sysfs.h> ··· 440 438 /* 441 439 * platform functions 442 440 */ 441 + static const struct of_device_id usbhs_of_match[] = { 442 + { 443 + .compatible = "renesas,usbhs-r8a7790", 444 + .data = (void *)USBHS_TYPE_R8A7790, 445 + }, 446 + { 447 + .compatible = "renesas,usbhs-r8a7791", 448 + .data = (void *)USBHS_TYPE_R8A7791, 449 + }, 450 + { }, 451 + }; 452 + MODULE_DEVICE_TABLE(of, usbhs_of_match); 453 + 454 + static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev) 455 + { 456 + struct renesas_usbhs_platform_info *info; 457 + struct renesas_usbhs_driver_param *dparam; 458 + const struct of_device_id *of_id = of_match_device(usbhs_of_match, dev); 459 + u32 tmp; 460 + int gpio; 461 + 462 + info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); 463 + if (!info) 464 + return NULL; 465 + 466 + dparam = &info->driver_param; 467 + dparam->type = of_id ? (u32)of_id->data : 0; 468 + if (!of_property_read_u32(dev->of_node, "renesas,buswait", &tmp)) 469 + dparam->buswait_bwait = tmp; 470 + gpio = of_get_named_gpio_flags(dev->of_node, "renesas,enable-gpio", 0, 471 + NULL); 472 + if (gpio > 0) 473 + dparam->enable_gpio = gpio; 474 + 475 + return info; 476 + } 477 + 443 478 static int usbhs_probe(struct platform_device *pdev) 444 479 { 445 480 struct renesas_usbhs_platform_info *info = dev_get_platdata(&pdev->dev); ··· 484 445 struct usbhs_priv *priv; 485 446 struct resource *res, *irq_res; 486 447 int ret; 448 + 449 + /* check device node */ 450 + if (pdev->dev.of_node) 451 + info = pdev->dev.platform_data = usbhs_parse_dt(&pdev->dev); 487 452 488 453 /* check platform information */ 489 454 if (!info) { ··· 732 689 .driver = { 733 690 .name = "renesas_usbhs", 734 691 .pm = &usbhsc_pm_ops, 692 + .of_match_table = of_match_ptr(usbhs_of_match), 735 693 }, 736 694 .probe = usbhs_probe, 737 695 .remove = usbhs_remove,
-27
include/linux/platform_data/samsung-usbphy.h
··· 1 - /* 2 - * Copyright (C) 2012 Samsung Electronics Co.Ltd 3 - * http://www.samsung.com/ 4 - * Author: Praveen Paneri <p.paneri@samsung.com> 5 - * 6 - * Defines platform data for samsung usb phy driver. 7 - * 8 - * This program is free software; you can redistribute it and/or modify it 9 - * under the terms of the GNU General Public License as published by the 10 - * Free Software Foundation; either version 2 of the License, or (at your 11 - * option) any later version. 12 - */ 13 - 14 - #ifndef __SAMSUNG_USBPHY_PLATFORM_H 15 - #define __SAMSUNG_USBPHY_PLATFORM_H 16 - 17 - /** 18 - * samsung_usbphy_data - Platform data for USB PHY driver. 19 - * @pmu_isolation: Function to control usb phy isolation in PMU. 20 - */ 21 - struct samsung_usbphy_data { 22 - void (*pmu_isolation)(int on); 23 - }; 24 - 25 - extern void samsung_usbphy_set_pdata(struct samsung_usbphy_data *pd); 26 - 27 - #endif /* __SAMSUNG_USBPHY_PLATFORM_H */
+14 -4
include/linux/usb/gadget.h
··· 345 345 * @ep:the endpoint associated with the request 346 346 * @req:the request being canceled 347 347 * 348 - * if the request is still active on the endpoint, it is dequeued and its 348 + * If the request is still active on the endpoint, it is dequeued and its 349 349 * completion routine is called (with status -ECONNRESET); else a negative 350 - * error code is returned. 350 + * error code is returned. This is guaranteed to happen before the call to 351 + * usb_ep_dequeue() returns. 351 352 * 352 - * note that some hardware can't clear out write fifos (to unlink the request 353 - * at the head of the queue) except as part of disconnecting from usb. such 353 + * Note that some hardware can't clear out write fifos (to unlink the request 354 + * at the head of the queue) except as part of disconnecting from usb. Such 354 355 * restrictions prevent drivers from supporting configuration changes, 355 356 * even to configuration zero (a "chapter 9" requirement). 356 357 */ ··· 817 816 * Called in a context that permits sleeping. 818 817 * @suspend: Invoked on USB suspend. May be called in_interrupt. 819 818 * @resume: Invoked on USB resume. May be called in_interrupt. 819 + * @reset: Invoked on USB bus reset. It is mandatory for all gadget drivers 820 + * and should be called in_interrupt. 820 821 * @driver: Driver model state for this driver. 821 822 * 822 823 * Devices are disabled till a gadget driver successfully bind()s, which ··· 876 873 void (*disconnect)(struct usb_gadget *); 877 874 void (*suspend)(struct usb_gadget *); 878 875 void (*resume)(struct usb_gadget *); 876 + void (*reset)(struct usb_gadget *); 879 877 880 878 /* FIXME support safe rmmod */ 881 879 struct device_driver driver; ··· 1014 1010 1015 1011 extern void usb_gadget_set_state(struct usb_gadget *gadget, 1016 1012 enum usb_device_state state); 1013 + 1014 + /*-------------------------------------------------------------------------*/ 1015 + 1016 + /* utility to tell udc core that the bus reset occurs */ 1017 + extern void usb_gadget_udc_reset(struct usb_gadget *gadget, 1018 + struct usb_gadget_driver *driver); 1017 1019 1018 1020 /*-------------------------------------------------------------------------*/ 1019 1021
+18 -1
include/uapi/linux/usb/functionfs.h
··· 19 19 FUNCTIONFS_HAS_HS_DESC = 2, 20 20 FUNCTIONFS_HAS_SS_DESC = 4, 21 21 FUNCTIONFS_HAS_MS_OS_DESC = 8, 22 + FUNCTIONFS_VIRTUAL_ADDR = 16, 22 23 }; 23 24 24 25 /* Descriptor of an non-audio endpoint */ ··· 31 30 __u8 bmAttributes; 32 31 __le16 wMaxPacketSize; 33 32 __u8 bInterval; 33 + } __attribute__((packed)); 34 + 35 + struct usb_functionfs_descs_head_v2 { 36 + __le32 magic; 37 + __le32 length; 38 + __le32 flags; 39 + /* 40 + * __le32 fs_count, hs_count, fs_count; must be included manually in 41 + * the structure taking flags into consideration. 42 + */ 34 43 } __attribute__((packed)); 35 44 36 45 /* Legacy format, deprecated as of 3.14. */ ··· 103 92 * structure. Any flags that are not recognised cause the whole block to be 104 93 * rejected with -ENOSYS. 105 94 * 106 - * Legacy descriptors format: 95 + * Legacy descriptors format (deprecated as of 3.14): 107 96 * 108 97 * | off | name | type | description | 109 98 * |-----+-----------+--------------+--------------------------------------| ··· 275 264 * active returns -ENODEV. 276 265 */ 277 266 #define FUNCTIONFS_ENDPOINT_REVMAP _IO('g', 129) 267 + 268 + /* 269 + * Returns endpoint descriptor. If function is not active returns -ENODEV. 270 + */ 271 + #define FUNCTIONFS_ENDPOINT_DESC _IOR('g', 130, \ 272 + struct usb_endpoint_descriptor) 278 273 279 274 280 275
+116 -10
tools/usb/ffs-test.c
··· 1 1 /* 2 - * ffs-test.c.c -- user mode filesystem api for usb composite function 2 + * ffs-test.c -- user mode filesystem api for usb composite function 3 3 * 4 4 * Copyright (C) 2010 Samsung Electronics 5 5 * Author: Michal Nazarewicz <mina86@mina86.com> ··· 29 29 #include <fcntl.h> 30 30 #include <pthread.h> 31 31 #include <stdarg.h> 32 + #include <stdbool.h> 32 33 #include <stdio.h> 33 34 #include <stdlib.h> 34 35 #include <string.h> ··· 107 106 /******************** Descriptors and Strings *******************************/ 108 107 109 108 static const struct { 110 - struct usb_functionfs_descs_head header; 109 + struct usb_functionfs_descs_head_v2 header; 110 + __le32 fs_count; 111 + __le32 hs_count; 111 112 struct { 112 113 struct usb_interface_descriptor intf; 113 114 struct usb_endpoint_descriptor_no_audio sink; ··· 117 114 } __attribute__((packed)) fs_descs, hs_descs; 118 115 } __attribute__((packed)) descriptors = { 119 116 .header = { 120 - .magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC), 117 + .magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC_V2), 118 + .flags = cpu_to_le32(FUNCTIONFS_HAS_FS_DESC | 119 + FUNCTIONFS_HAS_HS_DESC), 121 120 .length = cpu_to_le32(sizeof descriptors), 122 - .fs_count = cpu_to_le32(3), 123 - .hs_count = cpu_to_le32(3), 124 121 }, 122 + .fs_count = cpu_to_le32(3), 125 123 .fs_descs = { 126 124 .intf = { 127 125 .bLength = sizeof descriptors.fs_descs.intf, ··· 146 142 /* .wMaxPacketSize = autoconfiguration (kernel) */ 147 143 }, 148 144 }, 145 + .hs_count = cpu_to_le32(3), 149 146 .hs_descs = { 150 147 .intf = { 151 148 .bLength = sizeof descriptors.fs_descs.intf, ··· 172 167 }, 173 168 }, 174 169 }; 170 + 171 + static size_t descs_to_legacy(void **legacy, const void *descriptors_v2) 172 + { 173 + const unsigned char *descs_end, *descs_start; 174 + __u32 length, fs_count = 0, hs_count = 0, count; 175 + 176 + /* Read v2 header */ 177 + { 178 + const struct { 179 + const struct usb_functionfs_descs_head_v2 header; 180 + const __le32 counts[]; 181 + } __attribute__((packed)) *const in = descriptors_v2; 182 + const __le32 *counts = in->counts; 183 + __u32 flags; 184 + 185 + if (le32_to_cpu(in->header.magic) != 186 + FUNCTIONFS_DESCRIPTORS_MAGIC_V2) 187 + return 0; 188 + length = le32_to_cpu(in->header.length); 189 + if (length <= sizeof in->header) 190 + return 0; 191 + length -= sizeof in->header; 192 + flags = le32_to_cpu(in->header.flags); 193 + if (flags & ~(FUNCTIONFS_HAS_FS_DESC | FUNCTIONFS_HAS_HS_DESC | 194 + FUNCTIONFS_HAS_SS_DESC)) 195 + return 0; 196 + 197 + #define GET_NEXT_COUNT_IF_FLAG(ret, flg) do { \ 198 + if (!(flags & (flg))) \ 199 + break; \ 200 + if (length < 4) \ 201 + return 0; \ 202 + ret = le32_to_cpu(*counts); \ 203 + length -= 4; \ 204 + ++counts; \ 205 + } while (0) 206 + 207 + GET_NEXT_COUNT_IF_FLAG(fs_count, FUNCTIONFS_HAS_FS_DESC); 208 + GET_NEXT_COUNT_IF_FLAG(hs_count, FUNCTIONFS_HAS_HS_DESC); 209 + GET_NEXT_COUNT_IF_FLAG(count, FUNCTIONFS_HAS_SS_DESC); 210 + 211 + count = fs_count + hs_count; 212 + if (!count) 213 + return 0; 214 + descs_start = (const void *)counts; 215 + 216 + #undef GET_NEXT_COUNT_IF_FLAG 217 + } 218 + 219 + /* 220 + * Find the end of FS and HS USB descriptors. SS descriptors 221 + * are ignored since legacy format does not support them. 222 + */ 223 + descs_end = descs_start; 224 + do { 225 + if (length < *descs_end) 226 + return 0; 227 + length -= *descs_end; 228 + descs_end += *descs_end; 229 + } while (--count); 230 + 231 + /* Allocate legacy descriptors and copy the data. */ 232 + { 233 + #pragma GCC diagnostic push 234 + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 235 + struct { 236 + struct usb_functionfs_descs_head header; 237 + __u8 descriptors[]; 238 + } __attribute__((packed)) *out; 239 + #pragma GCC diagnostic pop 240 + 241 + length = sizeof out->header + (descs_end - descs_start); 242 + out = malloc(length); 243 + out->header.magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC); 244 + out->header.length = cpu_to_le32(length); 245 + out->header.fs_count = cpu_to_le32(fs_count); 246 + out->header.hs_count = cpu_to_le32(hs_count); 247 + memcpy(out->descriptors, descs_start, descs_end - descs_start); 248 + *legacy = out; 249 + } 250 + 251 + return length; 252 + } 175 253 176 254 177 255 #define STR_INTERFACE_ "Source/Sink" ··· 575 487 return nbytes; 576 488 } 577 489 578 - static void ep0_init(struct thread *t) 490 + static void ep0_init(struct thread *t, bool legacy_descriptors) 579 491 { 492 + void *legacy; 580 493 ssize_t ret; 494 + size_t len; 581 495 582 - info("%s: writing descriptors\n", t->filename); 496 + if (legacy_descriptors) { 497 + info("%s: writing descriptors\n", t->filename); 498 + goto legacy; 499 + } 500 + 501 + info("%s: writing descriptors (in v2 format)\n", t->filename); 583 502 ret = write(t->fd, &descriptors, sizeof descriptors); 503 + 504 + if (ret < 0 && errno == EINVAL) { 505 + warn("%s: new format rejected, trying legacy\n", t->filename); 506 + legacy: 507 + len = descs_to_legacy(&legacy, &descriptors); 508 + if (len) { 509 + ret = write(t->fd, legacy, len); 510 + free(legacy); 511 + } 512 + } 584 513 die_on(ret < 0, "%s: write: descriptors", t->filename); 585 514 586 515 info("%s: writing strings\n", t->filename); ··· 608 503 609 504 /******************** Main **************************************************/ 610 505 611 - int main(void) 506 + int main(int argc, char **argv) 612 507 { 508 + bool legacy_descriptors; 613 509 unsigned i; 614 510 615 - /* XXX TODO: Argument parsing missing */ 511 + legacy_descriptors = argc > 2 && !strcmp(argv[1], "-l"); 616 512 617 513 init_thread(threads); 618 - ep0_init(threads); 514 + ep0_init(threads, legacy_descriptors); 619 515 620 516 for (i = 1; i < sizeof threads / sizeof *threads; ++i) 621 517 init_thread(threads + i);