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

Merge 3.1-rc4 into usb-next

This was done to resolve a conflict in this file:
drivers/usb/host/xhci-ring.c

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

+7127 -429
+53
Documentation/usb/dwc3.txt
··· 1 + 2 + TODO 3 + ~~~~~~ 4 + Please pick something while reading :) 5 + 6 + - Implement streaming support for BULK endpoints 7 + Tatyana's patch "usb: Add streams support to the gadget framework" 8 + introduces streaming support for the gadget driver. 9 + Every usb_request has new field called stream_id which holds its id. 10 + Every usb_ep has a field num_supported_strms which describes the max 11 + number of streams supported (for this ep). 12 + UAS is AFAIK the only gadget with streaming support. 13 + 14 + - Convert interrupt handler to per-ep-thread-irq 15 + 16 + As it turns out some DWC3-commands ~1ms to complete. Currently we spin 17 + until the command completes which is bad. 18 + 19 + Implementation idea: 20 + - dwc core implements a demultiplexing irq chip for interrupts per 21 + endpoint. The interrupt numbers are allocated during probe and belong 22 + to the device. If MSI provides per-endpoint interrupt this dummy 23 + interrupt chip can be replaced with "real" interrupts. 24 + - interrupts are requested / allocated on usb_ep_enable() and removed on 25 + usb_ep_disable(). Worst case are 32 interrupts, the lower limit is two 26 + for ep0/1. 27 + - dwc3_send_gadget_ep_cmd() will sleep in wait_for_completion_timeout() 28 + until the command completes. 29 + - the interrupt handler is split into the following pieces: 30 + - primary handler of the device 31 + goes through every event and calls generic_handle_irq() for event 32 + it. On return from generic_handle_irq() in acknowledges the event 33 + counter so interrupt goes away (eventually). 34 + 35 + - threaded handler of the device 36 + none 37 + 38 + - primary handler of the EP-interrupt 39 + reads the event and tries to process it. Everything that requries 40 + sleeping is handed over to the Thread. The event is saved in an 41 + per-endpoint data-structure. 42 + We probably have to pay attention not to process events once we 43 + handed something to thread so we don't process event X prio Y 44 + where X > Y. 45 + 46 + - threaded handler of the EP-interrupt 47 + handles the remaining EP work which might sleep such as waiting 48 + for command completion. 49 + 50 + Latency: 51 + There should be no increase in latency since the interrupt-thread has a 52 + high priority and will be run before an average task in user land 53 + (except the user changed priorities).
+8
MAINTAINERS
··· 2139 2139 S: Maintained 2140 2140 F: drivers/platform/x86/dell-wmi.c 2141 2141 2142 + DESIGNWARE USB3 DRD IP DRIVER 2143 + M: Felipe Balbi <balbi@ti.com> 2144 + L: linux-usb@vger.kernel.org 2145 + L: linux-omap@vger.kernel.org 2146 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git 2147 + S: Maintained 2148 + F: drivers/usb/dwc3/ 2149 + 2142 2150 DEVICE NUMBER REGISTRY 2143 2151 M: Torben Mathiasen <device@lanana.org> 2144 2152 W: http://lanana.org/docs/device-list/index.html
+7
arch/arm/mach-mmp/include/mach/pxa168.h
··· 35 35 extern struct pxa_device_desc pxa168_device_keypad; 36 36 extern struct pxa_device_desc pxa168_device_eth; 37 37 38 + struct pxa168_usb_pdata { 39 + /* If NULL, default phy init routine for PXA168 would be called */ 40 + int (*phy_init)(void __iomem *usb_phy_reg_base); 41 + }; 42 + /* pdata can be NULL */ 43 + int __init pxa168_add_usb_host(struct pxa168_usb_pdata *pdata); 44 + 38 45 static inline int pxa168_add_uart(int id) 39 46 { 40 47 struct pxa_device_desc *d = NULL;
+46
arch/arm/mach-mmp/pxa168.c
··· 25 25 #include <mach/dma.h> 26 26 #include <mach/devices.h> 27 27 #include <mach/mfp.h> 28 + #include <linux/platform_device.h> 29 + #include <linux/dma-mapping.h> 30 + #include <mach/pxa168.h> 28 31 29 32 #include "common.h" 30 33 #include "clock.h" ··· 86 83 static APMU_CLK(nand, NAND, 0x19b, 156000000); 87 84 static APMU_CLK(lcd, LCD, 0x7f, 312000000); 88 85 static APMU_CLK(eth, ETH, 0x09, 0); 86 + static APMU_CLK(usb, USB, 0x12, 0); 89 87 90 88 /* device and clock bindings */ 91 89 static struct clk_lookup pxa168_clkregs[] = { ··· 108 104 INIT_CLKREG(&clk_lcd, "pxa168-fb", NULL), 109 105 INIT_CLKREG(&clk_keypad, "pxa27x-keypad", NULL), 110 106 INIT_CLKREG(&clk_eth, "pxa168-eth", "MFUCLK"), 107 + INIT_CLKREG(&clk_usb, "pxa168-ehci", "PXA168-USBCLK"), 111 108 }; 112 109 113 110 static int __init pxa168_init(void) ··· 174 169 PXA168_DEVICE(fb, "pxa168-fb", -1, LCD, 0xd420b000, 0x1c8); 175 170 PXA168_DEVICE(keypad, "pxa27x-keypad", -1, KEYPAD, 0xd4012000, 0x4c); 176 171 PXA168_DEVICE(eth, "pxa168-eth", -1, MFU, 0xc0800000, 0x0fff); 172 + 173 + struct resource pxa168_usb_host_resources[] = { 174 + /* USB Host conroller register base */ 175 + [0] = { 176 + .start = 0xd4209000, 177 + .end = 0xd4209000 + 0x200, 178 + .flags = IORESOURCE_MEM, 179 + .name = "pxa168-usb-host", 180 + }, 181 + /* USB PHY register base */ 182 + [1] = { 183 + .start = 0xd4206000, 184 + .end = 0xd4206000 + 0xff, 185 + .flags = IORESOURCE_MEM, 186 + .name = "pxa168-usb-phy", 187 + }, 188 + [2] = { 189 + .start = IRQ_PXA168_USB2, 190 + .end = IRQ_PXA168_USB2, 191 + .flags = IORESOURCE_IRQ, 192 + }, 193 + }; 194 + 195 + static u64 pxa168_usb_host_dmamask = DMA_BIT_MASK(32); 196 + struct platform_device pxa168_device_usb_host = { 197 + .name = "pxa168-ehci", 198 + .id = -1, 199 + .dev = { 200 + .dma_mask = &pxa168_usb_host_dmamask, 201 + .coherent_dma_mask = DMA_BIT_MASK(32), 202 + }, 203 + 204 + .num_resources = ARRAY_SIZE(pxa168_usb_host_resources), 205 + .resource = pxa168_usb_host_resources, 206 + }; 207 + 208 + int __init pxa168_add_usb_host(struct pxa168_usb_pdata *pdata) 209 + { 210 + pxa168_device_usb_host.dev.platform_data = pdata; 211 + return platform_device_register(&pxa168_device_usb_host); 212 + }
+3
drivers/usb/Kconfig
··· 69 69 default y if ARCH_MSM 70 70 default y if MICROBLAZE 71 71 default y if SPARC_LEON 72 + default y if ARCH_MMP 72 73 default PCI 73 74 74 75 # ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface. ··· 110 109 module will be called usbcore. 111 110 112 111 source "drivers/usb/core/Kconfig" 112 + 113 + source "drivers/usb/dwc3/Kconfig" 113 114 114 115 source "drivers/usb/mon/Kconfig" 115 116
+2
drivers/usb/Makefile
··· 6 6 7 7 obj-$(CONFIG_USB) += core/ 8 8 9 + obj-$(CONFIG_USB_DWC3) += dwc3/ 10 + 9 11 obj-$(CONFIG_USB_MON) += mon/ 10 12 11 13 obj-$(CONFIG_PCI) += host/
+3 -3
drivers/usb/class/cdc-acm.c
··· 1058 1058 goto alloc_fail; 1059 1059 } 1060 1060 1061 - ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize); 1062 - readsize = le16_to_cpu(epread->wMaxPacketSize) * 1061 + ctrlsize = usb_endpoint_maxp(epctrl); 1062 + readsize = usb_endpoint_maxp(epread) * 1063 1063 (quirks == SINGLE_RX_URB ? 1 : 2); 1064 1064 acm->combined_interfaces = combined_interfaces; 1065 - acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize) * 20; 1065 + acm->writesize = usb_endpoint_maxp(epwrite) * 20; 1066 1066 acm->control = control_interface; 1067 1067 acm->data = data_interface; 1068 1068 acm->minor = minor;
+1 -1
drivers/usb/class/cdc-wdm.c
··· 682 682 if (!ep || !usb_endpoint_is_int_in(ep)) 683 683 goto err; 684 684 685 - desc->wMaxPacketSize = le16_to_cpu(ep->wMaxPacketSize); 685 + desc->wMaxPacketSize = usb_endpoint_maxp(ep); 686 686 desc->bMaxPacketSize0 = udev->descriptor.bMaxPacketSize0; 687 687 688 688 desc->orq = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
+2 -3
drivers/usb/class/usbtmc.c
··· 186 186 for (n = 0; n < current_setting->desc.bNumEndpoints; n++) 187 187 if (current_setting->endpoint[n].desc.bEndpointAddress == 188 188 data->bulk_in) 189 - max_size = le16_to_cpu(current_setting->endpoint[n]. 190 - desc.wMaxPacketSize); 189 + max_size = usb_endpoint_maxp(&current_setting->endpoint[n].desc); 191 190 192 191 if (max_size == 0) { 193 192 dev_err(dev, "Couldn't get wMaxPacketSize\n"); ··· 635 636 for (n = 0; n < current_setting->desc.bNumEndpoints; n++) { 636 637 desc = &current_setting->endpoint[n].desc; 637 638 if (desc->bEndpointAddress == data->bulk_in) 638 - max_size = le16_to_cpu(desc->wMaxPacketSize); 639 + max_size = usb_endpoint_maxp(desc); 639 640 } 640 641 641 642 if (max_size == 0) {
+4 -4
drivers/usb/core/config.c
··· 124 124 125 125 if (usb_endpoint_xfer_isoc(&ep->desc)) 126 126 max_tx = (desc->bMaxBurst + 1) * (desc->bmAttributes + 1) * 127 - le16_to_cpu(ep->desc.wMaxPacketSize); 127 + usb_endpoint_maxp(&ep->desc); 128 128 else if (usb_endpoint_xfer_int(&ep->desc)) 129 - max_tx = le16_to_cpu(ep->desc.wMaxPacketSize) * 129 + max_tx = usb_endpoint_maxp(&ep->desc) * 130 130 (desc->bMaxBurst + 1); 131 131 else 132 132 max_tx = 999999; ··· 241 241 cfgno, inum, asnum, d->bEndpointAddress); 242 242 endpoint->desc.bmAttributes = USB_ENDPOINT_XFER_INT; 243 243 endpoint->desc.bInterval = 1; 244 - if (le16_to_cpu(endpoint->desc.wMaxPacketSize) > 8) 244 + if (usb_endpoint_maxp(&endpoint->desc) > 8) 245 245 endpoint->desc.wMaxPacketSize = cpu_to_le16(8); 246 246 } 247 247 ··· 254 254 && usb_endpoint_xfer_bulk(d)) { 255 255 unsigned maxp; 256 256 257 - maxp = le16_to_cpu(endpoint->desc.wMaxPacketSize) & 0x07ff; 257 + maxp = usb_endpoint_maxp(&endpoint->desc) & 0x07ff; 258 258 if (maxp != 512) 259 259 dev_warn(ddev, "config %d interface %d altsetting %d " 260 260 "bulk endpoint 0x%X has invalid maxpacket %d\n",
+2 -2
drivers/usb/core/devices.c
··· 190 190 dir = usb_endpoint_dir_in(desc) ? 'I' : 'O'; 191 191 192 192 if (speed == USB_SPEED_HIGH) { 193 - switch (le16_to_cpu(desc->wMaxPacketSize) & (0x03 << 11)) { 193 + switch (usb_endpoint_maxp(desc) & (0x03 << 11)) { 194 194 case 1 << 11: 195 195 bandwidth = 2; break; 196 196 case 2 << 11: ··· 240 240 241 241 start += sprintf(start, format_endpt, desc->bEndpointAddress, dir, 242 242 desc->bmAttributes, type, 243 - (le16_to_cpu(desc->wMaxPacketSize) & 0x07ff) * 243 + (usb_endpoint_maxp(desc) & 0x07ff) * 244 244 bandwidth, 245 245 interval, unit); 246 246 return start;
+1 -1
drivers/usb/core/endpoint.c
··· 56 56 { 57 57 struct ep_device *ep = to_ep_device(dev); 58 58 return sprintf(buf, "%04x\n", 59 - le16_to_cpu(ep->desc->wMaxPacketSize) & 0x07ff); 59 + usb_endpoint_maxp(ep->desc) & 0x07ff); 60 60 } 61 61 static DEVICE_ATTR(wMaxPacketSize, S_IRUGO, show_ep_wMaxPacketSize, NULL); 62 62
+1 -6
drivers/usb/core/hub.c
··· 1636 1636 int i; 1637 1637 struct usb_hcd *hcd = bus_to_hcd(udev->bus); 1638 1638 1639 - if (!udev) { 1640 - pr_debug ("%s nodev\n", __func__); 1641 - return; 1642 - } 1643 - 1644 1639 /* mark the device as inactive, so any further urb submissions for 1645 1640 * this device (and any of its children) will fail immediately. 1646 1641 * this quiesces everything except pending urbs. ··· 3018 3023 i = 512; 3019 3024 else 3020 3025 i = udev->descriptor.bMaxPacketSize0; 3021 - if (le16_to_cpu(udev->ep0.desc.wMaxPacketSize) != i) { 3026 + if (usb_endpoint_maxp(&udev->ep0.desc) != i) { 3022 3027 if (udev->speed == USB_SPEED_LOW || 3023 3028 !(i == 8 || i == 16 || i == 32 || i == 64)) { 3024 3029 dev_err(&udev->dev, "Invalid ep0 maxpacket: %d\n", i);
+1 -1
drivers/usb/core/urb.c
··· 350 350 dev->state < USB_STATE_CONFIGURED) 351 351 return -ENODEV; 352 352 353 - max = le16_to_cpu(ep->desc.wMaxPacketSize); 353 + max = usb_endpoint_maxp(&ep->desc); 354 354 if (max <= 0) { 355 355 dev_dbg(&dev->dev, 356 356 "bogus endpoint ep%d%s in %s (bad maxpacket %d)\n",
+25
drivers/usb/dwc3/Kconfig
··· 1 + config USB_DWC3 2 + tristate "DesignWare USB3 DRD Core Support" 3 + depends on (USB || USB_GADGET) 4 + select USB_OTG_UTILS 5 + help 6 + Say Y or M here if your system has a Dual Role SuperSpeed 7 + USB controller based on the DesignWare USB3 IP Core. 8 + 9 + If you choose to build this driver is a dynamically linked 10 + module, the module will be called dwc3.ko. 11 + 12 + if USB_DWC3 13 + 14 + config USB_DWC3_DEBUG 15 + bool "Enable Debugging Messages" 16 + help 17 + Say Y here to enable debugging messages on DWC3 Driver. 18 + 19 + config USB_DWC3_VERBOSE 20 + bool "Enable Verbose Debugging Messages" 21 + depends on USB_DWC3_DEBUG 22 + help 23 + Say Y here to enable verbose debugging messages on DWC3 Driver. 24 + 25 + endif
+36
drivers/usb/dwc3/Makefile
··· 1 + ccflags-$(CONFIG_USB_DWC3_DEBUG) := -DDEBUG 2 + ccflags-$(CONFIG_USB_DWC3_VERBOSE) += -DVERBOSE_DEBUG 3 + 4 + obj-$(CONFIG_USB_DWC3) += dwc3.o 5 + 6 + dwc3-y := core.o 7 + 8 + ifneq ($(CONFIG_USB_GADGET_DWC3),) 9 + dwc3-y += gadget.o ep0.o 10 + endif 11 + 12 + ifneq ($(CONFIG_DEBUG_FS),) 13 + dwc3-y += debugfs.o 14 + endif 15 + 16 + ## 17 + # Platform-specific glue layers go here 18 + # 19 + # NOTICE: Make sure your glue layer doesn't depend on anything 20 + # which is arch-specific and that it compiles on all situations. 21 + # 22 + # We want to keep this requirement in order to be able to compile 23 + # the entire driver (with all its glue layers) on several architectures 24 + # and make sure it compiles fine. This will also help with allmodconfig 25 + # and allyesconfig builds. 26 + # 27 + # The only exception is the PCI glue layer, but that's only because 28 + # PCI doesn't provide nops if CONFIG_PCI isn't enabled. 29 + ## 30 + 31 + obj-$(CONFIG_USB_DWC3) += dwc3-omap.o 32 + 33 + ifneq ($(CONFIG_PCI),) 34 + obj-$(CONFIG_USB_DWC3) += dwc3-pci.o 35 + endif 36 +
+467
drivers/usb/dwc3/core.c
··· 1 + /** 2 + * core.c - DesignWare USB3 DRD Controller Core file 3 + * 4 + * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com 5 + * All rights reserved. 6 + * 7 + * Authors: Felipe Balbi <balbi@ti.com>, 8 + * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 9 + * 10 + * Redistribution and use in source and binary forms, with or without 11 + * modification, are permitted provided that the following conditions 12 + * are met: 13 + * 1. Redistributions of source code must retain the above copyright 14 + * notice, this list of conditions, and the following disclaimer, 15 + * without modification. 16 + * 2. Redistributions in binary form must reproduce the above copyright 17 + * notice, this list of conditions and the following disclaimer in the 18 + * documentation and/or other materials provided with the distribution. 19 + * 3. The names of the above-listed copyright holders may not be used 20 + * to endorse or promote products derived from this software without 21 + * specific prior written permission. 22 + * 23 + * ALTERNATIVELY, this software may be distributed under the terms of the 24 + * GNU General Public License ("GPL") version 2, as published by the Free 25 + * Software Foundation. 26 + * 27 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 28 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 29 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 31 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 32 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 33 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 34 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 35 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 + */ 39 + 40 + #include <linux/kernel.h> 41 + #include <linux/slab.h> 42 + #include <linux/spinlock.h> 43 + #include <linux/platform_device.h> 44 + #include <linux/pm_runtime.h> 45 + #include <linux/interrupt.h> 46 + #include <linux/ioport.h> 47 + #include <linux/io.h> 48 + #include <linux/list.h> 49 + #include <linux/delay.h> 50 + #include <linux/dma-mapping.h> 51 + 52 + #include <linux/usb/ch9.h> 53 + #include <linux/usb/gadget.h> 54 + 55 + #include "core.h" 56 + #include "gadget.h" 57 + #include "io.h" 58 + 59 + #include "debug.h" 60 + 61 + /** 62 + * dwc3_core_soft_reset - Issues core soft reset and PHY reset 63 + * @dwc: pointer to our context structure 64 + */ 65 + static void dwc3_core_soft_reset(struct dwc3 *dwc) 66 + { 67 + u32 reg; 68 + 69 + /* Before Resetting PHY, put Core in Reset */ 70 + reg = dwc3_readl(dwc->regs, DWC3_GCTL); 71 + reg |= DWC3_GCTL_CORESOFTRESET; 72 + dwc3_writel(dwc->regs, DWC3_GCTL, reg); 73 + 74 + /* Assert USB3 PHY reset */ 75 + reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); 76 + reg |= DWC3_GUSB3PIPECTL_PHYSOFTRST; 77 + dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); 78 + 79 + /* Assert USB2 PHY reset */ 80 + reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); 81 + reg |= DWC3_GUSB2PHYCFG_PHYSOFTRST; 82 + dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); 83 + 84 + mdelay(100); 85 + 86 + /* Clear USB3 PHY reset */ 87 + reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); 88 + reg &= ~DWC3_GUSB3PIPECTL_PHYSOFTRST; 89 + dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); 90 + 91 + /* Clear USB2 PHY reset */ 92 + reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); 93 + reg &= ~DWC3_GUSB2PHYCFG_PHYSOFTRST; 94 + dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); 95 + 96 + /* After PHYs are stable we can take Core out of reset state */ 97 + reg = dwc3_readl(dwc->regs, DWC3_GCTL); 98 + reg &= ~DWC3_GCTL_CORESOFTRESET; 99 + dwc3_writel(dwc->regs, DWC3_GCTL, reg); 100 + } 101 + 102 + /** 103 + * dwc3_free_one_event_buffer - Frees one event buffer 104 + * @dwc: Pointer to our controller context structure 105 + * @evt: Pointer to event buffer to be freed 106 + */ 107 + static void dwc3_free_one_event_buffer(struct dwc3 *dwc, 108 + struct dwc3_event_buffer *evt) 109 + { 110 + dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma); 111 + kfree(evt); 112 + } 113 + 114 + /** 115 + * dwc3_alloc_one_event_buffer - Allocated one event buffer structure 116 + * @dwc: Pointer to our controller context structure 117 + * @length: size of the event buffer 118 + * 119 + * Returns a pointer to the allocated event buffer structure on succes 120 + * otherwise ERR_PTR(errno). 121 + */ 122 + static struct dwc3_event_buffer *__devinit 123 + dwc3_alloc_one_event_buffer(struct dwc3 *dwc, unsigned length) 124 + { 125 + struct dwc3_event_buffer *evt; 126 + 127 + evt = kzalloc(sizeof(*evt), GFP_KERNEL); 128 + if (!evt) 129 + return ERR_PTR(-ENOMEM); 130 + 131 + evt->dwc = dwc; 132 + evt->length = length; 133 + evt->buf = dma_alloc_coherent(dwc->dev, length, 134 + &evt->dma, GFP_KERNEL); 135 + if (!evt->buf) { 136 + kfree(evt); 137 + return ERR_PTR(-ENOMEM); 138 + } 139 + 140 + return evt; 141 + } 142 + 143 + /** 144 + * dwc3_free_event_buffers - frees all allocated event buffers 145 + * @dwc: Pointer to our controller context structure 146 + */ 147 + static void dwc3_free_event_buffers(struct dwc3 *dwc) 148 + { 149 + struct dwc3_event_buffer *evt; 150 + int i; 151 + 152 + for (i = 0; i < DWC3_EVENT_BUFFERS_NUM; i++) { 153 + evt = dwc->ev_buffs[i]; 154 + if (evt) { 155 + dwc3_free_one_event_buffer(dwc, evt); 156 + dwc->ev_buffs[i] = NULL; 157 + } 158 + } 159 + } 160 + 161 + /** 162 + * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length 163 + * @dwc: Pointer to out controller context structure 164 + * @num: number of event buffers to allocate 165 + * @length: size of event buffer 166 + * 167 + * Returns 0 on success otherwise negative errno. In error the case, dwc 168 + * may contain some buffers allocated but not all which were requested. 169 + */ 170 + static int __devinit dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned num, 171 + unsigned length) 172 + { 173 + int i; 174 + 175 + for (i = 0; i < num; i++) { 176 + struct dwc3_event_buffer *evt; 177 + 178 + evt = dwc3_alloc_one_event_buffer(dwc, length); 179 + if (IS_ERR(evt)) { 180 + dev_err(dwc->dev, "can't allocate event buffer\n"); 181 + return PTR_ERR(evt); 182 + } 183 + dwc->ev_buffs[i] = evt; 184 + } 185 + 186 + return 0; 187 + } 188 + 189 + /** 190 + * dwc3_event_buffers_setup - setup our allocated event buffers 191 + * @dwc: Pointer to out controller context structure 192 + * 193 + * Returns 0 on success otherwise negative errno. 194 + */ 195 + static int __devinit dwc3_event_buffers_setup(struct dwc3 *dwc) 196 + { 197 + struct dwc3_event_buffer *evt; 198 + int n; 199 + 200 + for (n = 0; n < DWC3_EVENT_BUFFERS_NUM; n++) { 201 + evt = dwc->ev_buffs[n]; 202 + dev_dbg(dwc->dev, "Event buf %p dma %08llx length %d\n", 203 + evt->buf, (unsigned long long) evt->dma, 204 + evt->length); 205 + 206 + dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 207 + lower_32_bits(evt->dma)); 208 + dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 209 + upper_32_bits(evt->dma)); 210 + dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), 211 + evt->length & 0xffff); 212 + dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0); 213 + } 214 + 215 + return 0; 216 + } 217 + 218 + static void dwc3_event_buffers_cleanup(struct dwc3 *dwc) 219 + { 220 + struct dwc3_event_buffer *evt; 221 + int n; 222 + 223 + for (n = 0; n < DWC3_EVENT_BUFFERS_NUM; n++) { 224 + evt = dwc->ev_buffs[n]; 225 + dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0); 226 + dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0); 227 + dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), 0); 228 + dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0); 229 + } 230 + } 231 + 232 + /** 233 + * dwc3_core_init - Low-level initialization of DWC3 Core 234 + * @dwc: Pointer to our controller context structure 235 + * 236 + * Returns 0 on success otherwise negative errno. 237 + */ 238 + static int __devinit dwc3_core_init(struct dwc3 *dwc) 239 + { 240 + unsigned long timeout; 241 + u32 reg; 242 + int ret; 243 + 244 + dwc3_core_soft_reset(dwc); 245 + 246 + /* issue device SoftReset too */ 247 + timeout = jiffies + msecs_to_jiffies(500); 248 + dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST); 249 + do { 250 + reg = dwc3_readl(dwc->regs, DWC3_DCTL); 251 + if (!(reg & DWC3_DCTL_CSFTRST)) 252 + break; 253 + 254 + if (time_after(jiffies, timeout)) { 255 + dev_err(dwc->dev, "Reset Timed Out\n"); 256 + ret = -ETIMEDOUT; 257 + goto err0; 258 + } 259 + 260 + cpu_relax(); 261 + } while (true); 262 + 263 + reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); 264 + /* This should read as U3 followed by revision number */ 265 + if ((reg & DWC3_GSNPSID_MASK) != 0x55330000) { 266 + dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); 267 + ret = -ENODEV; 268 + goto err0; 269 + } 270 + 271 + dwc->revision = reg & DWC3_GSNPSREV_MASK; 272 + 273 + ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_NUM, 274 + DWC3_EVENT_BUFFERS_SIZE); 275 + if (ret) { 276 + dev_err(dwc->dev, "failed to allocate event buffers\n"); 277 + ret = -ENOMEM; 278 + goto err1; 279 + } 280 + 281 + ret = dwc3_event_buffers_setup(dwc); 282 + if (ret) { 283 + dev_err(dwc->dev, "failed to setup event buffers\n"); 284 + goto err1; 285 + } 286 + 287 + return 0; 288 + 289 + err1: 290 + dwc3_free_event_buffers(dwc); 291 + 292 + err0: 293 + return ret; 294 + } 295 + 296 + static void dwc3_core_exit(struct dwc3 *dwc) 297 + { 298 + dwc3_event_buffers_cleanup(dwc); 299 + dwc3_free_event_buffers(dwc); 300 + } 301 + 302 + #define DWC3_ALIGN_MASK (16 - 1) 303 + 304 + static int __devinit dwc3_probe(struct platform_device *pdev) 305 + { 306 + const struct platform_device_id *id = platform_get_device_id(pdev); 307 + struct resource *res; 308 + struct dwc3 *dwc; 309 + void __iomem *regs; 310 + unsigned int features = id->driver_data; 311 + int ret = -ENOMEM; 312 + int irq; 313 + void *mem; 314 + 315 + mem = kzalloc(sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL); 316 + if (!mem) { 317 + dev_err(&pdev->dev, "not enough memory\n"); 318 + goto err0; 319 + } 320 + dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1); 321 + dwc->mem = mem; 322 + 323 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 324 + if (!res) { 325 + dev_err(&pdev->dev, "missing resource\n"); 326 + goto err1; 327 + } 328 + 329 + res = request_mem_region(res->start, resource_size(res), 330 + dev_name(&pdev->dev)); 331 + if (!res) { 332 + dev_err(&pdev->dev, "can't request mem region\n"); 333 + goto err1; 334 + } 335 + 336 + regs = ioremap(res->start, resource_size(res)); 337 + if (!regs) { 338 + dev_err(&pdev->dev, "ioremap failed\n"); 339 + goto err2; 340 + } 341 + 342 + irq = platform_get_irq(pdev, 0); 343 + if (irq < 0) { 344 + dev_err(&pdev->dev, "missing IRQ\n"); 345 + goto err3; 346 + } 347 + 348 + spin_lock_init(&dwc->lock); 349 + platform_set_drvdata(pdev, dwc); 350 + 351 + dwc->regs = regs; 352 + dwc->regs_size = resource_size(res); 353 + dwc->dev = &pdev->dev; 354 + dwc->irq = irq; 355 + 356 + pm_runtime_enable(&pdev->dev); 357 + pm_runtime_get_sync(&pdev->dev); 358 + pm_runtime_forbid(&pdev->dev); 359 + 360 + ret = dwc3_core_init(dwc); 361 + if (ret) { 362 + dev_err(&pdev->dev, "failed to initialize core\n"); 363 + goto err3; 364 + } 365 + 366 + if (features & DWC3_HAS_PERIPHERAL) { 367 + ret = dwc3_gadget_init(dwc); 368 + if (ret) { 369 + dev_err(&pdev->dev, "failed to initialized gadget\n"); 370 + goto err4; 371 + } 372 + } 373 + 374 + ret = dwc3_debugfs_init(dwc); 375 + if (ret) { 376 + dev_err(&pdev->dev, "failed to initialize debugfs\n"); 377 + goto err5; 378 + } 379 + 380 + pm_runtime_allow(&pdev->dev); 381 + 382 + return 0; 383 + 384 + err5: 385 + if (features & DWC3_HAS_PERIPHERAL) 386 + dwc3_gadget_exit(dwc); 387 + 388 + err4: 389 + dwc3_core_exit(dwc); 390 + 391 + err3: 392 + iounmap(regs); 393 + 394 + err2: 395 + release_mem_region(res->start, resource_size(res)); 396 + 397 + err1: 398 + kfree(dwc->mem); 399 + 400 + err0: 401 + return ret; 402 + } 403 + 404 + static int __devexit dwc3_remove(struct platform_device *pdev) 405 + { 406 + const struct platform_device_id *id = platform_get_device_id(pdev); 407 + struct dwc3 *dwc = platform_get_drvdata(pdev); 408 + struct resource *res; 409 + unsigned int features = id->driver_data; 410 + 411 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 412 + 413 + pm_runtime_put(&pdev->dev); 414 + pm_runtime_disable(&pdev->dev); 415 + 416 + dwc3_debugfs_exit(dwc); 417 + 418 + if (features & DWC3_HAS_PERIPHERAL) 419 + dwc3_gadget_exit(dwc); 420 + 421 + dwc3_core_exit(dwc); 422 + release_mem_region(res->start, resource_size(res)); 423 + iounmap(dwc->regs); 424 + kfree(dwc->mem); 425 + 426 + return 0; 427 + } 428 + 429 + static const struct platform_device_id dwc3_id_table[] __devinitconst = { 430 + { 431 + .name = "dwc3-omap", 432 + .driver_data = (DWC3_HAS_PERIPHERAL 433 + | DWC3_HAS_XHCI 434 + | DWC3_HAS_OTG), 435 + }, 436 + { 437 + .name = "dwc3-pci", 438 + .driver_data = DWC3_HAS_PERIPHERAL, 439 + }, 440 + { }, /* Terminating Entry */ 441 + }; 442 + MODULE_DEVICE_TABLE(platform, dwc3_id_table); 443 + 444 + static struct platform_driver dwc3_driver = { 445 + .probe = dwc3_probe, 446 + .remove = __devexit_p(dwc3_remove), 447 + .driver = { 448 + .name = "dwc3", 449 + }, 450 + .id_table = dwc3_id_table, 451 + }; 452 + 453 + MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); 454 + MODULE_LICENSE("Dual BSD/GPL"); 455 + MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver"); 456 + 457 + static int __devinit dwc3_init(void) 458 + { 459 + return platform_driver_register(&dwc3_driver); 460 + } 461 + module_init(dwc3_init); 462 + 463 + static void __exit dwc3_exit(void) 464 + { 465 + platform_driver_unregister(&dwc3_driver); 466 + } 467 + module_exit(dwc3_exit);
+709
drivers/usb/dwc3/core.h
··· 1 + /** 2 + * core.h - DesignWare USB3 DRD Core Header 3 + * 4 + * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com 5 + * All rights reserved. 6 + * 7 + * Authors: Felipe Balbi <balbi@ti.com>, 8 + * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 9 + * 10 + * Redistribution and use in source and binary forms, with or without 11 + * modification, are permitted provided that the following conditions 12 + * are met: 13 + * 1. Redistributions of source code must retain the above copyright 14 + * notice, this list of conditions, and the following disclaimer, 15 + * without modification. 16 + * 2. Redistributions in binary form must reproduce the above copyright 17 + * notice, this list of conditions and the following disclaimer in the 18 + * documentation and/or other materials provided with the distribution. 19 + * 3. The names of the above-listed copyright holders may not be used 20 + * to endorse or promote products derived from this software without 21 + * specific prior written permission. 22 + * 23 + * ALTERNATIVELY, this software may be distributed under the terms of the 24 + * GNU General Public License ("GPL") version 2, as published by the Free 25 + * Software Foundation. 26 + * 27 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 28 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 29 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 31 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 32 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 33 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 34 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 35 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 + */ 39 + 40 + #ifndef __DRIVERS_USB_DWC3_CORE_H 41 + #define __DRIVERS_USB_DWC3_CORE_H 42 + 43 + #include <linux/device.h> 44 + #include <linux/spinlock.h> 45 + #include <linux/list.h> 46 + #include <linux/dma-mapping.h> 47 + #include <linux/mm.h> 48 + #include <linux/debugfs.h> 49 + 50 + #include <linux/usb/ch9.h> 51 + #include <linux/usb/gadget.h> 52 + 53 + /* Global constants */ 54 + #define DWC3_ENDPOINTS_NUM 32 55 + 56 + #define DWC3_EVENT_BUFFERS_NUM 2 57 + #define DWC3_EVENT_BUFFERS_SIZE PAGE_SIZE 58 + #define DWC3_EVENT_TYPE_MASK 0xfe 59 + 60 + #define DWC3_EVENT_TYPE_DEV 0 61 + #define DWC3_EVENT_TYPE_CARKIT 3 62 + #define DWC3_EVENT_TYPE_I2C 4 63 + 64 + #define DWC3_DEVICE_EVENT_DISCONNECT 0 65 + #define DWC3_DEVICE_EVENT_RESET 1 66 + #define DWC3_DEVICE_EVENT_CONNECT_DONE 2 67 + #define DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE 3 68 + #define DWC3_DEVICE_EVENT_WAKEUP 4 69 + #define DWC3_DEVICE_EVENT_EOPF 6 70 + #define DWC3_DEVICE_EVENT_SOF 7 71 + #define DWC3_DEVICE_EVENT_ERRATIC_ERROR 9 72 + #define DWC3_DEVICE_EVENT_CMD_CMPL 10 73 + #define DWC3_DEVICE_EVENT_OVERFLOW 11 74 + 75 + #define DWC3_GEVNTCOUNT_MASK 0xfffc 76 + #define DWC3_GSNPSID_MASK 0xffff0000 77 + #define DWC3_GSNPSREV_MASK 0xffff 78 + 79 + /* Global Registers */ 80 + #define DWC3_GSBUSCFG0 0xc100 81 + #define DWC3_GSBUSCFG1 0xc104 82 + #define DWC3_GTXTHRCFG 0xc108 83 + #define DWC3_GRXTHRCFG 0xc10c 84 + #define DWC3_GCTL 0xc110 85 + #define DWC3_GEVTEN 0xc114 86 + #define DWC3_GSTS 0xc118 87 + #define DWC3_GSNPSID 0xc120 88 + #define DWC3_GGPIO 0xc124 89 + #define DWC3_GUID 0xc128 90 + #define DWC3_GUCTL 0xc12c 91 + #define DWC3_GBUSERRADDR0 0xc130 92 + #define DWC3_GBUSERRADDR1 0xc134 93 + #define DWC3_GPRTBIMAP0 0xc138 94 + #define DWC3_GPRTBIMAP1 0xc13c 95 + #define DWC3_GHWPARAMS0 0xc140 96 + #define DWC3_GHWPARAMS1 0xc144 97 + #define DWC3_GHWPARAMS2 0xc148 98 + #define DWC3_GHWPARAMS3 0xc14c 99 + #define DWC3_GHWPARAMS4 0xc150 100 + #define DWC3_GHWPARAMS5 0xc154 101 + #define DWC3_GHWPARAMS6 0xc158 102 + #define DWC3_GHWPARAMS7 0xc15c 103 + #define DWC3_GDBGFIFOSPACE 0xc160 104 + #define DWC3_GDBGLTSSM 0xc164 105 + #define DWC3_GPRTBIMAP_HS0 0xc180 106 + #define DWC3_GPRTBIMAP_HS1 0xc184 107 + #define DWC3_GPRTBIMAP_FS0 0xc188 108 + #define DWC3_GPRTBIMAP_FS1 0xc18c 109 + 110 + #define DWC3_GUSB2PHYCFG(n) (0xc200 + (n * 0x04)) 111 + #define DWC3_GUSB2I2CCTL(n) (0xc240 + (n * 0x04)) 112 + 113 + #define DWC3_GUSB2PHYACC(n) (0xc280 + (n * 0x04)) 114 + 115 + #define DWC3_GUSB3PIPECTL(n) (0xc2c0 + (n * 0x04)) 116 + 117 + #define DWC3_GTXFIFOSIZ(n) (0xc300 + (n * 0x04)) 118 + #define DWC3_GRXFIFOSIZ(n) (0xc380 + (n * 0x04)) 119 + 120 + #define DWC3_GEVNTADRLO(n) (0xc400 + (n * 0x10)) 121 + #define DWC3_GEVNTADRHI(n) (0xc404 + (n * 0x10)) 122 + #define DWC3_GEVNTSIZ(n) (0xc408 + (n * 0x10)) 123 + #define DWC3_GEVNTCOUNT(n) (0xc40c + (n * 0x10)) 124 + 125 + #define DWC3_GHWPARAMS8 0xc600 126 + 127 + /* Device Registers */ 128 + #define DWC3_DCFG 0xc700 129 + #define DWC3_DCTL 0xc704 130 + #define DWC3_DEVTEN 0xc708 131 + #define DWC3_DSTS 0xc70c 132 + #define DWC3_DGCMDPAR 0xc710 133 + #define DWC3_DGCMD 0xc714 134 + #define DWC3_DALEPENA 0xc720 135 + #define DWC3_DEPCMDPAR2(n) (0xc800 + (n * 0x10)) 136 + #define DWC3_DEPCMDPAR1(n) (0xc804 + (n * 0x10)) 137 + #define DWC3_DEPCMDPAR0(n) (0xc808 + (n * 0x10)) 138 + #define DWC3_DEPCMD(n) (0xc80c + (n * 0x10)) 139 + 140 + /* OTG Registers */ 141 + #define DWC3_OCFG 0xcc00 142 + #define DWC3_OCTL 0xcc04 143 + #define DWC3_OEVTEN 0xcc08 144 + #define DWC3_OSTS 0xcc0C 145 + 146 + /* Bit fields */ 147 + 148 + /* Global Configuration Register */ 149 + #define DWC3_GCTL_PWRDNSCALE(n) (n << 19) 150 + #define DWC3_GCTL_U2RSTECN 16 151 + #define DWC3_GCTL_RAMCLKSEL(x) ((x & DWC3_GCTL_CLK_MASK) << 6) 152 + #define DWC3_GCTL_CLK_BUS (0) 153 + #define DWC3_GCTL_CLK_PIPE (1) 154 + #define DWC3_GCTL_CLK_PIPEHALF (2) 155 + #define DWC3_GCTL_CLK_MASK (3) 156 + 157 + #define DWC3_GCTL_PRTCAPDIR(n) (n << 12) 158 + #define DWC3_GCTL_PRTCAP_HOST 1 159 + #define DWC3_GCTL_PRTCAP_DEVICE 2 160 + #define DWC3_GCTL_PRTCAP_OTG 3 161 + 162 + #define DWC3_GCTL_CORESOFTRESET (1 << 11) 163 + #define DWC3_GCTL_DISSCRAMBLE (1 << 3) 164 + 165 + /* Global USB2 PHY Configuration Register */ 166 + #define DWC3_GUSB2PHYCFG_PHYSOFTRST (1 << 31) 167 + #define DWC3_GUSB2PHYCFG_SUSPHY (1 << 6) 168 + 169 + /* Global USB3 PIPE Control Register */ 170 + #define DWC3_GUSB3PIPECTL_PHYSOFTRST (1 << 31) 171 + #define DWC3_GUSB3PIPECTL_SUSPHY (1 << 17) 172 + 173 + /* Device Configuration Register */ 174 + #define DWC3_DCFG_DEVADDR(addr) ((addr) << 3) 175 + #define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f) 176 + 177 + #define DWC3_DCFG_SPEED_MASK (7 << 0) 178 + #define DWC3_DCFG_SUPERSPEED (4 << 0) 179 + #define DWC3_DCFG_HIGHSPEED (0 << 0) 180 + #define DWC3_DCFG_FULLSPEED2 (1 << 0) 181 + #define DWC3_DCFG_LOWSPEED (2 << 0) 182 + #define DWC3_DCFG_FULLSPEED1 (3 << 0) 183 + 184 + /* Device Control Register */ 185 + #define DWC3_DCTL_RUN_STOP (1 << 31) 186 + #define DWC3_DCTL_CSFTRST (1 << 30) 187 + #define DWC3_DCTL_LSFTRST (1 << 29) 188 + 189 + #define DWC3_DCTL_HIRD_THRES_MASK (0x1f << 24) 190 + #define DWC3_DCTL_HIRD_THRES(n) (((n) & DWC3_DCTL_HIRD_THRES_MASK) >> 24) 191 + 192 + #define DWC3_DCTL_APPL1RES (1 << 23) 193 + 194 + #define DWC3_DCTL_INITU2ENA (1 << 12) 195 + #define DWC3_DCTL_ACCEPTU2ENA (1 << 11) 196 + #define DWC3_DCTL_INITU1ENA (1 << 10) 197 + #define DWC3_DCTL_ACCEPTU1ENA (1 << 9) 198 + #define DWC3_DCTL_TSTCTRL_MASK (0xf << 1) 199 + 200 + #define DWC3_DCTL_ULSTCHNGREQ_MASK (0x0f << 5) 201 + #define DWC3_DCTL_ULSTCHNGREQ(n) (((n) << 5) & DWC3_DCTL_ULSTCHNGREQ_MASK) 202 + 203 + #define DWC3_DCTL_ULSTCHNG_NO_ACTION (DWC3_DCTL_ULSTCHNGREQ(0)) 204 + #define DWC3_DCTL_ULSTCHNG_SS_DISABLED (DWC3_DCTL_ULSTCHNGREQ(4)) 205 + #define DWC3_DCTL_ULSTCHNG_RX_DETECT (DWC3_DCTL_ULSTCHNGREQ(5)) 206 + #define DWC3_DCTL_ULSTCHNG_SS_INACTIVE (DWC3_DCTL_ULSTCHNGREQ(6)) 207 + #define DWC3_DCTL_ULSTCHNG_RECOVERY (DWC3_DCTL_ULSTCHNGREQ(8)) 208 + #define DWC3_DCTL_ULSTCHNG_COMPLIANCE (DWC3_DCTL_ULSTCHNGREQ(10)) 209 + #define DWC3_DCTL_ULSTCHNG_LOOPBACK (DWC3_DCTL_ULSTCHNGREQ(11)) 210 + 211 + /* Device Event Enable Register */ 212 + #define DWC3_DEVTEN_VNDRDEVTSTRCVEDEN (1 << 12) 213 + #define DWC3_DEVTEN_EVNTOVERFLOWEN (1 << 11) 214 + #define DWC3_DEVTEN_CMDCMPLTEN (1 << 10) 215 + #define DWC3_DEVTEN_ERRTICERREN (1 << 9) 216 + #define DWC3_DEVTEN_SOFEN (1 << 7) 217 + #define DWC3_DEVTEN_EOPFEN (1 << 6) 218 + #define DWC3_DEVTEN_WKUPEVTEN (1 << 4) 219 + #define DWC3_DEVTEN_ULSTCNGEN (1 << 3) 220 + #define DWC3_DEVTEN_CONNECTDONEEN (1 << 2) 221 + #define DWC3_DEVTEN_USBRSTEN (1 << 1) 222 + #define DWC3_DEVTEN_DISCONNEVTEN (1 << 0) 223 + 224 + /* Device Status Register */ 225 + #define DWC3_DSTS_PWRUPREQ (1 << 24) 226 + #define DWC3_DSTS_COREIDLE (1 << 23) 227 + #define DWC3_DSTS_DEVCTRLHLT (1 << 22) 228 + 229 + #define DWC3_DSTS_USBLNKST_MASK (0x0f << 18) 230 + #define DWC3_DSTS_USBLNKST(n) (((n) & DWC3_DSTS_USBLNKST_MASK) >> 18) 231 + 232 + #define DWC3_DSTS_RXFIFOEMPTY (1 << 17) 233 + 234 + #define DWC3_DSTS_SOFFN_MASK (0x3ff << 3) 235 + #define DWC3_DSTS_SOFFN(n) (((n) & DWC3_DSTS_SOFFN_MASK) >> 3) 236 + 237 + #define DWC3_DSTS_CONNECTSPD (7 << 0) 238 + 239 + #define DWC3_DSTS_SUPERSPEED (4 << 0) 240 + #define DWC3_DSTS_HIGHSPEED (0 << 0) 241 + #define DWC3_DSTS_FULLSPEED2 (1 << 0) 242 + #define DWC3_DSTS_LOWSPEED (2 << 0) 243 + #define DWC3_DSTS_FULLSPEED1 (3 << 0) 244 + 245 + /* Device Generic Command Register */ 246 + #define DWC3_DGCMD_SET_LMP 0x01 247 + #define DWC3_DGCMD_SET_PERIODIC_PAR 0x02 248 + #define DWC3_DGCMD_XMIT_FUNCTION 0x03 249 + #define DWC3_DGCMD_SELECTED_FIFO_FLUSH 0x09 250 + #define DWC3_DGCMD_ALL_FIFO_FLUSH 0x0a 251 + #define DWC3_DGCMD_SET_ENDPOINT_NRDY 0x0c 252 + #define DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK 0x10 253 + 254 + /* Device Endpoint Command Register */ 255 + #define DWC3_DEPCMD_PARAM_SHIFT 16 256 + #define DWC3_DEPCMD_PARAM(x) (x << DWC3_DEPCMD_PARAM_SHIFT) 257 + #define DWC3_DEPCMD_GET_RSC_IDX(x) ((x >> DWC3_DEPCMD_PARAM_SHIFT) & 0x7f) 258 + #define DWC3_DEPCMD_STATUS_MASK (0x0f << 12) 259 + #define DWC3_DEPCMD_STATUS(x) ((x & DWC3_DEPCMD_STATUS_MASK) >> 12) 260 + #define DWC3_DEPCMD_HIPRI_FORCERM (1 << 11) 261 + #define DWC3_DEPCMD_CMDACT (1 << 10) 262 + #define DWC3_DEPCMD_CMDIOC (1 << 8) 263 + 264 + #define DWC3_DEPCMD_DEPSTARTCFG (0x09 << 0) 265 + #define DWC3_DEPCMD_ENDTRANSFER (0x08 << 0) 266 + #define DWC3_DEPCMD_UPDATETRANSFER (0x07 << 0) 267 + #define DWC3_DEPCMD_STARTTRANSFER (0x06 << 0) 268 + #define DWC3_DEPCMD_CLEARSTALL (0x05 << 0) 269 + #define DWC3_DEPCMD_SETSTALL (0x04 << 0) 270 + #define DWC3_DEPCMD_GETSEQNUMBER (0x03 << 0) 271 + #define DWC3_DEPCMD_SETTRANSFRESOURCE (0x02 << 0) 272 + #define DWC3_DEPCMD_SETEPCONFIG (0x01 << 0) 273 + 274 + /* The EP number goes 0..31 so ep0 is always out and ep1 is always in */ 275 + #define DWC3_DALEPENA_EP(n) (1 << n) 276 + 277 + #define DWC3_DEPCMD_TYPE_CONTROL 0 278 + #define DWC3_DEPCMD_TYPE_ISOC 1 279 + #define DWC3_DEPCMD_TYPE_BULK 2 280 + #define DWC3_DEPCMD_TYPE_INTR 3 281 + 282 + /* Structures */ 283 + 284 + struct dwc3_trb_hw; 285 + 286 + /** 287 + * struct dwc3_event_buffer - Software event buffer representation 288 + * @list: a list of event buffers 289 + * @buf: _THE_ buffer 290 + * @length: size of this buffer 291 + * @dma: dma_addr_t 292 + * @dwc: pointer to DWC controller 293 + */ 294 + struct dwc3_event_buffer { 295 + void *buf; 296 + unsigned length; 297 + unsigned int lpos; 298 + 299 + dma_addr_t dma; 300 + 301 + struct dwc3 *dwc; 302 + }; 303 + 304 + #define DWC3_EP_FLAG_STALLED (1 << 0) 305 + #define DWC3_EP_FLAG_WEDGED (1 << 1) 306 + 307 + #define DWC3_EP_DIRECTION_TX true 308 + #define DWC3_EP_DIRECTION_RX false 309 + 310 + #define DWC3_TRB_NUM 32 311 + #define DWC3_TRB_MASK (DWC3_TRB_NUM - 1) 312 + 313 + /** 314 + * struct dwc3_ep - device side endpoint representation 315 + * @endpoint: usb endpoint 316 + * @request_list: list of requests for this endpoint 317 + * @req_queued: list of requests on this ep which have TRBs setup 318 + * @trb_pool: array of transaction buffers 319 + * @trb_pool_dma: dma address of @trb_pool 320 + * @free_slot: next slot which is going to be used 321 + * @busy_slot: first slot which is owned by HW 322 + * @desc: usb_endpoint_descriptor pointer 323 + * @dwc: pointer to DWC controller 324 + * @flags: endpoint flags (wedged, stalled, ...) 325 + * @current_trb: index of current used trb 326 + * @number: endpoint number (1 - 15) 327 + * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK 328 + * @res_trans_idx: Resource transfer index 329 + * @interval: the intervall on which the ISOC transfer is started 330 + * @name: a human readable name e.g. ep1out-bulk 331 + * @direction: true for TX, false for RX 332 + */ 333 + struct dwc3_ep { 334 + struct usb_ep endpoint; 335 + struct list_head request_list; 336 + struct list_head req_queued; 337 + 338 + struct dwc3_trb_hw *trb_pool; 339 + dma_addr_t trb_pool_dma; 340 + u32 free_slot; 341 + u32 busy_slot; 342 + const struct usb_endpoint_descriptor *desc; 343 + struct dwc3 *dwc; 344 + 345 + unsigned flags; 346 + #define DWC3_EP_ENABLED (1 << 0) 347 + #define DWC3_EP_STALL (1 << 1) 348 + #define DWC3_EP_WEDGE (1 << 2) 349 + #define DWC3_EP_BUSY (1 << 4) 350 + #define DWC3_EP_PENDING_REQUEST (1 << 5) 351 + #define DWC3_EP_WILL_SHUTDOWN (1 << 6) 352 + 353 + unsigned current_trb; 354 + 355 + u8 number; 356 + u8 type; 357 + u8 res_trans_idx; 358 + u32 interval; 359 + 360 + char name[20]; 361 + 362 + unsigned direction:1; 363 + }; 364 + 365 + enum dwc3_phy { 366 + DWC3_PHY_UNKNOWN = 0, 367 + DWC3_PHY_USB3, 368 + DWC3_PHY_USB2, 369 + }; 370 + 371 + enum dwc3_ep0_state { 372 + EP0_UNCONNECTED = 0, 373 + EP0_IDLE, 374 + EP0_IN_DATA_PHASE, 375 + EP0_OUT_DATA_PHASE, 376 + EP0_IN_WAIT_GADGET, 377 + EP0_OUT_WAIT_GADGET, 378 + EP0_IN_WAIT_NRDY, 379 + EP0_OUT_WAIT_NRDY, 380 + EP0_IN_STATUS_PHASE, 381 + EP0_OUT_STATUS_PHASE, 382 + EP0_STALL, 383 + }; 384 + 385 + enum dwc3_link_state { 386 + /* In SuperSpeed */ 387 + DWC3_LINK_STATE_U0 = 0x00, /* in HS, means ON */ 388 + DWC3_LINK_STATE_U1 = 0x01, 389 + DWC3_LINK_STATE_U2 = 0x02, /* in HS, means SLEEP */ 390 + DWC3_LINK_STATE_U3 = 0x03, /* in HS, means SUSPEND */ 391 + DWC3_LINK_STATE_SS_DIS = 0x04, 392 + DWC3_LINK_STATE_RX_DET = 0x05, /* in HS, means Early Suspend */ 393 + DWC3_LINK_STATE_SS_INACT = 0x06, 394 + DWC3_LINK_STATE_POLL = 0x07, 395 + DWC3_LINK_STATE_RECOV = 0x08, 396 + DWC3_LINK_STATE_HRESET = 0x09, 397 + DWC3_LINK_STATE_CMPLY = 0x0a, 398 + DWC3_LINK_STATE_LPBK = 0x0b, 399 + DWC3_LINK_STATE_MASK = 0x0f, 400 + }; 401 + 402 + enum dwc3_device_state { 403 + DWC3_DEFAULT_STATE, 404 + DWC3_ADDRESS_STATE, 405 + DWC3_CONFIGURED_STATE, 406 + }; 407 + 408 + /** 409 + * struct dwc3_trb - transfer request block 410 + * @bpl: lower 32bit of the buffer 411 + * @bph: higher 32bit of the buffer 412 + * @length: buffer size (up to 16mb - 1) 413 + * @pcm1: packet count m1 414 + * @trbsts: trb status 415 + * 0 = ok 416 + * 1 = missed isoc 417 + * 2 = setup pending 418 + * @hwo: hardware owner of descriptor 419 + * @lst: last trb 420 + * @chn: chain buffers 421 + * @csp: continue on short packets (only supported on isoc eps) 422 + * @trbctl: trb control 423 + * 1 = normal 424 + * 2 = control-setup 425 + * 3 = control-status-2 426 + * 4 = control-status-3 427 + * 5 = control-data (first trb of data stage) 428 + * 6 = isochronous-first (first trb of service interval) 429 + * 7 = isochronous 430 + * 8 = link trb 431 + * others = reserved 432 + * @isp_imi: interrupt on short packet / interrupt on missed isoc 433 + * @ioc: interrupt on complete 434 + * @sid_sofn: Stream ID / SOF Number 435 + */ 436 + struct dwc3_trb { 437 + u64 bplh; 438 + 439 + union { 440 + struct { 441 + u32 length:24; 442 + u32 pcm1:2; 443 + u32 reserved27_26:2; 444 + u32 trbsts:4; 445 + #define DWC3_TRB_STS_OKAY 0 446 + #define DWC3_TRB_STS_MISSED_ISOC 1 447 + #define DWC3_TRB_STS_SETUP_PENDING 2 448 + }; 449 + u32 len_pcm; 450 + }; 451 + 452 + union { 453 + struct { 454 + u32 hwo:1; 455 + u32 lst:1; 456 + u32 chn:1; 457 + u32 csp:1; 458 + u32 trbctl:6; 459 + u32 isp_imi:1; 460 + u32 ioc:1; 461 + u32 reserved13_12:2; 462 + u32 sid_sofn:16; 463 + u32 reserved31_30:2; 464 + }; 465 + u32 control; 466 + }; 467 + } __packed; 468 + 469 + /** 470 + * struct dwc3_trb_hw - transfer request block (hw format) 471 + * @bpl: DW0-3 472 + * @bph: DW4-7 473 + * @size: DW8-B 474 + * @trl: DWC-F 475 + */ 476 + struct dwc3_trb_hw { 477 + __le32 bpl; 478 + __le32 bph; 479 + __le32 size; 480 + __le32 ctrl; 481 + } __packed; 482 + 483 + static inline void dwc3_trb_to_hw(struct dwc3_trb *nat, struct dwc3_trb_hw *hw) 484 + { 485 + hw->bpl = cpu_to_le32(lower_32_bits(nat->bplh)); 486 + hw->bph = cpu_to_le32(upper_32_bits(nat->bplh)); 487 + hw->size = cpu_to_le32p(&nat->len_pcm); 488 + /* HWO is written last */ 489 + hw->ctrl = cpu_to_le32p(&nat->control); 490 + } 491 + 492 + static inline void dwc3_trb_to_nat(struct dwc3_trb_hw *hw, struct dwc3_trb *nat) 493 + { 494 + u64 bplh; 495 + 496 + bplh = le32_to_cpup(&hw->bpl); 497 + bplh |= (u64) le32_to_cpup(&hw->bph) << 32; 498 + nat->bplh = bplh; 499 + 500 + nat->len_pcm = le32_to_cpup(&hw->size); 501 + nat->control = le32_to_cpup(&hw->ctrl); 502 + } 503 + 504 + /** 505 + * struct dwc3 - representation of our controller 506 + * ctrl_req: usb control request which is used for ep0 507 + * ep0_trb: trb which is used for the ctrl_req 508 + * setup_buf: used while precessing STD USB requests 509 + * ctrl_req_addr: dma address of ctrl_req 510 + * ep0_trb: dma address of ep0_trb 511 + * ep0_usb_req: dummy req used while handling STD USB requests 512 + * setup_buf_addr: dma address of setup_buf 513 + * @lock: for synchronizing 514 + * @dev: pointer to our struct device 515 + * @event_buffer_list: a list of event buffers 516 + * @gadget: device side representation of the peripheral controller 517 + * @gadget_driver: pointer to the gadget driver 518 + * @regs: base address for our registers 519 + * @regs_size: address space size 520 + * @irq: IRQ number 521 + * @revision: revision register contents 522 + * @is_selfpowered: true when we are selfpowered 523 + * @three_stage_setup: set if we perform a three phase setup 524 + * @ep0_status_pending: ep0 status response without a req is pending 525 + * @ep0state: state of endpoint zero 526 + * @link_state: link state 527 + * @speed: device speed (super, high, full, low) 528 + * @mem: points to start of memory which is used for this struct. 529 + * @root: debugfs root folder pointer 530 + */ 531 + struct dwc3 { 532 + struct usb_ctrlrequest *ctrl_req; 533 + struct dwc3_trb_hw *ep0_trb; 534 + u8 *setup_buf; 535 + dma_addr_t ctrl_req_addr; 536 + dma_addr_t ep0_trb_addr; 537 + dma_addr_t setup_buf_addr; 538 + struct usb_request ep0_usb_req; 539 + /* device lock */ 540 + spinlock_t lock; 541 + struct device *dev; 542 + 543 + struct dwc3_event_buffer *ev_buffs[DWC3_EVENT_BUFFERS_NUM]; 544 + struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM]; 545 + 546 + struct usb_gadget gadget; 547 + struct usb_gadget_driver *gadget_driver; 548 + 549 + void __iomem *regs; 550 + size_t regs_size; 551 + 552 + int irq; 553 + 554 + u32 revision; 555 + 556 + #define DWC3_REVISION_173A 0x5533173a 557 + #define DWC3_REVISION_175A 0x5533175a 558 + #define DWC3_REVISION_180A 0x5533180a 559 + #define DWC3_REVISION_183A 0x5533183a 560 + #define DWC3_REVISION_185A 0x5533185a 561 + #define DWC3_REVISION_188A 0x5533188a 562 + #define DWC3_REVISION_190A 0x5533190a 563 + 564 + unsigned is_selfpowered:1; 565 + unsigned three_stage_setup:1; 566 + unsigned ep0_status_pending:1; 567 + 568 + enum dwc3_ep0_state ep0state; 569 + enum dwc3_link_state link_state; 570 + enum dwc3_device_state dev_state; 571 + 572 + u8 speed; 573 + void *mem; 574 + 575 + struct dentry *root; 576 + }; 577 + 578 + /* -------------------------------------------------------------------------- */ 579 + 580 + #define DWC3_TRBSTS_OK 0 581 + #define DWC3_TRBSTS_MISSED_ISOC 1 582 + #define DWC3_TRBSTS_SETUP_PENDING 2 583 + 584 + #define DWC3_TRBCTL_NORMAL 1 585 + #define DWC3_TRBCTL_CONTROL_SETUP 2 586 + #define DWC3_TRBCTL_CONTROL_STATUS2 3 587 + #define DWC3_TRBCTL_CONTROL_STATUS3 4 588 + #define DWC3_TRBCTL_CONTROL_DATA 5 589 + #define DWC3_TRBCTL_ISOCHRONOUS_FIRST 6 590 + #define DWC3_TRBCTL_ISOCHRONOUS 7 591 + #define DWC3_TRBCTL_LINK_TRB 8 592 + 593 + /* -------------------------------------------------------------------------- */ 594 + 595 + struct dwc3_event_type { 596 + u32 is_devspec:1; 597 + u32 type:6; 598 + u32 reserved8_31:25; 599 + } __packed; 600 + 601 + #define DWC3_DEPEVT_XFERCOMPLETE 0x01 602 + #define DWC3_DEPEVT_XFERINPROGRESS 0x02 603 + #define DWC3_DEPEVT_XFERNOTREADY 0x03 604 + #define DWC3_DEPEVT_RXTXFIFOEVT 0x04 605 + #define DWC3_DEPEVT_STREAMEVT 0x06 606 + #define DWC3_DEPEVT_EPCMDCMPLT 0x07 607 + 608 + /** 609 + * struct dwc3_event_depvt - Device Endpoint Events 610 + * @one_bit: indicates this is an endpoint event (not used) 611 + * @endpoint_number: number of the endpoint 612 + * @endpoint_event: The event we have: 613 + * 0x00 - Reserved 614 + * 0x01 - XferComplete 615 + * 0x02 - XferInProgress 616 + * 0x03 - XferNotReady 617 + * 0x04 - RxTxFifoEvt (IN->Underrun, OUT->Overrun) 618 + * 0x05 - Reserved 619 + * 0x06 - StreamEvt 620 + * 0x07 - EPCmdCmplt 621 + * @reserved11_10: Reserved, don't use. 622 + * @status: Indicates the status of the event. Refer to databook for 623 + * more information. 624 + * @parameters: Parameters of the current event. Refer to databook for 625 + * more information. 626 + */ 627 + struct dwc3_event_depevt { 628 + u32 one_bit:1; 629 + u32 endpoint_number:5; 630 + u32 endpoint_event:4; 631 + u32 reserved11_10:2; 632 + u32 status:4; 633 + #define DEPEVT_STATUS_BUSERR (1 << 0) 634 + #define DEPEVT_STATUS_SHORT (1 << 1) 635 + #define DEPEVT_STATUS_IOC (1 << 2) 636 + #define DEPEVT_STATUS_LST (1 << 3) 637 + u32 parameters:16; 638 + } __packed; 639 + 640 + /** 641 + * struct dwc3_event_devt - Device Events 642 + * @one_bit: indicates this is a non-endpoint event (not used) 643 + * @device_event: indicates it's a device event. Should read as 0x00 644 + * @type: indicates the type of device event. 645 + * 0 - DisconnEvt 646 + * 1 - USBRst 647 + * 2 - ConnectDone 648 + * 3 - ULStChng 649 + * 4 - WkUpEvt 650 + * 5 - Reserved 651 + * 6 - EOPF 652 + * 7 - SOF 653 + * 8 - Reserved 654 + * 9 - ErrticErr 655 + * 10 - CmdCmplt 656 + * 11 - EvntOverflow 657 + * 12 - VndrDevTstRcved 658 + * @reserved15_12: Reserved, not used 659 + * @event_info: Information about this event 660 + * @reserved31_24: Reserved, not used 661 + */ 662 + struct dwc3_event_devt { 663 + u32 one_bit:1; 664 + u32 device_event:7; 665 + u32 type:4; 666 + u32 reserved15_12:4; 667 + u32 event_info:8; 668 + u32 reserved31_24:8; 669 + } __packed; 670 + 671 + /** 672 + * struct dwc3_event_gevt - Other Core Events 673 + * @one_bit: indicates this is a non-endpoint event (not used) 674 + * @device_event: indicates it's (0x03) Carkit or (0x04) I2C event. 675 + * @phy_port_number: self-explanatory 676 + * @reserved31_12: Reserved, not used. 677 + */ 678 + struct dwc3_event_gevt { 679 + u32 one_bit:1; 680 + u32 device_event:7; 681 + u32 phy_port_number:4; 682 + u32 reserved31_12:20; 683 + } __packed; 684 + 685 + /** 686 + * union dwc3_event - representation of Event Buffer contents 687 + * @raw: raw 32-bit event 688 + * @type: the type of the event 689 + * @depevt: Device Endpoint Event 690 + * @devt: Device Event 691 + * @gevt: Global Event 692 + */ 693 + union dwc3_event { 694 + u32 raw; 695 + struct dwc3_event_type type; 696 + struct dwc3_event_depevt depevt; 697 + struct dwc3_event_devt devt; 698 + struct dwc3_event_gevt gevt; 699 + }; 700 + 701 + /* 702 + * DWC3 Features to be used as Driver Data 703 + */ 704 + 705 + #define DWC3_HAS_PERIPHERAL BIT(0) 706 + #define DWC3_HAS_XHCI BIT(1) 707 + #define DWC3_HAS_OTG BIT(3) 708 + 709 + #endif /* __DRIVERS_USB_DWC3_CORE_H */
+51
drivers/usb/dwc3/debug.h
··· 1 + /** 2 + * debug.h - DesignWare USB3 DRD Controller Debug Header 3 + * 4 + * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com 5 + * All rights reserved. 6 + * 7 + * Authors: Felipe Balbi <balbi@ti.com>, 8 + * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 9 + * 10 + * Redistribution and use in source and binary forms, with or without 11 + * modification, are permitted provided that the following conditions 12 + * are met: 13 + * 1. Redistributions of source code must retain the above copyright 14 + * notice, this list of conditions, and the following disclaimer, 15 + * without modification. 16 + * 2. Redistributions in binary form must reproduce the above copyright 17 + * notice, this list of conditions and the following disclaimer in the 18 + * documentation and/or other materials provided with the distribution. 19 + * 3. The names of the above-listed copyright holders may not be used 20 + * to endorse or promote products derived from this software without 21 + * specific prior written permission. 22 + * 23 + * ALTERNATIVELY, this software may be distributed under the terms of the 24 + * GNU General Public License ("GPL") version 2, as published by the Free 25 + * Software Foundation. 26 + * 27 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 28 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 29 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 31 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 32 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 33 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 34 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 35 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 + */ 39 + 40 + #include "core.h" 41 + 42 + #ifdef CONFIG_DEBUG_FS 43 + extern int dwc3_debugfs_init(struct dwc3 *); 44 + extern void dwc3_debugfs_exit(struct dwc3 *); 45 + #else 46 + static inline int dwc3_debugfs_init(struct dwc3 *d) 47 + { return 0; } 48 + static inline void dwc3_debugfs_exit(struct dwc3 *d) 49 + { } 50 + #endif 51 +
+534
drivers/usb/dwc3/debugfs.c
··· 1 + /** 2 + * debugfs.c - DesignWare USB3 DRD Controller DebugFS file 3 + * 4 + * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com 5 + * All rights reserved. 6 + * 7 + * Authors: Felipe Balbi <balbi@ti.com>, 8 + * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 9 + * 10 + * Redistribution and use in source and binary forms, with or without 11 + * modification, are permitted provided that the following conditions 12 + * are met: 13 + * 1. Redistributions of source code must retain the above copyright 14 + * notice, this list of conditions, and the following disclaimer, 15 + * without modification. 16 + * 2. Redistributions in binary form must reproduce the above copyright 17 + * notice, this list of conditions and the following disclaimer in the 18 + * documentation and/or other materials provided with the distribution. 19 + * 3. The names of the above-listed copyright holders may not be used 20 + * to endorse or promote products derived from this software without 21 + * specific prior written permission. 22 + * 23 + * ALTERNATIVELY, this software may be distributed under the terms of the 24 + * GNU General Public License ("GPL") version 2, as published by the Free 25 + * Software Foundation. 26 + * 27 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 28 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 29 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 31 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 32 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 33 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 34 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 35 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 + */ 39 + 40 + #include <linux/kernel.h> 41 + #include <linux/slab.h> 42 + #include <linux/ptrace.h> 43 + #include <linux/types.h> 44 + #include <linux/spinlock.h> 45 + #include <linux/debugfs.h> 46 + #include <linux/seq_file.h> 47 + #include <linux/delay.h> 48 + 49 + #include <asm/uaccess.h> 50 + 51 + #include "core.h" 52 + #include "gadget.h" 53 + #include "io.h" 54 + 55 + struct dwc3_register { 56 + const char *name; 57 + u32 offset; 58 + }; 59 + 60 + #define dump_register(nm) \ 61 + { \ 62 + .name = __stringify(nm), \ 63 + .offset = DWC3_ ##nm, \ 64 + } 65 + 66 + static const struct dwc3_register dwc3_regs[] = { 67 + dump_register(GSBUSCFG0), 68 + dump_register(GSBUSCFG1), 69 + dump_register(GTXTHRCFG), 70 + dump_register(GRXTHRCFG), 71 + dump_register(GCTL), 72 + dump_register(GEVTEN), 73 + dump_register(GSTS), 74 + dump_register(GSNPSID), 75 + dump_register(GGPIO), 76 + dump_register(GUID), 77 + dump_register(GUCTL), 78 + dump_register(GBUSERRADDR0), 79 + dump_register(GBUSERRADDR1), 80 + dump_register(GPRTBIMAP0), 81 + dump_register(GPRTBIMAP1), 82 + dump_register(GHWPARAMS0), 83 + dump_register(GHWPARAMS1), 84 + dump_register(GHWPARAMS2), 85 + dump_register(GHWPARAMS3), 86 + dump_register(GHWPARAMS4), 87 + dump_register(GHWPARAMS5), 88 + dump_register(GHWPARAMS6), 89 + dump_register(GHWPARAMS7), 90 + dump_register(GDBGFIFOSPACE), 91 + dump_register(GDBGLTSSM), 92 + dump_register(GPRTBIMAP_HS0), 93 + dump_register(GPRTBIMAP_HS1), 94 + dump_register(GPRTBIMAP_FS0), 95 + dump_register(GPRTBIMAP_FS1), 96 + 97 + dump_register(GUSB2PHYCFG(0)), 98 + dump_register(GUSB2PHYCFG(1)), 99 + dump_register(GUSB2PHYCFG(2)), 100 + dump_register(GUSB2PHYCFG(3)), 101 + dump_register(GUSB2PHYCFG(4)), 102 + dump_register(GUSB2PHYCFG(5)), 103 + dump_register(GUSB2PHYCFG(6)), 104 + dump_register(GUSB2PHYCFG(7)), 105 + dump_register(GUSB2PHYCFG(8)), 106 + dump_register(GUSB2PHYCFG(9)), 107 + dump_register(GUSB2PHYCFG(10)), 108 + dump_register(GUSB2PHYCFG(11)), 109 + dump_register(GUSB2PHYCFG(12)), 110 + dump_register(GUSB2PHYCFG(13)), 111 + dump_register(GUSB2PHYCFG(14)), 112 + dump_register(GUSB2PHYCFG(15)), 113 + 114 + dump_register(GUSB2I2CCTL(0)), 115 + dump_register(GUSB2I2CCTL(1)), 116 + dump_register(GUSB2I2CCTL(2)), 117 + dump_register(GUSB2I2CCTL(3)), 118 + dump_register(GUSB2I2CCTL(4)), 119 + dump_register(GUSB2I2CCTL(5)), 120 + dump_register(GUSB2I2CCTL(6)), 121 + dump_register(GUSB2I2CCTL(7)), 122 + dump_register(GUSB2I2CCTL(8)), 123 + dump_register(GUSB2I2CCTL(9)), 124 + dump_register(GUSB2I2CCTL(10)), 125 + dump_register(GUSB2I2CCTL(11)), 126 + dump_register(GUSB2I2CCTL(12)), 127 + dump_register(GUSB2I2CCTL(13)), 128 + dump_register(GUSB2I2CCTL(14)), 129 + dump_register(GUSB2I2CCTL(15)), 130 + 131 + dump_register(GUSB2PHYACC(0)), 132 + dump_register(GUSB2PHYACC(1)), 133 + dump_register(GUSB2PHYACC(2)), 134 + dump_register(GUSB2PHYACC(3)), 135 + dump_register(GUSB2PHYACC(4)), 136 + dump_register(GUSB2PHYACC(5)), 137 + dump_register(GUSB2PHYACC(6)), 138 + dump_register(GUSB2PHYACC(7)), 139 + dump_register(GUSB2PHYACC(8)), 140 + dump_register(GUSB2PHYACC(9)), 141 + dump_register(GUSB2PHYACC(10)), 142 + dump_register(GUSB2PHYACC(11)), 143 + dump_register(GUSB2PHYACC(12)), 144 + dump_register(GUSB2PHYACC(13)), 145 + dump_register(GUSB2PHYACC(14)), 146 + dump_register(GUSB2PHYACC(15)), 147 + 148 + dump_register(GUSB3PIPECTL(0)), 149 + dump_register(GUSB3PIPECTL(1)), 150 + dump_register(GUSB3PIPECTL(2)), 151 + dump_register(GUSB3PIPECTL(3)), 152 + dump_register(GUSB3PIPECTL(4)), 153 + dump_register(GUSB3PIPECTL(5)), 154 + dump_register(GUSB3PIPECTL(6)), 155 + dump_register(GUSB3PIPECTL(7)), 156 + dump_register(GUSB3PIPECTL(8)), 157 + dump_register(GUSB3PIPECTL(9)), 158 + dump_register(GUSB3PIPECTL(10)), 159 + dump_register(GUSB3PIPECTL(11)), 160 + dump_register(GUSB3PIPECTL(12)), 161 + dump_register(GUSB3PIPECTL(13)), 162 + dump_register(GUSB3PIPECTL(14)), 163 + dump_register(GUSB3PIPECTL(15)), 164 + 165 + dump_register(GTXFIFOSIZ(0)), 166 + dump_register(GTXFIFOSIZ(1)), 167 + dump_register(GTXFIFOSIZ(2)), 168 + dump_register(GTXFIFOSIZ(3)), 169 + dump_register(GTXFIFOSIZ(4)), 170 + dump_register(GTXFIFOSIZ(5)), 171 + dump_register(GTXFIFOSIZ(6)), 172 + dump_register(GTXFIFOSIZ(7)), 173 + dump_register(GTXFIFOSIZ(8)), 174 + dump_register(GTXFIFOSIZ(9)), 175 + dump_register(GTXFIFOSIZ(10)), 176 + dump_register(GTXFIFOSIZ(11)), 177 + dump_register(GTXFIFOSIZ(12)), 178 + dump_register(GTXFIFOSIZ(13)), 179 + dump_register(GTXFIFOSIZ(14)), 180 + dump_register(GTXFIFOSIZ(15)), 181 + dump_register(GTXFIFOSIZ(16)), 182 + dump_register(GTXFIFOSIZ(17)), 183 + dump_register(GTXFIFOSIZ(18)), 184 + dump_register(GTXFIFOSIZ(19)), 185 + dump_register(GTXFIFOSIZ(20)), 186 + dump_register(GTXFIFOSIZ(21)), 187 + dump_register(GTXFIFOSIZ(22)), 188 + dump_register(GTXFIFOSIZ(23)), 189 + dump_register(GTXFIFOSIZ(24)), 190 + dump_register(GTXFIFOSIZ(25)), 191 + dump_register(GTXFIFOSIZ(26)), 192 + dump_register(GTXFIFOSIZ(27)), 193 + dump_register(GTXFIFOSIZ(28)), 194 + dump_register(GTXFIFOSIZ(29)), 195 + dump_register(GTXFIFOSIZ(30)), 196 + dump_register(GTXFIFOSIZ(31)), 197 + 198 + dump_register(GRXFIFOSIZ(0)), 199 + dump_register(GRXFIFOSIZ(1)), 200 + dump_register(GRXFIFOSIZ(2)), 201 + dump_register(GRXFIFOSIZ(3)), 202 + dump_register(GRXFIFOSIZ(4)), 203 + dump_register(GRXFIFOSIZ(5)), 204 + dump_register(GRXFIFOSIZ(6)), 205 + dump_register(GRXFIFOSIZ(7)), 206 + dump_register(GRXFIFOSIZ(8)), 207 + dump_register(GRXFIFOSIZ(9)), 208 + dump_register(GRXFIFOSIZ(10)), 209 + dump_register(GRXFIFOSIZ(11)), 210 + dump_register(GRXFIFOSIZ(12)), 211 + dump_register(GRXFIFOSIZ(13)), 212 + dump_register(GRXFIFOSIZ(14)), 213 + dump_register(GRXFIFOSIZ(15)), 214 + dump_register(GRXFIFOSIZ(16)), 215 + dump_register(GRXFIFOSIZ(17)), 216 + dump_register(GRXFIFOSIZ(18)), 217 + dump_register(GRXFIFOSIZ(19)), 218 + dump_register(GRXFIFOSIZ(20)), 219 + dump_register(GRXFIFOSIZ(21)), 220 + dump_register(GRXFIFOSIZ(22)), 221 + dump_register(GRXFIFOSIZ(23)), 222 + dump_register(GRXFIFOSIZ(24)), 223 + dump_register(GRXFIFOSIZ(25)), 224 + dump_register(GRXFIFOSIZ(26)), 225 + dump_register(GRXFIFOSIZ(27)), 226 + dump_register(GRXFIFOSIZ(28)), 227 + dump_register(GRXFIFOSIZ(29)), 228 + dump_register(GRXFIFOSIZ(30)), 229 + dump_register(GRXFIFOSIZ(31)), 230 + 231 + dump_register(GEVNTADRLO(0)), 232 + dump_register(GEVNTADRHI(0)), 233 + dump_register(GEVNTSIZ(0)), 234 + dump_register(GEVNTCOUNT(0)), 235 + 236 + dump_register(GHWPARAMS8), 237 + dump_register(DCFG), 238 + dump_register(DCTL), 239 + dump_register(DEVTEN), 240 + dump_register(DSTS), 241 + dump_register(DGCMDPAR), 242 + dump_register(DGCMD), 243 + dump_register(DALEPENA), 244 + 245 + dump_register(DEPCMDPAR2(0)), 246 + dump_register(DEPCMDPAR2(1)), 247 + dump_register(DEPCMDPAR2(2)), 248 + dump_register(DEPCMDPAR2(3)), 249 + dump_register(DEPCMDPAR2(4)), 250 + dump_register(DEPCMDPAR2(5)), 251 + dump_register(DEPCMDPAR2(6)), 252 + dump_register(DEPCMDPAR2(7)), 253 + dump_register(DEPCMDPAR2(8)), 254 + dump_register(DEPCMDPAR2(9)), 255 + dump_register(DEPCMDPAR2(10)), 256 + dump_register(DEPCMDPAR2(11)), 257 + dump_register(DEPCMDPAR2(12)), 258 + dump_register(DEPCMDPAR2(13)), 259 + dump_register(DEPCMDPAR2(14)), 260 + dump_register(DEPCMDPAR2(15)), 261 + dump_register(DEPCMDPAR2(16)), 262 + dump_register(DEPCMDPAR2(17)), 263 + dump_register(DEPCMDPAR2(18)), 264 + dump_register(DEPCMDPAR2(19)), 265 + dump_register(DEPCMDPAR2(20)), 266 + dump_register(DEPCMDPAR2(21)), 267 + dump_register(DEPCMDPAR2(22)), 268 + dump_register(DEPCMDPAR2(23)), 269 + dump_register(DEPCMDPAR2(24)), 270 + dump_register(DEPCMDPAR2(25)), 271 + dump_register(DEPCMDPAR2(26)), 272 + dump_register(DEPCMDPAR2(27)), 273 + dump_register(DEPCMDPAR2(28)), 274 + dump_register(DEPCMDPAR2(29)), 275 + dump_register(DEPCMDPAR2(30)), 276 + dump_register(DEPCMDPAR2(31)), 277 + 278 + dump_register(DEPCMDPAR1(0)), 279 + dump_register(DEPCMDPAR1(1)), 280 + dump_register(DEPCMDPAR1(2)), 281 + dump_register(DEPCMDPAR1(3)), 282 + dump_register(DEPCMDPAR1(4)), 283 + dump_register(DEPCMDPAR1(5)), 284 + dump_register(DEPCMDPAR1(6)), 285 + dump_register(DEPCMDPAR1(7)), 286 + dump_register(DEPCMDPAR1(8)), 287 + dump_register(DEPCMDPAR1(9)), 288 + dump_register(DEPCMDPAR1(10)), 289 + dump_register(DEPCMDPAR1(11)), 290 + dump_register(DEPCMDPAR1(12)), 291 + dump_register(DEPCMDPAR1(13)), 292 + dump_register(DEPCMDPAR1(14)), 293 + dump_register(DEPCMDPAR1(15)), 294 + dump_register(DEPCMDPAR1(16)), 295 + dump_register(DEPCMDPAR1(17)), 296 + dump_register(DEPCMDPAR1(18)), 297 + dump_register(DEPCMDPAR1(19)), 298 + dump_register(DEPCMDPAR1(20)), 299 + dump_register(DEPCMDPAR1(21)), 300 + dump_register(DEPCMDPAR1(22)), 301 + dump_register(DEPCMDPAR1(23)), 302 + dump_register(DEPCMDPAR1(24)), 303 + dump_register(DEPCMDPAR1(25)), 304 + dump_register(DEPCMDPAR1(26)), 305 + dump_register(DEPCMDPAR1(27)), 306 + dump_register(DEPCMDPAR1(28)), 307 + dump_register(DEPCMDPAR1(29)), 308 + dump_register(DEPCMDPAR1(30)), 309 + dump_register(DEPCMDPAR1(31)), 310 + 311 + dump_register(DEPCMDPAR0(0)), 312 + dump_register(DEPCMDPAR0(1)), 313 + dump_register(DEPCMDPAR0(2)), 314 + dump_register(DEPCMDPAR0(3)), 315 + dump_register(DEPCMDPAR0(4)), 316 + dump_register(DEPCMDPAR0(5)), 317 + dump_register(DEPCMDPAR0(6)), 318 + dump_register(DEPCMDPAR0(7)), 319 + dump_register(DEPCMDPAR0(8)), 320 + dump_register(DEPCMDPAR0(9)), 321 + dump_register(DEPCMDPAR0(10)), 322 + dump_register(DEPCMDPAR0(11)), 323 + dump_register(DEPCMDPAR0(12)), 324 + dump_register(DEPCMDPAR0(13)), 325 + dump_register(DEPCMDPAR0(14)), 326 + dump_register(DEPCMDPAR0(15)), 327 + dump_register(DEPCMDPAR0(16)), 328 + dump_register(DEPCMDPAR0(17)), 329 + dump_register(DEPCMDPAR0(18)), 330 + dump_register(DEPCMDPAR0(19)), 331 + dump_register(DEPCMDPAR0(20)), 332 + dump_register(DEPCMDPAR0(21)), 333 + dump_register(DEPCMDPAR0(22)), 334 + dump_register(DEPCMDPAR0(23)), 335 + dump_register(DEPCMDPAR0(24)), 336 + dump_register(DEPCMDPAR0(25)), 337 + dump_register(DEPCMDPAR0(26)), 338 + dump_register(DEPCMDPAR0(27)), 339 + dump_register(DEPCMDPAR0(28)), 340 + dump_register(DEPCMDPAR0(29)), 341 + dump_register(DEPCMDPAR0(30)), 342 + dump_register(DEPCMDPAR0(31)), 343 + 344 + dump_register(DEPCMD(0)), 345 + dump_register(DEPCMD(1)), 346 + dump_register(DEPCMD(2)), 347 + dump_register(DEPCMD(3)), 348 + dump_register(DEPCMD(4)), 349 + dump_register(DEPCMD(5)), 350 + dump_register(DEPCMD(6)), 351 + dump_register(DEPCMD(7)), 352 + dump_register(DEPCMD(8)), 353 + dump_register(DEPCMD(9)), 354 + dump_register(DEPCMD(10)), 355 + dump_register(DEPCMD(11)), 356 + dump_register(DEPCMD(12)), 357 + dump_register(DEPCMD(13)), 358 + dump_register(DEPCMD(14)), 359 + dump_register(DEPCMD(15)), 360 + dump_register(DEPCMD(16)), 361 + dump_register(DEPCMD(17)), 362 + dump_register(DEPCMD(18)), 363 + dump_register(DEPCMD(19)), 364 + dump_register(DEPCMD(20)), 365 + dump_register(DEPCMD(21)), 366 + dump_register(DEPCMD(22)), 367 + dump_register(DEPCMD(23)), 368 + dump_register(DEPCMD(24)), 369 + dump_register(DEPCMD(25)), 370 + dump_register(DEPCMD(26)), 371 + dump_register(DEPCMD(27)), 372 + dump_register(DEPCMD(28)), 373 + dump_register(DEPCMD(29)), 374 + dump_register(DEPCMD(30)), 375 + dump_register(DEPCMD(31)), 376 + 377 + dump_register(OCFG), 378 + dump_register(OCTL), 379 + dump_register(OEVTEN), 380 + dump_register(OSTS), 381 + }; 382 + 383 + static int dwc3_regdump_show(struct seq_file *s, void *unused) 384 + { 385 + struct dwc3 *dwc = s->private; 386 + int i; 387 + 388 + seq_printf(s, "DesignWare USB3 Core Register Dump\n"); 389 + 390 + for (i = 0; i < ARRAY_SIZE(dwc3_regs); i++) { 391 + seq_printf(s, "%-20s : %08x\n", dwc3_regs[i].name, 392 + dwc3_readl(dwc->regs, dwc3_regs[i].offset)); 393 + } 394 + 395 + return 0; 396 + } 397 + 398 + static int dwc3_regdump_open(struct inode *inode, struct file *file) 399 + { 400 + return single_open(file, dwc3_regdump_show, inode->i_private); 401 + } 402 + 403 + static const struct file_operations dwc3_regdump_fops = { 404 + .open = dwc3_regdump_open, 405 + .read = seq_read, 406 + .release = single_release, 407 + }; 408 + 409 + 410 + static int dwc3_send_testmode_cmd(struct dwc3 *dwc, int mode) 411 + { 412 + u32 timeout = 250; 413 + 414 + dwc3_writel(dwc->regs, DWC3_DGCMDPAR, mode); 415 + dwc3_writel(dwc->regs, DWC3_DGCMD, DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK | 416 + DWC3_DEPCMD_CMDACT); 417 + do { 418 + u32 reg; 419 + 420 + reg = dwc3_readl(dwc->regs, DWC3_DGCMD); 421 + if (!(reg & DWC3_DEPCMD_CMDACT)) 422 + return 0; 423 + timeout--; 424 + if (!timeout) 425 + return -ETIMEDOUT; 426 + mdelay(1); 427 + } while (1); 428 + } 429 + 430 + static struct dwc3_trb_hw trb_0 __aligned(16); 431 + static struct dwc3_trb_hw trb_1 __aligned(16); 432 + 433 + #define BUF_SIZE 4096 434 + static int dwc3_testmode_open(struct inode *inode, struct file *file) 435 + { 436 + struct dwc3 *dwc = inode->i_private; 437 + struct dwc3_gadget_ep_cmd_params par0; 438 + struct dwc3_gadget_ep_cmd_params par1; 439 + struct dwc3_trb trb; 440 + int ret; 441 + u8 *buf0; 442 + u8 *buf1; 443 + 444 + buf0 = kmalloc(BUF_SIZE, GFP_KERNEL); 445 + if (!buf0) 446 + return -ENOMEM; 447 + buf1 = kmalloc(BUF_SIZE, GFP_KERNEL); 448 + if (!buf1) 449 + return -ENOMEM; 450 + 451 + memset(buf0, 0xaa, BUF_SIZE); 452 + memset(buf1, 0x33, BUF_SIZE); 453 + 454 + memset(&trb, 0, sizeof(trb)); 455 + memset(&par0, 0, sizeof(par0)); 456 + memset(&par1, 0, sizeof(par1)); 457 + 458 + trb.lst = 1; 459 + trb.trbctl = DWC3_TRBCTL_NORMAL; 460 + trb.length = BUF_SIZE; 461 + trb.hwo = 1; 462 + 463 + trb.bplh = virt_to_phys(buf0); 464 + dwc3_trb_to_hw(&trb, &trb_0); 465 + 466 + trb.bplh = virt_to_phys(buf1); 467 + dwc3_trb_to_hw(&trb, &trb_1); 468 + 469 + par0.param0.depstrtxfer.transfer_desc_addr_high = 470 + upper_32_bits(virt_to_phys(&trb_0)); 471 + par0.param1.depstrtxfer.transfer_desc_addr_low = 472 + lower_32_bits(virt_to_phys(&trb_0)); 473 + 474 + par1.param0.depstrtxfer.transfer_desc_addr_high = 475 + upper_32_bits(virt_to_phys(&trb_1)); 476 + par1.param1.depstrtxfer.transfer_desc_addr_low = 477 + lower_32_bits(virt_to_phys(&trb_1)); 478 + 479 + dwc3_send_testmode_cmd(dwc, 1); 480 + 481 + ret = dwc3_send_gadget_ep_cmd(dwc, 0, DWC3_DEPCMD_STARTTRANSFER, &par0); 482 + ret = dwc3_send_gadget_ep_cmd(dwc, 1, DWC3_DEPCMD_STARTTRANSFER, &par1); 483 + 484 + dwc3_send_testmode_cmd(dwc, 0); 485 + return -EBUSY; 486 + } 487 + 488 + static const struct file_operations dwc3_testmode_fops = { 489 + .open = dwc3_testmode_open, 490 + .read = seq_read, 491 + .release = single_release, 492 + }; 493 + 494 + int __devinit dwc3_debugfs_init(struct dwc3 *dwc) 495 + { 496 + struct dentry *root; 497 + struct dentry *file; 498 + int ret; 499 + 500 + root = debugfs_create_dir(dev_name(dwc->dev), NULL); 501 + if (IS_ERR(root)){ 502 + ret = PTR_ERR(root); 503 + goto err0; 504 + } 505 + 506 + dwc->root = root; 507 + 508 + file = debugfs_create_file("regdump", S_IRUGO, root, dwc, 509 + &dwc3_regdump_fops); 510 + if (IS_ERR(file)) { 511 + ret = PTR_ERR(file); 512 + goto err1; 513 + } 514 + file = debugfs_create_file("testmode", S_IRUGO, root, dwc, 515 + &dwc3_testmode_fops); 516 + if (IS_ERR(file)) { 517 + ret = PTR_ERR(file); 518 + goto err1; 519 + } 520 + 521 + return 0; 522 + 523 + err1: 524 + debugfs_remove_recursive(root); 525 + 526 + err0: 527 + return ret; 528 + } 529 + 530 + void __devexit dwc3_debugfs_exit(struct dwc3 *dwc) 531 + { 532 + debugfs_remove_recursive(dwc->root); 533 + dwc->root = NULL; 534 + }
+410
drivers/usb/dwc3/dwc3-omap.c
··· 1 + /** 2 + * dwc3-omap.c - OMAP Specific Glue layer 3 + * 4 + * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com 5 + * All rights reserved. 6 + * 7 + * Authors: Felipe Balbi <balbi@ti.com>, 8 + * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 9 + * 10 + * Redistribution and use in source and binary forms, with or without 11 + * modification, are permitted provided that the following conditions 12 + * are met: 13 + * 1. Redistributions of source code must retain the above copyright 14 + * notice, this list of conditions, and the following disclaimer, 15 + * without modification. 16 + * 2. Redistributions in binary form must reproduce the above copyright 17 + * notice, this list of conditions and the following disclaimer in the 18 + * documentation and/or other materials provided with the distribution. 19 + * 3. The names of the above-listed copyright holders may not be used 20 + * to endorse or promote products derived from this software without 21 + * specific prior written permission. 22 + * 23 + * ALTERNATIVELY, this software may be distributed under the terms of the 24 + * GNU General Public License ("GPL") version 2, as published by the Free 25 + * Software Foundation. 26 + * 27 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 28 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 29 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 31 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 32 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 33 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 34 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 35 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 + */ 39 + 40 + #include <linux/kernel.h> 41 + #include <linux/slab.h> 42 + #include <linux/interrupt.h> 43 + #include <linux/spinlock.h> 44 + #include <linux/platform_device.h> 45 + #include <linux/dma-mapping.h> 46 + #include <linux/ioport.h> 47 + #include <linux/io.h> 48 + 49 + #include "io.h" 50 + 51 + /* 52 + * All these registers belong to OMAP's Wrapper around the 53 + * DesignWare USB3 Core. 54 + */ 55 + 56 + #define USBOTGSS_REVISION 0x0000 57 + #define USBOTGSS_SYSCONFIG 0x0010 58 + #define USBOTGSS_IRQ_EOI 0x0020 59 + #define USBOTGSS_IRQSTATUS_RAW_0 0x0024 60 + #define USBOTGSS_IRQSTATUS_0 0x0028 61 + #define USBOTGSS_IRQENABLE_SET_0 0x002c 62 + #define USBOTGSS_IRQENABLE_CLR_0 0x0030 63 + #define USBOTGSS_IRQSTATUS_RAW_1 0x0034 64 + #define USBOTGSS_IRQSTATUS_1 0x0038 65 + #define USBOTGSS_IRQENABLE_SET_1 0x003c 66 + #define USBOTGSS_IRQENABLE_CLR_1 0x0040 67 + #define USBOTGSS_UTMI_OTG_CTRL 0x0080 68 + #define USBOTGSS_UTMI_OTG_STATUS 0x0084 69 + #define USBOTGSS_MMRAM_OFFSET 0x0100 70 + #define USBOTGSS_FLADJ 0x0104 71 + #define USBOTGSS_DEBUG_CFG 0x0108 72 + #define USBOTGSS_DEBUG_DATA 0x010c 73 + 74 + /* SYSCONFIG REGISTER */ 75 + #define USBOTGSS_SYSCONFIG_DMADISABLE (1 << 16) 76 + #define USBOTGSS_SYSCONFIG_STANDBYMODE(x) ((x) << 4) 77 + #define USBOTGSS_SYSCONFIG_IDLEMODE(x) ((x) << 2) 78 + 79 + /* IRQ_EOI REGISTER */ 80 + #define USBOTGSS_IRQ_EOI_LINE_NUMBER (1 << 0) 81 + 82 + /* IRQS0 BITS */ 83 + #define USBOTGSS_IRQO_COREIRQ_ST (1 << 0) 84 + 85 + /* IRQ1 BITS */ 86 + #define USBOTGSS_IRQ1_DMADISABLECLR (1 << 17) 87 + #define USBOTGSS_IRQ1_OEVT (1 << 16) 88 + #define USBOTGSS_IRQ1_DRVVBUS_RISE (1 << 13) 89 + #define USBOTGSS_IRQ1_CHRGVBUS_RISE (1 << 12) 90 + #define USBOTGSS_IRQ1_DISCHRGVBUS_RISE (1 << 11) 91 + #define USBOTGSS_IRQ1_IDPULLUP_RISE (1 << 8) 92 + #define USBOTGSS_IRQ1_DRVVBUS_FALL (1 << 5) 93 + #define USBOTGSS_IRQ1_CHRGVBUS_FALL (1 << 4) 94 + #define USBOTGSS_IRQ1_DISCHRGVBUS_FALL (1 << 3) 95 + #define USBOTGSS_IRQ1_IDPULLUP_FALL (1 << 0) 96 + 97 + /* UTMI_OTG_CTRL REGISTER */ 98 + #define USBOTGSS_UTMI_OTG_CTRL_DRVVBUS (1 << 5) 99 + #define USBOTGSS_UTMI_OTG_CTRL_CHRGVBUS (1 << 4) 100 + #define USBOTGSS_UTMI_OTG_CTRL_DISCHRGVBUS (1 << 3) 101 + #define USBOTGSS_UTMI_OTG_CTRL_IDPULLUP (1 << 0) 102 + 103 + /* UTMI_OTG_STATUS REGISTER */ 104 + #define USBOTGSS_UTMI_OTG_STATUS_SW_MODE (1 << 31) 105 + #define USBOTGSS_UTMI_OTG_STATUS_POWERPRESENT (1 << 9) 106 + #define USBOTGSS_UTMI_OTG_STATUS_TXBITSTUFFENABLE (1 << 8) 107 + #define USBOTGSS_UTMI_OTG_STATUS_IDDIG (1 << 4) 108 + #define USBOTGSS_UTMI_OTG_STATUS_SESSEND (1 << 3) 109 + #define USBOTGSS_UTMI_OTG_STATUS_SESSVALID (1 << 2) 110 + #define USBOTGSS_UTMI_OTG_STATUS_VBUSVALID (1 << 1) 111 + 112 + struct dwc3_omap { 113 + /* device lock */ 114 + spinlock_t lock; 115 + 116 + struct platform_device *dwc3; 117 + struct device *dev; 118 + 119 + int irq; 120 + void __iomem *base; 121 + 122 + void *context; 123 + u32 resource_size; 124 + 125 + u32 dma_status:1; 126 + }; 127 + 128 + #ifdef CONFIG_PM 129 + static int dwc3_omap_suspend(struct device *dev) 130 + { 131 + struct dwc3_omap *omap = dev_get_drvdata(dev); 132 + 133 + memcpy_fromio(omap->context, omap->base, omap->resource_size); 134 + 135 + return 0; 136 + } 137 + 138 + static int dwc3_omap_resume(struct device *dev) 139 + { 140 + struct dwc3_omap *omap = dev_get_drvdata(dev); 141 + 142 + memcpy_toio(omap->base, omap->context, omap->resource_size); 143 + 144 + return 0; 145 + } 146 + 147 + static int dwc3_omap_idle(struct device *dev) 148 + { 149 + struct dwc3_omap *omap = dev_get_drvdata(dev); 150 + u32 reg; 151 + 152 + /* stop DMA Engine */ 153 + reg = dwc3_readl(omap->base, USBOTGSS_SYSCONFIG); 154 + reg &= ~(USBOTGSS_SYSCONFIG_DMADISABLE); 155 + dwc3_writel(omap->base, USBOTGSS_SYSCONFIG, reg); 156 + 157 + return 0; 158 + } 159 + 160 + static UNIVERSAL_DEV_PM_OPS(dwc3_omap_pm_ops, dwc3_omap_suspend, 161 + dwc3_omap_resume, dwc3_omap_idle); 162 + 163 + #define DEV_PM_OPS (&dwc3_omap_pm_ops) 164 + #else 165 + #define DEV_PM_OPS NULL 166 + #endif 167 + 168 + static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap) 169 + { 170 + struct dwc3_omap *omap = _omap; 171 + u32 reg; 172 + u32 ctrl; 173 + 174 + spin_lock(&omap->lock); 175 + 176 + reg = dwc3_readl(omap->base, USBOTGSS_IRQSTATUS_1); 177 + ctrl = dwc3_readl(omap->base, USBOTGSS_UTMI_OTG_CTRL); 178 + 179 + if (reg & USBOTGSS_IRQ1_DMADISABLECLR) { 180 + dev_dbg(omap->base, "DMA Disable was Cleared\n"); 181 + omap->dma_status = false; 182 + } 183 + 184 + if (reg & USBOTGSS_IRQ1_OEVT) 185 + dev_dbg(omap->base, "OTG Event\n"); 186 + 187 + if (reg & USBOTGSS_IRQ1_DRVVBUS_RISE) { 188 + dev_dbg(omap->base, "DRVVBUS Rise\n"); 189 + ctrl |= USBOTGSS_UTMI_OTG_CTRL_DRVVBUS; 190 + } 191 + 192 + if (reg & USBOTGSS_IRQ1_CHRGVBUS_RISE) { 193 + dev_dbg(omap->base, "CHRGVBUS Rise\n"); 194 + ctrl |= USBOTGSS_UTMI_OTG_CTRL_CHRGVBUS; 195 + } 196 + 197 + if (reg & USBOTGSS_IRQ1_DISCHRGVBUS_RISE) { 198 + dev_dbg(omap->base, "DISCHRGVBUS Rise\n"); 199 + ctrl |= USBOTGSS_UTMI_OTG_CTRL_DISCHRGVBUS; 200 + } 201 + 202 + if (reg & USBOTGSS_IRQ1_IDPULLUP_RISE) { 203 + dev_dbg(omap->base, "IDPULLUP Rise\n"); 204 + ctrl |= USBOTGSS_UTMI_OTG_CTRL_IDPULLUP; 205 + } 206 + 207 + if (reg & USBOTGSS_IRQ1_DRVVBUS_FALL) { 208 + dev_dbg(omap->base, "DRVVBUS Fall\n"); 209 + ctrl &= ~USBOTGSS_UTMI_OTG_CTRL_DRVVBUS; 210 + } 211 + 212 + if (reg & USBOTGSS_IRQ1_CHRGVBUS_FALL) { 213 + dev_dbg(omap->base, "CHRGVBUS Fall\n"); 214 + ctrl &= ~USBOTGSS_UTMI_OTG_CTRL_CHRGVBUS; 215 + } 216 + 217 + if (reg & USBOTGSS_IRQ1_DISCHRGVBUS_FALL) { 218 + dev_dbg(omap->base, "DISCHRGVBUS Fall\n"); 219 + ctrl &= ~USBOTGSS_UTMI_OTG_CTRL_DISCHRGVBUS; 220 + } 221 + 222 + if (reg & USBOTGSS_IRQ1_IDPULLUP_FALL) { 223 + dev_dbg(omap->base, "IDPULLUP Fall\n"); 224 + ctrl &= ~USBOTGSS_UTMI_OTG_CTRL_IDPULLUP; 225 + } 226 + 227 + dwc3_writel(omap->base, USBOTGSS_UTMI_OTG_CTRL, ctrl); 228 + 229 + spin_unlock(&omap->lock); 230 + 231 + return IRQ_HANDLED; 232 + } 233 + 234 + static int __devinit dwc3_omap_probe(struct platform_device *pdev) 235 + { 236 + struct platform_device *dwc3; 237 + struct dwc3_omap *omap; 238 + struct resource *res; 239 + 240 + int ret = -ENOMEM; 241 + int irq; 242 + 243 + u32 reg; 244 + 245 + void __iomem *base; 246 + void *context; 247 + 248 + omap = kzalloc(sizeof(*omap), GFP_KERNEL); 249 + if (!omap) { 250 + dev_err(&pdev->dev, "not enough memory\n"); 251 + goto err0; 252 + } 253 + 254 + platform_set_drvdata(pdev, omap); 255 + 256 + irq = platform_get_irq(pdev, 1); 257 + if (irq < 0) { 258 + dev_err(&pdev->dev, "missing IRQ resource\n"); 259 + ret = -EINVAL; 260 + goto err1; 261 + } 262 + 263 + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 264 + if (!res) { 265 + dev_err(&pdev->dev, "missing memory base resource\n"); 266 + ret = -EINVAL; 267 + goto err1; 268 + } 269 + 270 + base = ioremap_nocache(res->start, resource_size(res)); 271 + if (!base) { 272 + dev_err(&pdev->dev, "ioremap failed\n"); 273 + goto err1; 274 + } 275 + 276 + dwc3 = platform_device_alloc("dwc3-omap", -1); 277 + if (!dwc3) { 278 + dev_err(&pdev->dev, "couldn't allocate dwc3 device\n"); 279 + goto err2; 280 + } 281 + 282 + context = kzalloc(resource_size(res), GFP_KERNEL); 283 + if (!context) { 284 + dev_err(&pdev->dev, "couldn't allocate dwc3 context memory\n"); 285 + goto err3; 286 + } 287 + 288 + spin_lock_init(&omap->lock); 289 + dma_set_coherent_mask(&dwc3->dev, pdev->dev.coherent_dma_mask); 290 + 291 + dwc3->dev.parent = &pdev->dev; 292 + dwc3->dev.dma_mask = pdev->dev.dma_mask; 293 + dwc3->dev.dma_parms = pdev->dev.dma_parms; 294 + omap->resource_size = resource_size(res); 295 + omap->context = context; 296 + omap->dev = &pdev->dev; 297 + omap->irq = irq; 298 + omap->base = base; 299 + omap->dwc3 = dwc3; 300 + 301 + /* check the DMA Status */ 302 + reg = dwc3_readl(omap->base, USBOTGSS_SYSCONFIG); 303 + omap->dma_status = !!(reg & USBOTGSS_SYSCONFIG_DMADISABLE); 304 + 305 + ret = request_irq(omap->irq, dwc3_omap_interrupt, 0, 306 + "dwc3-wrapper", omap); 307 + if (ret) { 308 + dev_err(&pdev->dev, "failed to request IRQ #%d --> %d\n", 309 + omap->irq, ret); 310 + goto err4; 311 + } 312 + 313 + /* enable all IRQs */ 314 + dwc3_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, 0x01); 315 + 316 + reg = (USBOTGSS_IRQ1_DMADISABLECLR | 317 + USBOTGSS_IRQ1_OEVT | 318 + USBOTGSS_IRQ1_DRVVBUS_RISE | 319 + USBOTGSS_IRQ1_CHRGVBUS_RISE | 320 + USBOTGSS_IRQ1_DISCHRGVBUS_RISE | 321 + USBOTGSS_IRQ1_IDPULLUP_RISE | 322 + USBOTGSS_IRQ1_DRVVBUS_FALL | 323 + USBOTGSS_IRQ1_CHRGVBUS_FALL | 324 + USBOTGSS_IRQ1_DISCHRGVBUS_FALL | 325 + USBOTGSS_IRQ1_IDPULLUP_FALL); 326 + 327 + dwc3_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg); 328 + 329 + ret = platform_device_add_resources(dwc3, pdev->resource, 330 + pdev->num_resources); 331 + if (ret) { 332 + dev_err(&pdev->dev, "couldn't add resources to dwc3 device\n"); 333 + goto err5; 334 + } 335 + 336 + ret = platform_device_add(dwc3); 337 + if (ret) { 338 + dev_err(&pdev->dev, "failed to register dwc3 device\n"); 339 + goto err5; 340 + } 341 + 342 + return 0; 343 + 344 + err5: 345 + free_irq(omap->irq, omap); 346 + 347 + err4: 348 + kfree(omap->context); 349 + 350 + err3: 351 + platform_device_put(dwc3); 352 + 353 + err2: 354 + iounmap(base); 355 + 356 + err1: 357 + kfree(omap); 358 + 359 + err0: 360 + return ret; 361 + } 362 + 363 + static int __devexit dwc3_omap_remove(struct platform_device *pdev) 364 + { 365 + struct dwc3_omap *omap = platform_get_drvdata(pdev); 366 + 367 + platform_device_unregister(omap->dwc3); 368 + 369 + free_irq(omap->irq, omap); 370 + iounmap(omap->base); 371 + 372 + kfree(omap->context); 373 + kfree(omap); 374 + 375 + return 0; 376 + } 377 + 378 + static const struct of_device_id of_dwc3_matach[] = { 379 + { 380 + "ti,dwc3", 381 + }, 382 + { }, 383 + }; 384 + MODULE_DEVICE_TABLE(of, of_dwc3_matach); 385 + 386 + static struct platform_driver dwc3_omap_driver = { 387 + .probe = dwc3_omap_probe, 388 + .remove = __devexit_p(dwc3_omap_remove), 389 + .driver = { 390 + .name = "omap-dwc3", 391 + .pm = DEV_PM_OPS, 392 + .of_match_table = of_dwc3_matach, 393 + }, 394 + }; 395 + 396 + MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); 397 + MODULE_LICENSE("Dual BSD/GPL"); 398 + MODULE_DESCRIPTION("DesignWare USB3 OMAP Glue Layer"); 399 + 400 + static int __devinit dwc3_omap_init(void) 401 + { 402 + return platform_driver_register(&dwc3_omap_driver); 403 + } 404 + module_init(dwc3_omap_init); 405 + 406 + static void __exit dwc3_omap_exit(void) 407 + { 408 + platform_driver_unregister(&dwc3_omap_driver); 409 + } 410 + module_exit(dwc3_omap_exit);
+220
drivers/usb/dwc3/dwc3-pci.c
··· 1 + /** 2 + * dwc3-pci.c - PCI Specific glue layer 3 + * 4 + * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com 5 + * All rights reserved. 6 + * 7 + * Authors: Felipe Balbi <balbi@ti.com>, 8 + * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 9 + * 10 + * Redistribution and use in source and binary forms, with or without 11 + * modification, are permitted provided that the following conditions 12 + * are met: 13 + * 1. Redistributions of source code must retain the above copyright 14 + * notice, this list of conditions, and the following disclaimer, 15 + * without modification. 16 + * 2. Redistributions in binary form must reproduce the above copyright 17 + * notice, this list of conditions and the following disclaimer in the 18 + * documentation and/or other materials provided with the distribution. 19 + * 3. The names of the above-listed copyright holders may not be used 20 + * to endorse or promote products derived from this software without 21 + * specific prior written permission. 22 + * 23 + * ALTERNATIVELY, this software may be distributed under the terms of the 24 + * GNU General Public License ("GPL") version 2, as published by the Free 25 + * Software Foundation. 26 + * 27 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 28 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 29 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 31 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 32 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 33 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 34 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 35 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 + */ 39 + 40 + #include <linux/kernel.h> 41 + #include <linux/module.h> 42 + #include <linux/slab.h> 43 + #include <linux/pci.h> 44 + #include <linux/platform_device.h> 45 + 46 + /* FIXME define these in <linux/pci_ids.h> */ 47 + #define PCI_VENDOR_ID_SYNOPSYS 0x16c3 48 + #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd 49 + 50 + #define DWC3_PCI_DEVS_POSSIBLE 32 51 + 52 + struct dwc3_pci { 53 + struct device *dev; 54 + struct platform_device *dwc3; 55 + }; 56 + 57 + static DECLARE_BITMAP(dwc3_pci_devs, DWC3_PCI_DEVS_POSSIBLE); 58 + 59 + static int dwc3_pci_get_device_id(struct dwc3_pci *glue) 60 + { 61 + int id; 62 + 63 + again: 64 + id = find_first_zero_bit(dwc3_pci_devs, DWC3_PCI_DEVS_POSSIBLE); 65 + if (id < DWC3_PCI_DEVS_POSSIBLE) { 66 + int old; 67 + 68 + old = test_and_set_bit(id, dwc3_pci_devs); 69 + if (old) 70 + goto again; 71 + } else { 72 + dev_err(glue->dev, "no space for new device\n"); 73 + id = -ENOMEM; 74 + } 75 + 76 + return 0; 77 + } 78 + 79 + static void dwc3_pci_put_device_id(struct dwc3_pci *glue, int id) 80 + { 81 + int ret; 82 + 83 + if (id < 0) 84 + return; 85 + 86 + ret = test_bit(id, dwc3_pci_devs); 87 + WARN(!ret, "Device: %s\nID %d not in use\n", 88 + dev_driver_string(glue->dev), id); 89 + clear_bit(id, dwc3_pci_devs); 90 + } 91 + 92 + static int __devinit dwc3_pci_probe(struct pci_dev *pci, 93 + const struct pci_device_id *id) 94 + { 95 + struct resource res[2]; 96 + struct platform_device *dwc3; 97 + struct dwc3_pci *glue; 98 + int ret = -ENOMEM; 99 + int devid; 100 + 101 + glue = kzalloc(sizeof(*glue), GFP_KERNEL); 102 + if (!glue) { 103 + dev_err(&pci->dev, "not enough memory\n"); 104 + goto err0; 105 + } 106 + 107 + glue->dev = &pci->dev; 108 + 109 + ret = pci_enable_device(pci); 110 + if (ret) { 111 + dev_err(&pci->dev, "failed to enable pci device\n"); 112 + goto err1; 113 + } 114 + 115 + pci_set_power_state(pci, PCI_D0); 116 + pci_set_master(pci); 117 + 118 + devid = dwc3_pci_get_device_id(glue); 119 + if (devid < 0) 120 + goto err2; 121 + 122 + dwc3 = platform_device_alloc("dwc3-pci", devid); 123 + if (!dwc3) { 124 + dev_err(&pci->dev, "couldn't allocate dwc3 device\n"); 125 + goto err3; 126 + } 127 + 128 + memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res)); 129 + 130 + res[0].start = pci_resource_start(pci, 0); 131 + res[0].end = pci_resource_end(pci, 0); 132 + res[0].name = "dwc_usb3"; 133 + res[0].flags = IORESOURCE_MEM; 134 + 135 + res[1].start = pci->irq; 136 + res[1].name = "dwc_usb3"; 137 + res[1].flags = IORESOURCE_IRQ; 138 + 139 + ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res)); 140 + if (ret) { 141 + dev_err(&pci->dev, "couldn't add resources to dwc3 device\n"); 142 + goto err4; 143 + } 144 + 145 + pci_set_drvdata(pci, glue); 146 + 147 + dma_set_coherent_mask(&dwc3->dev, pci->dev.coherent_dma_mask); 148 + 149 + dwc3->dev.dma_mask = pci->dev.dma_mask; 150 + dwc3->dev.dma_parms = pci->dev.dma_parms; 151 + dwc3->dev.parent = &pci->dev; 152 + glue->dwc3 = dwc3; 153 + 154 + ret = platform_device_add(dwc3); 155 + if (ret) { 156 + dev_err(&pci->dev, "failed to register dwc3 device\n"); 157 + goto err4; 158 + } 159 + 160 + return 0; 161 + 162 + err4: 163 + pci_set_drvdata(pci, NULL); 164 + platform_device_put(dwc3); 165 + 166 + err3: 167 + dwc3_pci_put_device_id(glue, devid); 168 + 169 + err2: 170 + pci_disable_device(pci); 171 + 172 + err1: 173 + kfree(pci); 174 + 175 + err0: 176 + return ret; 177 + } 178 + 179 + static void __devexit dwc3_pci_remove(struct pci_dev *pci) 180 + { 181 + struct dwc3_pci *glue = pci_get_drvdata(pci); 182 + 183 + dwc3_pci_put_device_id(glue, glue->dwc3->id); 184 + platform_device_unregister(glue->dwc3); 185 + pci_set_drvdata(pci, NULL); 186 + pci_disable_device(pci); 187 + kfree(glue); 188 + } 189 + 190 + static DEFINE_PCI_DEVICE_TABLE(dwc3_pci_id_table) = { 191 + { 192 + PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 193 + PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3), 194 + }, 195 + { } /* Terminating Entry */ 196 + }; 197 + MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table); 198 + 199 + static struct pci_driver dwc3_pci_driver = { 200 + .name = "pci-dwc3", 201 + .id_table = dwc3_pci_id_table, 202 + .probe = dwc3_pci_probe, 203 + .remove = __devexit_p(dwc3_pci_remove), 204 + }; 205 + 206 + MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); 207 + MODULE_LICENSE("Dual BSD/GPL"); 208 + MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer"); 209 + 210 + static int __devinit dwc3_pci_init(void) 211 + { 212 + return pci_register_driver(&dwc3_pci_driver); 213 + } 214 + module_init(dwc3_pci_init); 215 + 216 + static void __exit dwc3_pci_exit(void) 217 + { 218 + pci_unregister_driver(&dwc3_pci_driver); 219 + } 220 + module_exit(dwc3_pci_exit);
+782
drivers/usb/dwc3/ep0.c
··· 1 + /** 2 + * ep0.c - DesignWare USB3 DRD Controller Endpoint 0 Handling 3 + * 4 + * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com 5 + * All rights reserved. 6 + * 7 + * Authors: Felipe Balbi <balbi@ti.com>, 8 + * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 9 + * 10 + * Redistribution and use in source and binary forms, with or without 11 + * modification, are permitted provided that the following conditions 12 + * are met: 13 + * 1. Redistributions of source code must retain the above copyright 14 + * notice, this list of conditions, and the following disclaimer, 15 + * without modification. 16 + * 2. Redistributions in binary form must reproduce the above copyright 17 + * notice, this list of conditions and the following disclaimer in the 18 + * documentation and/or other materials provided with the distribution. 19 + * 3. The names of the above-listed copyright holders may not be used 20 + * to endorse or promote products derived from this software without 21 + * specific prior written permission. 22 + * 23 + * ALTERNATIVELY, this software may be distributed under the terms of the 24 + * GNU General Public License ("GPL") version 2, as published by the Free 25 + * Software Foundation. 26 + * 27 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 28 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 29 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 31 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 32 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 33 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 34 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 35 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 + */ 39 + 40 + #include <linux/kernel.h> 41 + #include <linux/slab.h> 42 + #include <linux/spinlock.h> 43 + #include <linux/platform_device.h> 44 + #include <linux/pm_runtime.h> 45 + #include <linux/interrupt.h> 46 + #include <linux/io.h> 47 + #include <linux/list.h> 48 + #include <linux/dma-mapping.h> 49 + 50 + #include <linux/usb/ch9.h> 51 + #include <linux/usb/gadget.h> 52 + 53 + #include "core.h" 54 + #include "gadget.h" 55 + #include "io.h" 56 + 57 + static void dwc3_ep0_inspect_setup(struct dwc3 *dwc, 58 + const struct dwc3_event_depevt *event); 59 + 60 + static const char *dwc3_ep0_state_string(enum dwc3_ep0_state state) 61 + { 62 + switch (state) { 63 + case EP0_UNCONNECTED: 64 + return "Unconnected"; 65 + case EP0_IDLE: 66 + return "Idle"; 67 + case EP0_IN_DATA_PHASE: 68 + return "IN Data Phase"; 69 + case EP0_OUT_DATA_PHASE: 70 + return "OUT Data Phase"; 71 + case EP0_IN_WAIT_GADGET: 72 + return "IN Wait Gadget"; 73 + case EP0_OUT_WAIT_GADGET: 74 + return "OUT Wait Gadget"; 75 + case EP0_IN_WAIT_NRDY: 76 + return "IN Wait NRDY"; 77 + case EP0_OUT_WAIT_NRDY: 78 + return "OUT Wait NRDY"; 79 + case EP0_IN_STATUS_PHASE: 80 + return "IN Status Phase"; 81 + case EP0_OUT_STATUS_PHASE: 82 + return "OUT Status Phase"; 83 + case EP0_STALL: 84 + return "Stall"; 85 + default: 86 + return "UNKNOWN"; 87 + } 88 + } 89 + 90 + static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma, 91 + u32 len) 92 + { 93 + struct dwc3_gadget_ep_cmd_params params; 94 + struct dwc3_trb_hw *trb_hw; 95 + struct dwc3_trb trb; 96 + struct dwc3_ep *dep; 97 + 98 + int ret; 99 + 100 + dep = dwc->eps[epnum]; 101 + 102 + trb_hw = dwc->ep0_trb; 103 + memset(&trb, 0, sizeof(trb)); 104 + 105 + switch (dwc->ep0state) { 106 + case EP0_IDLE: 107 + trb.trbctl = DWC3_TRBCTL_CONTROL_SETUP; 108 + break; 109 + 110 + case EP0_IN_WAIT_NRDY: 111 + case EP0_OUT_WAIT_NRDY: 112 + case EP0_IN_STATUS_PHASE: 113 + case EP0_OUT_STATUS_PHASE: 114 + if (dwc->three_stage_setup) 115 + trb.trbctl = DWC3_TRBCTL_CONTROL_STATUS3; 116 + else 117 + trb.trbctl = DWC3_TRBCTL_CONTROL_STATUS2; 118 + 119 + if (dwc->ep0state == EP0_IN_WAIT_NRDY) 120 + dwc->ep0state = EP0_IN_STATUS_PHASE; 121 + else if (dwc->ep0state == EP0_OUT_WAIT_NRDY) 122 + dwc->ep0state = EP0_OUT_STATUS_PHASE; 123 + break; 124 + 125 + case EP0_IN_WAIT_GADGET: 126 + dwc->ep0state = EP0_IN_WAIT_NRDY; 127 + return 0; 128 + break; 129 + 130 + case EP0_OUT_WAIT_GADGET: 131 + dwc->ep0state = EP0_OUT_WAIT_NRDY; 132 + return 0; 133 + 134 + break; 135 + 136 + case EP0_IN_DATA_PHASE: 137 + case EP0_OUT_DATA_PHASE: 138 + trb.trbctl = DWC3_TRBCTL_CONTROL_DATA; 139 + break; 140 + 141 + default: 142 + dev_err(dwc->dev, "%s() can't in state %d\n", __func__, 143 + dwc->ep0state); 144 + return -EINVAL; 145 + } 146 + 147 + trb.bplh = buf_dma; 148 + trb.length = len; 149 + 150 + trb.hwo = 1; 151 + trb.lst = 1; 152 + trb.ioc = 1; 153 + trb.isp_imi = 1; 154 + 155 + dwc3_trb_to_hw(&trb, trb_hw); 156 + 157 + memset(&params, 0, sizeof(params)); 158 + params.param0.depstrtxfer.transfer_desc_addr_high = 159 + upper_32_bits(dwc->ep0_trb_addr); 160 + params.param1.depstrtxfer.transfer_desc_addr_low = 161 + lower_32_bits(dwc->ep0_trb_addr); 162 + 163 + ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, 164 + DWC3_DEPCMD_STARTTRANSFER, &params); 165 + if (ret < 0) { 166 + dev_dbg(dwc->dev, "failed to send STARTTRANSFER command\n"); 167 + return ret; 168 + } 169 + 170 + dep->res_trans_idx = dwc3_gadget_ep_get_transfer_index(dwc, 171 + dep->number); 172 + 173 + return 0; 174 + } 175 + 176 + static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep, 177 + struct dwc3_request *req) 178 + { 179 + struct dwc3 *dwc = dep->dwc; 180 + int ret; 181 + 182 + req->request.actual = 0; 183 + req->request.status = -EINPROGRESS; 184 + req->direction = dep->direction; 185 + req->epnum = dep->number; 186 + 187 + list_add_tail(&req->list, &dep->request_list); 188 + dwc3_map_buffer_to_dma(req); 189 + 190 + ret = dwc3_ep0_start_trans(dwc, dep->number, req->request.dma, 191 + req->request.length); 192 + if (ret < 0) { 193 + list_del(&req->list); 194 + dwc3_unmap_buffer_from_dma(req); 195 + } 196 + 197 + return ret; 198 + } 199 + 200 + int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request, 201 + gfp_t gfp_flags) 202 + { 203 + struct dwc3_request *req = to_dwc3_request(request); 204 + struct dwc3_ep *dep = to_dwc3_ep(ep); 205 + struct dwc3 *dwc = dep->dwc; 206 + 207 + unsigned long flags; 208 + 209 + int ret; 210 + 211 + switch (dwc->ep0state) { 212 + case EP0_IN_DATA_PHASE: 213 + case EP0_IN_WAIT_GADGET: 214 + case EP0_IN_WAIT_NRDY: 215 + case EP0_IN_STATUS_PHASE: 216 + dep = dwc->eps[1]; 217 + break; 218 + 219 + case EP0_OUT_DATA_PHASE: 220 + case EP0_OUT_WAIT_GADGET: 221 + case EP0_OUT_WAIT_NRDY: 222 + case EP0_OUT_STATUS_PHASE: 223 + dep = dwc->eps[0]; 224 + break; 225 + default: 226 + return -EINVAL; 227 + } 228 + 229 + spin_lock_irqsave(&dwc->lock, flags); 230 + if (!dep->desc) { 231 + dev_dbg(dwc->dev, "trying to queue request %p to disabled %s\n", 232 + request, dep->name); 233 + ret = -ESHUTDOWN; 234 + goto out; 235 + } 236 + 237 + /* we share one TRB for ep0/1 */ 238 + if (!list_empty(&dwc->eps[0]->request_list) || 239 + !list_empty(&dwc->eps[1]->request_list) || 240 + dwc->ep0_status_pending) { 241 + ret = -EBUSY; 242 + goto out; 243 + } 244 + 245 + dev_vdbg(dwc->dev, "queueing request %p to %s length %d, state '%s'\n", 246 + request, dep->name, request->length, 247 + dwc3_ep0_state_string(dwc->ep0state)); 248 + 249 + ret = __dwc3_gadget_ep0_queue(dep, req); 250 + 251 + out: 252 + spin_unlock_irqrestore(&dwc->lock, flags); 253 + 254 + return ret; 255 + } 256 + 257 + static void dwc3_ep0_stall_and_restart(struct dwc3 *dwc) 258 + { 259 + /* stall is always issued on EP0 */ 260 + __dwc3_gadget_ep_set_halt(dwc->eps[0], 1); 261 + dwc->eps[0]->flags &= ~DWC3_EP_STALL; 262 + dwc->ep0state = EP0_IDLE; 263 + dwc3_ep0_out_start(dwc); 264 + } 265 + 266 + void dwc3_ep0_out_start(struct dwc3 *dwc) 267 + { 268 + struct dwc3_ep *dep; 269 + int ret; 270 + 271 + dep = dwc->eps[0]; 272 + 273 + ret = dwc3_ep0_start_trans(dwc, 0, dwc->ctrl_req_addr, 8); 274 + WARN_ON(ret < 0); 275 + } 276 + 277 + /* 278 + * Send a zero length packet for the status phase of the control transfer 279 + */ 280 + static void dwc3_ep0_do_setup_status(struct dwc3 *dwc, 281 + const struct dwc3_event_depevt *event) 282 + { 283 + struct dwc3_ep *dep; 284 + int ret; 285 + u32 epnum; 286 + 287 + epnum = event->endpoint_number; 288 + dep = dwc->eps[epnum]; 289 + 290 + if (epnum) 291 + dwc->ep0state = EP0_IN_STATUS_PHASE; 292 + else 293 + dwc->ep0state = EP0_OUT_STATUS_PHASE; 294 + 295 + /* 296 + * Not sure Why I need a buffer for a zero transfer. Maybe the 297 + * HW reacts strange on a NULL pointer 298 + */ 299 + ret = dwc3_ep0_start_trans(dwc, epnum, dwc->ctrl_req_addr, 0); 300 + if (ret) { 301 + dev_dbg(dwc->dev, "failed to start transfer, stalling\n"); 302 + dwc3_ep0_stall_and_restart(dwc); 303 + } 304 + } 305 + 306 + static struct dwc3_ep *dwc3_wIndex_to_dep(struct dwc3 *dwc, __le16 wIndex_le) 307 + { 308 + struct dwc3_ep *dep; 309 + u32 windex = le16_to_cpu(wIndex_le); 310 + u32 epnum; 311 + 312 + epnum = (windex & USB_ENDPOINT_NUMBER_MASK) << 1; 313 + if ((windex & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) 314 + epnum |= 1; 315 + 316 + dep = dwc->eps[epnum]; 317 + if (dep->flags & DWC3_EP_ENABLED) 318 + return dep; 319 + 320 + return NULL; 321 + } 322 + 323 + static void dwc3_ep0_send_status_response(struct dwc3 *dwc) 324 + { 325 + u32 epnum; 326 + 327 + if (dwc->ep0state == EP0_IN_DATA_PHASE) 328 + epnum = 1; 329 + else 330 + epnum = 0; 331 + 332 + dwc3_ep0_start_trans(dwc, epnum, dwc->ctrl_req_addr, 333 + dwc->ep0_usb_req.length); 334 + dwc->ep0_status_pending = 1; 335 + } 336 + 337 + /* 338 + * ch 9.4.5 339 + */ 340 + static int dwc3_ep0_handle_status(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 341 + { 342 + struct dwc3_ep *dep; 343 + u32 recip; 344 + u16 usb_status = 0; 345 + __le16 *response_pkt; 346 + 347 + recip = ctrl->bRequestType & USB_RECIP_MASK; 348 + switch (recip) { 349 + case USB_RECIP_DEVICE: 350 + /* 351 + * We are self-powered. U1/U2/LTM will be set later 352 + * once we handle this states. RemoteWakeup is 0 on SS 353 + */ 354 + usb_status |= dwc->is_selfpowered << USB_DEVICE_SELF_POWERED; 355 + break; 356 + 357 + case USB_RECIP_INTERFACE: 358 + /* 359 + * Function Remote Wake Capable D0 360 + * Function Remote Wakeup D1 361 + */ 362 + break; 363 + 364 + case USB_RECIP_ENDPOINT: 365 + dep = dwc3_wIndex_to_dep(dwc, ctrl->wIndex); 366 + if (!dep) 367 + return -EINVAL; 368 + 369 + if (dep->flags & DWC3_EP_STALL) 370 + usb_status = 1 << USB_ENDPOINT_HALT; 371 + break; 372 + default: 373 + return -EINVAL; 374 + }; 375 + 376 + response_pkt = (__le16 *) dwc->setup_buf; 377 + *response_pkt = cpu_to_le16(usb_status); 378 + dwc->ep0_usb_req.length = sizeof(*response_pkt); 379 + dwc3_ep0_send_status_response(dwc); 380 + 381 + return 0; 382 + } 383 + 384 + static int dwc3_ep0_handle_feature(struct dwc3 *dwc, 385 + struct usb_ctrlrequest *ctrl, int set) 386 + { 387 + struct dwc3_ep *dep; 388 + u32 recip; 389 + u32 wValue; 390 + u32 wIndex; 391 + u32 reg; 392 + int ret; 393 + u32 mode; 394 + 395 + wValue = le16_to_cpu(ctrl->wValue); 396 + wIndex = le16_to_cpu(ctrl->wIndex); 397 + recip = ctrl->bRequestType & USB_RECIP_MASK; 398 + switch (recip) { 399 + case USB_RECIP_DEVICE: 400 + 401 + /* 402 + * 9.4.1 says only only for SS, in AddressState only for 403 + * default control pipe 404 + */ 405 + switch (wValue) { 406 + case USB_DEVICE_U1_ENABLE: 407 + case USB_DEVICE_U2_ENABLE: 408 + case USB_DEVICE_LTM_ENABLE: 409 + if (dwc->dev_state != DWC3_CONFIGURED_STATE) 410 + return -EINVAL; 411 + if (dwc->speed != DWC3_DSTS_SUPERSPEED) 412 + return -EINVAL; 413 + } 414 + 415 + /* XXX add U[12] & LTM */ 416 + switch (wValue) { 417 + case USB_DEVICE_REMOTE_WAKEUP: 418 + break; 419 + case USB_DEVICE_U1_ENABLE: 420 + break; 421 + case USB_DEVICE_U2_ENABLE: 422 + break; 423 + case USB_DEVICE_LTM_ENABLE: 424 + break; 425 + 426 + case USB_DEVICE_TEST_MODE: 427 + if ((wIndex & 0xff) != 0) 428 + return -EINVAL; 429 + if (!set) 430 + return -EINVAL; 431 + 432 + mode = wIndex >> 8; 433 + reg = dwc3_readl(dwc->regs, DWC3_DCTL); 434 + reg &= ~DWC3_DCTL_TSTCTRL_MASK; 435 + 436 + switch (mode) { 437 + case TEST_J: 438 + case TEST_K: 439 + case TEST_SE0_NAK: 440 + case TEST_PACKET: 441 + case TEST_FORCE_EN: 442 + reg |= mode << 1; 443 + break; 444 + default: 445 + return -EINVAL; 446 + } 447 + dwc3_writel(dwc->regs, DWC3_DCTL, reg); 448 + break; 449 + default: 450 + return -EINVAL; 451 + } 452 + break; 453 + 454 + case USB_RECIP_INTERFACE: 455 + switch (wValue) { 456 + case USB_INTRF_FUNC_SUSPEND: 457 + if (wIndex & USB_INTRF_FUNC_SUSPEND_LP) 458 + /* XXX enable Low power suspend */ 459 + ; 460 + if (wIndex & USB_INTRF_FUNC_SUSPEND_RW) 461 + /* XXX enable remote wakeup */ 462 + ; 463 + break; 464 + default: 465 + return -EINVAL; 466 + } 467 + break; 468 + 469 + case USB_RECIP_ENDPOINT: 470 + switch (wValue) { 471 + case USB_ENDPOINT_HALT: 472 + 473 + dep = dwc3_wIndex_to_dep(dwc, ctrl->wIndex); 474 + if (!dep) 475 + return -EINVAL; 476 + ret = __dwc3_gadget_ep_set_halt(dep, set); 477 + if (ret) 478 + return -EINVAL; 479 + break; 480 + default: 481 + return -EINVAL; 482 + } 483 + break; 484 + 485 + default: 486 + return -EINVAL; 487 + }; 488 + 489 + dwc->ep0state = EP0_IN_WAIT_NRDY; 490 + 491 + return 0; 492 + } 493 + 494 + static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 495 + { 496 + int ret = 0; 497 + u32 addr; 498 + u32 reg; 499 + 500 + addr = le16_to_cpu(ctrl->wValue); 501 + if (addr > 127) 502 + return -EINVAL; 503 + 504 + switch (dwc->dev_state) { 505 + case DWC3_DEFAULT_STATE: 506 + case DWC3_ADDRESS_STATE: 507 + /* 508 + * Not sure if we should program DevAddr now or later 509 + */ 510 + reg = dwc3_readl(dwc->regs, DWC3_DCFG); 511 + reg &= ~(DWC3_DCFG_DEVADDR_MASK); 512 + reg |= DWC3_DCFG_DEVADDR(addr); 513 + dwc3_writel(dwc->regs, DWC3_DCFG, reg); 514 + 515 + if (addr) 516 + dwc->dev_state = DWC3_ADDRESS_STATE; 517 + else 518 + dwc->dev_state = DWC3_DEFAULT_STATE; 519 + break; 520 + 521 + case DWC3_CONFIGURED_STATE: 522 + ret = -EINVAL; 523 + break; 524 + } 525 + dwc->ep0state = EP0_IN_WAIT_NRDY; 526 + return ret; 527 + } 528 + 529 + static int dwc3_ep0_delegate_req(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 530 + { 531 + int ret; 532 + 533 + spin_unlock(&dwc->lock); 534 + ret = dwc->gadget_driver->setup(&dwc->gadget, ctrl); 535 + spin_lock(&dwc->lock); 536 + return ret; 537 + } 538 + 539 + static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 540 + { 541 + u32 cfg; 542 + int ret; 543 + 544 + cfg = le16_to_cpu(ctrl->wValue); 545 + 546 + switch (dwc->dev_state) { 547 + case DWC3_DEFAULT_STATE: 548 + return -EINVAL; 549 + break; 550 + 551 + case DWC3_ADDRESS_STATE: 552 + ret = dwc3_ep0_delegate_req(dwc, ctrl); 553 + /* if the cfg matches and the cfg is non zero */ 554 + if (!ret && cfg) 555 + dwc->dev_state = DWC3_CONFIGURED_STATE; 556 + break; 557 + 558 + case DWC3_CONFIGURED_STATE: 559 + ret = dwc3_ep0_delegate_req(dwc, ctrl); 560 + if (!cfg) 561 + dwc->dev_state = DWC3_ADDRESS_STATE; 562 + break; 563 + } 564 + return 0; 565 + } 566 + 567 + static int dwc3_ep0_std_request(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 568 + { 569 + int ret; 570 + 571 + switch (ctrl->bRequest) { 572 + case USB_REQ_GET_STATUS: 573 + dev_vdbg(dwc->dev, "USB_REQ_GET_STATUS\n"); 574 + ret = dwc3_ep0_handle_status(dwc, ctrl); 575 + break; 576 + case USB_REQ_CLEAR_FEATURE: 577 + dev_vdbg(dwc->dev, "USB_REQ_CLEAR_FEATURE\n"); 578 + ret = dwc3_ep0_handle_feature(dwc, ctrl, 0); 579 + break; 580 + case USB_REQ_SET_FEATURE: 581 + dev_vdbg(dwc->dev, "USB_REQ_SET_FEATURE\n"); 582 + ret = dwc3_ep0_handle_feature(dwc, ctrl, 1); 583 + break; 584 + case USB_REQ_SET_ADDRESS: 585 + dev_vdbg(dwc->dev, "USB_REQ_SET_ADDRESS\n"); 586 + ret = dwc3_ep0_set_address(dwc, ctrl); 587 + break; 588 + case USB_REQ_SET_CONFIGURATION: 589 + dev_vdbg(dwc->dev, "USB_REQ_SET_CONFIGURATION\n"); 590 + ret = dwc3_ep0_set_config(dwc, ctrl); 591 + break; 592 + default: 593 + dev_vdbg(dwc->dev, "Forwarding to gadget driver\n"); 594 + ret = dwc3_ep0_delegate_req(dwc, ctrl); 595 + break; 596 + }; 597 + 598 + return ret; 599 + } 600 + 601 + static void dwc3_ep0_inspect_setup(struct dwc3 *dwc, 602 + const struct dwc3_event_depevt *event) 603 + { 604 + struct usb_ctrlrequest *ctrl = dwc->ctrl_req; 605 + int ret; 606 + u32 len; 607 + 608 + if (!dwc->gadget_driver) 609 + goto err; 610 + 611 + len = le16_to_cpu(ctrl->wLength); 612 + if (!len) { 613 + dwc->ep0state = EP0_IN_WAIT_GADGET; 614 + dwc->three_stage_setup = 0; 615 + } else { 616 + dwc->three_stage_setup = 1; 617 + if (ctrl->bRequestType & USB_DIR_IN) 618 + dwc->ep0state = EP0_IN_DATA_PHASE; 619 + else 620 + dwc->ep0state = EP0_OUT_DATA_PHASE; 621 + } 622 + 623 + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) 624 + ret = dwc3_ep0_std_request(dwc, ctrl); 625 + else 626 + ret = dwc3_ep0_delegate_req(dwc, ctrl); 627 + 628 + if (ret >= 0) 629 + return; 630 + 631 + err: 632 + dwc3_ep0_stall_and_restart(dwc); 633 + } 634 + 635 + static void dwc3_ep0_complete_data(struct dwc3 *dwc, 636 + const struct dwc3_event_depevt *event) 637 + { 638 + struct dwc3_request *r = NULL; 639 + struct usb_request *ur; 640 + struct dwc3_trb trb; 641 + struct dwc3_ep *dep; 642 + u32 transfered; 643 + u8 epnum; 644 + 645 + epnum = event->endpoint_number; 646 + dep = dwc->eps[epnum]; 647 + 648 + if (!dwc->ep0_status_pending) { 649 + r = next_request(&dep->request_list); 650 + ur = &r->request; 651 + } else { 652 + ur = &dwc->ep0_usb_req; 653 + dwc->ep0_status_pending = 0; 654 + } 655 + 656 + dwc3_trb_to_nat(dwc->ep0_trb, &trb); 657 + 658 + transfered = ur->length - trb.length; 659 + ur->actual += transfered; 660 + 661 + if ((epnum & 1) && ur->actual < ur->length) { 662 + /* for some reason we did not get everything out */ 663 + 664 + dwc3_ep0_stall_and_restart(dwc); 665 + dwc3_gadget_giveback(dep, r, -ECONNRESET); 666 + } else { 667 + /* 668 + * handle the case where we have to send a zero packet. This 669 + * seems to be case when req.length > maxpacket. Could it be? 670 + */ 671 + /* The transfer is complete, wait for HOST */ 672 + if (epnum & 1) 673 + dwc->ep0state = EP0_IN_WAIT_NRDY; 674 + else 675 + dwc->ep0state = EP0_OUT_WAIT_NRDY; 676 + 677 + if (r) 678 + dwc3_gadget_giveback(dep, r, 0); 679 + } 680 + } 681 + 682 + static void dwc3_ep0_complete_req(struct dwc3 *dwc, 683 + const struct dwc3_event_depevt *event) 684 + { 685 + struct dwc3_request *r; 686 + struct dwc3_ep *dep; 687 + u8 epnum; 688 + 689 + epnum = event->endpoint_number; 690 + dep = dwc->eps[epnum]; 691 + 692 + if (!list_empty(&dep->request_list)) { 693 + r = next_request(&dep->request_list); 694 + 695 + dwc3_gadget_giveback(dep, r, 0); 696 + } 697 + 698 + dwc->ep0state = EP0_IDLE; 699 + dwc3_ep0_out_start(dwc); 700 + } 701 + 702 + static void dwc3_ep0_xfer_complete(struct dwc3 *dwc, 703 + const struct dwc3_event_depevt *event) 704 + { 705 + switch (dwc->ep0state) { 706 + case EP0_IDLE: 707 + dwc3_ep0_inspect_setup(dwc, event); 708 + break; 709 + 710 + case EP0_IN_DATA_PHASE: 711 + case EP0_OUT_DATA_PHASE: 712 + dwc3_ep0_complete_data(dwc, event); 713 + break; 714 + 715 + case EP0_IN_STATUS_PHASE: 716 + case EP0_OUT_STATUS_PHASE: 717 + dwc3_ep0_complete_req(dwc, event); 718 + break; 719 + 720 + case EP0_IN_WAIT_NRDY: 721 + case EP0_OUT_WAIT_NRDY: 722 + case EP0_IN_WAIT_GADGET: 723 + case EP0_OUT_WAIT_GADGET: 724 + case EP0_UNCONNECTED: 725 + case EP0_STALL: 726 + break; 727 + } 728 + } 729 + 730 + static void dwc3_ep0_xfernotready(struct dwc3 *dwc, 731 + const struct dwc3_event_depevt *event) 732 + { 733 + switch (dwc->ep0state) { 734 + case EP0_IN_WAIT_GADGET: 735 + dwc->ep0state = EP0_IN_WAIT_NRDY; 736 + break; 737 + case EP0_OUT_WAIT_GADGET: 738 + dwc->ep0state = EP0_OUT_WAIT_NRDY; 739 + break; 740 + 741 + case EP0_IN_WAIT_NRDY: 742 + case EP0_OUT_WAIT_NRDY: 743 + dwc3_ep0_do_setup_status(dwc, event); 744 + break; 745 + 746 + case EP0_IDLE: 747 + case EP0_IN_STATUS_PHASE: 748 + case EP0_OUT_STATUS_PHASE: 749 + case EP0_IN_DATA_PHASE: 750 + case EP0_OUT_DATA_PHASE: 751 + case EP0_UNCONNECTED: 752 + case EP0_STALL: 753 + break; 754 + } 755 + } 756 + 757 + void dwc3_ep0_interrupt(struct dwc3 *dwc, 758 + const const struct dwc3_event_depevt *event) 759 + { 760 + u8 epnum = event->endpoint_number; 761 + 762 + dev_dbg(dwc->dev, "%s while ep%d%s in state '%s'\n", 763 + dwc3_ep_event_string(event->endpoint_event), 764 + epnum, (epnum & 1) ? "in" : "out", 765 + dwc3_ep0_state_string(dwc->ep0state)); 766 + 767 + switch (event->endpoint_event) { 768 + case DWC3_DEPEVT_XFERCOMPLETE: 769 + dwc3_ep0_xfer_complete(dwc, event); 770 + break; 771 + 772 + case DWC3_DEPEVT_XFERNOTREADY: 773 + dwc3_ep0_xfernotready(dwc, event); 774 + break; 775 + 776 + case DWC3_DEPEVT_XFERINPROGRESS: 777 + case DWC3_DEPEVT_RXTXFIFOEVT: 778 + case DWC3_DEPEVT_STREAMEVT: 779 + case DWC3_DEPEVT_EPCMDCMPLT: 780 + break; 781 + } 782 + }
+2062
drivers/usb/dwc3/gadget.c
··· 1 + /** 2 + * gadget.c - DesignWare USB3 DRD Controller Gadget Framework Link 3 + * 4 + * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com 5 + * All rights reserved. 6 + * 7 + * Authors: Felipe Balbi <balbi@ti.com>, 8 + * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 9 + * 10 + * Redistribution and use in source and binary forms, with or without 11 + * modification, are permitted provided that the following conditions 12 + * are met: 13 + * 1. Redistributions of source code must retain the above copyright 14 + * notice, this list of conditions, and the following disclaimer, 15 + * without modification. 16 + * 2. Redistributions in binary form must reproduce the above copyright 17 + * notice, this list of conditions and the following disclaimer in the 18 + * documentation and/or other materials provided with the distribution. 19 + * 3. The names of the above-listed copyright holders may not be used 20 + * to endorse or promote products derived from this software without 21 + * specific prior written permission. 22 + * 23 + * ALTERNATIVELY, this software may be distributed under the terms of the 24 + * GNU General Public License ("GPL") version 2, as published by the Free 25 + * Software Foundation. 26 + * 27 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 28 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 29 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 31 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 32 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 33 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 34 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 35 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 + */ 39 + 40 + #include <linux/kernel.h> 41 + #include <linux/delay.h> 42 + #include <linux/slab.h> 43 + #include <linux/spinlock.h> 44 + #include <linux/platform_device.h> 45 + #include <linux/pm_runtime.h> 46 + #include <linux/interrupt.h> 47 + #include <linux/io.h> 48 + #include <linux/list.h> 49 + #include <linux/dma-mapping.h> 50 + 51 + #include <linux/usb/ch9.h> 52 + #include <linux/usb/gadget.h> 53 + 54 + #include "core.h" 55 + #include "gadget.h" 56 + #include "io.h" 57 + 58 + #define DMA_ADDR_INVALID (~(dma_addr_t)0) 59 + 60 + void dwc3_map_buffer_to_dma(struct dwc3_request *req) 61 + { 62 + struct dwc3 *dwc = req->dep->dwc; 63 + 64 + if (req->request.dma == DMA_ADDR_INVALID) { 65 + req->request.dma = dma_map_single(dwc->dev, req->request.buf, 66 + req->request.length, req->direction 67 + ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 68 + req->mapped = true; 69 + } else { 70 + dma_sync_single_for_device(dwc->dev, req->request.dma, 71 + req->request.length, req->direction 72 + ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 73 + req->mapped = false; 74 + } 75 + } 76 + 77 + void dwc3_unmap_buffer_from_dma(struct dwc3_request *req) 78 + { 79 + struct dwc3 *dwc = req->dep->dwc; 80 + 81 + if (req->mapped) { 82 + dma_unmap_single(dwc->dev, req->request.dma, 83 + req->request.length, req->direction 84 + ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 85 + req->mapped = 0; 86 + } else { 87 + dma_sync_single_for_cpu(dwc->dev, req->request.dma, 88 + req->request.length, req->direction 89 + ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 90 + } 91 + } 92 + 93 + void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req, 94 + int status) 95 + { 96 + struct dwc3 *dwc = dep->dwc; 97 + 98 + if (req->queued) { 99 + dep->busy_slot++; 100 + /* 101 + * Skip LINK TRB. We can't use req->trb and check for 102 + * DWC3_TRBCTL_LINK_TRB because it points the TRB we just 103 + * completed (not the LINK TRB). 104 + */ 105 + if (((dep->busy_slot & DWC3_TRB_MASK) == DWC3_TRB_NUM - 1) && 106 + usb_endpoint_xfer_isoc(dep->desc)) 107 + dep->busy_slot++; 108 + } 109 + list_del(&req->list); 110 + 111 + if (req->request.status == -EINPROGRESS) 112 + req->request.status = status; 113 + 114 + dwc3_unmap_buffer_from_dma(req); 115 + 116 + dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n", 117 + req, dep->name, req->request.actual, 118 + req->request.length, status); 119 + 120 + spin_unlock(&dwc->lock); 121 + req->request.complete(&req->dep->endpoint, &req->request); 122 + spin_lock(&dwc->lock); 123 + } 124 + 125 + static const char *dwc3_gadget_ep_cmd_string(u8 cmd) 126 + { 127 + switch (cmd) { 128 + case DWC3_DEPCMD_DEPSTARTCFG: 129 + return "Start New Configuration"; 130 + case DWC3_DEPCMD_ENDTRANSFER: 131 + return "End Transfer"; 132 + case DWC3_DEPCMD_UPDATETRANSFER: 133 + return "Update Transfer"; 134 + case DWC3_DEPCMD_STARTTRANSFER: 135 + return "Start Transfer"; 136 + case DWC3_DEPCMD_CLEARSTALL: 137 + return "Clear Stall"; 138 + case DWC3_DEPCMD_SETSTALL: 139 + return "Set Stall"; 140 + case DWC3_DEPCMD_GETSEQNUMBER: 141 + return "Get Data Sequence Number"; 142 + case DWC3_DEPCMD_SETTRANSFRESOURCE: 143 + return "Set Endpoint Transfer Resource"; 144 + case DWC3_DEPCMD_SETEPCONFIG: 145 + return "Set Endpoint Configuration"; 146 + default: 147 + return "UNKNOWN command"; 148 + } 149 + } 150 + 151 + int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep, 152 + unsigned cmd, struct dwc3_gadget_ep_cmd_params *params) 153 + { 154 + struct dwc3_ep *dep = dwc->eps[ep]; 155 + unsigned long timeout = 500; 156 + u32 reg; 157 + 158 + dev_vdbg(dwc->dev, "%s: cmd '%s' params %08x %08x %08x\n", 159 + dep->name, 160 + dwc3_gadget_ep_cmd_string(cmd), params->param0.raw, 161 + params->param1.raw, params->param2.raw); 162 + 163 + dwc3_writel(dwc->regs, DWC3_DEPCMDPAR0(ep), params->param0.raw); 164 + dwc3_writel(dwc->regs, DWC3_DEPCMDPAR1(ep), params->param1.raw); 165 + dwc3_writel(dwc->regs, DWC3_DEPCMDPAR2(ep), params->param2.raw); 166 + 167 + dwc3_writel(dwc->regs, DWC3_DEPCMD(ep), cmd | DWC3_DEPCMD_CMDACT); 168 + do { 169 + reg = dwc3_readl(dwc->regs, DWC3_DEPCMD(ep)); 170 + if (!(reg & DWC3_DEPCMD_CMDACT)) { 171 + dev_vdbg(dwc->dev, "CMD Compl Status %d DEPCMD %04x\n", 172 + ((reg & 0xf000) >> 12), reg); 173 + return 0; 174 + } 175 + 176 + /* 177 + * XXX Figure out a sane timeout here. 500ms is way too much. 178 + * We can't sleep here, because it is also called from 179 + * interrupt context. 180 + */ 181 + timeout--; 182 + if (!timeout) 183 + return -ETIMEDOUT; 184 + 185 + mdelay(1); 186 + } while (1); 187 + } 188 + 189 + static dma_addr_t dwc3_trb_dma_offset(struct dwc3_ep *dep, 190 + struct dwc3_trb_hw *trb) 191 + { 192 + u32 offset = trb - dep->trb_pool; 193 + 194 + return dep->trb_pool_dma + offset; 195 + } 196 + 197 + static int dwc3_alloc_trb_pool(struct dwc3_ep *dep) 198 + { 199 + struct dwc3 *dwc = dep->dwc; 200 + 201 + if (dep->trb_pool) 202 + return 0; 203 + 204 + if (dep->number == 0 || dep->number == 1) 205 + return 0; 206 + 207 + dep->trb_pool = dma_alloc_coherent(dwc->dev, 208 + sizeof(struct dwc3_trb) * DWC3_TRB_NUM, 209 + &dep->trb_pool_dma, GFP_KERNEL); 210 + if (!dep->trb_pool) { 211 + dev_err(dep->dwc->dev, "failed to allocate trb pool for %s\n", 212 + dep->name); 213 + return -ENOMEM; 214 + } 215 + 216 + return 0; 217 + } 218 + 219 + static void dwc3_free_trb_pool(struct dwc3_ep *dep) 220 + { 221 + struct dwc3 *dwc = dep->dwc; 222 + 223 + dma_free_coherent(dwc->dev, sizeof(struct dwc3_trb) * DWC3_TRB_NUM, 224 + dep->trb_pool, dep->trb_pool_dma); 225 + 226 + dep->trb_pool = NULL; 227 + dep->trb_pool_dma = 0; 228 + } 229 + 230 + static int dwc3_gadget_start_config(struct dwc3 *dwc, struct dwc3_ep *dep) 231 + { 232 + struct dwc3_gadget_ep_cmd_params params; 233 + u32 cmd; 234 + 235 + memset(&params, 0x00, sizeof(params)); 236 + 237 + if (dep->number != 1) { 238 + cmd = DWC3_DEPCMD_DEPSTARTCFG; 239 + /* XferRscIdx == 0 for ep0 and 2 for the remaining */ 240 + if (dep->number > 1) 241 + cmd |= DWC3_DEPCMD_PARAM(2); 242 + 243 + return dwc3_send_gadget_ep_cmd(dwc, 0, cmd, &params); 244 + } 245 + 246 + return 0; 247 + } 248 + 249 + static int dwc3_gadget_set_ep_config(struct dwc3 *dwc, struct dwc3_ep *dep, 250 + const struct usb_endpoint_descriptor *desc) 251 + { 252 + struct dwc3_gadget_ep_cmd_params params; 253 + 254 + memset(&params, 0x00, sizeof(params)); 255 + 256 + params.param0.depcfg.ep_type = usb_endpoint_type(desc); 257 + params.param0.depcfg.max_packet_size = usb_endpoint_maxp(desc); 258 + 259 + params.param1.depcfg.xfer_complete_enable = true; 260 + params.param1.depcfg.xfer_not_ready_enable = true; 261 + 262 + if (usb_endpoint_xfer_isoc(desc)) 263 + params.param1.depcfg.xfer_in_progress_enable = true; 264 + 265 + /* 266 + * We are doing 1:1 mapping for endpoints, meaning 267 + * Physical Endpoints 2 maps to Logical Endpoint 2 and 268 + * so on. We consider the direction bit as part of the physical 269 + * endpoint number. So USB endpoint 0x81 is 0x03. 270 + */ 271 + params.param1.depcfg.ep_number = dep->number; 272 + 273 + /* 274 + * We must use the lower 16 TX FIFOs even though 275 + * HW might have more 276 + */ 277 + if (dep->direction) 278 + params.param0.depcfg.fifo_number = dep->number >> 1; 279 + 280 + if (desc->bInterval) { 281 + params.param1.depcfg.binterval_m1 = desc->bInterval - 1; 282 + dep->interval = 1 << (desc->bInterval - 1); 283 + } 284 + 285 + return dwc3_send_gadget_ep_cmd(dwc, dep->number, 286 + DWC3_DEPCMD_SETEPCONFIG, &params); 287 + } 288 + 289 + static int dwc3_gadget_set_xfer_resource(struct dwc3 *dwc, struct dwc3_ep *dep) 290 + { 291 + struct dwc3_gadget_ep_cmd_params params; 292 + 293 + memset(&params, 0x00, sizeof(params)); 294 + 295 + params.param0.depxfercfg.number_xfer_resources = 1; 296 + 297 + return dwc3_send_gadget_ep_cmd(dwc, dep->number, 298 + DWC3_DEPCMD_SETTRANSFRESOURCE, &params); 299 + } 300 + 301 + /** 302 + * __dwc3_gadget_ep_enable - Initializes a HW endpoint 303 + * @dep: endpoint to be initialized 304 + * @desc: USB Endpoint Descriptor 305 + * 306 + * Caller should take care of locking 307 + */ 308 + static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, 309 + const struct usb_endpoint_descriptor *desc) 310 + { 311 + struct dwc3 *dwc = dep->dwc; 312 + u32 reg; 313 + int ret = -ENOMEM; 314 + 315 + if (!(dep->flags & DWC3_EP_ENABLED)) { 316 + ret = dwc3_gadget_start_config(dwc, dep); 317 + if (ret) 318 + return ret; 319 + } 320 + 321 + ret = dwc3_gadget_set_ep_config(dwc, dep, desc); 322 + if (ret) 323 + return ret; 324 + 325 + if (!(dep->flags & DWC3_EP_ENABLED)) { 326 + struct dwc3_trb_hw *trb_st_hw; 327 + struct dwc3_trb_hw *trb_link_hw; 328 + struct dwc3_trb trb_link; 329 + 330 + ret = dwc3_gadget_set_xfer_resource(dwc, dep); 331 + if (ret) 332 + return ret; 333 + 334 + dep->desc = desc; 335 + dep->type = usb_endpoint_type(desc); 336 + dep->flags |= DWC3_EP_ENABLED; 337 + 338 + reg = dwc3_readl(dwc->regs, DWC3_DALEPENA); 339 + reg |= DWC3_DALEPENA_EP(dep->number); 340 + dwc3_writel(dwc->regs, DWC3_DALEPENA, reg); 341 + 342 + if (!usb_endpoint_xfer_isoc(desc)) 343 + return 0; 344 + 345 + memset(&trb_link, 0, sizeof(trb_link)); 346 + 347 + /* Link TRB for ISOC. The HWO but is never reset */ 348 + trb_st_hw = &dep->trb_pool[0]; 349 + 350 + trb_link.bplh = dwc3_trb_dma_offset(dep, trb_st_hw); 351 + trb_link.trbctl = DWC3_TRBCTL_LINK_TRB; 352 + trb_link.hwo = true; 353 + 354 + trb_link_hw = &dep->trb_pool[DWC3_TRB_NUM - 1]; 355 + dwc3_trb_to_hw(&trb_link, trb_link_hw); 356 + } 357 + 358 + return 0; 359 + } 360 + 361 + static void dwc3_gadget_nuke_reqs(struct dwc3_ep *dep, const int status) 362 + { 363 + struct dwc3_request *req; 364 + 365 + while (!list_empty(&dep->request_list)) { 366 + req = next_request(&dep->request_list); 367 + 368 + dwc3_gadget_giveback(dep, req, status); 369 + } 370 + /* nuke queued TRBs as well on command complete */ 371 + dep->flags |= DWC3_EP_WILL_SHUTDOWN; 372 + } 373 + 374 + /** 375 + * __dwc3_gadget_ep_disable - Disables a HW endpoint 376 + * @dep: the endpoint to disable 377 + * 378 + * Caller should take care of locking 379 + */ 380 + static void dwc3_stop_active_transfer(struct dwc3 *dwc, u32 epnum); 381 + static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep) 382 + { 383 + struct dwc3 *dwc = dep->dwc; 384 + u32 reg; 385 + 386 + dep->flags &= ~DWC3_EP_ENABLED; 387 + dwc3_stop_active_transfer(dwc, dep->number); 388 + dwc3_gadget_nuke_reqs(dep, -ESHUTDOWN); 389 + 390 + reg = dwc3_readl(dwc->regs, DWC3_DALEPENA); 391 + reg &= ~DWC3_DALEPENA_EP(dep->number); 392 + dwc3_writel(dwc->regs, DWC3_DALEPENA, reg); 393 + 394 + dep->desc = NULL; 395 + dep->type = 0; 396 + 397 + return 0; 398 + } 399 + 400 + /* -------------------------------------------------------------------------- */ 401 + 402 + static int dwc3_gadget_ep0_enable(struct usb_ep *ep, 403 + const struct usb_endpoint_descriptor *desc) 404 + { 405 + return -EINVAL; 406 + } 407 + 408 + static int dwc3_gadget_ep0_disable(struct usb_ep *ep) 409 + { 410 + return -EINVAL; 411 + } 412 + 413 + /* -------------------------------------------------------------------------- */ 414 + 415 + static int dwc3_gadget_ep_enable(struct usb_ep *ep, 416 + const struct usb_endpoint_descriptor *desc) 417 + { 418 + struct dwc3_ep *dep; 419 + struct dwc3 *dwc; 420 + unsigned long flags; 421 + int ret; 422 + 423 + if (!ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) { 424 + pr_debug("dwc3: invalid parameters\n"); 425 + return -EINVAL; 426 + } 427 + 428 + if (!desc->wMaxPacketSize) { 429 + pr_debug("dwc3: missing wMaxPacketSize\n"); 430 + return -EINVAL; 431 + } 432 + 433 + dep = to_dwc3_ep(ep); 434 + dwc = dep->dwc; 435 + 436 + switch (usb_endpoint_type(desc)) { 437 + case USB_ENDPOINT_XFER_CONTROL: 438 + strncat(dep->name, "-control", sizeof(dep->name)); 439 + break; 440 + case USB_ENDPOINT_XFER_ISOC: 441 + strncat(dep->name, "-isoc", sizeof(dep->name)); 442 + break; 443 + case USB_ENDPOINT_XFER_BULK: 444 + strncat(dep->name, "-bulk", sizeof(dep->name)); 445 + break; 446 + case USB_ENDPOINT_XFER_INT: 447 + strncat(dep->name, "-int", sizeof(dep->name)); 448 + break; 449 + default: 450 + dev_err(dwc->dev, "invalid endpoint transfer type\n"); 451 + } 452 + 453 + if (dep->flags & DWC3_EP_ENABLED) { 454 + dev_WARN_ONCE(dwc->dev, true, "%s is already enabled\n", 455 + dep->name); 456 + return 0; 457 + } 458 + 459 + dev_vdbg(dwc->dev, "Enabling %s\n", dep->name); 460 + 461 + spin_lock_irqsave(&dwc->lock, flags); 462 + ret = __dwc3_gadget_ep_enable(dep, desc); 463 + spin_unlock_irqrestore(&dwc->lock, flags); 464 + 465 + return ret; 466 + } 467 + 468 + static int dwc3_gadget_ep_disable(struct usb_ep *ep) 469 + { 470 + struct dwc3_ep *dep; 471 + struct dwc3 *dwc; 472 + unsigned long flags; 473 + int ret; 474 + 475 + if (!ep) { 476 + pr_debug("dwc3: invalid parameters\n"); 477 + return -EINVAL; 478 + } 479 + 480 + dep = to_dwc3_ep(ep); 481 + dwc = dep->dwc; 482 + 483 + if (!(dep->flags & DWC3_EP_ENABLED)) { 484 + dev_WARN_ONCE(dwc->dev, true, "%s is already disabled\n", 485 + dep->name); 486 + return 0; 487 + } 488 + 489 + snprintf(dep->name, sizeof(dep->name), "ep%d%s", 490 + dep->number >> 1, 491 + (dep->number & 1) ? "in" : "out"); 492 + 493 + spin_lock_irqsave(&dwc->lock, flags); 494 + ret = __dwc3_gadget_ep_disable(dep); 495 + spin_unlock_irqrestore(&dwc->lock, flags); 496 + 497 + return ret; 498 + } 499 + 500 + static struct usb_request *dwc3_gadget_ep_alloc_request(struct usb_ep *ep, 501 + gfp_t gfp_flags) 502 + { 503 + struct dwc3_request *req; 504 + struct dwc3_ep *dep = to_dwc3_ep(ep); 505 + struct dwc3 *dwc = dep->dwc; 506 + 507 + req = kzalloc(sizeof(*req), gfp_flags); 508 + if (!req) { 509 + dev_err(dwc->dev, "not enough memory\n"); 510 + return NULL; 511 + } 512 + 513 + req->epnum = dep->number; 514 + req->dep = dep; 515 + req->request.dma = DMA_ADDR_INVALID; 516 + 517 + return &req->request; 518 + } 519 + 520 + static void dwc3_gadget_ep_free_request(struct usb_ep *ep, 521 + struct usb_request *request) 522 + { 523 + struct dwc3_request *req = to_dwc3_request(request); 524 + 525 + kfree(req); 526 + } 527 + 528 + /* 529 + * dwc3_prepare_trbs - setup TRBs from requests 530 + * @dep: endpoint for which requests are being prepared 531 + * @starting: true if the endpoint is idle and no requests are queued. 532 + * 533 + * The functions goes through the requests list and setups TRBs for the 534 + * transfers. The functions returns once there are not more TRBs available or 535 + * it run out of requests. 536 + */ 537 + static struct dwc3_request *dwc3_prepare_trbs(struct dwc3_ep *dep, 538 + bool starting) 539 + { 540 + struct dwc3_request *req, *n, *ret = NULL; 541 + struct dwc3_trb_hw *trb_hw; 542 + struct dwc3_trb trb; 543 + u32 trbs_left; 544 + 545 + BUILD_BUG_ON_NOT_POWER_OF_2(DWC3_TRB_NUM); 546 + 547 + /* the first request must not be queued */ 548 + trbs_left = (dep->busy_slot - dep->free_slot) & DWC3_TRB_MASK; 549 + /* 550 + * if busy & slot are equal than it is either full or empty. If we are 551 + * starting to proceed requests then we are empty. Otherwise we ar 552 + * full and don't do anything 553 + */ 554 + if (!trbs_left) { 555 + if (!starting) 556 + return NULL; 557 + trbs_left = DWC3_TRB_NUM; 558 + /* 559 + * In case we start from scratch, we queue the ISOC requests 560 + * starting from slot 1. This is done because we use ring 561 + * buffer and have no LST bit to stop us. Instead, we place 562 + * IOC bit TRB_NUM/4. We try to avoid to having an interrupt 563 + * after the first request so we start at slot 1 and have 564 + * 7 requests proceed before we hit the first IOC. 565 + * Other transfer types don't use the ring buffer and are 566 + * processed from the first TRB until the last one. Since we 567 + * don't wrap around we have to start at the beginning. 568 + */ 569 + if (usb_endpoint_xfer_isoc(dep->desc)) { 570 + dep->busy_slot = 1; 571 + dep->free_slot = 1; 572 + } else { 573 + dep->busy_slot = 0; 574 + dep->free_slot = 0; 575 + } 576 + } 577 + 578 + /* The last TRB is a link TRB, not used for xfer */ 579 + if ((trbs_left <= 1) && usb_endpoint_xfer_isoc(dep->desc)) 580 + return NULL; 581 + 582 + list_for_each_entry_safe(req, n, &dep->request_list, list) { 583 + unsigned int last_one = 0; 584 + unsigned int cur_slot; 585 + 586 + trb_hw = &dep->trb_pool[dep->free_slot & DWC3_TRB_MASK]; 587 + cur_slot = dep->free_slot; 588 + dep->free_slot++; 589 + 590 + /* Skip the LINK-TRB on ISOC */ 591 + if (((cur_slot & DWC3_TRB_MASK) == DWC3_TRB_NUM - 1) && 592 + usb_endpoint_xfer_isoc(dep->desc)) 593 + continue; 594 + 595 + dwc3_gadget_move_request_queued(req); 596 + memset(&trb, 0, sizeof(trb)); 597 + trbs_left--; 598 + 599 + /* Is our TRB pool empty? */ 600 + if (!trbs_left) 601 + last_one = 1; 602 + /* Is this the last request? */ 603 + if (list_empty(&dep->request_list)) 604 + last_one = 1; 605 + 606 + /* 607 + * FIXME we shouldn't need to set LST bit always but we are 608 + * facing some weird problem with the Hardware where it doesn't 609 + * complete even though it has been previously started. 610 + * 611 + * While we're debugging the problem, as a workaround to 612 + * multiple TRBs handling, use only one TRB at a time. 613 + */ 614 + last_one = 1; 615 + 616 + req->trb = trb_hw; 617 + if (!ret) 618 + ret = req; 619 + 620 + trb.bplh = req->request.dma; 621 + 622 + if (usb_endpoint_xfer_isoc(dep->desc)) { 623 + trb.isp_imi = true; 624 + trb.csp = true; 625 + } else { 626 + trb.lst = last_one; 627 + } 628 + 629 + switch (usb_endpoint_type(dep->desc)) { 630 + case USB_ENDPOINT_XFER_CONTROL: 631 + trb.trbctl = DWC3_TRBCTL_CONTROL_SETUP; 632 + break; 633 + 634 + case USB_ENDPOINT_XFER_ISOC: 635 + trb.trbctl = DWC3_TRBCTL_ISOCHRONOUS; 636 + 637 + /* IOC every DWC3_TRB_NUM / 4 so we can refill */ 638 + if (!(cur_slot % (DWC3_TRB_NUM / 4))) 639 + trb.ioc = last_one; 640 + break; 641 + 642 + case USB_ENDPOINT_XFER_BULK: 643 + case USB_ENDPOINT_XFER_INT: 644 + trb.trbctl = DWC3_TRBCTL_NORMAL; 645 + break; 646 + default: 647 + /* 648 + * This is only possible with faulty memory because we 649 + * checked it already :) 650 + */ 651 + BUG(); 652 + } 653 + 654 + trb.length = req->request.length; 655 + trb.hwo = true; 656 + 657 + dwc3_trb_to_hw(&trb, trb_hw); 658 + req->trb_dma = dwc3_trb_dma_offset(dep, trb_hw); 659 + 660 + if (last_one) 661 + break; 662 + } 663 + 664 + return ret; 665 + } 666 + 667 + static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep, u16 cmd_param, 668 + int start_new) 669 + { 670 + struct dwc3_gadget_ep_cmd_params params; 671 + struct dwc3_request *req; 672 + struct dwc3 *dwc = dep->dwc; 673 + int ret; 674 + u32 cmd; 675 + 676 + if (start_new && (dep->flags & DWC3_EP_BUSY)) { 677 + dev_vdbg(dwc->dev, "%s: endpoint busy\n", dep->name); 678 + return -EBUSY; 679 + } 680 + dep->flags &= ~DWC3_EP_PENDING_REQUEST; 681 + 682 + /* 683 + * If we are getting here after a short-out-packet we don't enqueue any 684 + * new requests as we try to set the IOC bit only on the last request. 685 + */ 686 + if (start_new) { 687 + if (list_empty(&dep->req_queued)) 688 + dwc3_prepare_trbs(dep, start_new); 689 + 690 + /* req points to the first request which will be sent */ 691 + req = next_request(&dep->req_queued); 692 + } else { 693 + /* 694 + * req points to the first request where HWO changed 695 + * from 0 to 1 696 + */ 697 + req = dwc3_prepare_trbs(dep, start_new); 698 + } 699 + if (!req) { 700 + dep->flags |= DWC3_EP_PENDING_REQUEST; 701 + return 0; 702 + } 703 + 704 + memset(&params, 0, sizeof(params)); 705 + params.param0.depstrtxfer.transfer_desc_addr_high = 706 + upper_32_bits(req->trb_dma); 707 + params.param1.depstrtxfer.transfer_desc_addr_low = 708 + lower_32_bits(req->trb_dma); 709 + 710 + if (start_new) 711 + cmd = DWC3_DEPCMD_STARTTRANSFER; 712 + else 713 + cmd = DWC3_DEPCMD_UPDATETRANSFER; 714 + 715 + cmd |= DWC3_DEPCMD_PARAM(cmd_param); 716 + ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params); 717 + if (ret < 0) { 718 + dev_dbg(dwc->dev, "failed to send STARTTRANSFER command\n"); 719 + 720 + /* 721 + * FIXME we need to iterate over the list of requests 722 + * here and stop, unmap, free and del each of the linked 723 + * requests instead of we do now. 724 + */ 725 + dwc3_unmap_buffer_from_dma(req); 726 + list_del(&req->list); 727 + return ret; 728 + } 729 + 730 + dep->flags |= DWC3_EP_BUSY; 731 + dep->res_trans_idx = dwc3_gadget_ep_get_transfer_index(dwc, 732 + dep->number); 733 + if (!dep->res_trans_idx) 734 + printk_once(KERN_ERR "%s() res_trans_idx is invalid\n", __func__); 735 + return 0; 736 + } 737 + 738 + static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req) 739 + { 740 + req->request.actual = 0; 741 + req->request.status = -EINPROGRESS; 742 + req->direction = dep->direction; 743 + req->epnum = dep->number; 744 + 745 + /* 746 + * We only add to our list of requests now and 747 + * start consuming the list once we get XferNotReady 748 + * IRQ. 749 + * 750 + * That way, we avoid doing anything that we don't need 751 + * to do now and defer it until the point we receive a 752 + * particular token from the Host side. 753 + * 754 + * This will also avoid Host cancelling URBs due to too 755 + * many NACKs. 756 + */ 757 + dwc3_map_buffer_to_dma(req); 758 + list_add_tail(&req->list, &dep->request_list); 759 + 760 + /* 761 + * There is one special case: XferNotReady with 762 + * empty list of requests. We need to kick the 763 + * transfer here in that situation, otherwise 764 + * we will be NAKing forever. 765 + * 766 + * If we get XferNotReady before gadget driver 767 + * has a chance to queue a request, we will ACK 768 + * the IRQ but won't be able to receive the data 769 + * until the next request is queued. The following 770 + * code is handling exactly that. 771 + */ 772 + if (dep->flags & DWC3_EP_PENDING_REQUEST) { 773 + int ret; 774 + int start_trans; 775 + 776 + start_trans = 1; 777 + if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && 778 + dep->flags & DWC3_EP_BUSY) 779 + start_trans = 0; 780 + 781 + ret = __dwc3_gadget_kick_transfer(dep, 0, start_trans); 782 + if (ret && ret != -EBUSY) { 783 + struct dwc3 *dwc = dep->dwc; 784 + 785 + dev_dbg(dwc->dev, "%s: failed to kick transfers\n", 786 + dep->name); 787 + } 788 + }; 789 + 790 + return 0; 791 + } 792 + 793 + static int dwc3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request, 794 + gfp_t gfp_flags) 795 + { 796 + struct dwc3_request *req = to_dwc3_request(request); 797 + struct dwc3_ep *dep = to_dwc3_ep(ep); 798 + struct dwc3 *dwc = dep->dwc; 799 + 800 + unsigned long flags; 801 + 802 + int ret; 803 + 804 + if (!dep->desc) { 805 + dev_dbg(dwc->dev, "trying to queue request %p to disabled %s\n", 806 + request, ep->name); 807 + return -ESHUTDOWN; 808 + } 809 + 810 + dev_vdbg(dwc->dev, "queing request %p to %s length %d\n", 811 + request, ep->name, request->length); 812 + 813 + spin_lock_irqsave(&dwc->lock, flags); 814 + ret = __dwc3_gadget_ep_queue(dep, req); 815 + spin_unlock_irqrestore(&dwc->lock, flags); 816 + 817 + return ret; 818 + } 819 + 820 + static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, 821 + struct usb_request *request) 822 + { 823 + struct dwc3_request *req = to_dwc3_request(request); 824 + struct dwc3_request *r = NULL; 825 + 826 + struct dwc3_ep *dep = to_dwc3_ep(ep); 827 + struct dwc3 *dwc = dep->dwc; 828 + 829 + unsigned long flags; 830 + int ret = 0; 831 + 832 + spin_lock_irqsave(&dwc->lock, flags); 833 + 834 + list_for_each_entry(r, &dep->request_list, list) { 835 + if (r == req) 836 + break; 837 + } 838 + 839 + if (r != req) { 840 + list_for_each_entry(r, &dep->req_queued, list) { 841 + if (r == req) 842 + break; 843 + } 844 + if (r == req) { 845 + /* wait until it is processed */ 846 + dwc3_stop_active_transfer(dwc, dep->number); 847 + goto out0; 848 + } 849 + dev_err(dwc->dev, "request %p was not queued to %s\n", 850 + request, ep->name); 851 + ret = -EINVAL; 852 + goto out0; 853 + } 854 + 855 + /* giveback the request */ 856 + dwc3_gadget_giveback(dep, req, -ECONNRESET); 857 + 858 + out0: 859 + spin_unlock_irqrestore(&dwc->lock, flags); 860 + 861 + return ret; 862 + } 863 + 864 + int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value) 865 + { 866 + struct dwc3_gadget_ep_cmd_params params; 867 + struct dwc3 *dwc = dep->dwc; 868 + int ret; 869 + 870 + memset(&params, 0x00, sizeof(params)); 871 + 872 + if (value) { 873 + if (dep->number == 0 || dep->number == 1) 874 + dwc->ep0state = EP0_STALL; 875 + 876 + ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, 877 + DWC3_DEPCMD_SETSTALL, &params); 878 + if (ret) 879 + dev_err(dwc->dev, "failed to %s STALL on %s\n", 880 + value ? "set" : "clear", 881 + dep->name); 882 + else 883 + dep->flags |= DWC3_EP_STALL; 884 + } else { 885 + ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, 886 + DWC3_DEPCMD_CLEARSTALL, &params); 887 + if (ret) 888 + dev_err(dwc->dev, "failed to %s STALL on %s\n", 889 + value ? "set" : "clear", 890 + dep->name); 891 + else 892 + dep->flags &= ~DWC3_EP_STALL; 893 + } 894 + return ret; 895 + } 896 + 897 + static int dwc3_gadget_ep_set_halt(struct usb_ep *ep, int value) 898 + { 899 + struct dwc3_ep *dep = to_dwc3_ep(ep); 900 + struct dwc3 *dwc = dep->dwc; 901 + 902 + unsigned long flags; 903 + 904 + int ret; 905 + 906 + spin_lock_irqsave(&dwc->lock, flags); 907 + 908 + if (usb_endpoint_xfer_isoc(dep->desc)) { 909 + dev_err(dwc->dev, "%s is of Isochronous type\n", dep->name); 910 + ret = -EINVAL; 911 + goto out; 912 + } 913 + 914 + ret = __dwc3_gadget_ep_set_halt(dep, value); 915 + out: 916 + spin_unlock_irqrestore(&dwc->lock, flags); 917 + 918 + return ret; 919 + } 920 + 921 + static int dwc3_gadget_ep_set_wedge(struct usb_ep *ep) 922 + { 923 + struct dwc3_ep *dep = to_dwc3_ep(ep); 924 + 925 + dep->flags |= DWC3_EP_WEDGE; 926 + 927 + return usb_ep_set_halt(ep); 928 + } 929 + 930 + /* -------------------------------------------------------------------------- */ 931 + 932 + static struct usb_endpoint_descriptor dwc3_gadget_ep0_desc = { 933 + .bLength = USB_DT_ENDPOINT_SIZE, 934 + .bDescriptorType = USB_DT_ENDPOINT, 935 + .bmAttributes = USB_ENDPOINT_XFER_CONTROL, 936 + }; 937 + 938 + static const struct usb_ep_ops dwc3_gadget_ep0_ops = { 939 + .enable = dwc3_gadget_ep0_enable, 940 + .disable = dwc3_gadget_ep0_disable, 941 + .alloc_request = dwc3_gadget_ep_alloc_request, 942 + .free_request = dwc3_gadget_ep_free_request, 943 + .queue = dwc3_gadget_ep0_queue, 944 + .dequeue = dwc3_gadget_ep_dequeue, 945 + .set_halt = dwc3_gadget_ep_set_halt, 946 + .set_wedge = dwc3_gadget_ep_set_wedge, 947 + }; 948 + 949 + static const struct usb_ep_ops dwc3_gadget_ep_ops = { 950 + .enable = dwc3_gadget_ep_enable, 951 + .disable = dwc3_gadget_ep_disable, 952 + .alloc_request = dwc3_gadget_ep_alloc_request, 953 + .free_request = dwc3_gadget_ep_free_request, 954 + .queue = dwc3_gadget_ep_queue, 955 + .dequeue = dwc3_gadget_ep_dequeue, 956 + .set_halt = dwc3_gadget_ep_set_halt, 957 + .set_wedge = dwc3_gadget_ep_set_wedge, 958 + }; 959 + 960 + /* -------------------------------------------------------------------------- */ 961 + 962 + static int dwc3_gadget_get_frame(struct usb_gadget *g) 963 + { 964 + struct dwc3 *dwc = gadget_to_dwc(g); 965 + u32 reg; 966 + 967 + reg = dwc3_readl(dwc->regs, DWC3_DSTS); 968 + return DWC3_DSTS_SOFFN(reg); 969 + } 970 + 971 + static int dwc3_gadget_wakeup(struct usb_gadget *g) 972 + { 973 + struct dwc3 *dwc = gadget_to_dwc(g); 974 + 975 + unsigned long timeout; 976 + unsigned long flags; 977 + 978 + u32 reg; 979 + 980 + int ret = 0; 981 + 982 + u8 link_state; 983 + u8 speed; 984 + 985 + spin_lock_irqsave(&dwc->lock, flags); 986 + 987 + /* 988 + * According to the Databook Remote wakeup request should 989 + * be issued only when the device is in early suspend state. 990 + * 991 + * We can check that via USB Link State bits in DSTS register. 992 + */ 993 + reg = dwc3_readl(dwc->regs, DWC3_DSTS); 994 + 995 + speed = reg & DWC3_DSTS_CONNECTSPD; 996 + if (speed == DWC3_DSTS_SUPERSPEED) { 997 + dev_dbg(dwc->dev, "no wakeup on SuperSpeed\n"); 998 + ret = -EINVAL; 999 + goto out; 1000 + } 1001 + 1002 + link_state = DWC3_DSTS_USBLNKST(reg); 1003 + 1004 + switch (link_state) { 1005 + case DWC3_LINK_STATE_RX_DET: /* in HS, means Early Suspend */ 1006 + case DWC3_LINK_STATE_U3: /* in HS, means SUSPEND */ 1007 + break; 1008 + default: 1009 + dev_dbg(dwc->dev, "can't wakeup from link state %d\n", 1010 + link_state); 1011 + ret = -EINVAL; 1012 + goto out; 1013 + } 1014 + 1015 + reg = dwc3_readl(dwc->regs, DWC3_DCTL); 1016 + 1017 + /* 1018 + * Switch link state to Recovery. In HS/FS/LS this means 1019 + * RemoteWakeup Request 1020 + */ 1021 + reg |= DWC3_DCTL_ULSTCHNG_RECOVERY; 1022 + dwc3_writel(dwc->regs, DWC3_DCTL, reg); 1023 + 1024 + /* wait for at least 2000us */ 1025 + usleep_range(2000, 2500); 1026 + 1027 + /* write zeroes to Link Change Request */ 1028 + reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK; 1029 + dwc3_writel(dwc->regs, DWC3_DCTL, reg); 1030 + 1031 + /* pool until Link State change to ON */ 1032 + timeout = jiffies + msecs_to_jiffies(100); 1033 + 1034 + while (!(time_after(jiffies, timeout))) { 1035 + reg = dwc3_readl(dwc->regs, DWC3_DSTS); 1036 + 1037 + /* in HS, means ON */ 1038 + if (DWC3_DSTS_USBLNKST(reg) == DWC3_LINK_STATE_U0) 1039 + break; 1040 + } 1041 + 1042 + if (DWC3_DSTS_USBLNKST(reg) != DWC3_LINK_STATE_U0) { 1043 + dev_err(dwc->dev, "failed to send remote wakeup\n"); 1044 + ret = -EINVAL; 1045 + } 1046 + 1047 + out: 1048 + spin_unlock_irqrestore(&dwc->lock, flags); 1049 + 1050 + return ret; 1051 + } 1052 + 1053 + static int dwc3_gadget_set_selfpowered(struct usb_gadget *g, 1054 + int is_selfpowered) 1055 + { 1056 + struct dwc3 *dwc = gadget_to_dwc(g); 1057 + 1058 + dwc->is_selfpowered = !!is_selfpowered; 1059 + 1060 + return 0; 1061 + } 1062 + 1063 + static void dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on) 1064 + { 1065 + u32 reg; 1066 + unsigned long timeout = 500; 1067 + 1068 + reg = dwc3_readl(dwc->regs, DWC3_DCTL); 1069 + if (is_on) 1070 + reg |= DWC3_DCTL_RUN_STOP; 1071 + else 1072 + reg &= ~DWC3_DCTL_RUN_STOP; 1073 + 1074 + dwc3_writel(dwc->regs, DWC3_DCTL, reg); 1075 + 1076 + do { 1077 + reg = dwc3_readl(dwc->regs, DWC3_DSTS); 1078 + if (is_on) { 1079 + if (!(reg & DWC3_DSTS_DEVCTRLHLT)) 1080 + break; 1081 + } else { 1082 + if (reg & DWC3_DSTS_DEVCTRLHLT) 1083 + break; 1084 + } 1085 + /* 1086 + * XXX reduce the 500ms delay 1087 + */ 1088 + timeout--; 1089 + if (!timeout) 1090 + break; 1091 + mdelay(1); 1092 + } while (1); 1093 + 1094 + dev_vdbg(dwc->dev, "gadget %s data soft-%s\n", 1095 + dwc->gadget_driver 1096 + ? dwc->gadget_driver->function : "no-function", 1097 + is_on ? "connect" : "disconnect"); 1098 + } 1099 + 1100 + static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) 1101 + { 1102 + struct dwc3 *dwc = gadget_to_dwc(g); 1103 + unsigned long flags; 1104 + 1105 + is_on = !!is_on; 1106 + 1107 + spin_lock_irqsave(&dwc->lock, flags); 1108 + dwc3_gadget_run_stop(dwc, is_on); 1109 + spin_unlock_irqrestore(&dwc->lock, flags); 1110 + 1111 + return 0; 1112 + } 1113 + 1114 + static int dwc3_gadget_start(struct usb_gadget *g, 1115 + struct usb_gadget_driver *driver) 1116 + { 1117 + struct dwc3 *dwc = gadget_to_dwc(g); 1118 + struct dwc3_ep *dep; 1119 + unsigned long flags; 1120 + int ret = 0; 1121 + u32 reg; 1122 + 1123 + spin_lock_irqsave(&dwc->lock, flags); 1124 + 1125 + if (dwc->gadget_driver) { 1126 + dev_err(dwc->dev, "%s is already bound to %s\n", 1127 + dwc->gadget.name, 1128 + dwc->gadget_driver->driver.name); 1129 + ret = -EBUSY; 1130 + goto err0; 1131 + } 1132 + 1133 + dwc->gadget_driver = driver; 1134 + dwc->gadget.dev.driver = &driver->driver; 1135 + 1136 + reg = dwc3_readl(dwc->regs, DWC3_GCTL); 1137 + 1138 + /* 1139 + * REVISIT: power down scale might be different 1140 + * depending on PHY used, need to pass that via platform_data 1141 + */ 1142 + reg |= DWC3_GCTL_PWRDNSCALE(0x61a) 1143 + | DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_DEVICE); 1144 + reg &= ~DWC3_GCTL_DISSCRAMBLE; 1145 + 1146 + /* 1147 + * WORKAROUND: DWC3 revisions <1.90a have a bug 1148 + * when The device fails to connect at SuperSpeed 1149 + * and falls back to high-speed mode which causes 1150 + * the device to enter in a Connect/Disconnect loop 1151 + */ 1152 + if (dwc->revision < DWC3_REVISION_190A) 1153 + reg |= DWC3_GCTL_U2RSTECN; 1154 + 1155 + dwc3_writel(dwc->regs, DWC3_GCTL, reg); 1156 + 1157 + reg = dwc3_readl(dwc->regs, DWC3_DCFG); 1158 + reg &= ~(DWC3_DCFG_SPEED_MASK); 1159 + reg |= DWC3_DCFG_SUPERSPEED; 1160 + dwc3_writel(dwc->regs, DWC3_DCFG, reg); 1161 + 1162 + /* Start with SuperSpeed Default */ 1163 + dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); 1164 + 1165 + dep = dwc->eps[0]; 1166 + ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc); 1167 + if (ret) { 1168 + dev_err(dwc->dev, "failed to enable %s\n", dep->name); 1169 + goto err0; 1170 + } 1171 + 1172 + dep = dwc->eps[1]; 1173 + ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc); 1174 + if (ret) { 1175 + dev_err(dwc->dev, "failed to enable %s\n", dep->name); 1176 + goto err1; 1177 + } 1178 + 1179 + /* begin to receive SETUP packets */ 1180 + dwc->ep0state = EP0_IDLE; 1181 + dwc3_ep0_out_start(dwc); 1182 + 1183 + spin_unlock_irqrestore(&dwc->lock, flags); 1184 + 1185 + return 0; 1186 + 1187 + err1: 1188 + __dwc3_gadget_ep_disable(dwc->eps[0]); 1189 + 1190 + err0: 1191 + spin_unlock_irqrestore(&dwc->lock, flags); 1192 + 1193 + return ret; 1194 + } 1195 + 1196 + static int dwc3_gadget_stop(struct usb_gadget *g, 1197 + struct usb_gadget_driver *driver) 1198 + { 1199 + struct dwc3 *dwc = gadget_to_dwc(g); 1200 + unsigned long flags; 1201 + 1202 + spin_lock_irqsave(&dwc->lock, flags); 1203 + 1204 + __dwc3_gadget_ep_disable(dwc->eps[0]); 1205 + __dwc3_gadget_ep_disable(dwc->eps[1]); 1206 + 1207 + dwc->gadget_driver = NULL; 1208 + dwc->gadget.dev.driver = NULL; 1209 + 1210 + spin_unlock_irqrestore(&dwc->lock, flags); 1211 + 1212 + return 0; 1213 + } 1214 + static const struct usb_gadget_ops dwc3_gadget_ops = { 1215 + .get_frame = dwc3_gadget_get_frame, 1216 + .wakeup = dwc3_gadget_wakeup, 1217 + .set_selfpowered = dwc3_gadget_set_selfpowered, 1218 + .pullup = dwc3_gadget_pullup, 1219 + .udc_start = dwc3_gadget_start, 1220 + .udc_stop = dwc3_gadget_stop, 1221 + }; 1222 + 1223 + /* -------------------------------------------------------------------------- */ 1224 + 1225 + static int __devinit dwc3_gadget_init_endpoints(struct dwc3 *dwc) 1226 + { 1227 + struct dwc3_ep *dep; 1228 + u8 epnum; 1229 + 1230 + INIT_LIST_HEAD(&dwc->gadget.ep_list); 1231 + 1232 + for (epnum = 0; epnum < DWC3_ENDPOINTS_NUM; epnum++) { 1233 + dep = kzalloc(sizeof(*dep), GFP_KERNEL); 1234 + if (!dep) { 1235 + dev_err(dwc->dev, "can't allocate endpoint %d\n", 1236 + epnum); 1237 + return -ENOMEM; 1238 + } 1239 + 1240 + dep->dwc = dwc; 1241 + dep->number = epnum; 1242 + dwc->eps[epnum] = dep; 1243 + 1244 + snprintf(dep->name, sizeof(dep->name), "ep%d%s", epnum >> 1, 1245 + (epnum & 1) ? "in" : "out"); 1246 + dep->endpoint.name = dep->name; 1247 + dep->direction = (epnum & 1); 1248 + 1249 + if (epnum == 0 || epnum == 1) { 1250 + dep->endpoint.maxpacket = 512; 1251 + dep->endpoint.ops = &dwc3_gadget_ep0_ops; 1252 + if (!epnum) 1253 + dwc->gadget.ep0 = &dep->endpoint; 1254 + } else { 1255 + int ret; 1256 + 1257 + dep->endpoint.maxpacket = 1024; 1258 + dep->endpoint.ops = &dwc3_gadget_ep_ops; 1259 + list_add_tail(&dep->endpoint.ep_list, 1260 + &dwc->gadget.ep_list); 1261 + 1262 + ret = dwc3_alloc_trb_pool(dep); 1263 + if (ret) { 1264 + dev_err(dwc->dev, "%s: failed to allocate TRB pool\n", dep->name); 1265 + return ret; 1266 + } 1267 + } 1268 + INIT_LIST_HEAD(&dep->request_list); 1269 + INIT_LIST_HEAD(&dep->req_queued); 1270 + } 1271 + 1272 + return 0; 1273 + } 1274 + 1275 + static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) 1276 + { 1277 + struct dwc3_ep *dep; 1278 + u8 epnum; 1279 + 1280 + for (epnum = 0; epnum < DWC3_ENDPOINTS_NUM; epnum++) { 1281 + dep = dwc->eps[epnum]; 1282 + dwc3_free_trb_pool(dep); 1283 + 1284 + if (epnum != 0 && epnum != 1) 1285 + list_del(&dep->endpoint.ep_list); 1286 + 1287 + kfree(dep); 1288 + } 1289 + } 1290 + 1291 + static void dwc3_gadget_release(struct device *dev) 1292 + { 1293 + dev_dbg(dev, "%s\n", __func__); 1294 + } 1295 + 1296 + /* -------------------------------------------------------------------------- */ 1297 + static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep, 1298 + const struct dwc3_event_depevt *event, int status) 1299 + { 1300 + struct dwc3_request *req; 1301 + struct dwc3_trb trb; 1302 + unsigned int count; 1303 + unsigned int s_pkt = 0; 1304 + 1305 + do { 1306 + req = next_request(&dep->req_queued); 1307 + if (!req) 1308 + break; 1309 + 1310 + dwc3_trb_to_nat(req->trb, &trb); 1311 + 1312 + if (trb.hwo) { 1313 + dev_err(dwc->dev, "%s's TRB (%p) still owned by HW\n", 1314 + dep->name, req->trb); 1315 + continue; 1316 + } 1317 + count = trb.length; 1318 + 1319 + if (dep->direction) { 1320 + if (count) { 1321 + dev_err(dwc->dev, "incomplete IN transfer %s\n", 1322 + dep->name); 1323 + status = -ECONNRESET; 1324 + } 1325 + } else { 1326 + if (count && (event->status & DEPEVT_STATUS_SHORT)) 1327 + s_pkt = 1; 1328 + } 1329 + 1330 + /* 1331 + * We assume here we will always receive the entire data block 1332 + * which we should receive. Meaning, if we program RX to 1333 + * receive 4K but we receive only 2K, we assume that's all we 1334 + * should receive and we simply bounce the request back to the 1335 + * gadget driver for further processing. 1336 + */ 1337 + req->request.actual += req->request.length - count; 1338 + dwc3_gadget_giveback(dep, req, status); 1339 + if (s_pkt) 1340 + break; 1341 + if ((event->status & DEPEVT_STATUS_LST) && trb.lst) 1342 + break; 1343 + if ((event->status & DEPEVT_STATUS_IOC) && trb.ioc) 1344 + break; 1345 + } while (1); 1346 + 1347 + if ((event->status & DEPEVT_STATUS_IOC) && trb.ioc) 1348 + return 0; 1349 + return 1; 1350 + } 1351 + 1352 + static void dwc3_endpoint_transfer_complete(struct dwc3 *dwc, 1353 + struct dwc3_ep *dep, const struct dwc3_event_depevt *event, 1354 + int start_new) 1355 + { 1356 + unsigned status = 0; 1357 + int clean_busy; 1358 + 1359 + if (event->status & DEPEVT_STATUS_BUSERR) 1360 + status = -ECONNRESET; 1361 + 1362 + clean_busy = dwc3_cleanup_done_reqs(dwc, dep, event, status); 1363 + if (clean_busy) 1364 + dep->flags &= ~DWC3_EP_BUSY; 1365 + } 1366 + 1367 + static void dwc3_gadget_start_isoc(struct dwc3 *dwc, 1368 + struct dwc3_ep *dep, const struct dwc3_event_depevt *event) 1369 + { 1370 + u32 uf; 1371 + 1372 + if (list_empty(&dep->request_list)) { 1373 + dev_vdbg(dwc->dev, "ISOC ep %s run out for requests.\n", 1374 + dep->name); 1375 + return; 1376 + } 1377 + 1378 + if (event->parameters) { 1379 + u32 mask; 1380 + 1381 + mask = ~(dep->interval - 1); 1382 + uf = event->parameters & mask; 1383 + /* 4 micro frames in the future */ 1384 + uf += dep->interval * 4; 1385 + } else { 1386 + uf = 0; 1387 + } 1388 + 1389 + __dwc3_gadget_kick_transfer(dep, uf, 1); 1390 + } 1391 + 1392 + static void dwc3_process_ep_cmd_complete(struct dwc3_ep *dep, 1393 + const struct dwc3_event_depevt *event) 1394 + { 1395 + struct dwc3 *dwc = dep->dwc; 1396 + struct dwc3_event_depevt mod_ev = *event; 1397 + 1398 + /* 1399 + * We were asked to remove one requests. It is possible that this 1400 + * request and a few other were started together and have the same 1401 + * transfer index. Since we stopped the complete endpoint we don't 1402 + * know how many requests were already completed (and not yet) 1403 + * reported and how could be done (later). We purge them all until 1404 + * the end of the list. 1405 + */ 1406 + mod_ev.status = DEPEVT_STATUS_LST; 1407 + dwc3_cleanup_done_reqs(dwc, dep, &mod_ev, -ESHUTDOWN); 1408 + dep->flags &= ~DWC3_EP_BUSY; 1409 + /* pending requets are ignored and are queued on XferNotReady */ 1410 + 1411 + if (dep->flags & DWC3_EP_WILL_SHUTDOWN) { 1412 + while (!list_empty(&dep->req_queued)) { 1413 + struct dwc3_request *req; 1414 + 1415 + req = next_request(&dep->req_queued); 1416 + dwc3_gadget_giveback(dep, req, -ESHUTDOWN); 1417 + } 1418 + dep->flags &= DWC3_EP_WILL_SHUTDOWN; 1419 + } 1420 + } 1421 + 1422 + static void dwc3_ep_cmd_compl(struct dwc3_ep *dep, 1423 + const struct dwc3_event_depevt *event) 1424 + { 1425 + u32 param = event->parameters; 1426 + u32 cmd_type = (param >> 8) & ((1 << 5) - 1); 1427 + 1428 + switch (cmd_type) { 1429 + case DWC3_DEPCMD_ENDTRANSFER: 1430 + dwc3_process_ep_cmd_complete(dep, event); 1431 + break; 1432 + case DWC3_DEPCMD_STARTTRANSFER: 1433 + dep->res_trans_idx = param & 0x7f; 1434 + break; 1435 + default: 1436 + printk(KERN_ERR "%s() unknown /unexpected type: %d\n", 1437 + __func__, cmd_type); 1438 + break; 1439 + }; 1440 + } 1441 + 1442 + static void dwc3_endpoint_interrupt(struct dwc3 *dwc, 1443 + const struct dwc3_event_depevt *event) 1444 + { 1445 + struct dwc3_ep *dep; 1446 + u8 epnum = event->endpoint_number; 1447 + 1448 + dep = dwc->eps[epnum]; 1449 + 1450 + dev_vdbg(dwc->dev, "%s: %s\n", dep->name, 1451 + dwc3_ep_event_string(event->endpoint_event)); 1452 + 1453 + if (epnum == 0 || epnum == 1) { 1454 + dwc3_ep0_interrupt(dwc, event); 1455 + return; 1456 + } 1457 + 1458 + switch (event->endpoint_event) { 1459 + case DWC3_DEPEVT_XFERCOMPLETE: 1460 + if (usb_endpoint_xfer_isoc(dep->desc)) { 1461 + dev_dbg(dwc->dev, "%s is an Isochronous endpoint\n", 1462 + dep->name); 1463 + return; 1464 + } 1465 + 1466 + dwc3_endpoint_transfer_complete(dwc, dep, event, 1); 1467 + break; 1468 + case DWC3_DEPEVT_XFERINPROGRESS: 1469 + if (!usb_endpoint_xfer_isoc(dep->desc)) { 1470 + dev_dbg(dwc->dev, "%s is not an Isochronous endpoint\n", 1471 + dep->name); 1472 + return; 1473 + } 1474 + 1475 + dwc3_endpoint_transfer_complete(dwc, dep, event, 0); 1476 + break; 1477 + case DWC3_DEPEVT_XFERNOTREADY: 1478 + if (usb_endpoint_xfer_isoc(dep->desc)) { 1479 + dwc3_gadget_start_isoc(dwc, dep, event); 1480 + } else { 1481 + int ret; 1482 + 1483 + dev_vdbg(dwc->dev, "%s: reason %s\n", 1484 + dep->name, event->status 1485 + ? "Transfer Active" 1486 + : "Transfer Not Active"); 1487 + 1488 + ret = __dwc3_gadget_kick_transfer(dep, 0, 1); 1489 + if (!ret || ret == -EBUSY) 1490 + return; 1491 + 1492 + dev_dbg(dwc->dev, "%s: failed to kick transfers\n", 1493 + dep->name); 1494 + } 1495 + 1496 + break; 1497 + case DWC3_DEPEVT_RXTXFIFOEVT: 1498 + dev_dbg(dwc->dev, "%s FIFO Overrun\n", dep->name); 1499 + break; 1500 + case DWC3_DEPEVT_STREAMEVT: 1501 + dev_dbg(dwc->dev, "%s Stream Event\n", dep->name); 1502 + break; 1503 + case DWC3_DEPEVT_EPCMDCMPLT: 1504 + dwc3_ep_cmd_compl(dep, event); 1505 + break; 1506 + } 1507 + } 1508 + 1509 + static void dwc3_disconnect_gadget(struct dwc3 *dwc) 1510 + { 1511 + if (dwc->gadget_driver && dwc->gadget_driver->disconnect) { 1512 + spin_unlock(&dwc->lock); 1513 + dwc->gadget_driver->disconnect(&dwc->gadget); 1514 + spin_lock(&dwc->lock); 1515 + } 1516 + } 1517 + 1518 + static void dwc3_stop_active_transfer(struct dwc3 *dwc, u32 epnum) 1519 + { 1520 + struct dwc3_ep *dep; 1521 + struct dwc3_gadget_ep_cmd_params params; 1522 + u32 cmd; 1523 + int ret; 1524 + 1525 + dep = dwc->eps[epnum]; 1526 + 1527 + if (dep->res_trans_idx) { 1528 + cmd = DWC3_DEPCMD_ENDTRANSFER; 1529 + cmd |= DWC3_DEPCMD_HIPRI_FORCERM | DWC3_DEPCMD_CMDIOC; 1530 + cmd |= DWC3_DEPCMD_PARAM(dep->res_trans_idx); 1531 + memset(&params, 0, sizeof(params)); 1532 + ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, &params); 1533 + WARN_ON_ONCE(ret); 1534 + } 1535 + } 1536 + 1537 + static void dwc3_stop_active_transfers(struct dwc3 *dwc) 1538 + { 1539 + u32 epnum; 1540 + 1541 + for (epnum = 2; epnum < DWC3_ENDPOINTS_NUM; epnum++) { 1542 + struct dwc3_ep *dep; 1543 + 1544 + dep = dwc->eps[epnum]; 1545 + if (!(dep->flags & DWC3_EP_ENABLED)) 1546 + continue; 1547 + 1548 + __dwc3_gadget_ep_disable(dep); 1549 + } 1550 + } 1551 + 1552 + static void dwc3_clear_stall_all_ep(struct dwc3 *dwc) 1553 + { 1554 + u32 epnum; 1555 + 1556 + for (epnum = 1; epnum < DWC3_ENDPOINTS_NUM; epnum++) { 1557 + struct dwc3_ep *dep; 1558 + struct dwc3_gadget_ep_cmd_params params; 1559 + int ret; 1560 + 1561 + dep = dwc->eps[epnum]; 1562 + 1563 + if (!(dep->flags & DWC3_EP_STALL)) 1564 + continue; 1565 + 1566 + dep->flags &= ~DWC3_EP_STALL; 1567 + 1568 + memset(&params, 0, sizeof(params)); 1569 + ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, 1570 + DWC3_DEPCMD_CLEARSTALL, &params); 1571 + WARN_ON_ONCE(ret); 1572 + } 1573 + } 1574 + 1575 + static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) 1576 + { 1577 + dev_vdbg(dwc->dev, "%s\n", __func__); 1578 + #if 0 1579 + XXX 1580 + U1/U2 is powersave optimization. Skip it for now. Anyway we need to 1581 + enable it before we can disable it. 1582 + 1583 + reg = dwc3_readl(dwc->regs, DWC3_DCTL); 1584 + reg &= ~DWC3_DCTL_INITU1ENA; 1585 + dwc3_writel(dwc->regs, DWC3_DCTL, reg); 1586 + 1587 + reg &= ~DWC3_DCTL_INITU2ENA; 1588 + dwc3_writel(dwc->regs, DWC3_DCTL, reg); 1589 + #endif 1590 + 1591 + dwc3_stop_active_transfers(dwc); 1592 + dwc3_disconnect_gadget(dwc); 1593 + 1594 + dwc->gadget.speed = USB_SPEED_UNKNOWN; 1595 + } 1596 + 1597 + static void dwc3_gadget_usb3_phy_power(struct dwc3 *dwc, int on) 1598 + { 1599 + u32 reg; 1600 + 1601 + reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); 1602 + 1603 + if (on) 1604 + reg &= ~DWC3_GUSB3PIPECTL_SUSPHY; 1605 + else 1606 + reg |= DWC3_GUSB3PIPECTL_SUSPHY; 1607 + 1608 + dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); 1609 + } 1610 + 1611 + static void dwc3_gadget_usb2_phy_power(struct dwc3 *dwc, int on) 1612 + { 1613 + u32 reg; 1614 + 1615 + reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); 1616 + 1617 + if (on) 1618 + reg &= ~DWC3_GUSB2PHYCFG_SUSPHY; 1619 + else 1620 + reg |= DWC3_GUSB2PHYCFG_SUSPHY; 1621 + 1622 + dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); 1623 + } 1624 + 1625 + static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) 1626 + { 1627 + u32 reg; 1628 + 1629 + dev_vdbg(dwc->dev, "%s\n", __func__); 1630 + 1631 + /* Enable PHYs */ 1632 + dwc3_gadget_usb2_phy_power(dwc, true); 1633 + dwc3_gadget_usb3_phy_power(dwc, true); 1634 + 1635 + if (dwc->gadget.speed != USB_SPEED_UNKNOWN) 1636 + dwc3_disconnect_gadget(dwc); 1637 + 1638 + reg = dwc3_readl(dwc->regs, DWC3_DCTL); 1639 + reg &= ~DWC3_DCTL_TSTCTRL_MASK; 1640 + dwc3_writel(dwc->regs, DWC3_DCTL, reg); 1641 + 1642 + dwc3_stop_active_transfers(dwc); 1643 + dwc3_clear_stall_all_ep(dwc); 1644 + 1645 + /* Reset device address to zero */ 1646 + reg = dwc3_readl(dwc->regs, DWC3_DCFG); 1647 + reg &= ~(DWC3_DCFG_DEVADDR_MASK); 1648 + dwc3_writel(dwc->regs, DWC3_DCFG, reg); 1649 + 1650 + /* 1651 + * Wait for RxFifo to drain 1652 + * 1653 + * REVISIT probably shouldn't wait forever. 1654 + * In case Hardware ends up in a screwed up 1655 + * case, we error out, notify the user and, 1656 + * maybe, WARN() or BUG() but leave the rest 1657 + * of the kernel working fine. 1658 + * 1659 + * REVISIT the below is rather CPU intensive, 1660 + * maybe we should read and if it doesn't work 1661 + * sleep (not busy wait) for a few useconds. 1662 + * 1663 + * REVISIT why wait until the RXFIFO is empty anyway? 1664 + */ 1665 + while (!(dwc3_readl(dwc->regs, DWC3_DSTS) 1666 + & DWC3_DSTS_RXFIFOEMPTY)) 1667 + cpu_relax(); 1668 + } 1669 + 1670 + static void dwc3_update_ram_clk_sel(struct dwc3 *dwc, u32 speed) 1671 + { 1672 + u32 reg; 1673 + u32 usb30_clock = DWC3_GCTL_CLK_BUS; 1674 + 1675 + /* 1676 + * We change the clock only at SS but I dunno why I would want to do 1677 + * this. Maybe it becomes part of the power saving plan. 1678 + */ 1679 + 1680 + if (speed != DWC3_DSTS_SUPERSPEED) 1681 + return; 1682 + 1683 + /* 1684 + * RAMClkSel is reset to 0 after USB reset, so it must be reprogrammed 1685 + * each time on Connect Done. 1686 + */ 1687 + if (!usb30_clock) 1688 + return; 1689 + 1690 + reg = dwc3_readl(dwc->regs, DWC3_GCTL); 1691 + reg |= DWC3_GCTL_RAMCLKSEL(usb30_clock); 1692 + dwc3_writel(dwc->regs, DWC3_GCTL, reg); 1693 + } 1694 + 1695 + static void dwc3_gadget_disable_phy(struct dwc3 *dwc, u8 speed) 1696 + { 1697 + switch (speed) { 1698 + case USB_SPEED_SUPER: 1699 + dwc3_gadget_usb2_phy_power(dwc, false); 1700 + break; 1701 + case USB_SPEED_HIGH: 1702 + case USB_SPEED_FULL: 1703 + case USB_SPEED_LOW: 1704 + dwc3_gadget_usb3_phy_power(dwc, false); 1705 + break; 1706 + } 1707 + } 1708 + 1709 + static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) 1710 + { 1711 + struct dwc3_gadget_ep_cmd_params params; 1712 + struct dwc3_ep *dep; 1713 + int ret; 1714 + u32 reg; 1715 + u8 speed; 1716 + 1717 + dev_vdbg(dwc->dev, "%s\n", __func__); 1718 + 1719 + memset(&params, 0x00, sizeof(params)); 1720 + 1721 + dwc->ep0state = EP0_IDLE; 1722 + reg = dwc3_readl(dwc->regs, DWC3_DSTS); 1723 + speed = reg & DWC3_DSTS_CONNECTSPD; 1724 + dwc->speed = speed; 1725 + 1726 + dwc3_update_ram_clk_sel(dwc, speed); 1727 + 1728 + switch (speed) { 1729 + case DWC3_DCFG_SUPERSPEED: 1730 + dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512); 1731 + dwc->gadget.ep0->maxpacket = 512; 1732 + dwc->gadget.speed = USB_SPEED_SUPER; 1733 + break; 1734 + case DWC3_DCFG_HIGHSPEED: 1735 + dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64); 1736 + dwc->gadget.ep0->maxpacket = 64; 1737 + dwc->gadget.speed = USB_SPEED_HIGH; 1738 + break; 1739 + case DWC3_DCFG_FULLSPEED2: 1740 + case DWC3_DCFG_FULLSPEED1: 1741 + dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(64); 1742 + dwc->gadget.ep0->maxpacket = 64; 1743 + dwc->gadget.speed = USB_SPEED_FULL; 1744 + break; 1745 + case DWC3_DCFG_LOWSPEED: 1746 + dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(8); 1747 + dwc->gadget.ep0->maxpacket = 8; 1748 + dwc->gadget.speed = USB_SPEED_LOW; 1749 + break; 1750 + } 1751 + 1752 + /* Disable unneded PHY */ 1753 + dwc3_gadget_disable_phy(dwc, dwc->gadget.speed); 1754 + 1755 + dep = dwc->eps[0]; 1756 + ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc); 1757 + if (ret) { 1758 + dev_err(dwc->dev, "failed to enable %s\n", dep->name); 1759 + return; 1760 + } 1761 + 1762 + dep = dwc->eps[1]; 1763 + ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc); 1764 + if (ret) { 1765 + dev_err(dwc->dev, "failed to enable %s\n", dep->name); 1766 + return; 1767 + } 1768 + 1769 + /* 1770 + * Configure PHY via GUSB3PIPECTLn if required. 1771 + * 1772 + * Update GTXFIFOSIZn 1773 + * 1774 + * In both cases reset values should be sufficient. 1775 + */ 1776 + } 1777 + 1778 + static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc) 1779 + { 1780 + dev_vdbg(dwc->dev, "%s\n", __func__); 1781 + 1782 + /* 1783 + * TODO take core out of low power mode when that's 1784 + * implemented. 1785 + */ 1786 + 1787 + dwc->gadget_driver->resume(&dwc->gadget); 1788 + } 1789 + 1790 + static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc, 1791 + unsigned int evtinfo) 1792 + { 1793 + dev_vdbg(dwc->dev, "%s\n", __func__); 1794 + 1795 + /* The fith bit says SuperSpeed yes or no. */ 1796 + dwc->link_state = evtinfo & DWC3_LINK_STATE_MASK; 1797 + } 1798 + 1799 + static void dwc3_gadget_interrupt(struct dwc3 *dwc, 1800 + const struct dwc3_event_devt *event) 1801 + { 1802 + switch (event->type) { 1803 + case DWC3_DEVICE_EVENT_DISCONNECT: 1804 + dwc3_gadget_disconnect_interrupt(dwc); 1805 + break; 1806 + case DWC3_DEVICE_EVENT_RESET: 1807 + dwc3_gadget_reset_interrupt(dwc); 1808 + break; 1809 + case DWC3_DEVICE_EVENT_CONNECT_DONE: 1810 + dwc3_gadget_conndone_interrupt(dwc); 1811 + break; 1812 + case DWC3_DEVICE_EVENT_WAKEUP: 1813 + dwc3_gadget_wakeup_interrupt(dwc); 1814 + break; 1815 + case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE: 1816 + dwc3_gadget_linksts_change_interrupt(dwc, event->event_info); 1817 + break; 1818 + case DWC3_DEVICE_EVENT_EOPF: 1819 + dev_vdbg(dwc->dev, "End of Periodic Frame\n"); 1820 + break; 1821 + case DWC3_DEVICE_EVENT_SOF: 1822 + dev_vdbg(dwc->dev, "Start of Periodic Frame\n"); 1823 + break; 1824 + case DWC3_DEVICE_EVENT_ERRATIC_ERROR: 1825 + dev_vdbg(dwc->dev, "Erratic Error\n"); 1826 + break; 1827 + case DWC3_DEVICE_EVENT_CMD_CMPL: 1828 + dev_vdbg(dwc->dev, "Command Complete\n"); 1829 + break; 1830 + case DWC3_DEVICE_EVENT_OVERFLOW: 1831 + dev_vdbg(dwc->dev, "Overflow\n"); 1832 + break; 1833 + default: 1834 + dev_dbg(dwc->dev, "UNKNOWN IRQ %d\n", event->type); 1835 + } 1836 + } 1837 + 1838 + static void dwc3_process_event_entry(struct dwc3 *dwc, 1839 + const union dwc3_event *event) 1840 + { 1841 + /* Endpoint IRQ, handle it and return early */ 1842 + if (event->type.is_devspec == 0) { 1843 + /* depevt */ 1844 + return dwc3_endpoint_interrupt(dwc, &event->depevt); 1845 + } 1846 + 1847 + switch (event->type.type) { 1848 + case DWC3_EVENT_TYPE_DEV: 1849 + dwc3_gadget_interrupt(dwc, &event->devt); 1850 + break; 1851 + /* REVISIT what to do with Carkit and I2C events ? */ 1852 + default: 1853 + dev_err(dwc->dev, "UNKNOWN IRQ type %d\n", event->raw); 1854 + } 1855 + } 1856 + 1857 + static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc, u32 buf) 1858 + { 1859 + struct dwc3_event_buffer *evt; 1860 + int left; 1861 + u32 count; 1862 + 1863 + count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(buf)); 1864 + count &= DWC3_GEVNTCOUNT_MASK; 1865 + if (!count) 1866 + return IRQ_NONE; 1867 + 1868 + evt = dwc->ev_buffs[buf]; 1869 + left = count; 1870 + 1871 + while (left > 0) { 1872 + union dwc3_event event; 1873 + 1874 + memcpy(&event.raw, (evt->buf + evt->lpos), sizeof(event.raw)); 1875 + dwc3_process_event_entry(dwc, &event); 1876 + /* 1877 + * XXX we wrap around correctly to the next entry as almost all 1878 + * entries are 4 bytes in size. There is one entry which has 12 1879 + * bytes which is a regular entry followed by 8 bytes data. ATM 1880 + * I don't know how things are organized if were get next to the 1881 + * a boundary so I worry about that once we try to handle that. 1882 + */ 1883 + evt->lpos = (evt->lpos + 4) % DWC3_EVENT_BUFFERS_SIZE; 1884 + left -= 4; 1885 + 1886 + dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(buf), 4); 1887 + } 1888 + 1889 + return IRQ_HANDLED; 1890 + } 1891 + 1892 + static irqreturn_t dwc3_interrupt(int irq, void *_dwc) 1893 + { 1894 + struct dwc3 *dwc = _dwc; 1895 + int i; 1896 + irqreturn_t ret = IRQ_NONE; 1897 + 1898 + spin_lock(&dwc->lock); 1899 + 1900 + for (i = 0; i < DWC3_EVENT_BUFFERS_NUM; i++) { 1901 + irqreturn_t status; 1902 + 1903 + status = dwc3_process_event_buf(dwc, i); 1904 + if (status == IRQ_HANDLED) 1905 + ret = status; 1906 + } 1907 + 1908 + spin_unlock(&dwc->lock); 1909 + 1910 + return ret; 1911 + } 1912 + 1913 + /** 1914 + * dwc3_gadget_init - Initializes gadget related registers 1915 + * @dwc: Pointer to out controller context structure 1916 + * 1917 + * Returns 0 on success otherwise negative errno. 1918 + */ 1919 + int __devinit dwc3_gadget_init(struct dwc3 *dwc) 1920 + { 1921 + u32 reg; 1922 + int ret; 1923 + int irq; 1924 + 1925 + dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req), 1926 + &dwc->ctrl_req_addr, GFP_KERNEL); 1927 + if (!dwc->ctrl_req) { 1928 + dev_err(dwc->dev, "failed to allocate ctrl request\n"); 1929 + ret = -ENOMEM; 1930 + goto err0; 1931 + } 1932 + 1933 + dwc->ep0_trb = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ep0_trb), 1934 + &dwc->ep0_trb_addr, GFP_KERNEL); 1935 + if (!dwc->ep0_trb) { 1936 + dev_err(dwc->dev, "failed to allocate ep0 trb\n"); 1937 + ret = -ENOMEM; 1938 + goto err1; 1939 + } 1940 + 1941 + dwc->setup_buf = dma_alloc_coherent(dwc->dev, 1942 + sizeof(*dwc->setup_buf) * 2, 1943 + &dwc->setup_buf_addr, GFP_KERNEL); 1944 + if (!dwc->setup_buf) { 1945 + dev_err(dwc->dev, "failed to allocate setup buffer\n"); 1946 + ret = -ENOMEM; 1947 + goto err2; 1948 + } 1949 + 1950 + dev_set_name(&dwc->gadget.dev, "gadget"); 1951 + 1952 + dwc->gadget.ops = &dwc3_gadget_ops; 1953 + dwc->gadget.is_dualspeed = true; 1954 + dwc->gadget.speed = USB_SPEED_UNKNOWN; 1955 + dwc->gadget.dev.parent = dwc->dev; 1956 + 1957 + dma_set_coherent_mask(&dwc->gadget.dev, dwc->dev->coherent_dma_mask); 1958 + 1959 + dwc->gadget.dev.dma_parms = dwc->dev->dma_parms; 1960 + dwc->gadget.dev.dma_mask = dwc->dev->dma_mask; 1961 + dwc->gadget.dev.release = dwc3_gadget_release; 1962 + dwc->gadget.name = "dwc3-gadget"; 1963 + 1964 + /* 1965 + * REVISIT: Here we should clear all pending IRQs to be 1966 + * sure we're starting from a well known location. 1967 + */ 1968 + 1969 + ret = dwc3_gadget_init_endpoints(dwc); 1970 + if (ret) 1971 + goto err3; 1972 + 1973 + irq = platform_get_irq(to_platform_device(dwc->dev), 0); 1974 + 1975 + ret = request_irq(irq, dwc3_interrupt, IRQF_SHARED, 1976 + "dwc3", dwc); 1977 + if (ret) { 1978 + dev_err(dwc->dev, "failed to request irq #%d --> %d\n", 1979 + irq, ret); 1980 + goto err4; 1981 + } 1982 + 1983 + /* Enable all but Start and End of Frame IRQs */ 1984 + reg = (DWC3_DEVTEN_VNDRDEVTSTRCVEDEN | 1985 + DWC3_DEVTEN_EVNTOVERFLOWEN | 1986 + DWC3_DEVTEN_CMDCMPLTEN | 1987 + DWC3_DEVTEN_ERRTICERREN | 1988 + DWC3_DEVTEN_WKUPEVTEN | 1989 + DWC3_DEVTEN_ULSTCNGEN | 1990 + DWC3_DEVTEN_CONNECTDONEEN | 1991 + DWC3_DEVTEN_USBRSTEN | 1992 + DWC3_DEVTEN_DISCONNEVTEN); 1993 + dwc3_writel(dwc->regs, DWC3_DEVTEN, reg); 1994 + 1995 + ret = device_register(&dwc->gadget.dev); 1996 + if (ret) { 1997 + dev_err(dwc->dev, "failed to register gadget device\n"); 1998 + put_device(&dwc->gadget.dev); 1999 + goto err5; 2000 + } 2001 + 2002 + ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget); 2003 + if (ret) { 2004 + dev_err(dwc->dev, "failed to register udc\n"); 2005 + goto err6; 2006 + } 2007 + 2008 + return 0; 2009 + 2010 + err6: 2011 + device_unregister(&dwc->gadget.dev); 2012 + 2013 + err5: 2014 + dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00); 2015 + free_irq(irq, dwc); 2016 + 2017 + err4: 2018 + dwc3_gadget_free_endpoints(dwc); 2019 + 2020 + err3: 2021 + dma_free_coherent(dwc->dev, sizeof(*dwc->setup_buf) * 2, 2022 + dwc->setup_buf, dwc->setup_buf_addr); 2023 + 2024 + err2: 2025 + dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb), 2026 + dwc->ep0_trb, dwc->ep0_trb_addr); 2027 + 2028 + err1: 2029 + dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req), 2030 + dwc->ctrl_req, dwc->ctrl_req_addr); 2031 + 2032 + err0: 2033 + return ret; 2034 + } 2035 + 2036 + void dwc3_gadget_exit(struct dwc3 *dwc) 2037 + { 2038 + int irq; 2039 + int i; 2040 + 2041 + usb_del_gadget_udc(&dwc->gadget); 2042 + irq = platform_get_irq(to_platform_device(dwc->dev), 0); 2043 + 2044 + dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00); 2045 + free_irq(irq, dwc); 2046 + 2047 + for (i = 0; i < ARRAY_SIZE(dwc->eps); i++) 2048 + __dwc3_gadget_ep_disable(dwc->eps[i]); 2049 + 2050 + dwc3_gadget_free_endpoints(dwc); 2051 + 2052 + dma_free_coherent(dwc->dev, sizeof(*dwc->setup_buf) * 2, 2053 + dwc->setup_buf, dwc->setup_buf_addr); 2054 + 2055 + dma_free_coherent(dwc->dev, sizeof(*dwc->ep0_trb), 2056 + dwc->ep0_trb, dwc->ep0_trb_addr); 2057 + 2058 + dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req), 2059 + dwc->ctrl_req, dwc->ctrl_req_addr); 2060 + 2061 + device_unregister(&dwc->gadget.dev); 2062 + }
+297
drivers/usb/dwc3/gadget.h
··· 1 + /** 2 + * gadget.h - DesignWare USB3 DRD Gadget Header 3 + * 4 + * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com 5 + * All rights reserved. 6 + * 7 + * Authors: Felipe Balbi <balbi@ti.com>, 8 + * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 9 + * 10 + * Redistribution and use in source and binary forms, with or without 11 + * modification, are permitted provided that the following conditions 12 + * are met: 13 + * 1. Redistributions of source code must retain the above copyright 14 + * notice, this list of conditions, and the following disclaimer, 15 + * without modification. 16 + * 2. Redistributions in binary form must reproduce the above copyright 17 + * notice, this list of conditions and the following disclaimer in the 18 + * documentation and/or other materials provided with the distribution. 19 + * 3. The names of the above-listed copyright holders may not be used 20 + * to endorse or promote products derived from this software without 21 + * specific prior written permission. 22 + * 23 + * ALTERNATIVELY, this software may be distributed under the terms of the 24 + * GNU General Public License ("GPL") version 2, as published by the Free 25 + * Software Foundation. 26 + * 27 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 28 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 29 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 31 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 32 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 33 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 34 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 35 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 + */ 39 + 40 + #ifndef __DRIVERS_USB_DWC3_GADGET_H 41 + #define __DRIVERS_USB_DWC3_GADGET_H 42 + 43 + #include <linux/list.h> 44 + #include <linux/usb/gadget.h> 45 + #include "io.h" 46 + 47 + struct dwc3; 48 + #define to_dwc3_ep(ep) (container_of(ep, struct dwc3_ep, endpoint)) 49 + #define gadget_to_dwc(g) (container_of(g, struct dwc3, gadget)) 50 + 51 + /** 52 + * struct dwc3_gadget_ep_depcfg_param1 - DEPCMDPAR0 for DEPCFG command 53 + * @interrupt_number: self-explanatory 54 + * @reserved7_5: set to zero 55 + * @xfer_complete_enable: event generated when transfer completed 56 + * @xfer_in_progress_enable: event generated when transfer in progress 57 + * @xfer_not_ready_enable: event generated when transfer not read 58 + * @fifo_error_enable: generates events when FIFO Underrun (IN eps) 59 + * or FIFO Overrun (OUT) eps 60 + * @reserved_12: set to zero 61 + * @stream_event_enable: event generated on stream 62 + * @reserved14_15: set to zero 63 + * @binterval_m1: bInterval minus 1 64 + * @stream_capable: this EP is capable of handling streams 65 + * @ep_number: self-explanatory 66 + * @bulk_based: Set to ‘1’ if this isochronous endpoint represents a bulk 67 + * data stream that ignores the relationship of bus time to the 68 + * intervals programmed in TRBs. 69 + * @fifo_based: Set to ‘1’ if this isochronous endpoint represents a 70 + * FIFO-based data stream where TRBs have fixed values and are never 71 + * written back by the core. 72 + */ 73 + struct dwc3_gadget_ep_depcfg_param1 { 74 + u32 interrupt_number:5; 75 + u32 reserved7_5:3; /* set to zero */ 76 + u32 xfer_complete_enable:1; 77 + u32 xfer_in_progress_enable:1; 78 + u32 xfer_not_ready_enable:1; 79 + u32 fifo_error_enable:1; /* IN-underrun, OUT-overrun */ 80 + u32 reserved12:1; /* set to zero */ 81 + u32 stream_event_enable:1; 82 + u32 reserved14_15:2; 83 + u32 binterval_m1:8; /* bInterval minus 1 */ 84 + u32 stream_capable:1; 85 + u32 ep_number:5; 86 + u32 bulk_based:1; 87 + u32 fifo_based:1; 88 + } __packed; 89 + 90 + /** 91 + * struct dwc3_gadget_ep_depcfg_param0 - Parameter 0 for DEPCFG 92 + * @reserved0: set to zero 93 + * @ep_type: Endpoint Type (control, bulk, iso, interrupt) 94 + * @max_packet_size: max packet size in bytes 95 + * @reserved16_14: set to zero 96 + * @fifo_number: self-explanatory 97 + * @burst_size: burst size minus 1 98 + * @data_sequence_number: Must be 0 when an endpoint is initially configured 99 + * May be non-zero when an endpoint is configured after a power transition 100 + * that requires a save/restore. 101 + * @ignore_sequence_number: Set to ‘1’ to avoid resetting the sequence 102 + * number. This setting is used by software to modify the DEPEVTEN 103 + * event enable bits without modifying other endpoint settings. 104 + */ 105 + struct dwc3_gadget_ep_depcfg_param0 { 106 + u32 reserved0:1; 107 + u32 ep_type:2; 108 + u32 max_packet_size:11; 109 + u32 reserved16_14:3; 110 + u32 fifo_number:5; 111 + u32 burst_size:4; 112 + u32 data_sequence_number:5; 113 + u32 ignore_sequence_number:1; 114 + } __packed; 115 + 116 + /** 117 + * struct dwc3_gadget_ep_depxfercfg_param0 - Parameter 0 of DEPXFERCFG 118 + * @number_xfer_resources: Defines the number of Transfer Resources allocated 119 + * to this endpoint. This field must be set to 1. 120 + * @reserved16_31: set to zero; 121 + */ 122 + struct dwc3_gadget_ep_depxfercfg_param0 { 123 + u32 number_xfer_resources:16; 124 + u32 reserved16_31:16; 125 + } __packed; 126 + 127 + /** 128 + * struct dwc3_gadget_ep_depstrtxfer_param1 - Parameter 1 of DEPSTRTXFER 129 + * @transfer_desc_addr_low: Indicates the lower 32 bits of the external 130 + * memory's start address for the transfer descriptor. Because TRBs 131 + * must be aligned to a 16-byte boundary, the lower 4 bits of this 132 + * address must be 0. 133 + */ 134 + struct dwc3_gadget_ep_depstrtxfer_param1 { 135 + u32 transfer_desc_addr_low; 136 + } __packed; 137 + 138 + /** 139 + * struct dwc3_gadget_ep_depstrtxfer_param1 - Parameter 1 of DEPSTRTXFER 140 + * @transfer_desc_addr_high: Indicates the higher 32 bits of the external 141 + * memory’s start address for the transfer descriptor. 142 + */ 143 + struct dwc3_gadget_ep_depstrtxfer_param0 { 144 + u32 transfer_desc_addr_high; 145 + } __packed; 146 + 147 + struct dwc3_gadget_ep_cmd_params { 148 + union { 149 + u32 raw; 150 + } param2; 151 + 152 + union { 153 + u32 raw; 154 + struct dwc3_gadget_ep_depcfg_param1 depcfg; 155 + struct dwc3_gadget_ep_depstrtxfer_param1 depstrtxfer; 156 + } param1; 157 + 158 + union { 159 + u32 raw; 160 + struct dwc3_gadget_ep_depcfg_param0 depcfg; 161 + struct dwc3_gadget_ep_depxfercfg_param0 depxfercfg; 162 + struct dwc3_gadget_ep_depstrtxfer_param0 depstrtxfer; 163 + } param0; 164 + } __packed; 165 + 166 + /* -------------------------------------------------------------------------- */ 167 + 168 + struct dwc3_request { 169 + struct usb_request request; 170 + struct list_head list; 171 + struct dwc3_ep *dep; 172 + 173 + u8 epnum; 174 + struct dwc3_trb_hw *trb; 175 + dma_addr_t trb_dma; 176 + 177 + unsigned direction:1; 178 + unsigned mapped:1; 179 + unsigned queued:1; 180 + }; 181 + #define to_dwc3_request(r) (container_of(r, struct dwc3_request, request)) 182 + 183 + static inline struct dwc3_request *next_request(struct list_head *list) 184 + { 185 + if (list_empty(list)) 186 + return NULL; 187 + 188 + return list_first_entry(list, struct dwc3_request, list); 189 + } 190 + 191 + static inline void dwc3_gadget_move_request_queued(struct dwc3_request *req) 192 + { 193 + struct dwc3_ep *dep = req->dep; 194 + 195 + req->queued = true; 196 + list_move_tail(&req->list, &dep->req_queued); 197 + } 198 + 199 + #if defined(CONFIG_USB_GADGET_DWC3) || defined(CONFIG_USB_GADGET_DWC3_MODULE) 200 + int dwc3_gadget_init(struct dwc3 *dwc); 201 + void dwc3_gadget_exit(struct dwc3 *dwc); 202 + #else 203 + static inline int dwc3_gadget_init(struct dwc3 *dwc) { return 0; } 204 + static inline void dwc3_gadget_exit(struct dwc3 *dwc) { } 205 + static inline int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep, 206 + unsigned cmd, struct dwc3_gadget_ep_cmd_params *params) 207 + { 208 + return 0; 209 + } 210 + #endif 211 + 212 + void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req, 213 + int status); 214 + 215 + void dwc3_ep0_interrupt(struct dwc3 *dwc, const struct dwc3_event_depevt *event); 216 + void dwc3_ep0_out_start(struct dwc3 *dwc); 217 + int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request, 218 + gfp_t gfp_flags); 219 + int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value); 220 + int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep, 221 + unsigned cmd, struct dwc3_gadget_ep_cmd_params *params); 222 + void dwc3_map_buffer_to_dma(struct dwc3_request *req); 223 + void dwc3_unmap_buffer_from_dma(struct dwc3_request *req); 224 + 225 + /** 226 + * dwc3_gadget_ep_get_transfer_index - Gets transfer index from HW 227 + * @dwc: DesignWare USB3 Pointer 228 + * @number: DWC endpoint number 229 + * 230 + * Caller should take care of locking 231 + */ 232 + static inline u32 dwc3_gadget_ep_get_transfer_index(struct dwc3 *dwc, u8 number) 233 + { 234 + u32 res_id; 235 + 236 + res_id = dwc3_readl(dwc->regs, DWC3_DEPCMD(number)); 237 + 238 + return DWC3_DEPCMD_GET_RSC_IDX(res_id); 239 + } 240 + 241 + /** 242 + * dwc3_gadget_event_string - returns event name 243 + * @event: the event code 244 + */ 245 + static inline const char *dwc3_gadget_event_string(u8 event) 246 + { 247 + switch (event) { 248 + case DWC3_DEVICE_EVENT_DISCONNECT: 249 + return "Disconnect"; 250 + case DWC3_DEVICE_EVENT_RESET: 251 + return "Reset"; 252 + case DWC3_DEVICE_EVENT_CONNECT_DONE: 253 + return "Connection Done"; 254 + case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE: 255 + return "Link Status Change"; 256 + case DWC3_DEVICE_EVENT_WAKEUP: 257 + return "WakeUp"; 258 + case DWC3_DEVICE_EVENT_EOPF: 259 + return "End-Of-Frame"; 260 + case DWC3_DEVICE_EVENT_SOF: 261 + return "Start-Of-Frame"; 262 + case DWC3_DEVICE_EVENT_ERRATIC_ERROR: 263 + return "Erratic Error"; 264 + case DWC3_DEVICE_EVENT_CMD_CMPL: 265 + return "Command Complete"; 266 + case DWC3_DEVICE_EVENT_OVERFLOW: 267 + return "Overflow"; 268 + } 269 + 270 + return "UNKNOWN"; 271 + } 272 + 273 + /** 274 + * dwc3_ep_event_string - returns event name 275 + * @event: then event code 276 + */ 277 + static inline const char *dwc3_ep_event_string(u8 event) 278 + { 279 + switch (event) { 280 + case DWC3_DEPEVT_XFERCOMPLETE: 281 + return "Transfer Complete"; 282 + case DWC3_DEPEVT_XFERINPROGRESS: 283 + return "Transfer In-Progress"; 284 + case DWC3_DEPEVT_XFERNOTREADY: 285 + return "Transfer Not Ready"; 286 + case DWC3_DEPEVT_RXTXFIFOEVT: 287 + return "FIFO"; 288 + case DWC3_DEPEVT_STREAMEVT: 289 + return "Stream"; 290 + case DWC3_DEPEVT_EPCMDCMPLT: 291 + return "Endpoint Command Complete"; 292 + } 293 + 294 + return "UNKNOWN"; 295 + } 296 + 297 + #endif /* __DRIVERS_USB_DWC3_GADGET_H */
+55
drivers/usb/dwc3/io.h
··· 1 + /** 2 + * io.h - DesignWare USB3 DRD IO Header 3 + * 4 + * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com 5 + * All rights reserved. 6 + * 7 + * Authors: Felipe Balbi <balbi@ti.com>, 8 + * Sebastian Andrzej Siewior <bigeasy@linutronix.de> 9 + * 10 + * Redistribution and use in source and binary forms, with or without 11 + * modification, are permitted provided that the following conditions 12 + * are met: 13 + * 1. Redistributions of source code must retain the above copyright 14 + * notice, this list of conditions, and the following disclaimer, 15 + * without modification. 16 + * 2. Redistributions in binary form must reproduce the above copyright 17 + * notice, this list of conditions and the following disclaimer in the 18 + * documentation and/or other materials provided with the distribution. 19 + * 3. The names of the above-listed copyright holders may not be used 20 + * to endorse or promote products derived from this software without 21 + * specific prior written permission. 22 + * 23 + * ALTERNATIVELY, this software may be distributed under the terms of the 24 + * GNU General Public License ("GPL") version 2, as published by the Free 25 + * Software Foundation. 26 + * 27 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 28 + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 29 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 31 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 32 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 33 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 34 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 35 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 36 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 37 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 + */ 39 + 40 + #ifndef __DRIVERS_USB_DWC3_IO_H 41 + #define __DRIVERS_USB_DWC3_IO_H 42 + 43 + #include <asm/io.h> 44 + 45 + static inline u32 dwc3_readl(void __iomem *base, u32 offset) 46 + { 47 + return readl(base + offset); 48 + } 49 + 50 + static inline void dwc3_writel(void __iomem *base, u32 offset, u32 value) 51 + { 52 + writel(value, base + offset); 53 + } 54 + 55 + #endif /* __DRIVERS_USB_DWC3_IO_H */
+16 -5
drivers/usb/gadget/Kconfig
··· 255 255 integrated into the S3C64XX series SoC. 256 256 257 257 config USB_IMX 258 - tristate "Freescale IMX USB Peripheral Controller" 259 - depends on ARCH_MX1 258 + tristate "Freescale i.MX1 USB Peripheral Controller" 259 + depends on ARCH_MXC 260 260 help 261 - Freescale's IMX series include an integrated full speed 262 - USB 1.1 device controller. The controller in the IMX series 263 - is register-compatible. 261 + Freescale's i.MX1 includes an integrated full speed 262 + USB 1.1 device controller. 264 263 265 264 It has Six fixed-function endpoints, as well as endpoint 266 265 zero (for control transfers). ··· 301 302 help 302 303 PXA9xx Processor series include a high speed USB2.0 device 303 304 controller, which support high speed and full speed USB peripheral. 305 + 306 + config USB_GADGET_DWC3 307 + tristate "DesignWare USB3.0 (DRD) Controller" 308 + depends on USB_DWC3 309 + select USB_GADGET_DUALSPEED 310 + select USB_GADGET_SUPERSPEED 311 + help 312 + DesignWare USB3.0 controller is a SuperSpeed USB3.0 Controller 313 + which can be configured for peripheral-only, host-only, hub-only 314 + and Dual-Role operation. This Controller was first integrated into 315 + the OMAP5 series of processors. More information about the OMAP5 316 + version of this controller, refer to http://www.ti.com/omap5. 304 317 305 318 # 306 319 # Controllers available in both integrated and discrete versions
+1 -1
drivers/usb/gadget/amd5536udc.c
··· 354 354 writel(tmp, &dev->ep[ep->num].regs->ctl); 355 355 356 356 /* set max packet size */ 357 - maxpacket = le16_to_cpu(desc->wMaxPacketSize); 357 + maxpacket = usb_endpoint_maxp(desc); 358 358 tmp = readl(&dev->ep[ep->num].regs->bufout_maxpkt); 359 359 tmp = AMD_ADDBITS(tmp, maxpacket, UDC_EP_MAX_PKT_SIZE); 360 360 ep->ep.maxpacket = maxpacket;
+1 -1
drivers/usb/gadget/at91_udc.c
··· 487 487 || !desc || ep->desc 488 488 || _ep->name == ep0name 489 489 || desc->bDescriptorType != USB_DT_ENDPOINT 490 - || (maxpacket = le16_to_cpu(desc->wMaxPacketSize)) == 0 490 + || (maxpacket = usb_endpoint_maxp(desc)) == 0 491 491 || maxpacket > ep->maxpacket) { 492 492 DBG("bad ep or descriptor\n"); 493 493 return -EINVAL;
+2 -2
drivers/usb/gadget/atmel_usba_udc.c
··· 527 527 528 528 DBG(DBG_GADGET, "%s: ep_enable: desc=%p\n", ep->ep.name, desc); 529 529 530 - maxpacket = le16_to_cpu(desc->wMaxPacketSize) & 0x7ff; 530 + maxpacket = usb_endpoint_maxp(desc) & 0x7ff; 531 531 532 532 if (((desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) != ep->index) 533 533 || ep->index == 0 ··· 571 571 * Bits 11:12 specify number of _additional_ 572 572 * transactions per microframe. 573 573 */ 574 - nr_trans = ((le16_to_cpu(desc->wMaxPacketSize) >> 11) & 3) + 1; 574 + nr_trans = ((usb_endpoint_maxp(desc) >> 11) & 3) + 1; 575 575 if (nr_trans > 3) 576 576 return -EINVAL; 577 577
+1 -1
drivers/usb/gadget/ci13xxx_udc.c
··· 2101 2101 mEp->num = usb_endpoint_num(desc); 2102 2102 mEp->type = usb_endpoint_type(desc); 2103 2103 2104 - mEp->ep.maxpacket = __constant_le16_to_cpu(desc->wMaxPacketSize); 2104 + mEp->ep.maxpacket = usb_endpoint_maxp(desc); 2105 2105 2106 2106 dbg_event(_usb_addr(mEp), "ENABLE", 0); 2107 2107
+1 -1
drivers/usb/gadget/composite.c
··· 164 164 165 165 ep_found: 166 166 /* commit results */ 167 - _ep->maxpacket = le16_to_cpu(chosen_desc->wMaxPacketSize); 167 + _ep->maxpacket = usb_endpoint_maxp(chosen_desc); 168 168 _ep->desc = chosen_desc; 169 169 _ep->comp_desc = NULL; 170 170 _ep->maxburst = 0;
+2 -2
drivers/usb/gadget/dummy_hcd.c
··· 439 439 * maximum packet size. 440 440 * For SS devices the wMaxPacketSize is limited by 1024. 441 441 */ 442 - max = le16_to_cpu(desc->wMaxPacketSize) & 0x7ff; 442 + max = usb_endpoint_maxp(desc) & 0x7ff; 443 443 444 444 /* drivers must not request bad settings, since lower levels 445 445 * (hardware or its drivers) may not check. some endpoints ··· 1277 1277 int tmp; 1278 1278 1279 1279 /* high bandwidth mode */ 1280 - tmp = le16_to_cpu(ep->desc->wMaxPacketSize); 1280 + tmp = usb_endpoint_maxp(ep->desc); 1281 1281 tmp = (tmp >> 11) & 0x03; 1282 1282 tmp *= 8 /* applies to entire frame */; 1283 1283 limit += limit * tmp;
+1 -1
drivers/usb/gadget/epautoconf.c
··· 158 158 * where it's an output parameter representing the full speed limit. 159 159 * the usb spec fixes high speed bulk maxpacket at 512 bytes. 160 160 */ 161 - max = 0x7ff & le16_to_cpu(desc->wMaxPacketSize); 161 + max = 0x7ff & usb_endpoint_maxp(desc); 162 162 switch (type) { 163 163 case USB_ENDPOINT_XFER_INT: 164 164 /* INT: limit 64 bytes full speed, 1024 high/super speed */
+1 -2
drivers/usb/gadget/f_mass_storage.c
··· 2401 2401 goto reset; 2402 2402 fsg->bulk_out->driver_data = common; 2403 2403 fsg->bulk_out_enabled = 1; 2404 - common->bulk_out_maxpacket = 2405 - le16_to_cpu(fsg->bulk_out->desc->wMaxPacketSize); 2404 + common->bulk_out_maxpacket = usb_endpoint_maxp(fsg->bulk_out->desc); 2406 2405 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); 2407 2406 2408 2407 /* Allocate the requests */
+1 -1
drivers/usb/gadget/file_storage.c
··· 2801 2801 if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0) 2802 2802 goto reset; 2803 2803 fsg->bulk_out_enabled = 1; 2804 - fsg->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize); 2804 + fsg->bulk_out_maxpacket = usb_endpoint_maxp(d); 2805 2805 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); 2806 2806 2807 2807 if (transport_is_cbi()) {
+1 -1
drivers/usb/gadget/fsl_qe_udc.c
··· 540 540 int reval = 0; 541 541 u16 max = 0; 542 542 543 - max = le16_to_cpu(desc->wMaxPacketSize); 543 + max = usb_endpoint_maxp(desc); 544 544 545 545 /* check the max package size validate for this endpoint */ 546 546 /* Refer to USB2.0 spec table 9-13,
+1 -1
drivers/usb/gadget/fsl_udc_core.c
··· 559 559 if (!udc->driver || (udc->gadget.speed == USB_SPEED_UNKNOWN)) 560 560 return -ESHUTDOWN; 561 561 562 - max = le16_to_cpu(desc->wMaxPacketSize); 562 + max = usb_endpoint_maxp(desc); 563 563 564 564 /* Disable automatic zlp generation. Driver is responsible to indicate 565 565 * explicitly through req->req.zero. This is needed to enable multi-td
+1 -1
drivers/usb/gadget/fusb300_udc.c
··· 220 220 221 221 info.type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; 222 222 info.dir_in = (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ? 1 : 0; 223 - info.maxpacket = le16_to_cpu(desc->wMaxPacketSize); 223 + info.maxpacket = usb_endpoint_maxp(desc); 224 224 info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; 225 225 226 226 if ((info.type == USB_ENDPOINT_XFER_INT) ||
+3
drivers/usb/gadget/gadget_chips.h
··· 31 31 #define gadget_is_ci13xxx_msm(g) (!strcmp("ci13xxx_msm", (g)->name)) 32 32 #define gadget_is_ci13xxx_pci(g) (!strcmp("ci13xxx_pci", (g)->name)) 33 33 #define gadget_is_dummy(g) (!strcmp("dummy_udc", (g)->name)) 34 + #define gadget_is_dwc3(g) (!strcmp("dwc3-gadget", (g)->name)) 34 35 #define gadget_is_fsl_qe(g) (!strcmp("fsl_qe_udc", (g)->name)) 35 36 #define gadget_is_fsl_usb2(g) (!strcmp("fsl-usb2-udc", (g)->name)) 36 37 #define gadget_is_goku(g) (!strcmp("goku_udc", (g)->name)) ··· 116 115 return 0x30; 117 116 else if (gadget_is_net2272(gadget)) 118 117 return 0x31; 118 + else if (gadget_is_dwc3(gadget)) 119 + return 0x32; 119 120 120 121 return -ENOENT; 121 122 }
+1 -1
drivers/usb/gadget/imx_udc.c
··· 689 689 return -EINVAL; 690 690 } 691 691 692 - if (imx_ep->fifosize < le16_to_cpu(desc->wMaxPacketSize)) { 692 + if (imx_ep->fifosize < usb_endpoint_maxp(desc)) { 693 693 D_ERR(imx_usb->dev, 694 694 "<%s> bad %s maxpacket\n", __func__, usb_ep->name); 695 695 return -ERANGE;
+1 -1
drivers/usb/gadget/langwell_udc.c
··· 283 283 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) 284 284 return -ESHUTDOWN; 285 285 286 - max = le16_to_cpu(desc->wMaxPacketSize); 286 + max = usb_endpoint_maxp(desc); 287 287 288 288 /* 289 289 * disable HW zero length termination select
+2 -2
drivers/usb/gadget/m66592-udc.c
··· 370 370 371 371 ep->pipectr = get_pipectr_addr(pipenum); 372 372 ep->pipenum = pipenum; 373 - ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize); 373 + ep->ep.maxpacket = usb_endpoint_maxp(desc); 374 374 m66592->pipenum2ep[pipenum] = ep; 375 375 m66592->epaddr2ep[desc->bEndpointAddress&USB_ENDPOINT_NUMBER_MASK] = ep; 376 376 INIT_LIST_HEAD(&ep->queue); ··· 447 447 ep->type = info.type; 448 448 449 449 info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; 450 - info.maxpacket = le16_to_cpu(desc->wMaxPacketSize); 450 + info.maxpacket = usb_endpoint_maxp(desc); 451 451 info.interval = desc->bInterval; 452 452 if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) 453 453 info.dir_in = 1;
+1 -1
drivers/usb/gadget/mv_udc_core.c
··· 493 493 return -ESHUTDOWN; 494 494 495 495 direction = ep_dir(ep); 496 - max = le16_to_cpu(desc->wMaxPacketSize); 496 + max = usb_endpoint_maxp(desc); 497 497 498 498 /* 499 499 * disable HW zero length termination select
+1 -1
drivers/usb/gadget/net2272.c
··· 204 204 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) 205 205 return -ESHUTDOWN; 206 206 207 - max = le16_to_cpu(desc->wMaxPacketSize) & 0x1fff; 207 + max = usb_endpoint_maxp(desc) & 0x1fff; 208 208 209 209 spin_lock_irqsave(&dev->lock, flags); 210 210 _ep->maxpacket = max & 0x7fff;
+2 -2
drivers/usb/gadget/net2280.c
··· 169 169 return -EDOM; 170 170 171 171 /* sanity check ep-e/ep-f since their fifos are small */ 172 - max = le16_to_cpu (desc->wMaxPacketSize) & 0x1fff; 172 + max = usb_endpoint_maxp (desc) & 0x1fff; 173 173 if (ep->num > 4 && max > 64) 174 174 return -ERANGE; 175 175 ··· 1640 1640 default: 1641 1641 val = "iso"; break; 1642 1642 }; val; }), 1643 - le16_to_cpu (d->wMaxPacketSize) & 0x1fff, 1643 + usb_endpoint_maxp (d) & 0x1fff, 1644 1644 ep->dma ? "dma" : "pio", ep->fifo_size 1645 1645 ); 1646 1646 } else /* ep0 should only have one transfer queued */
+3 -4
drivers/usb/gadget/omap_udc.c
··· 166 166 if (!_ep || !desc || ep->desc 167 167 || desc->bDescriptorType != USB_DT_ENDPOINT 168 168 || ep->bEndpointAddress != desc->bEndpointAddress 169 - || ep->maxpacket < le16_to_cpu 170 - (desc->wMaxPacketSize)) { 169 + || ep->maxpacket < usb_endpoint_maxp(desc)) { 171 170 DBG("%s, bad ep or descriptor\n", __func__); 172 171 return -EINVAL; 173 172 } 174 - maxp = le16_to_cpu (desc->wMaxPacketSize); 173 + maxp = usb_endpoint_maxp(desc); 175 174 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK 176 175 && maxp != ep->maxpacket) 177 - || le16_to_cpu(desc->wMaxPacketSize) > ep->maxpacket 176 + || usb_endpoint_maxp(desc) > ep->maxpacket 178 177 || !desc->wMaxPacketSize) { 179 178 DBG("%s, bad %s maxpacket\n", __func__, _ep->name); 180 179 return -ERANGE;
+3 -3
drivers/usb/gadget/pch_udc.c
··· 947 947 else 948 948 buff_size = UDC_EPOUT_BUFF_SIZE; 949 949 pch_udc_ep_set_bufsz(ep, buff_size, ep->in); 950 - pch_udc_ep_set_maxpkt(ep, le16_to_cpu(desc->wMaxPacketSize)); 950 + pch_udc_ep_set_maxpkt(ep, usb_endpoint_maxp(desc)); 951 951 pch_udc_ep_set_nak(ep); 952 952 pch_udc_ep_fifo_flush(ep, ep->in); 953 953 /* Configure the endpoint */ ··· 957 957 (cfg->cur_cfg << UDC_CSR_NE_CFG_SHIFT) | 958 958 (cfg->cur_intf << UDC_CSR_NE_INTF_SHIFT) | 959 959 (cfg->cur_alt << UDC_CSR_NE_ALT_SHIFT) | 960 - le16_to_cpu(desc->wMaxPacketSize) << UDC_CSR_NE_MAX_PKT_SHIFT; 960 + usb_endpoint_maxp(desc) << UDC_CSR_NE_MAX_PKT_SHIFT; 961 961 962 962 if (ep->in) 963 963 pch_udc_write_csr(ep->dev, val, UDC_EPIN_IDX(ep->num)); ··· 1466 1466 ep->desc = desc; 1467 1467 ep->halted = 0; 1468 1468 pch_udc_ep_enable(ep, &ep->dev->cfg_data, desc); 1469 - ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize); 1469 + ep->ep.maxpacket = usb_endpoint_maxp(desc); 1470 1470 pch_udc_enable_ep_interrupts(ep->dev, PCH_UDC_EPINT(ep->in, ep->num)); 1471 1471 spin_unlock_irqrestore(&dev->lock, iflags); 1472 1472 return 0;
+6 -8
drivers/usb/gadget/pxa25x_udc.c
··· 232 232 if (!_ep || !desc || ep->desc || _ep->name == ep0name 233 233 || desc->bDescriptorType != USB_DT_ENDPOINT 234 234 || ep->bEndpointAddress != desc->bEndpointAddress 235 - || ep->fifo_size < le16_to_cpu 236 - (desc->wMaxPacketSize)) { 235 + || ep->fifo_size < usb_endpoint_maxp (desc)) { 237 236 DMSG("%s, bad ep or descriptor\n", __func__); 238 237 return -EINVAL; 239 238 } ··· 247 248 248 249 /* hardware _could_ do smaller, but driver doesn't */ 249 250 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK 250 - && le16_to_cpu (desc->wMaxPacketSize) 251 + && usb_endpoint_maxp (desc) 251 252 != BULK_FIFO_SIZE) 252 253 || !desc->wMaxPacketSize) { 253 254 DMSG("%s, bad %s maxpacket\n", __func__, _ep->name); ··· 263 264 ep->desc = desc; 264 265 ep->stopped = 0; 265 266 ep->pio_irqs = 0; 266 - ep->ep.maxpacket = le16_to_cpu (desc->wMaxPacketSize); 267 + ep->ep.maxpacket = usb_endpoint_maxp (desc); 267 268 268 269 /* flush fifo (mostly for OUT buffers) */ 269 270 pxa25x_ep_fifo_flush (_ep); ··· 400 401 { 401 402 unsigned max; 402 403 403 - max = le16_to_cpu(ep->desc->wMaxPacketSize); 404 + max = usb_endpoint_maxp(ep->desc); 404 405 do { 405 406 unsigned count; 406 407 int is_last, is_short; ··· 670 671 * we can report per-packet status. that also helps with dma. 671 672 */ 672 673 if (unlikely (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC 673 - && req->req.length > le16_to_cpu 674 - (ep->desc->wMaxPacketSize))) 674 + && req->req.length > usb_endpoint_maxp (ep->desc))) 675 675 return -EMSGSIZE; 676 676 677 677 DBG(DBG_NOISY, "%s queue req %p, len %d buf %p\n", ··· 1103 1105 tmp = *dev->ep [i].reg_udccs; 1104 1106 seq_printf(m, 1105 1107 "%s max %d %s udccs %02x irqs %lu\n", 1106 - ep->ep.name, le16_to_cpu(desc->wMaxPacketSize), 1108 + ep->ep.name, usb_endpoint_maxp(desc), 1107 1109 "pio", tmp, ep->pio_irqs); 1108 1110 /* TODO translate all five groups of udccs bits! */ 1109 1111
+1 -1
drivers/usb/gadget/pxa27x_udc.c
··· 1439 1439 return -EINVAL; 1440 1440 } 1441 1441 1442 - if (ep->fifo_size < le16_to_cpu(desc->wMaxPacketSize)) { 1442 + if (ep->fifo_size < usb_endpoint_maxp(desc)) { 1443 1443 ep_err(ep, "bad maxpacket\n"); 1444 1444 return -ERANGE; 1445 1445 }
+2 -2
drivers/usb/gadget/r8a66597-udc.c
··· 341 341 342 342 ep->pipectr = get_pipectr_addr(pipenum); 343 343 ep->pipenum = pipenum; 344 - ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize); 344 + ep->ep.maxpacket = usb_endpoint_maxp(desc); 345 345 r8a66597->pipenum2ep[pipenum] = ep; 346 346 r8a66597->epaddr2ep[desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK] 347 347 = ep; ··· 420 420 ep->type = info.type; 421 421 422 422 info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; 423 - info.maxpacket = le16_to_cpu(desc->wMaxPacketSize); 423 + info.maxpacket = usb_endpoint_maxp(desc); 424 424 info.interval = desc->bInterval; 425 425 if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) 426 426 info.dir_in = 1;
+1 -1
drivers/usb/gadget/s3c-hsotg.c
··· 2297 2297 return -EINVAL; 2298 2298 } 2299 2299 2300 - mps = le16_to_cpu(desc->wMaxPacketSize); 2300 + mps = usb_endpoint_maxp(desc); 2301 2301 2302 2302 /* note, we handle this here instead of s3c_hsotg_set_ep_maxpacket */ 2303 2303
+39 -16
drivers/usb/gadget/s3c-hsudc.c
··· 26 26 #include <linux/clk.h> 27 27 #include <linux/usb/ch9.h> 28 28 #include <linux/usb/gadget.h> 29 + #include <linux/usb/otg.h> 29 30 #include <linux/prefetch.h> 30 31 31 32 #include <mach/regs-s3c2443-clock.h> ··· 138 137 struct usb_gadget_driver *driver; 139 138 struct device *dev; 140 139 struct s3c24xx_hsudc_platdata *pd; 140 + struct otg_transceiver *transceiver; 141 141 spinlock_t lock; 142 142 void __iomem *regs; 143 143 struct resource *mem_rsrc; ··· 761 759 if (!_ep || !desc || hsep->desc || _ep->name == ep0name 762 760 || desc->bDescriptorType != USB_DT_ENDPOINT 763 761 || hsep->bEndpointAddress != desc->bEndpointAddress 764 - || ep_maxpacket(hsep) < le16_to_cpu(desc->wMaxPacketSize)) 762 + || ep_maxpacket(hsep) < usb_endpoint_maxp(desc)) 765 763 return -EINVAL; 766 764 767 765 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK 768 - && le16_to_cpu(desc->wMaxPacketSize) != ep_maxpacket(hsep)) 766 + && usb_endpoint_maxp(desc) != ep_maxpacket(hsep)) 769 767 || !desc->wMaxPacketSize) 770 768 return -ERANGE; 771 769 ··· 781 779 782 780 hsep->stopped = hsep->wedge = 0; 783 781 hsep->desc = desc; 784 - hsep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize); 782 + hsep->ep.maxpacket = usb_endpoint_maxp(desc); 785 783 786 784 s3c_hsudc_set_halt(_ep, 0); 787 785 __set_bit(ep_index(hsep), hsudc->regs + S3C_EIER); ··· 1173 1171 return ret; 1174 1172 } 1175 1173 1174 + /* connect to bus through transceiver */ 1175 + if (hsudc->transceiver) { 1176 + ret = otg_set_peripheral(hsudc->transceiver, &hsudc->gadget); 1177 + if (ret) { 1178 + dev_err(hsudc->dev, "%s: can't bind to transceiver\n", 1179 + hsudc->gadget.name); 1180 + driver->unbind(&hsudc->gadget); 1181 + 1182 + device_del(&hsudc->gadget.dev); 1183 + 1184 + hsudc->driver = NULL; 1185 + hsudc->gadget.dev.driver = NULL; 1186 + return ret; 1187 + } 1188 + } 1189 + 1176 1190 enable_irq(hsudc->irq); 1177 1191 dev_info(hsudc->dev, "bound driver %s\n", driver->driver.name); 1178 1192 ··· 1218 1200 hsudc->pd->gpio_uninit(); 1219 1201 s3c_hsudc_stop_activity(hsudc, driver); 1220 1202 spin_unlock_irqrestore(&hsudc->lock, flags); 1203 + 1204 + if (hsudc->transceiver) 1205 + (void) otg_set_peripheral(hsudc->transceiver, NULL); 1221 1206 1222 1207 driver->unbind(&hsudc->gadget); 1223 1208 device_del(&hsudc->gadget.dev); ··· 1268 1247 hsudc->dev = dev; 1269 1248 hsudc->pd = pdev->dev.platform_data; 1270 1249 1250 + hsudc->transceiver = otg_get_transceiver(); 1251 + 1271 1252 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1272 1253 if (!res) { 1273 1254 dev_err(dev, "unable to obtain driver resource data\n"); ··· 1292 1269 goto err_remap; 1293 1270 } 1294 1271 1295 - ret = platform_get_irq(pdev, 0); 1296 - if (ret < 0) { 1297 - dev_err(dev, "unable to obtain IRQ number\n"); 1298 - goto err_irq; 1299 - } 1300 - hsudc->irq = ret; 1301 - 1302 - ret = request_irq(hsudc->irq, s3c_hsudc_irq, 0, driver_name, hsudc); 1303 - if (ret < 0) { 1304 - dev_err(dev, "irq request failed\n"); 1305 - goto err_irq; 1306 - } 1307 - 1308 1272 spin_lock_init(&hsudc->lock); 1309 1273 1310 1274 device_initialize(&hsudc->gadget.dev); ··· 1308 1298 hsudc->gadget.is_a_peripheral = 0; 1309 1299 1310 1300 s3c_hsudc_setup_ep(hsudc); 1301 + 1302 + ret = platform_get_irq(pdev, 0); 1303 + if (ret < 0) { 1304 + dev_err(dev, "unable to obtain IRQ number\n"); 1305 + goto err_irq; 1306 + } 1307 + hsudc->irq = ret; 1308 + 1309 + ret = request_irq(hsudc->irq, s3c_hsudc_irq, 0, driver_name, hsudc); 1310 + if (ret < 0) { 1311 + dev_err(dev, "irq request failed\n"); 1312 + goto err_irq; 1313 + } 1311 1314 1312 1315 hsudc->uclk = clk_get(&pdev->dev, "usb-device"); 1313 1316 if (IS_ERR(hsudc->uclk)) {
+1 -1
drivers/usb/gadget/s3c2410_udc.c
··· 1082 1082 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) 1083 1083 return -ESHUTDOWN; 1084 1084 1085 - max = le16_to_cpu(desc->wMaxPacketSize) & 0x1fff; 1085 + max = usb_endpoint_maxp(desc) & 0x1fff; 1086 1086 1087 1087 local_irq_save (flags); 1088 1088 _ep->maxpacket = max & 0x7ff;
+10 -3
drivers/usb/host/Kconfig
··· 544 544 will be called "hwa-hc". 545 545 546 546 config USB_IMX21_HCD 547 - tristate "iMX21 HCD support" 548 - depends on USB && ARM && MACH_MX21 547 + tristate "i.MX21 HCD support" 548 + depends on USB && ARM && ARCH_MXC 549 549 help 550 550 This driver enables support for the on-chip USB host in the 551 - iMX21 processor. 551 + i.MX21 processor. 552 552 553 553 To compile this driver as a module, choose M here: the 554 554 module will be called "imx21-hcd". ··· 578 578 config USB_OCTEON2_COMMON 579 579 bool 580 580 default y if USB_OCTEON_EHCI || USB_OCTEON_OHCI 581 + 582 + config USB_PXA168_EHCI 583 + bool "Marvell PXA168 on-chip EHCI HCD support" 584 + depends on USB_EHCI_HCD && ARCH_MMP 585 + help 586 + Enable support for Marvell PXA168 SoC's on-chip EHCI 587 + host controller
+1 -1
drivers/usb/host/ehci-au1xxx.c
··· 293 293 /* here we "know" root ports should always stay powered */ 294 294 ehci_port_power(ehci, 1); 295 295 296 - hcd->state = HC_STATE_SUSPENDED; 296 + ehci->rh_state = EHCI_RH_SUSPENDED; 297 297 298 298 return 0; 299 299 }
+15 -2
drivers/usb/host/ehci-dbg.c
··· 697 697 } 698 698 #undef DBG_SCHED_LIMIT 699 699 700 + static const char *rh_state_string(struct ehci_hcd *ehci) 701 + { 702 + switch (ehci->rh_state) { 703 + case EHCI_RH_HALTED: 704 + return "halted"; 705 + case EHCI_RH_SUSPENDED: 706 + return "suspended"; 707 + case EHCI_RH_RUNNING: 708 + return "running"; 709 + } 710 + return "?"; 711 + } 712 + 700 713 static ssize_t fill_registers_buffer(struct debug_buffer *buf) 701 714 { 702 715 struct usb_hcd *hcd; ··· 743 730 temp = scnprintf (next, size, 744 731 "bus %s, device %s\n" 745 732 "%s\n" 746 - "EHCI %x.%02x, hcd state %d\n", 733 + "EHCI %x.%02x, rh state %s\n", 747 734 hcd->self.controller->bus->name, 748 735 dev_name(hcd->self.controller), 749 736 hcd->product_desc, 750 - i >> 8, i & 0x0ff, hcd->state); 737 + i >> 8, i & 0x0ff, rh_state_string(ehci)); 751 738 size -= temp; 752 739 next += temp; 753 740
+2 -2
drivers/usb/host/ehci-fsl.c
··· 392 392 393 393 dev_dbg(dev, "suspending...\n"); 394 394 395 - hcd->state = HC_STATE_SUSPENDED; 395 + ehci->rh_state = EHCI_RH_SUSPENDED; 396 396 dev->power.power_state = PMSG_SUSPEND; 397 397 398 398 /* ignore non-host interrupts */ ··· 481 481 ehci_writel(ehci, pdata->pm_portsc, &ehci->regs->port_status[0]); 482 482 483 483 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 484 - hcd->state = HC_STATE_RUNNING; 484 + ehci->rh_state = EHCI_RH_RUNNING; 485 485 dev->power.power_state = PMSG_ON; 486 486 487 487 tmp = ehci_readl(ehci, &ehci->regs->command);
+20 -10
drivers/usb/host/ehci-hcd.c
··· 238 238 error = handshake(ehci, ptr, mask, done, usec); 239 239 if (error) { 240 240 ehci_halt(ehci); 241 - ehci_to_hcd(ehci)->state = HC_STATE_HALT; 241 + ehci->rh_state = EHCI_RH_HALTED; 242 242 ehci_err(ehci, "force halt; handshake %p %08x %08x -> %d\n", 243 243 ptr, mask, done, error); 244 244 } ··· 278 278 command |= CMD_RESET; 279 279 dbg_cmd (ehci, "reset", command); 280 280 ehci_writel(ehci, command, &ehci->regs->command); 281 - ehci_to_hcd(ehci)->state = HC_STATE_HALT; 281 + ehci->rh_state = EHCI_RH_HALTED; 282 282 ehci->next_statechange = jiffies; 283 283 retval = handshake (ehci, &ehci->regs->command, 284 284 CMD_RESET, 0, 250 * 1000); ··· 307 307 u32 temp; 308 308 309 309 #ifdef DEBUG 310 - if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state)) 310 + if (ehci->rh_state != EHCI_RH_RUNNING) 311 311 BUG (); 312 312 #endif 313 313 ··· 356 356 */ 357 357 if (ehci->reclaim 358 358 && !timer_pending(&ehci->iaa_watchdog) 359 - && HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { 359 + && ehci->rh_state == EHCI_RH_RUNNING) { 360 360 u32 cmd, status; 361 361 362 362 /* If we get here, IAA is *REALLY* late. It's barely ··· 496 496 * misplace IRQs, and should let us run completely without IRQs. 497 497 * such lossage has been observed on both VT6202 and VT8235. 498 498 */ 499 - if (HC_IS_RUNNING (ehci_to_hcd(ehci)->state) && 499 + if (ehci->rh_state == EHCI_RH_RUNNING && 500 500 (ehci->async->qh_next.ptr != NULL || 501 501 ehci->periodic_sched != 0)) 502 502 timer_action (ehci, TIMER_IO_WATCHDOG); ··· 516 516 del_timer_sync(&ehci->iaa_watchdog); 517 517 518 518 spin_lock_irq(&ehci->lock); 519 - if (HC_IS_RUNNING (hcd->state)) 519 + if (ehci->rh_state == EHCI_RH_RUNNING) 520 520 ehci_quiesce (ehci); 521 521 522 522 ehci_silence_controller(ehci); ··· 741 741 * be started before the port switching actions could complete. 742 742 */ 743 743 down_write(&ehci_cf_port_reset_rwsem); 744 - hcd->state = HC_STATE_RUNNING; 744 + ehci->rh_state = EHCI_RH_RUNNING; 745 745 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); 746 746 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ 747 747 msleep(5); ··· 788 788 789 789 /* Shared IRQ? */ 790 790 masked_status = status & INTR_MASK; 791 - if (!masked_status || unlikely(hcd->state == HC_STATE_HALT)) { 791 + if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) { 792 792 spin_unlock(&ehci->lock); 793 793 return IRQ_NONE; 794 794 } ··· 952 952 static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) 953 953 { 954 954 /* failfast */ 955 - if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state) && ehci->reclaim) 955 + if (ehci->rh_state != EHCI_RH_RUNNING && ehci->reclaim) 956 956 end_unlink_async(ehci); 957 957 958 958 /* If the QH isn't linked then there's nothing we can do ··· 1079 1079 goto idle_timeout; 1080 1080 } 1081 1081 1082 - if (!HC_IS_RUNNING (hcd->state)) 1082 + if (ehci->rh_state != EHCI_RH_RUNNING) 1083 1083 qh->qh_state = QH_STATE_IDLE; 1084 1084 switch (qh->qh_state) { 1085 1085 case QH_STATE_LINKED: ··· 1289 1289 #ifdef CONFIG_SPARC_LEON 1290 1290 #include "ehci-grlib.c" 1291 1291 #define PLATFORM_DRIVER ehci_grlib_driver 1292 + #endif 1293 + 1294 + #ifdef CONFIG_USB_PXA168_EHCI 1295 + #include "ehci-pxa168.c" 1296 + #define PLATFORM_DRIVER ehci_pxa168_driver 1297 + #endif 1298 + 1299 + #ifdef CONFIG_NLM_XLR 1300 + #include "ehci-xls.c" 1301 + #define PLATFORM_DRIVER ehci_xls_driver 1292 1302 #endif 1293 1303 1294 1304 #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
+4 -6
drivers/usb/host/ehci-hub.c
··· 236 236 } 237 237 238 238 /* stop schedules, clean any completed work */ 239 - if (HC_IS_RUNNING(hcd->state)) { 239 + if (ehci->rh_state == EHCI_RH_RUNNING) 240 240 ehci_quiesce (ehci); 241 - hcd->state = HC_STATE_QUIESCING; 242 - } 243 241 ehci->command = ehci_readl(ehci, &ehci->regs->command); 244 242 ehci_work(ehci); 245 243 ··· 311 313 312 314 /* turn off now-idle HC */ 313 315 ehci_halt (ehci); 314 - hcd->state = HC_STATE_SUSPENDED; 316 + ehci->rh_state = EHCI_RH_SUSPENDED; 315 317 316 318 if (ehci->reclaim) 317 319 end_unlink_async(ehci); ··· 380 382 381 383 /* restore CMD_RUN, framelist size, and irq threshold */ 382 384 ehci_writel(ehci, ehci->command, &ehci->regs->command); 385 + ehci->rh_state = EHCI_RH_RUNNING; 383 386 384 387 /* Some controller/firmware combinations need a delay during which 385 388 * they set up the port statuses. See Bugzilla #8190. */ ··· 450 451 } 451 452 452 453 ehci->next_statechange = jiffies + msecs_to_jiffies(5); 453 - hcd->state = HC_STATE_RUNNING; 454 454 455 455 /* Now we can safely re-enable irqs */ 456 456 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); ··· 561 563 u32 ppcd = 0; 562 564 563 565 /* if !USB_SUSPEND, root hub timers won't get shut down ... */ 564 - if (!HC_IS_RUNNING(hcd->state)) 566 + if (ehci->rh_state != EHCI_RH_RUNNING) 565 567 return 0; 566 568 567 569 /* init status to no-changes */
+1 -1
drivers/usb/host/ehci-pci.c
··· 439 439 /* here we "know" root ports should always stay powered */ 440 440 ehci_port_power(ehci, 1); 441 441 442 - hcd->state = HC_STATE_SUSPENDED; 442 + ehci->rh_state = EHCI_RH_SUSPENDED; 443 443 return 0; 444 444 } 445 445 #endif
+363
drivers/usb/host/ehci-pxa168.c
··· 1 + /* 2 + * drivers/usb/host/ehci-pxa168.c 3 + * 4 + * Tanmay Upadhyay <tanmay.upadhyay@einfochips.com> 5 + * 6 + * Based on drivers/usb/host/ehci-orion.c 7 + * 8 + * This file is licensed under the terms of the GNU General Public 9 + * License version 2. This program is licensed "as is" without any 10 + * warranty of any kind, whether express or implied. 11 + */ 12 + 13 + #include <linux/kernel.h> 14 + #include <linux/module.h> 15 + #include <linux/platform_device.h> 16 + #include <linux/clk.h> 17 + #include <mach/pxa168.h> 18 + 19 + #define USB_PHY_CTRL_REG 0x4 20 + #define USB_PHY_PLL_REG 0x8 21 + #define USB_PHY_TX_REG 0xc 22 + 23 + #define FBDIV_SHIFT 4 24 + 25 + #define ICP_SHIFT 12 26 + #define ICP_15 2 27 + #define ICP_20 3 28 + #define ICP_25 4 29 + 30 + #define KVCO_SHIFT 15 31 + 32 + #define PLLCALI12_SHIFT 25 33 + #define CALI12_VDD 0 34 + #define CALI12_09 1 35 + #define CALI12_10 2 36 + #define CALI12_11 3 37 + 38 + #define PLLVDD12_SHIFT 27 39 + #define VDD12_VDD 0 40 + #define VDD12_10 1 41 + #define VDD12_11 2 42 + #define VDD12_12 3 43 + 44 + #define PLLVDD18_SHIFT 29 45 + #define VDD18_19 0 46 + #define VDD18_20 1 47 + #define VDD18_21 2 48 + #define VDD18_22 3 49 + 50 + 51 + #define PLL_READY (1 << 23) 52 + #define VCOCAL_START (1 << 21) 53 + #define REG_RCAL_START (1 << 12) 54 + 55 + struct pxa168_usb_drv_data { 56 + struct ehci_hcd ehci; 57 + struct clk *pxa168_usb_clk; 58 + struct resource *usb_phy_res; 59 + void __iomem *usb_phy_reg_base; 60 + }; 61 + 62 + static int ehci_pxa168_setup(struct usb_hcd *hcd) 63 + { 64 + struct ehci_hcd *ehci = hcd_to_ehci(hcd); 65 + int retval; 66 + 67 + ehci_reset(ehci); 68 + retval = ehci_halt(ehci); 69 + if (retval) 70 + return retval; 71 + 72 + /* 73 + * data structure init 74 + */ 75 + retval = ehci_init(hcd); 76 + if (retval) 77 + return retval; 78 + 79 + hcd->has_tt = 1; 80 + 81 + ehci_port_power(ehci, 0); 82 + 83 + return retval; 84 + } 85 + 86 + static const struct hc_driver ehci_pxa168_hc_driver = { 87 + .description = hcd_name, 88 + .product_desc = "Marvell PXA168 EHCI", 89 + .hcd_priv_size = sizeof(struct pxa168_usb_drv_data), 90 + 91 + /* 92 + * generic hardware linkage 93 + */ 94 + .irq = ehci_irq, 95 + .flags = HCD_MEMORY | HCD_USB2, 96 + 97 + /* 98 + * basic lifecycle operations 99 + */ 100 + .reset = ehci_pxa168_setup, 101 + .start = ehci_run, 102 + .stop = ehci_stop, 103 + .shutdown = ehci_shutdown, 104 + 105 + /* 106 + * managing i/o requests and associated device resources 107 + */ 108 + .urb_enqueue = ehci_urb_enqueue, 109 + .urb_dequeue = ehci_urb_dequeue, 110 + .endpoint_disable = ehci_endpoint_disable, 111 + .endpoint_reset = ehci_endpoint_reset, 112 + 113 + /* 114 + * scheduling support 115 + */ 116 + .get_frame_number = ehci_get_frame, 117 + 118 + /* 119 + * root hub support 120 + */ 121 + .hub_status_data = ehci_hub_status_data, 122 + .hub_control = ehci_hub_control, 123 + .bus_suspend = ehci_bus_suspend, 124 + .bus_resume = ehci_bus_resume, 125 + .relinquish_port = ehci_relinquish_port, 126 + .port_handed_over = ehci_port_handed_over, 127 + 128 + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 129 + }; 130 + 131 + static int pxa168_usb_phy_init(struct platform_device *pdev) 132 + { 133 + struct resource *res; 134 + void __iomem *usb_phy_reg_base; 135 + struct pxa168_usb_pdata *pdata; 136 + struct pxa168_usb_drv_data *drv_data; 137 + struct usb_hcd *hcd = platform_get_drvdata(pdev); 138 + unsigned long reg_val; 139 + int pll_retry_cont = 10000, err = 0; 140 + 141 + drv_data = (struct pxa168_usb_drv_data *)hcd->hcd_priv; 142 + pdata = (struct pxa168_usb_pdata *)pdev->dev.platform_data; 143 + 144 + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 145 + if (!res) { 146 + dev_err(&pdev->dev, 147 + "Found HC with no PHY register addr. Check %s setup!\n", 148 + dev_name(&pdev->dev)); 149 + return -ENODEV; 150 + } 151 + 152 + if (!request_mem_region(res->start, resource_size(res), 153 + ehci_pxa168_hc_driver.description)) { 154 + dev_dbg(&pdev->dev, "controller already in use\n"); 155 + return -EBUSY; 156 + } 157 + 158 + usb_phy_reg_base = ioremap(res->start, resource_size(res)); 159 + if (usb_phy_reg_base == NULL) { 160 + dev_dbg(&pdev->dev, "error mapping memory\n"); 161 + err = -EFAULT; 162 + goto err1; 163 + } 164 + drv_data->usb_phy_reg_base = usb_phy_reg_base; 165 + drv_data->usb_phy_res = res; 166 + 167 + /* If someone wants to init USB phy in board specific way */ 168 + if (pdata && pdata->phy_init) 169 + return pdata->phy_init(usb_phy_reg_base); 170 + 171 + /* Power up the PHY and PLL */ 172 + writel(readl(usb_phy_reg_base + USB_PHY_CTRL_REG) | 0x3, 173 + usb_phy_reg_base + USB_PHY_CTRL_REG); 174 + 175 + /* Configure PHY PLL */ 176 + reg_val = readl(usb_phy_reg_base + USB_PHY_PLL_REG) & ~(0x7e03ffff); 177 + reg_val |= (VDD18_22 << PLLVDD18_SHIFT | VDD12_12 << PLLVDD12_SHIFT | 178 + CALI12_11 << PLLCALI12_SHIFT | 3 << KVCO_SHIFT | 179 + ICP_15 << ICP_SHIFT | 0xee << FBDIV_SHIFT | 0xb); 180 + writel(reg_val, usb_phy_reg_base + USB_PHY_PLL_REG); 181 + 182 + /* Make sure PHY PLL is ready */ 183 + while (!(readl(usb_phy_reg_base + USB_PHY_PLL_REG) & PLL_READY)) { 184 + if (!(pll_retry_cont--)) { 185 + dev_dbg(&pdev->dev, "USB PHY PLL not ready\n"); 186 + err = -EIO; 187 + goto err2; 188 + } 189 + } 190 + 191 + /* Toggle VCOCAL_START bit of U2PLL for PLL calibration */ 192 + udelay(200); 193 + writel(readl(usb_phy_reg_base + USB_PHY_PLL_REG) | VCOCAL_START, 194 + usb_phy_reg_base + USB_PHY_PLL_REG); 195 + udelay(40); 196 + writel(readl(usb_phy_reg_base + USB_PHY_PLL_REG) & ~VCOCAL_START, 197 + usb_phy_reg_base + USB_PHY_PLL_REG); 198 + 199 + /* Toggle REG_RCAL_START bit of U2PTX for impedance calibration */ 200 + udelay(400); 201 + writel(readl(usb_phy_reg_base + USB_PHY_TX_REG) | REG_RCAL_START, 202 + usb_phy_reg_base + USB_PHY_TX_REG); 203 + udelay(40); 204 + writel(readl(usb_phy_reg_base + USB_PHY_TX_REG) & ~REG_RCAL_START, 205 + usb_phy_reg_base + USB_PHY_TX_REG); 206 + 207 + /* Make sure PHY PLL is ready again */ 208 + pll_retry_cont = 0; 209 + while (!(readl(usb_phy_reg_base + USB_PHY_PLL_REG) & PLL_READY)) { 210 + if (!(pll_retry_cont--)) { 211 + dev_dbg(&pdev->dev, "USB PHY PLL not ready\n"); 212 + err = -EIO; 213 + goto err2; 214 + } 215 + } 216 + 217 + return 0; 218 + err2: 219 + iounmap(usb_phy_reg_base); 220 + err1: 221 + release_mem_region(res->start, resource_size(res)); 222 + return err; 223 + } 224 + 225 + static int __devinit ehci_pxa168_drv_probe(struct platform_device *pdev) 226 + { 227 + struct resource *res; 228 + struct usb_hcd *hcd; 229 + struct ehci_hcd *ehci; 230 + struct pxa168_usb_drv_data *drv_data; 231 + void __iomem *regs; 232 + int irq, err = 0; 233 + 234 + if (usb_disabled()) 235 + return -ENODEV; 236 + 237 + pr_debug("Initializing pxa168-SoC USB Host Controller\n"); 238 + 239 + irq = platform_get_irq(pdev, 0); 240 + if (irq <= 0) { 241 + dev_err(&pdev->dev, 242 + "Found HC with no IRQ. Check %s setup!\n", 243 + dev_name(&pdev->dev)); 244 + err = -ENODEV; 245 + goto err1; 246 + } 247 + 248 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 249 + if (!res) { 250 + dev_err(&pdev->dev, 251 + "Found HC with no register addr. Check %s setup!\n", 252 + dev_name(&pdev->dev)); 253 + err = -ENODEV; 254 + goto err1; 255 + } 256 + 257 + if (!request_mem_region(res->start, resource_size(res), 258 + ehci_pxa168_hc_driver.description)) { 259 + dev_dbg(&pdev->dev, "controller already in use\n"); 260 + err = -EBUSY; 261 + goto err1; 262 + } 263 + 264 + regs = ioremap(res->start, resource_size(res)); 265 + if (regs == NULL) { 266 + dev_dbg(&pdev->dev, "error mapping memory\n"); 267 + err = -EFAULT; 268 + goto err2; 269 + } 270 + 271 + hcd = usb_create_hcd(&ehci_pxa168_hc_driver, 272 + &pdev->dev, dev_name(&pdev->dev)); 273 + if (!hcd) { 274 + err = -ENOMEM; 275 + goto err3; 276 + } 277 + 278 + drv_data = (struct pxa168_usb_drv_data *)hcd->hcd_priv; 279 + 280 + /* Enable USB clock */ 281 + drv_data->pxa168_usb_clk = clk_get(&pdev->dev, "PXA168-USBCLK"); 282 + if (IS_ERR(drv_data->pxa168_usb_clk)) { 283 + dev_err(&pdev->dev, "Couldn't get USB clock\n"); 284 + err = PTR_ERR(drv_data->pxa168_usb_clk); 285 + goto err4; 286 + } 287 + clk_enable(drv_data->pxa168_usb_clk); 288 + 289 + err = pxa168_usb_phy_init(pdev); 290 + if (err) { 291 + dev_err(&pdev->dev, "USB PHY initialization failed\n"); 292 + goto err5; 293 + } 294 + 295 + hcd->rsrc_start = res->start; 296 + hcd->rsrc_len = resource_size(res); 297 + hcd->regs = regs; 298 + 299 + ehci = hcd_to_ehci(hcd); 300 + ehci->caps = hcd->regs + 0x100; 301 + ehci->regs = hcd->regs + 0x100 + 302 + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); 303 + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); 304 + hcd->has_tt = 1; 305 + ehci->sbrn = 0x20; 306 + 307 + err = usb_add_hcd(hcd, irq, IRQF_SHARED | IRQF_DISABLED); 308 + if (err) 309 + goto err5; 310 + 311 + return 0; 312 + 313 + err5: 314 + clk_disable(drv_data->pxa168_usb_clk); 315 + clk_put(drv_data->pxa168_usb_clk); 316 + err4: 317 + usb_put_hcd(hcd); 318 + err3: 319 + iounmap(regs); 320 + err2: 321 + release_mem_region(res->start, resource_size(res)); 322 + err1: 323 + dev_err(&pdev->dev, "init %s fail, %d\n", 324 + dev_name(&pdev->dev), err); 325 + 326 + return err; 327 + } 328 + 329 + static int __exit ehci_pxa168_drv_remove(struct platform_device *pdev) 330 + { 331 + struct usb_hcd *hcd = platform_get_drvdata(pdev); 332 + struct pxa168_usb_drv_data *drv_data = 333 + (struct pxa168_usb_drv_data *)hcd->hcd_priv; 334 + 335 + usb_remove_hcd(hcd); 336 + 337 + /* Power down PHY & PLL */ 338 + writel(readl(drv_data->usb_phy_reg_base + USB_PHY_CTRL_REG) & (~0x3), 339 + drv_data->usb_phy_reg_base + USB_PHY_CTRL_REG); 340 + 341 + clk_disable(drv_data->pxa168_usb_clk); 342 + clk_put(drv_data->pxa168_usb_clk); 343 + 344 + iounmap(hcd->regs); 345 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 346 + 347 + iounmap(drv_data->usb_phy_reg_base); 348 + release_mem_region(drv_data->usb_phy_res->start, 349 + resource_size(drv_data->usb_phy_res)); 350 + 351 + usb_put_hcd(hcd); 352 + 353 + return 0; 354 + } 355 + 356 + MODULE_ALIAS("platform:pxa168-ehci"); 357 + 358 + static struct platform_driver ehci_pxa168_driver = { 359 + .probe = ehci_pxa168_drv_probe, 360 + .remove = __exit_p(ehci_pxa168_drv_remove), 361 + .shutdown = usb_hcd_platform_shutdown, 362 + .driver.name = "pxa168-ehci", 363 + };
+10 -12
drivers/usb/host/ehci-q.c
··· 153 153 spin_lock_irqsave(&ehci->lock, flags); 154 154 qh->clearing_tt = 0; 155 155 if (qh->qh_state == QH_STATE_IDLE && !list_empty(&qh->qtd_list) 156 - && HC_IS_RUNNING(hcd->state)) 156 + && ehci->rh_state == EHCI_RH_RUNNING) 157 157 qh_link_async(ehci, qh); 158 158 spin_unlock_irqrestore(&ehci->lock, flags); 159 159 } ··· 425 425 426 426 /* stop scanning when we reach qtds the hc is using */ 427 427 } else if (likely (!stopped 428 - && HC_IS_RUNNING (ehci_to_hcd(ehci)->state))) { 428 + && ehci->rh_state == EHCI_RH_RUNNING)) { 429 429 break; 430 430 431 431 /* scan the whole queue for unlinks whenever it stops */ ··· 433 433 stopped = 1; 434 434 435 435 /* cancel everything if we halt, suspend, etc */ 436 - if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) 436 + if (ehci->rh_state != EHCI_RH_RUNNING) 437 437 last_status = -ESHUTDOWN; 438 438 439 439 /* this qtd is active; skip it unless a previous qtd ··· 977 977 /* in case a clear of CMD_ASE didn't take yet */ 978 978 (void)handshake(ehci, &ehci->regs->status, 979 979 STS_ASS, 0, 150); 980 - cmd |= CMD_ASE | CMD_RUN; 980 + cmd |= CMD_ASE; 981 981 ehci_writel(ehci, cmd, &ehci->regs->command); 982 - ehci_to_hcd(ehci)->state = HC_STATE_RUNNING; 983 982 /* posted write need not be known to HC yet ... */ 984 983 } 985 984 } ··· 1167 1168 1168 1169 qh_completions (ehci, qh); 1169 1170 1170 - if (!list_empty (&qh->qtd_list) 1171 - && HC_IS_RUNNING (ehci_to_hcd(ehci)->state)) 1171 + if (!list_empty(&qh->qtd_list) && ehci->rh_state == EHCI_RH_RUNNING) { 1172 1172 qh_link_async (ehci, qh); 1173 - else { 1173 + } else { 1174 1174 /* it's not free to turn the async schedule on/off; leave it 1175 1175 * active but idle for a while once it empties. 1176 1176 */ 1177 - if (HC_IS_RUNNING (ehci_to_hcd(ehci)->state) 1177 + if (ehci->rh_state == EHCI_RH_RUNNING 1178 1178 && ehci->async->qh_next.qh == NULL) 1179 1179 timer_action (ehci, TIMER_ASYNC_OFF); 1180 1180 } ··· 1209 1211 /* stop async schedule right now? */ 1210 1212 if (unlikely (qh == ehci->async)) { 1211 1213 /* can't get here without STS_ASS set */ 1212 - if (ehci_to_hcd(ehci)->state != HC_STATE_HALT 1214 + if (ehci->rh_state != EHCI_RH_HALTED 1213 1215 && !ehci->reclaim) { 1214 1216 /* ... and CMD_IAAD clear */ 1215 1217 ehci_writel(ehci, cmd & ~CMD_ASE, ··· 1235 1237 wmb (); 1236 1238 1237 1239 /* If the controller isn't running, we don't have to wait for it */ 1238 - if (unlikely(!HC_IS_RUNNING(ehci_to_hcd(ehci)->state))) { 1240 + if (unlikely(ehci->rh_state != EHCI_RH_RUNNING)) { 1239 1241 /* if (unlikely (qh->reclaim != 0)) 1240 1242 * this will recurse, probably not much 1241 1243 */ ··· 1258 1260 enum ehci_timer_action action = TIMER_IO_WATCHDOG; 1259 1261 1260 1262 timer_action_done (ehci, TIMER_ASYNC_SHRINK); 1261 - stopped = !HC_IS_RUNNING(ehci_to_hcd(ehci)->state); 1263 + stopped = (ehci->rh_state != EHCI_RH_RUNNING); 1262 1264 1263 1265 ehci->qh_scan_next = ehci->async->qh_next.qh; 1264 1266 while (ehci->qh_scan_next) {
+1 -1
drivers/usb/host/ehci-s5p.c
··· 270 270 /* here we "know" root ports should always stay powered */ 271 271 ehci_port_power(ehci, 1); 272 272 273 - hcd->state = HC_STATE_SUSPENDED; 273 + ehci->rh_state = EHCI_RH_SUSPENDED; 274 274 275 275 return 0; 276 276 }
+5 -6
drivers/usb/host/ehci-sched.c
··· 479 479 cmd = ehci_readl(ehci, &ehci->regs->command) | CMD_PSE; 480 480 ehci_writel(ehci, cmd, &ehci->regs->command); 481 481 /* posted write ... PSS happens later */ 482 - ehci_to_hcd(ehci)->state = HC_STATE_RUNNING; 483 482 484 483 /* make sure ehci_work scans these */ 485 484 ehci->next_uframe = ehci_readl(ehci, &ehci->regs->frame_index) ··· 676 677 677 678 /* reschedule QH iff another request is queued */ 678 679 if (!list_empty(&qh->qtd_list) && 679 - HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { 680 + ehci->rh_state == EHCI_RH_RUNNING) { 680 681 rc = qh_schedule(ehci, qh); 681 682 682 683 /* An error here likely indicates handshake failure ··· 2274 2275 * Touches as few pages as possible: cache-friendly. 2275 2276 */ 2276 2277 now_uframe = ehci->next_uframe; 2277 - if (HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { 2278 + if (ehci->rh_state == EHCI_RH_RUNNING) { 2278 2279 clock = ehci_readl(ehci, &ehci->regs->frame_index); 2279 2280 clock_frame = (clock >> 3) & (ehci->periodic_size - 1); 2280 2281 } else { ··· 2309 2310 union ehci_shadow temp; 2310 2311 int live; 2311 2312 2312 - live = HC_IS_RUNNING (ehci_to_hcd(ehci)->state); 2313 + live = (ehci->rh_state == EHCI_RH_RUNNING); 2313 2314 switch (hc32_to_cpu(ehci, type)) { 2314 2315 case Q_TYPE_QH: 2315 2316 /* handle any completions */ ··· 2434 2435 * We can't advance our scan without collecting the ISO 2435 2436 * transfers that are still pending in this frame. 2436 2437 */ 2437 - if (incomplete && HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { 2438 + if (incomplete && ehci->rh_state == EHCI_RH_RUNNING) { 2438 2439 ehci->next_uframe = now_uframe; 2439 2440 break; 2440 2441 } ··· 2450 2451 if (now_uframe == clock) { 2451 2452 unsigned now; 2452 2453 2453 - if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state) 2454 + if (ehci->rh_state != EHCI_RH_RUNNING 2454 2455 || ehci->periodic_sched == 0) 2455 2456 break; 2456 2457 ehci->next_uframe = now_uframe;
+161
drivers/usb/host/ehci-xls.c
··· 1 + /* 2 + * EHCI HCD for Netlogic XLS processors. 3 + * 4 + * (C) Copyright 2011 Netlogic Microsystems Inc. 5 + * 6 + * Based on various ehci-*.c drivers 7 + * 8 + * This file is subject to the terms and conditions of the GNU General Public 9 + * License. See the file COPYING in the main directory of this archive for 10 + * more details. 11 + */ 12 + 13 + #include <linux/platform_device.h> 14 + 15 + static int ehci_xls_setup(struct usb_hcd *hcd) 16 + { 17 + int retval; 18 + struct ehci_hcd *ehci = hcd_to_ehci(hcd); 19 + 20 + ehci->caps = hcd->regs; 21 + ehci->regs = hcd->regs + 22 + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); 23 + dbg_hcs_params(ehci, "reset"); 24 + dbg_hcc_params(ehci, "reset"); 25 + 26 + /* cache this readonly data; minimize chip reads */ 27 + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); 28 + 29 + retval = ehci_halt(ehci); 30 + if (retval) 31 + return retval; 32 + 33 + /* data structure init */ 34 + retval = ehci_init(hcd); 35 + if (retval) 36 + return retval; 37 + 38 + ehci_reset(ehci); 39 + 40 + return retval; 41 + } 42 + 43 + int ehci_xls_probe_internal(const struct hc_driver *driver, 44 + struct platform_device *pdev) 45 + { 46 + struct usb_hcd *hcd; 47 + struct resource *res; 48 + int retval, irq; 49 + 50 + /* Get our IRQ from an earlier registered Platform Resource */ 51 + irq = platform_get_irq(pdev, 0); 52 + if (irq < 0) { 53 + dev_err(&pdev->dev, "Found HC with no IRQ. Check %s setup!\n", 54 + dev_name(&pdev->dev)); 55 + return -ENODEV; 56 + } 57 + 58 + /* Get our Memory Handle */ 59 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 60 + if (!res) { 61 + dev_err(&pdev->dev, "Error: MMIO Handle %s setup!\n", 62 + dev_name(&pdev->dev)); 63 + return -ENODEV; 64 + } 65 + hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev)); 66 + if (!hcd) { 67 + retval = -ENOMEM; 68 + goto err1; 69 + } 70 + 71 + hcd->rsrc_start = res->start; 72 + hcd->rsrc_len = res->end - res->start + 1; 73 + 74 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, 75 + driver->description)) { 76 + dev_dbg(&pdev->dev, "controller already in use\n"); 77 + retval = -EBUSY; 78 + goto err2; 79 + } 80 + hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); 81 + 82 + if (hcd->regs == NULL) { 83 + dev_dbg(&pdev->dev, "error mapping memory\n"); 84 + retval = -EFAULT; 85 + goto err3; 86 + } 87 + 88 + retval = usb_add_hcd(hcd, irq, IRQF_SHARED); 89 + if (retval != 0) 90 + goto err4; 91 + return retval; 92 + 93 + err4: 94 + iounmap(hcd->regs); 95 + err3: 96 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 97 + err2: 98 + usb_put_hcd(hcd); 99 + err1: 100 + dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), 101 + retval); 102 + return retval; 103 + } 104 + 105 + static struct hc_driver ehci_xls_hc_driver = { 106 + .description = hcd_name, 107 + .product_desc = "XLS EHCI Host Controller", 108 + .hcd_priv_size = sizeof(struct ehci_hcd), 109 + .irq = ehci_irq, 110 + .flags = HCD_USB2 | HCD_MEMORY, 111 + .reset = ehci_xls_setup, 112 + .start = ehci_run, 113 + .stop = ehci_stop, 114 + .shutdown = ehci_shutdown, 115 + 116 + .urb_enqueue = ehci_urb_enqueue, 117 + .urb_dequeue = ehci_urb_dequeue, 118 + .endpoint_disable = ehci_endpoint_disable, 119 + .endpoint_reset = ehci_endpoint_reset, 120 + 121 + .get_frame_number = ehci_get_frame, 122 + 123 + .hub_status_data = ehci_hub_status_data, 124 + .hub_control = ehci_hub_control, 125 + .bus_suspend = ehci_bus_suspend, 126 + .bus_resume = ehci_bus_resume, 127 + .relinquish_port = ehci_relinquish_port, 128 + .port_handed_over = ehci_port_handed_over, 129 + 130 + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 131 + }; 132 + 133 + static int ehci_xls_probe(struct platform_device *pdev) 134 + { 135 + if (usb_disabled()) 136 + return -ENODEV; 137 + 138 + return ehci_xls_probe_internal(&ehci_xls_hc_driver, pdev); 139 + } 140 + 141 + static int ehci_xls_remove(struct platform_device *pdev) 142 + { 143 + struct usb_hcd *hcd = platform_get_drvdata(pdev); 144 + 145 + usb_remove_hcd(hcd); 146 + iounmap(hcd->regs); 147 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 148 + usb_put_hcd(hcd); 149 + return 0; 150 + } 151 + 152 + MODULE_ALIAS("ehci-xls"); 153 + 154 + static struct platform_driver ehci_xls_driver = { 155 + .probe = ehci_xls_probe, 156 + .remove = ehci_xls_remove, 157 + .shutdown = usb_hcd_platform_shutdown, 158 + .driver = { 159 + .name = "ehci-xls", 160 + }, 161 + };
+7
drivers/usb/host/ehci.h
··· 62 62 63 63 #define EHCI_MAX_ROOT_PORTS 15 /* see HCS_N_PORTS */ 64 64 65 + enum ehci_rh_state { 66 + EHCI_RH_HALTED, 67 + EHCI_RH_SUSPENDED, 68 + EHCI_RH_RUNNING 69 + }; 70 + 65 71 struct ehci_hcd { /* one per controller */ 66 72 /* glue to PCI and HCD framework */ 67 73 struct ehci_caps __iomem *caps; ··· 76 70 77 71 __u32 hcs_params; /* cached register copy */ 78 72 spinlock_t lock; 73 + enum ehci_rh_state rh_state; 79 74 80 75 /* async schedule support */ 81 76 struct ehci_qh *async;
+4 -1
drivers/usb/host/fhci-hcd.c
··· 621 621 goto err_pram; 622 622 } 623 623 624 - pram_addr = cpm_muram_alloc_fixed(iprop[2], FHCI_PRAM_SIZE); 624 + pram_addr = cpm_muram_alloc(FHCI_PRAM_SIZE, 64); 625 625 if (IS_ERR_VALUE(pram_addr)) { 626 626 dev_err(dev, "failed to allocate usb pram\n"); 627 627 ret = -ENOMEM; 628 628 goto err_pram; 629 629 } 630 + 631 + qe_issue_cmd(QE_ASSIGN_PAGE_TO_DEVICE, QE_CR_SUBBLOCK_USB, 632 + QE_CR_PROTOCOL_UNSPECIFIED, pram_addr); 630 633 fhci->pram = cpm_muram_addr(pram_addr); 631 634 632 635 /* GPIOs and pins */
+3 -3
drivers/usb/host/isp1362-hcd.c
··· 2358 2358 unsigned long flags; 2359 2359 int clkrdy = 0; 2360 2360 2361 - pr_info("%s:\n", __func__); 2361 + pr_debug("%s:\n", __func__); 2362 2362 2363 2363 if (isp1362_hcd->board && isp1362_hcd->board->reset) { 2364 2364 isp1362_hcd->board->reset(hcd->self.controller, 1); ··· 2395 2395 unsigned long flags; 2396 2396 u32 tmp; 2397 2397 2398 - pr_info("%s:\n", __func__); 2398 + pr_debug("%s:\n", __func__); 2399 2399 2400 2400 del_timer_sync(&hcd->rh_timer); 2401 2401 ··· 2523 2523 u16 chipid; 2524 2524 unsigned long flags; 2525 2525 2526 - pr_info("%s:\n", __func__); 2526 + pr_debug("%s:\n", __func__); 2527 2527 2528 2528 spin_lock_irqsave(&isp1362_hcd->lock, flags); 2529 2529 chipid = isp1362_read_reg16(isp1362_hcd, HCCHIPID);
+253 -148
drivers/usb/host/isp1760-hcd.c
··· 21 21 #include <linux/uaccess.h> 22 22 #include <linux/io.h> 23 23 #include <linux/mm.h> 24 + #include <linux/timer.h> 24 25 #include <asm/unaligned.h> 25 26 #include <asm/cacheflush.h> 26 27 ··· 40 39 int int_done_map; 41 40 struct memory_chunk memory_pool[BLOCKS]; 42 41 struct list_head controlqhs, bulkqhs, interruptqhs; 43 - int active_ptds; 44 42 45 43 /* periodic schedule support */ 46 44 #define DEFAULT_I_TDPS 1024 ··· 114 114 u32 toggle; 115 115 u32 ping; 116 116 int slot; 117 + int tt_buffer_dirty; /* See USB2.0 spec section 11.17.5 */ 117 118 }; 118 119 119 120 struct urb_listitem { ··· 490 489 16 : 32, (priv->devflags & ISP1760_FLAG_ANALOG_OC) ? 491 490 "analog" : "digital"); 492 491 493 - /* This is weird: at the first plug-in of a device there seems to be 494 - one packet queued that never gets returned? */ 495 - priv->active_ptds = -1; 496 - 497 492 /* ATL reset */ 498 493 reg_write32(hcd->regs, HC_HW_MODE_CTRL, hwmode | ALL_ATX_RESET); 499 494 mdelay(10); ··· 509 512 priv->hcs_params = reg_read32(hcd->regs, HC_HCSPARAMS); 510 513 511 514 return priv_init(hcd); 512 - } 513 - 514 - static void isp1760_init_maps(struct usb_hcd *hcd) 515 - { 516 - /*set last maps, for iso its only 1, else 32 tds bitmap*/ 517 - reg_write32(hcd->regs, HC_ATL_PTD_LASTPTD_REG, 0x80000000); 518 - reg_write32(hcd->regs, HC_INT_PTD_LASTPTD_REG, 0x80000000); 519 - reg_write32(hcd->regs, HC_ISO_PTD_LASTPTD_REG, 0x00000001); 520 - 521 - reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, 0xffffffff); 522 - reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, 0xffffffff); 523 - reg_write32(hcd->regs, HC_ISO_PTD_SKIPMAP_REG, 0xffffffff); 524 - 525 - reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, 526 - ATL_BUF_FILL | INT_BUF_FILL); 527 - } 528 - 529 - static void isp1760_enable_interrupts(struct usb_hcd *hcd) 530 - { 531 - reg_write32(hcd->regs, HC_ATL_IRQ_MASK_AND_REG, 0); 532 - reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, 0xffffffff); 533 - reg_write32(hcd->regs, HC_INT_IRQ_MASK_AND_REG, 0); 534 - reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, 0xffffffff); 535 - reg_write32(hcd->regs, HC_ISO_IRQ_MASK_AND_REG, 0); 536 - reg_write32(hcd->regs, HC_ISO_IRQ_MASK_OR_REG, 0xffffffff); 537 - /* step 23 passed */ 538 - } 539 - 540 - static int isp1760_run(struct usb_hcd *hcd) 541 - { 542 - int retval; 543 - u32 temp; 544 - u32 command; 545 - u32 chipid; 546 - 547 - hcd->uses_new_polling = 1; 548 - 549 - hcd->state = HC_STATE_RUNNING; 550 - isp1760_enable_interrupts(hcd); 551 - temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL); 552 - reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp | HW_GLOBAL_INTR_EN); 553 - 554 - command = reg_read32(hcd->regs, HC_USBCMD); 555 - command &= ~(CMD_LRESET|CMD_RESET); 556 - command |= CMD_RUN; 557 - reg_write32(hcd->regs, HC_USBCMD, command); 558 - 559 - retval = handshake(hcd, HC_USBCMD, CMD_RUN, CMD_RUN, 250 * 1000); 560 - if (retval) 561 - return retval; 562 - 563 - /* 564 - * XXX 565 - * Spec says to write FLAG_CF as last config action, priv code grabs 566 - * the semaphore while doing so. 567 - */ 568 - down_write(&ehci_cf_port_reset_rwsem); 569 - reg_write32(hcd->regs, HC_CONFIGFLAG, FLAG_CF); 570 - 571 - retval = handshake(hcd, HC_CONFIGFLAG, FLAG_CF, FLAG_CF, 250 * 1000); 572 - up_write(&ehci_cf_port_reset_rwsem); 573 - if (retval) 574 - return retval; 575 - 576 - chipid = reg_read32(hcd->regs, HC_CHIP_ID_REG); 577 - dev_info(hcd->self.controller, "USB ISP %04x HW rev. %d started\n", 578 - chipid & 0xffff, chipid >> 16); 579 - 580 - /* PTD Register Init Part 2, Step 28 */ 581 - /* enable INTs */ 582 - isp1760_init_maps(hcd); 583 - 584 - /* GRR this is run-once init(), being done every time the HC starts. 585 - * So long as they're part of class devices, we can't do it init() 586 - * since the class device isn't created that early. 587 - */ 588 - return 0; 589 515 } 590 516 591 517 static u32 base_to_chip(u32 base) ··· 733 813 WARN_ON(slots[slot].qh); 734 814 WARN_ON(qtd->status != QTD_PAYLOAD_ALLOC); 735 815 736 - slots[slot].qtd = qtd; 737 - slots[slot].qh = qh; 738 - qh->slot = slot; 739 - qtd->status = QTD_XFER_STARTED; /* Set this before writing ptd, since 740 - interrupt routine may preempt and expects this value. */ 741 - ptd_write(hcd->regs, ptd_offset, slot, ptd); 742 - priv->active_ptds++; 743 - 744 816 /* Make sure done map has not triggered from some unlinked transfer */ 745 817 if (ptd_offset == ATL_PTD_OFFSET) { 746 818 priv->atl_done_map |= reg_read32(hcd->regs, 747 819 HC_ATL_PTD_DONEMAP_REG); 748 - priv->atl_done_map &= ~(1 << qh->slot); 820 + priv->atl_done_map &= ~(1 << slot); 821 + } else { 822 + priv->int_done_map |= reg_read32(hcd->regs, 823 + HC_INT_PTD_DONEMAP_REG); 824 + priv->int_done_map &= ~(1 << slot); 825 + } 749 826 827 + qh->slot = slot; 828 + qtd->status = QTD_XFER_STARTED; 829 + slots[slot].timestamp = jiffies; 830 + slots[slot].qtd = qtd; 831 + slots[slot].qh = qh; 832 + ptd_write(hcd->regs, ptd_offset, slot, ptd); 833 + 834 + if (ptd_offset == ATL_PTD_OFFSET) { 750 835 skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); 751 836 skip_map &= ~(1 << qh->slot); 752 837 reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, skip_map); 753 838 } else { 754 - priv->int_done_map |= reg_read32(hcd->regs, 755 - HC_INT_PTD_DONEMAP_REG); 756 - priv->int_done_map &= ~(1 << qh->slot); 757 - 758 839 skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); 759 840 skip_map &= ~(1 << qh->slot); 760 841 reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, skip_map); ··· 779 858 if (qtd->status < QTD_XFER_COMPLETE) 780 859 break; 781 860 782 - if (list_is_last(&qtd->qtd_list, &qh->qtd_list)) 783 - last_qtd = 1; 784 - else 785 - last_qtd = qtd->urb != qtd_next->urb; 861 + last_qtd = last_qtd_of_urb(qtd, qh); 786 862 787 863 if ((!last_qtd) && (qtd->status == QTD_RETIRE)) 788 864 qtd_next->status = QTD_RETIRE; ··· 820 902 urb_listitem = kmem_cache_zalloc(urb_listitem_cachep, 821 903 GFP_ATOMIC); 822 904 if (unlikely(!urb_listitem)) 823 - break; 905 + break; /* Try again on next call */ 824 906 urb_listitem->urb = qtd->urb; 825 907 list_add_tail(&urb_listitem->urb_list, urb_list); 826 908 } ··· 845 927 WARN_ON(1); 846 928 return; 847 929 } 930 + 931 + /* Make sure this endpoint's TT buffer is clean before queueing ptds */ 932 + if (qh->tt_buffer_dirty) 933 + return; 848 934 849 935 if (usb_pipeint(list_entry(qh->qtd_list.next, struct isp1760_qtd, 850 936 qtd_list)->urb->pipe)) { ··· 1090 1168 return PTD_STATE_QTD_DONE; 1091 1169 } 1092 1170 1093 - static irqreturn_t isp1760_irq(struct usb_hcd *hcd) 1171 + static void handle_done_ptds(struct usb_hcd *hcd) 1094 1172 { 1095 1173 struct isp1760_hcd *priv = hcd_to_priv(hcd); 1096 - u32 imask; 1097 - irqreturn_t irqret = IRQ_NONE; 1098 1174 struct ptd ptd; 1099 1175 struct isp1760_qh *qh; 1100 1176 int slot; ··· 1101 1181 u32 ptd_offset; 1102 1182 struct isp1760_qtd *qtd; 1103 1183 int modified; 1104 - static int last_active_ptds; 1105 - int int_skip_map, atl_skip_map; 1184 + int skip_map; 1106 1185 1107 - spin_lock(&priv->lock); 1186 + skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); 1187 + priv->int_done_map &= ~skip_map; 1188 + skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); 1189 + priv->atl_done_map &= ~skip_map; 1108 1190 1109 - if (!(hcd->state & HC_STATE_RUNNING)) 1110 - goto leave; 1111 - 1112 - imask = reg_read32(hcd->regs, HC_INTERRUPT_REG); 1113 - if (unlikely(!imask)) 1114 - goto leave; 1115 - reg_write32(hcd->regs, HC_INTERRUPT_REG, imask); /* Clear */ 1116 - 1117 - int_skip_map = reg_read32(hcd->regs, HC_INT_PTD_SKIPMAP_REG); 1118 - atl_skip_map = reg_read32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG); 1119 - priv->int_done_map |= reg_read32(hcd->regs, HC_INT_PTD_DONEMAP_REG); 1120 - priv->atl_done_map |= reg_read32(hcd->regs, HC_ATL_PTD_DONEMAP_REG); 1121 - priv->int_done_map &= ~int_skip_map; 1122 - priv->atl_done_map &= ~atl_skip_map; 1123 - 1124 - modified = priv->int_done_map | priv->atl_done_map; 1191 + modified = priv->int_done_map || priv->atl_done_map; 1125 1192 1126 1193 while (priv->int_done_map || priv->atl_done_map) { 1127 1194 if (priv->int_done_map) { ··· 1147 1240 slots[slot].qtd = NULL; 1148 1241 qh = slots[slot].qh; 1149 1242 slots[slot].qh = NULL; 1150 - priv->active_ptds--; 1151 1243 qh->slot = -1; 1152 1244 1153 1245 WARN_ON(qtd->status != QTD_XFER_STARTED); ··· 1187 1281 1188 1282 case PTD_STATE_URB_RETIRE: 1189 1283 qtd->status = QTD_RETIRE; 1284 + if ((qtd->urb->dev->speed != USB_SPEED_HIGH) && 1285 + (qtd->urb->status != -EPIPE) && 1286 + (qtd->urb->status != -EREMOTEIO)) { 1287 + qh->tt_buffer_dirty = 1; 1288 + if (usb_hub_clear_tt_buffer(qtd->urb)) 1289 + /* Clear failed; let's hope things work 1290 + anyway */ 1291 + qh->tt_buffer_dirty = 0; 1292 + } 1190 1293 qtd = NULL; 1191 1294 qh->toggle = 0; 1192 1295 qh->ping = 0; ··· 1226 1311 1227 1312 if (modified) 1228 1313 schedule_ptds(hcd); 1314 + } 1229 1315 1230 - /* ISP1760 Errata 2 explains that interrupts may be missed (or not 1231 - happen?) if two USB devices are running simultaneously. Perhaps 1232 - this happens when a PTD is finished during interrupt handling; 1233 - enable SOF interrupts if PTDs are still scheduled when exiting this 1234 - interrupt handler, just to be safe. */ 1316 + static irqreturn_t isp1760_irq(struct usb_hcd *hcd) 1317 + { 1318 + struct isp1760_hcd *priv = hcd_to_priv(hcd); 1319 + u32 imask; 1320 + irqreturn_t irqret = IRQ_NONE; 1235 1321 1236 - if (priv->active_ptds != last_active_ptds) { 1237 - if (priv->active_ptds > 0) 1238 - reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, 1239 - INTERRUPT_ENABLE_SOT_MASK); 1240 - else 1241 - reg_write32(hcd->regs, HC_INTERRUPT_ENABLE, 1242 - INTERRUPT_ENABLE_MASK); 1243 - last_active_ptds = priv->active_ptds; 1244 - } 1322 + spin_lock(&priv->lock); 1323 + 1324 + if (!(hcd->state & HC_STATE_RUNNING)) 1325 + goto leave; 1326 + 1327 + imask = reg_read32(hcd->regs, HC_INTERRUPT_REG); 1328 + if (unlikely(!imask)) 1329 + goto leave; 1330 + reg_write32(hcd->regs, HC_INTERRUPT_REG, imask); /* Clear */ 1331 + 1332 + priv->int_done_map |= reg_read32(hcd->regs, HC_INT_PTD_DONEMAP_REG); 1333 + priv->atl_done_map |= reg_read32(hcd->regs, HC_ATL_PTD_DONEMAP_REG); 1334 + 1335 + handle_done_ptds(hcd); 1245 1336 1246 1337 irqret = IRQ_HANDLED; 1247 1338 leave: 1248 1339 spin_unlock(&priv->lock); 1249 1340 1250 1341 return irqret; 1342 + } 1343 + 1344 + /* 1345 + * Workaround for problem described in chip errata 2: 1346 + * 1347 + * Sometimes interrupts are not generated when ATL (not INT?) completion occurs. 1348 + * One solution suggested in the errata is to use SOF interrupts _instead_of_ 1349 + * ATL done interrupts (the "instead of" might be important since it seems 1350 + * enabling ATL interrupts also causes the chip to sometimes - rarely - "forget" 1351 + * to set the PTD's done bit in addition to not generating an interrupt!). 1352 + * 1353 + * So if we use SOF + ATL interrupts, we sometimes get stale PTDs since their 1354 + * done bit is not being set. This is bad - it blocks the endpoint until reboot. 1355 + * 1356 + * If we use SOF interrupts only, we get latency between ptd completion and the 1357 + * actual handling. This is very noticeable in testusb runs which takes several 1358 + * minutes longer without ATL interrupts. 1359 + * 1360 + * A better solution is to run the code below every SLOT_CHECK_PERIOD ms. If it 1361 + * finds active ATL slots which are older than SLOT_TIMEOUT ms, it checks the 1362 + * slot's ACTIVE and VALID bits. If these are not set, the ptd is considered 1363 + * completed and its done map bit is set. 1364 + * 1365 + * The values of SLOT_TIMEOUT and SLOT_CHECK_PERIOD have been arbitrarily chosen 1366 + * not to cause too much lag when this HW bug occurs, while still hopefully 1367 + * ensuring that the check does not falsely trigger. 1368 + */ 1369 + #define SLOT_TIMEOUT 300 1370 + #define SLOT_CHECK_PERIOD 200 1371 + static struct timer_list errata2_timer; 1372 + 1373 + void errata2_function(unsigned long data) 1374 + { 1375 + struct usb_hcd *hcd = (struct usb_hcd *) data; 1376 + struct isp1760_hcd *priv = hcd_to_priv(hcd); 1377 + int slot; 1378 + struct ptd ptd; 1379 + unsigned long spinflags; 1380 + 1381 + spin_lock_irqsave(&priv->lock, spinflags); 1382 + 1383 + for (slot = 0; slot < 32; slot++) 1384 + if (priv->atl_slots[slot].qh && time_after(jiffies, 1385 + priv->atl_slots[slot].timestamp + 1386 + SLOT_TIMEOUT * HZ / 1000)) { 1387 + ptd_read(hcd->regs, ATL_PTD_OFFSET, slot, &ptd); 1388 + if (!FROM_DW0_VALID(ptd.dw0) && 1389 + !FROM_DW3_ACTIVE(ptd.dw3)) 1390 + priv->atl_done_map |= 1 << slot; 1391 + } 1392 + 1393 + if (priv->atl_done_map) 1394 + handle_done_ptds(hcd); 1395 + 1396 + spin_unlock_irqrestore(&priv->lock, spinflags); 1397 + 1398 + errata2_timer.expires = jiffies + SLOT_CHECK_PERIOD * HZ / 1000; 1399 + add_timer(&errata2_timer); 1400 + } 1401 + 1402 + static int isp1760_run(struct usb_hcd *hcd) 1403 + { 1404 + int retval; 1405 + u32 temp; 1406 + u32 command; 1407 + u32 chipid; 1408 + 1409 + hcd->uses_new_polling = 1; 1410 + 1411 + hcd->state = HC_STATE_RUNNING; 1412 + 1413 + /* Set PTD interrupt AND & OR maps */ 1414 + reg_write32(hcd->regs, HC_ATL_IRQ_MASK_AND_REG, 0); 1415 + reg_write32(hcd->regs, HC_ATL_IRQ_MASK_OR_REG, 0xffffffff); 1416 + reg_write32(hcd->regs, HC_INT_IRQ_MASK_AND_REG, 0); 1417 + reg_write32(hcd->regs, HC_INT_IRQ_MASK_OR_REG, 0xffffffff); 1418 + reg_write32(hcd->regs, HC_ISO_IRQ_MASK_AND_REG, 0); 1419 + reg_write32(hcd->regs, HC_ISO_IRQ_MASK_OR_REG, 0xffffffff); 1420 + /* step 23 passed */ 1421 + 1422 + temp = reg_read32(hcd->regs, HC_HW_MODE_CTRL); 1423 + reg_write32(hcd->regs, HC_HW_MODE_CTRL, temp | HW_GLOBAL_INTR_EN); 1424 + 1425 + command = reg_read32(hcd->regs, HC_USBCMD); 1426 + command &= ~(CMD_LRESET|CMD_RESET); 1427 + command |= CMD_RUN; 1428 + reg_write32(hcd->regs, HC_USBCMD, command); 1429 + 1430 + retval = handshake(hcd, HC_USBCMD, CMD_RUN, CMD_RUN, 250 * 1000); 1431 + if (retval) 1432 + return retval; 1433 + 1434 + /* 1435 + * XXX 1436 + * Spec says to write FLAG_CF as last config action, priv code grabs 1437 + * the semaphore while doing so. 1438 + */ 1439 + down_write(&ehci_cf_port_reset_rwsem); 1440 + reg_write32(hcd->regs, HC_CONFIGFLAG, FLAG_CF); 1441 + 1442 + retval = handshake(hcd, HC_CONFIGFLAG, FLAG_CF, FLAG_CF, 250 * 1000); 1443 + up_write(&ehci_cf_port_reset_rwsem); 1444 + if (retval) 1445 + return retval; 1446 + 1447 + init_timer(&errata2_timer); 1448 + errata2_timer.function = errata2_function; 1449 + errata2_timer.data = (unsigned long) hcd; 1450 + errata2_timer.expires = jiffies + SLOT_CHECK_PERIOD * HZ / 1000; 1451 + add_timer(&errata2_timer); 1452 + 1453 + chipid = reg_read32(hcd->regs, HC_CHIP_ID_REG); 1454 + dev_info(hcd->self.controller, "USB ISP %04x HW rev. %d started\n", 1455 + chipid & 0xffff, chipid >> 16); 1456 + 1457 + /* PTD Register Init Part 2, Step 28 */ 1458 + 1459 + /* Setup registers controlling PTD checking */ 1460 + reg_write32(hcd->regs, HC_ATL_PTD_LASTPTD_REG, 0x80000000); 1461 + reg_write32(hcd->regs, HC_INT_PTD_LASTPTD_REG, 0x80000000); 1462 + reg_write32(hcd->regs, HC_ISO_PTD_LASTPTD_REG, 0x00000001); 1463 + reg_write32(hcd->regs, HC_ATL_PTD_SKIPMAP_REG, 0xffffffff); 1464 + reg_write32(hcd->regs, HC_INT_PTD_SKIPMAP_REG, 0xffffffff); 1465 + reg_write32(hcd->regs, HC_ISO_PTD_SKIPMAP_REG, 0xffffffff); 1466 + reg_write32(hcd->regs, HC_BUFFER_STATUS_REG, 1467 + ATL_BUF_FILL | INT_BUF_FILL); 1468 + 1469 + /* GRR this is run-once init(), being done every time the HC starts. 1470 + * So long as they're part of class devices, we can't do it init() 1471 + * since the class device isn't created that early. 1472 + */ 1473 + return 0; 1251 1474 } 1252 1475 1253 1476 static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len) ··· 1556 1503 packetize_urb(hcd, urb, &new_qtds, mem_flags); 1557 1504 if (list_empty(&new_qtds)) 1558 1505 return -ENOMEM; 1559 - urb->hcpriv = NULL; /* Used to signal unlink to interrupt handler */ 1560 1506 1561 1507 retval = 0; 1562 1508 spin_lock_irqsave(&priv->lock, spinflags); ··· 1583 1531 qh = qh_alloc(GFP_ATOMIC); 1584 1532 if (!qh) { 1585 1533 retval = -ENOMEM; 1534 + usb_hcd_unlink_urb_from_ep(hcd, urb); 1586 1535 goto out; 1587 1536 } 1588 1537 list_add_tail(&qh->qh_list, ep_queue); ··· 1623 1570 } 1624 1571 1625 1572 qh->slot = -1; 1626 - priv->active_ptds--; 1573 + } 1574 + 1575 + /* 1576 + * Retire the qtds beginning at 'qtd' and belonging all to the same urb, killing 1577 + * any active transfer belonging to the urb in the process. 1578 + */ 1579 + static void dequeue_urb_from_qtd(struct usb_hcd *hcd, struct isp1760_qh *qh, 1580 + struct isp1760_qtd *qtd) 1581 + { 1582 + struct urb *urb; 1583 + int urb_was_running; 1584 + 1585 + urb = qtd->urb; 1586 + urb_was_running = 0; 1587 + list_for_each_entry_from(qtd, &qh->qtd_list, qtd_list) { 1588 + if (qtd->urb != urb) 1589 + break; 1590 + 1591 + if (qtd->status >= QTD_XFER_STARTED) 1592 + urb_was_running = 1; 1593 + if (last_qtd_of_urb(qtd, qh) && 1594 + (qtd->status >= QTD_XFER_COMPLETE)) 1595 + urb_was_running = 0; 1596 + 1597 + if (qtd->status == QTD_XFER_STARTED) 1598 + kill_transfer(hcd, urb, qh); 1599 + qtd->status = QTD_RETIRE; 1600 + } 1601 + 1602 + if ((urb->dev->speed != USB_SPEED_HIGH) && urb_was_running) { 1603 + qh->tt_buffer_dirty = 1; 1604 + if (usb_hub_clear_tt_buffer(urb)) 1605 + /* Clear failed; let's hope things work anyway */ 1606 + qh->tt_buffer_dirty = 0; 1607 + } 1627 1608 } 1628 1609 1629 1610 static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, ··· 1682 1595 1683 1596 list_for_each_entry(qtd, &qh->qtd_list, qtd_list) 1684 1597 if (qtd->urb == urb) { 1685 - if (qtd->status == QTD_XFER_STARTED) 1686 - kill_transfer(hcd, urb, qh); 1687 - qtd->status = QTD_RETIRE; 1598 + dequeue_urb_from_qtd(hcd, qh, qtd); 1599 + break; 1688 1600 } 1689 1601 1690 1602 urb->status = status; ··· 1708 1622 if (!qh) 1709 1623 goto out; 1710 1624 1711 - list_for_each_entry(qtd, &qh->qtd_list, qtd_list) { 1712 - if (qtd->status == QTD_XFER_STARTED) 1713 - kill_transfer(hcd, qtd->urb, qh); 1714 - qtd->status = QTD_RETIRE; 1715 - qtd->urb->status = -ECONNRESET; 1716 - } 1625 + list_for_each_entry(qtd, &qh->qtd_list, qtd_list) 1626 + if (qtd->status != QTD_RETIRE) { 1627 + dequeue_urb_from_qtd(hcd, qh, qtd); 1628 + qtd->urb->status = -ECONNRESET; 1629 + } 1717 1630 1718 1631 ep->hcpriv = NULL; 1719 1632 /* Cannot free qh here since it will be parsed by schedule_ptds() */ ··· 2106 2021 struct isp1760_hcd *priv = hcd_to_priv(hcd); 2107 2022 u32 temp; 2108 2023 2024 + del_timer(&errata2_timer); 2025 + 2109 2026 isp1760_hub_control(hcd, ClearPortFeature, USB_PORT_FEAT_POWER, 1, 2110 2027 NULL, 0); 2111 2028 mdelay(20); ··· 2135 2048 reg_write32(hcd->regs, HC_USBCMD, command); 2136 2049 } 2137 2050 2051 + static void isp1760_clear_tt_buffer_complete(struct usb_hcd *hcd, 2052 + struct usb_host_endpoint *ep) 2053 + { 2054 + struct isp1760_hcd *priv = hcd_to_priv(hcd); 2055 + struct isp1760_qh *qh = ep->hcpriv; 2056 + unsigned long spinflags; 2057 + 2058 + if (!qh) 2059 + return; 2060 + 2061 + spin_lock_irqsave(&priv->lock, spinflags); 2062 + qh->tt_buffer_dirty = 0; 2063 + schedule_ptds(hcd); 2064 + spin_unlock_irqrestore(&priv->lock, spinflags); 2065 + } 2066 + 2067 + 2138 2068 static const struct hc_driver isp1760_hc_driver = { 2139 2069 .description = "isp1760-hcd", 2140 2070 .product_desc = "NXP ISP1760 USB Host Controller", ··· 2168 2064 .get_frame_number = isp1760_get_frame, 2169 2065 .hub_status_data = isp1760_hub_status_data, 2170 2066 .hub_control = isp1760_hub_control, 2067 + .clear_tt_buffer_complete = isp1760_clear_tt_buffer_complete, 2171 2068 }; 2172 2069 2173 2070 int __init init_kmem_once(void)
+2 -1
drivers/usb/host/isp1760-hcd.h
··· 73 73 #define HC_EOT_INT (1 << 3) 74 74 #define HC_SOT_INT (1 << 1) 75 75 #define INTERRUPT_ENABLE_MASK (HC_INTL_INT | HC_ATL_INT) 76 - #define INTERRUPT_ENABLE_SOT_MASK (HC_SOT_INT) 77 76 78 77 #define HC_ISO_IRQ_MASK_OR_REG 0x318 79 78 #define HC_INT_IRQ_MASK_OR_REG 0x31C ··· 106 107 struct slotinfo { 107 108 struct isp1760_qh *qh; 108 109 struct isp1760_qtd *qtd; 110 + unsigned long timestamp; 109 111 }; 110 112 111 113 ··· 188 188 #define DW3_BABBLE_BIT (1 << 29) 189 189 #define DW3_HALT_BIT (1 << 30) 190 190 #define DW3_ACTIVE_BIT (1 << 31) 191 + #define FROM_DW3_ACTIVE(x) (((x) >> 31) & 0x01) 191 192 192 193 #define INT_UNDERRUN (1 << 2) 193 194 #define INT_BABBLE (1 << 1)
+5
drivers/usb/host/ohci-hcd.c
··· 1114 1114 #define PLATFORM_DRIVER ohci_hcd_ath79_driver 1115 1115 #endif 1116 1116 1117 + #ifdef CONFIG_NLM_XLR 1118 + #include "ohci-xls.c" 1119 + #define PLATFORM_DRIVER ohci_xls_driver 1120 + #endif 1121 + 1117 1122 #if !defined(PCI_DRIVER) && \ 1118 1123 !defined(PLATFORM_DRIVER) && \ 1119 1124 !defined(OMAP1_PLATFORM_DRIVER) && \
+1 -1
drivers/usb/host/ohci-omap3.c
··· 149 149 150 150 res = platform_get_resource_byname(pdev, 151 151 IORESOURCE_MEM, "ohci"); 152 - if (!ret) { 152 + if (!res) { 153 153 dev_err(dev, "UHH OHCI get resource failed\n"); 154 154 return -ENOMEM; 155 155 }
+2 -2
drivers/usb/host/ohci-q.c
··· 428 428 ed->type = usb_pipetype(pipe); 429 429 430 430 info |= (ep->desc.bEndpointAddress & ~USB_DIR_IN) << 7; 431 - info |= le16_to_cpu(ep->desc.wMaxPacketSize) << 16; 431 + info |= usb_endpoint_maxp(&ep->desc) << 16; 432 432 if (udev->speed == USB_SPEED_LOW) 433 433 info |= ED_LOWSPEED; 434 434 /* only control transfers store pids in tds */ ··· 444 444 ed->load = usb_calc_bus_time ( 445 445 udev->speed, !is_out, 446 446 ed->type == PIPE_ISOCHRONOUS, 447 - le16_to_cpu(ep->desc.wMaxPacketSize)) 447 + usb_endpoint_maxp(&ep->desc)) 448 448 / 1000; 449 449 } 450 450 }
+151
drivers/usb/host/ohci-xls.c
··· 1 + /* 2 + * OHCI HCD for Netlogic XLS processors. 3 + * 4 + * (C) Copyright 2011 Netlogic Microsystems Inc. 5 + * 6 + * Based on ohci-au1xxx.c, and other Linux OHCI drivers. 7 + * 8 + * This file is subject to the terms and conditions of the GNU General Public 9 + * License. See the file COPYING in the main directory of this archive for 10 + * more details. 11 + */ 12 + 13 + #include <linux/platform_device.h> 14 + #include <linux/signal.h> 15 + 16 + static int ohci_xls_probe_internal(const struct hc_driver *driver, 17 + struct platform_device *dev) 18 + { 19 + struct resource *res; 20 + struct usb_hcd *hcd; 21 + int retval, irq; 22 + 23 + /* Get our IRQ from an earlier registered Platform Resource */ 24 + irq = platform_get_irq(dev, 0); 25 + if (irq < 0) { 26 + dev_err(&dev->dev, "Found HC with no IRQ\n"); 27 + return -ENODEV; 28 + } 29 + 30 + /* Get our Memory Handle */ 31 + res = platform_get_resource(dev, IORESOURCE_MEM, 0); 32 + if (!res) { 33 + dev_err(&dev->dev, "MMIO Handle incorrect!\n"); 34 + return -ENODEV; 35 + } 36 + 37 + hcd = usb_create_hcd(driver, &dev->dev, "XLS"); 38 + if (!hcd) { 39 + retval = -ENOMEM; 40 + goto err1; 41 + } 42 + hcd->rsrc_start = res->start; 43 + hcd->rsrc_len = res->end - res->start + 1; 44 + 45 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, 46 + driver->description)) { 47 + dev_dbg(&dev->dev, "Controller already in use\n"); 48 + retval = -EBUSY; 49 + goto err2; 50 + } 51 + 52 + hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); 53 + if (hcd->regs == NULL) { 54 + dev_dbg(&dev->dev, "error mapping memory\n"); 55 + retval = -EFAULT; 56 + goto err3; 57 + } 58 + 59 + retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); 60 + if (retval != 0) 61 + goto err4; 62 + return retval; 63 + 64 + err4: 65 + iounmap(hcd->regs); 66 + err3: 67 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 68 + err2: 69 + usb_put_hcd(hcd); 70 + err1: 71 + dev_err(&dev->dev, "init fail, %d\n", retval); 72 + return retval; 73 + } 74 + 75 + static int ohci_xls_reset(struct usb_hcd *hcd) 76 + { 77 + struct ohci_hcd *ohci = hcd_to_ohci(hcd); 78 + 79 + ohci_hcd_init(ohci); 80 + return ohci_init(ohci); 81 + } 82 + 83 + static int __devinit ohci_xls_start(struct usb_hcd *hcd) 84 + { 85 + struct ohci_hcd *ohci; 86 + int ret; 87 + 88 + ohci = hcd_to_ohci(hcd); 89 + ret = ohci_run(ohci); 90 + if (ret < 0) { 91 + err("can't start %s", hcd->self.bus_name); 92 + ohci_stop(hcd); 93 + return ret; 94 + } 95 + return 0; 96 + } 97 + 98 + static struct hc_driver ohci_xls_hc_driver = { 99 + .description = hcd_name, 100 + .product_desc = "XLS OHCI Host Controller", 101 + .hcd_priv_size = sizeof(struct ohci_hcd), 102 + .irq = ohci_irq, 103 + .flags = HCD_MEMORY | HCD_USB11, 104 + .reset = ohci_xls_reset, 105 + .start = ohci_xls_start, 106 + .stop = ohci_stop, 107 + .shutdown = ohci_shutdown, 108 + .urb_enqueue = ohci_urb_enqueue, 109 + .urb_dequeue = ohci_urb_dequeue, 110 + .endpoint_disable = ohci_endpoint_disable, 111 + .get_frame_number = ohci_get_frame, 112 + .hub_status_data = ohci_hub_status_data, 113 + .hub_control = ohci_hub_control, 114 + #ifdef CONFIG_PM 115 + .bus_suspend = ohci_bus_suspend, 116 + .bus_resume = ohci_bus_resume, 117 + #endif 118 + .start_port_reset = ohci_start_port_reset, 119 + }; 120 + 121 + static int ohci_xls_probe(struct platform_device *dev) 122 + { 123 + int ret; 124 + 125 + pr_debug("In ohci_xls_probe"); 126 + if (usb_disabled()) 127 + return -ENODEV; 128 + ret = ohci_xls_probe_internal(&ohci_xls_hc_driver, dev); 129 + return ret; 130 + } 131 + 132 + static int ohci_xls_remove(struct platform_device *dev) 133 + { 134 + struct usb_hcd *hcd = platform_get_drvdata(dev); 135 + 136 + usb_remove_hcd(hcd); 137 + iounmap(hcd->regs); 138 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 139 + usb_put_hcd(hcd); 140 + return 0; 141 + } 142 + 143 + static struct platform_driver ohci_xls_driver = { 144 + .probe = ohci_xls_probe, 145 + .remove = ohci_xls_remove, 146 + .shutdown = usb_hcd_platform_shutdown, 147 + .driver = { 148 + .name = "ohci-xls-0", 149 + .owner = THIS_MODULE, 150 + }, 151 + };
+1 -1
drivers/usb/host/r8a66597-hcd.c
··· 959 959 info.pipenum = get_empty_pipenum(r8a66597, ep); 960 960 info.address = get_urb_to_r8a66597_addr(r8a66597, urb); 961 961 info.epnum = usb_endpoint_num(ep); 962 - info.maxpacket = le16_to_cpu(ep->wMaxPacketSize); 962 + info.maxpacket = usb_endpoint_maxp(ep); 963 963 info.type = get_r8a66597_type(usb_endpoint_type(ep)); 964 964 info.bufnum = get_bufnum(info.pipenum); 965 965 info.buf_bsize = get_buf_bsize(info.pipenum);
+3 -3
drivers/usb/host/uhci-q.c
··· 280 280 qh->load = usb_calc_bus_time(udev->speed, 281 281 usb_endpoint_dir_in(&hep->desc), 282 282 qh->type == USB_ENDPOINT_XFER_ISOC, 283 - le16_to_cpu(hep->desc.wMaxPacketSize)) 283 + usb_endpoint_maxp(&hep->desc)) 284 284 / 1000 + 1; 285 285 286 286 } else { /* Skeleton QH */ ··· 792 792 { 793 793 struct uhci_td *td; 794 794 unsigned long destination, status; 795 - int maxsze = le16_to_cpu(qh->hep->desc.wMaxPacketSize); 795 + int maxsze = usb_endpoint_maxp(&qh->hep->desc); 796 796 int len = urb->transfer_buffer_length; 797 797 dma_addr_t data = urb->transfer_dma; 798 798 __hc32 *plink; ··· 918 918 { 919 919 struct uhci_td *td; 920 920 unsigned long destination, status; 921 - int maxsze = le16_to_cpu(qh->hep->desc.wMaxPacketSize); 921 + int maxsze = usb_endpoint_maxp(&qh->hep->desc); 922 922 int len = urb->transfer_buffer_length; 923 923 int this_sg_len; 924 924 dma_addr_t data;
+5 -5
drivers/usb/host/xhci-mem.c
··· 1141 1141 if (udev->speed == USB_SPEED_SUPER) 1142 1142 return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval); 1143 1143 1144 - max_packet = GET_MAX_PACKET(le16_to_cpu(ep->desc.wMaxPacketSize)); 1145 - max_burst = (le16_to_cpu(ep->desc.wMaxPacketSize) & 0x1800) >> 11; 1144 + max_packet = GET_MAX_PACKET(usb_endpoint_maxp(&ep->desc)); 1145 + max_burst = (usb_endpoint_maxp(&ep->desc) & 0x1800) >> 11; 1146 1146 /* A 0 in max burst means 1 transfer per ESIT */ 1147 1147 return max_packet * (max_burst + 1); 1148 1148 } ··· 1211 1211 /* Set the max packet size and max burst */ 1212 1212 switch (udev->speed) { 1213 1213 case USB_SPEED_SUPER: 1214 - max_packet = le16_to_cpu(ep->desc.wMaxPacketSize); 1214 + max_packet = usb_endpoint_maxp(&ep->desc); 1215 1215 ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet)); 1216 1216 /* dig out max burst from ep companion desc */ 1217 1217 max_packet = ep->ss_ep_comp.bMaxBurst; ··· 1223 1223 */ 1224 1224 if (usb_endpoint_xfer_isoc(&ep->desc) || 1225 1225 usb_endpoint_xfer_int(&ep->desc)) { 1226 - max_burst = (le16_to_cpu(ep->desc.wMaxPacketSize) 1226 + max_burst = (usb_endpoint_maxp(&ep->desc) 1227 1227 & 0x1800) >> 11; 1228 1228 ep_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(max_burst)); 1229 1229 } 1230 1230 /* Fall through */ 1231 1231 case USB_SPEED_FULL: 1232 1232 case USB_SPEED_LOW: 1233 - max_packet = GET_MAX_PACKET(le16_to_cpu(ep->desc.wMaxPacketSize)); 1233 + max_packet = GET_MAX_PACKET(usb_endpoint_maxp(&ep->desc)); 1234 1234 ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet)); 1235 1235 break; 1236 1236 default:
+4 -4
drivers/usb/host/xhci-ring.c
··· 2692 2692 * running_total. 2693 2693 */ 2694 2694 packets_transferred = (running_total + trb_buff_len) / 2695 - le16_to_cpu(urb->ep->desc.wMaxPacketSize); 2695 + usb_endpoint_maxp(&urb->ep->desc); 2696 2696 2697 2697 return xhci_td_remainder(total_packet_count - packets_transferred); 2698 2698 } ··· 2722 2722 num_trbs = count_sg_trbs_needed(xhci, urb); 2723 2723 num_sgs = urb->num_sgs; 2724 2724 total_packet_count = roundup(urb->transfer_buffer_length, 2725 - le16_to_cpu(urb->ep->desc.wMaxPacketSize)); 2725 + usb_endpoint_maxp(&urb->ep->desc)); 2726 2726 2727 2727 trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id], 2728 2728 ep_index, urb->stream_id, ··· 2929 2929 2930 2930 running_total = 0; 2931 2931 total_packet_count = roundup(urb->transfer_buffer_length, 2932 - le16_to_cpu(urb->ep->desc.wMaxPacketSize)); 2932 + usb_endpoint_maxp(&urb->ep->desc)); 2933 2933 /* How much data is in the first TRB? */ 2934 2934 addr = (u64) urb->transfer_dma; 2935 2935 trb_buff_len = TRB_MAX_BUFF_SIZE - ··· 3250 3250 td_len = urb->iso_frame_desc[i].length; 3251 3251 td_remain_len = td_len; 3252 3252 total_packet_count = roundup(td_len, 3253 - le16_to_cpu(urb->ep->desc.wMaxPacketSize)); 3253 + usb_endpoint_maxp(&urb->ep->desc)); 3254 3254 /* A zero-length transfer still involves at least one packet. */ 3255 3255 if (total_packet_count == 0) 3256 3256 total_packet_count++;
+1 -1
drivers/usb/host/xhci.c
··· 987 987 out_ctx = xhci->devs[slot_id]->out_ctx; 988 988 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); 989 989 hw_max_packet_size = MAX_PACKET_DECODED(le32_to_cpu(ep_ctx->ep_info2)); 990 - max_packet_size = le16_to_cpu(urb->dev->ep0.desc.wMaxPacketSize); 990 + max_packet_size = usb_endpoint_maxp(&urb->dev->ep0.desc); 991 991 if (hw_max_packet_size != max_packet_size) { 992 992 xhci_dbg(xhci, "Max Packet Size for ep 0 changed.\n"); 993 993 xhci_dbg(xhci, "Max packet size in usb_device = %d\n",
+7 -7
drivers/usb/misc/adutux.c
··· 213 213 214 214 if (urb->actual_length > 0 && dev->interrupt_in_buffer[0] != 0x00) { 215 215 if (dev->read_buffer_length < 216 - (4 * le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize)) - 216 + (4 * usb_endpoint_maxp(dev->interrupt_in_endpoint)) - 217 217 (urb->actual_length)) { 218 218 memcpy (dev->read_buffer_primary + 219 219 dev->read_buffer_length, ··· 315 315 usb_rcvintpipe(dev->udev, 316 316 dev->interrupt_in_endpoint->bEndpointAddress), 317 317 dev->interrupt_in_buffer, 318 - le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize), 318 + usb_endpoint_maxp(dev->interrupt_in_endpoint), 319 319 adu_interrupt_in_callback, dev, 320 320 dev->interrupt_in_endpoint->bInterval); 321 321 dev->read_urb_finished = 0; ··· 483 483 usb_rcvintpipe(dev->udev, 484 484 dev->interrupt_in_endpoint->bEndpointAddress), 485 485 dev->interrupt_in_buffer, 486 - le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize), 486 + usb_endpoint_maxp(dev->interrupt_in_endpoint), 487 487 adu_interrupt_in_callback, 488 488 dev, 489 489 dev->interrupt_in_endpoint->bInterval); ··· 536 536 usb_rcvintpipe(dev->udev, 537 537 dev->interrupt_in_endpoint->bEndpointAddress), 538 538 dev->interrupt_in_buffer, 539 - le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize), 539 + usb_endpoint_maxp(dev->interrupt_in_endpoint), 540 540 adu_interrupt_in_callback, 541 541 dev, 542 542 dev->interrupt_in_endpoint->bInterval); ··· 622 622 dbg(4," %s : sending, count = %Zd", __func__, count); 623 623 624 624 /* write the data into interrupt_out_buffer from userspace */ 625 - buffer_size = le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize); 625 + buffer_size = usb_endpoint_maxp(dev->interrupt_out_endpoint); 626 626 bytes_to_write = count > buffer_size ? buffer_size : count; 627 627 dbg(4," %s : buffer_size = %Zd, count = %Zd, bytes_to_write = %Zd", 628 628 __func__, buffer_size, count, bytes_to_write); ··· 752 752 goto error; 753 753 } 754 754 755 - in_end_size = le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize); 756 - out_end_size = le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize); 755 + in_end_size = usb_endpoint_maxp(dev->interrupt_in_endpoint); 756 + out_end_size = usb_endpoint_maxp(dev->interrupt_out_endpoint); 757 757 758 758 dev->read_buffer_primary = kmalloc((4 * in_end_size), GFP_KERNEL); 759 759 if (!dev->read_buffer_primary) {
+1 -1
drivers/usb/misc/ftdi-elan.c
··· 2777 2777 endpoint = &iface_desc->endpoint[i].desc; 2778 2778 if (!ftdi->bulk_in_endpointAddr && 2779 2779 usb_endpoint_is_bulk_in(endpoint)) { 2780 - buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 2780 + buffer_size = usb_endpoint_maxp(endpoint); 2781 2781 ftdi->bulk_in_size = buffer_size; 2782 2782 ftdi->bulk_in_endpointAddr = endpoint->bEndpointAddress; 2783 2783 ftdi->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
+1 -1
drivers/usb/misc/idmouse.c
··· 359 359 endpoint = &iface_desc->endpoint[0].desc; 360 360 if (!dev->bulk_in_endpointAddr && usb_endpoint_is_bulk_in(endpoint)) { 361 361 /* we found a bulk in endpoint */ 362 - dev->orig_bi_size = le16_to_cpu(endpoint->wMaxPacketSize); 362 + dev->orig_bi_size = usb_endpoint_maxp(endpoint); 363 363 dev->bulk_in_size = 0x200; /* works _much_ faster */ 364 364 dev->bulk_in_endpointAddr = endpoint->bEndpointAddress; 365 365 dev->bulk_in_buffer =
+1 -1
drivers/usb/misc/iowarrior.c
··· 803 803 dev->int_out_endpoint = endpoint; 804 804 } 805 805 /* we have to check the report_size often, so remember it in the endianess suitable for our machine */ 806 - dev->report_size = le16_to_cpu(dev->int_in_endpoint->wMaxPacketSize); 806 + dev->report_size = usb_endpoint_maxp(dev->int_in_endpoint); 807 807 if ((dev->interface->cur_altsetting->desc.bInterfaceNumber == 0) && 808 808 (dev->product_id == USB_DEVICE_ID_CODEMERCS_IOW56)) 809 809 /* IOWarrior56 has wMaxPacketSize different from report size */
+2 -2
drivers/usb/misc/ldusb.c
··· 721 721 if (dev->interrupt_out_endpoint == NULL) 722 722 dev_warn(&intf->dev, "Interrupt out endpoint not found (using control endpoint instead)\n"); 723 723 724 - dev->interrupt_in_endpoint_size = le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize); 724 + dev->interrupt_in_endpoint_size = usb_endpoint_maxp(dev->interrupt_in_endpoint); 725 725 dev->ring_buffer = kmalloc(ring_buffer_size*(sizeof(size_t)+dev->interrupt_in_endpoint_size), GFP_KERNEL); 726 726 if (!dev->ring_buffer) { 727 727 dev_err(&intf->dev, "Couldn't allocate ring_buffer\n"); ··· 737 737 dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb\n"); 738 738 goto error; 739 739 } 740 - dev->interrupt_out_endpoint_size = dev->interrupt_out_endpoint ? le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize) : 740 + dev->interrupt_out_endpoint_size = dev->interrupt_out_endpoint ? usb_endpoint_maxp(dev->interrupt_out_endpoint) : 741 741 udev->descriptor.bMaxPacketSize0; 742 742 dev->interrupt_out_buffer = kmalloc(write_buffer_size*dev->interrupt_out_endpoint_size, GFP_KERNEL); 743 743 if (!dev->interrupt_out_buffer) {
+2 -2
drivers/usb/misc/legousbtower.c
··· 409 409 dev->udev, 410 410 usb_rcvintpipe(dev->udev, dev->interrupt_in_endpoint->bEndpointAddress), 411 411 dev->interrupt_in_buffer, 412 - le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize), 412 + usb_endpoint_maxp(dev->interrupt_in_endpoint), 413 413 tower_interrupt_in_callback, 414 414 dev, 415 415 dev->interrupt_in_interval); ··· 928 928 err("Couldn't allocate read_buffer"); 929 929 goto error; 930 930 } 931 - dev->interrupt_in_buffer = kmalloc (le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize), GFP_KERNEL); 931 + dev->interrupt_in_buffer = kmalloc (usb_endpoint_maxp(dev->interrupt_in_endpoint), GFP_KERNEL); 932 932 if (!dev->interrupt_in_buffer) { 933 933 err("Couldn't allocate interrupt_in_buffer"); 934 934 goto error;
+72 -57
drivers/usb/misc/usblcd.c
··· 18 18 #include <linux/slab.h> 19 19 #include <linux/errno.h> 20 20 #include <linux/mutex.h> 21 - #include <asm/uaccess.h> 21 + #include <linux/uaccess.h> 22 22 #include <linux/usb.h> 23 23 24 24 #define DRIVER_VERSION "USBLCD Driver Version 1.05" ··· 34 34 { .idVendor = 0x10D2, .match_flags = USB_DEVICE_ID_MATCH_VENDOR, }, 35 35 { }, 36 36 }; 37 - MODULE_DEVICE_TABLE (usb, id_table); 37 + MODULE_DEVICE_TABLE(usb, id_table); 38 38 39 39 static DEFINE_MUTEX(open_disc_mutex); 40 40 41 41 42 42 struct usb_lcd { 43 - struct usb_device * udev; /* init: probe_lcd */ 44 - struct usb_interface * interface; /* the interface for this device */ 45 - unsigned char * bulk_in_buffer; /* the buffer to receive data */ 46 - size_t bulk_in_size; /* the size of the receive buffer */ 47 - __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ 48 - __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ 43 + struct usb_device *udev; /* init: probe_lcd */ 44 + struct usb_interface *interface; /* the interface for 45 + this device */ 46 + unsigned char *bulk_in_buffer; /* the buffer to receive 47 + data */ 48 + size_t bulk_in_size; /* the size of the 49 + receive buffer */ 50 + __u8 bulk_in_endpointAddr; /* the address of the 51 + bulk in endpoint */ 52 + __u8 bulk_out_endpointAddr; /* the address of the 53 + bulk out endpoint */ 49 54 struct kref kref; 50 - struct semaphore limit_sem; /* to stop writes at full throttle from 51 - * using up all RAM */ 52 - struct usb_anchor submitted; /* URBs to wait for before suspend */ 55 + struct semaphore limit_sem; /* to stop writes at 56 + full throttle from 57 + using up all RAM */ 58 + struct usb_anchor submitted; /* URBs to wait for 59 + before suspend */ 53 60 }; 54 61 #define to_lcd_dev(d) container_of(d, struct usb_lcd, kref) 55 62 ··· 70 63 struct usb_lcd *dev = to_lcd_dev(kref); 71 64 72 65 usb_put_dev(dev->udev); 73 - kfree (dev->bulk_in_buffer); 74 - kfree (dev); 66 + kfree(dev->bulk_in_buffer); 67 + kfree(dev); 75 68 } 76 69 77 70 ··· 87 80 interface = usb_find_interface(&lcd_driver, subminor); 88 81 if (!interface) { 89 82 mutex_unlock(&lcd_mutex); 90 - err ("USBLCD: %s - error, can't find device for minor %d", 83 + err("USBLCD: %s - error, can't find device for minor %d", 91 84 __func__, subminor); 92 85 return -ENODEV; 93 86 } ··· 133 126 return 0; 134 127 } 135 128 136 - static ssize_t lcd_read(struct file *file, char __user * buffer, size_t count, loff_t *ppos) 129 + static ssize_t lcd_read(struct file *file, char __user * buffer, 130 + size_t count, loff_t *ppos) 137 131 { 138 132 struct usb_lcd *dev; 139 133 int retval = 0; ··· 143 135 dev = file->private_data; 144 136 145 137 /* do a blocking bulk read to get data from the device */ 146 - retval = usb_bulk_msg(dev->udev, 147 - usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr), 138 + retval = usb_bulk_msg(dev->udev, 139 + usb_rcvbulkpipe(dev->udev, 140 + dev->bulk_in_endpointAddr), 148 141 dev->bulk_in_buffer, 149 142 min(dev->bulk_in_size, count), 150 143 &bytes_read, 10000); ··· 170 161 dev = file->private_data; 171 162 if (dev == NULL) 172 163 return -ENODEV; 173 - 164 + 174 165 switch (cmd) { 175 166 case IOCTL_GET_HARD_VERSION: 176 167 mutex_lock(&lcd_mutex); 177 168 bcdDevice = le16_to_cpu((dev->udev)->descriptor.bcdDevice); 178 - sprintf(buf,"%1d%1d.%1d%1d", 169 + sprintf(buf, "%1d%1d.%1d%1d", 179 170 (bcdDevice & 0xF000)>>12, 180 171 (bcdDevice & 0xF00)>>8, 181 172 (bcdDevice & 0xF0)>>4, 182 173 (bcdDevice & 0xF)); 183 174 mutex_unlock(&lcd_mutex); 184 - if (copy_to_user((void __user *)arg,buf,strlen(buf))!=0) 175 + if (copy_to_user((void __user *)arg, buf, strlen(buf)) != 0) 185 176 return -EFAULT; 186 177 break; 187 178 case IOCTL_GET_DRV_VERSION: 188 - sprintf(buf,DRIVER_VERSION); 189 - if (copy_to_user((void __user *)arg,buf,strlen(buf))!=0) 179 + sprintf(buf, DRIVER_VERSION); 180 + if (copy_to_user((void __user *)arg, buf, strlen(buf)) != 0) 190 181 return -EFAULT; 191 182 break; 192 183 default: ··· 208 199 if (status && 209 200 !(status == -ENOENT || 210 201 status == -ECONNRESET || 211 - status == -ESHUTDOWN)) { 202 + status == -ESHUTDOWN)) { 212 203 dbg("USBLCD: %s - nonzero write bulk status received: %d", 213 204 __func__, status); 214 205 } ··· 219 210 up(&dev->limit_sem); 220 211 } 221 212 222 - static ssize_t lcd_write(struct file *file, const char __user * user_buffer, size_t count, loff_t *ppos) 213 + static ssize_t lcd_write(struct file *file, const char __user * user_buffer, 214 + size_t count, loff_t *ppos) 223 215 { 224 216 struct usb_lcd *dev; 225 - int retval = 0, r; 217 + int retval = 0, r; 226 218 struct urb *urb = NULL; 227 219 char *buf = NULL; 228 - 220 + 229 221 dev = file->private_data; 230 - 222 + 231 223 /* verify that we actually have some data to write */ 232 224 if (count == 0) 233 225 goto exit; ··· 243 233 retval = -ENOMEM; 244 234 goto err_no_buf; 245 235 } 246 - 247 - buf = usb_alloc_coherent(dev->udev, count, GFP_KERNEL, &urb->transfer_dma); 236 + 237 + buf = usb_alloc_coherent(dev->udev, count, GFP_KERNEL, 238 + &urb->transfer_dma); 248 239 if (!buf) { 249 240 retval = -ENOMEM; 250 241 goto error; 251 242 } 252 - 243 + 253 244 if (copy_from_user(buf, user_buffer, count)) { 254 245 retval = -EFAULT; 255 246 goto error; 256 247 } 257 - 248 + 258 249 /* initialize the urb properly */ 259 250 usb_fill_bulk_urb(urb, dev->udev, 260 - usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr), 251 + usb_sndbulkpipe(dev->udev, 252 + dev->bulk_out_endpointAddr), 261 253 buf, count, lcd_write_bulk_callback, dev); 262 254 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 263 255 264 256 usb_anchor_urb(urb, &dev->submitted); 265 - 257 + 266 258 /* send the data out the bulk port */ 267 259 retval = usb_submit_urb(urb, GFP_KERNEL); 268 260 if (retval) { 269 - err("USBLCD: %s - failed submitting write urb, error %d", __func__, retval); 261 + err("USBLCD: %s - failed submitting write urb, error %d", 262 + __func__, retval); 270 263 goto error_unanchor; 271 264 } 272 - 273 - /* release our reference to this urb, the USB core will eventually free it entirely */ 265 + 266 + /* release our reference to this urb, 267 + the USB core will eventually free it entirely */ 274 268 usb_free_urb(urb); 275 269 276 270 exit: ··· 290 276 } 291 277 292 278 static const struct file_operations lcd_fops = { 293 - .owner = THIS_MODULE, 294 - .read = lcd_read, 295 - .write = lcd_write, 296 - .open = lcd_open, 279 + .owner = THIS_MODULE, 280 + .read = lcd_read, 281 + .write = lcd_write, 282 + .open = lcd_open, 297 283 .unlocked_ioctl = lcd_ioctl, 298 - .release = lcd_release, 299 - .llseek = noop_llseek, 284 + .release = lcd_release, 285 + .llseek = noop_llseek, 300 286 }; 301 287 302 288 /* ··· 304 290 * and to have the device registered with the driver core 305 291 */ 306 292 static struct usb_class_driver lcd_class = { 307 - .name = "lcd%d", 308 - .fops = &lcd_fops, 309 - .minor_base = USBLCD_MINOR, 293 + .name = "lcd%d", 294 + .fops = &lcd_fops, 295 + .minor_base = USBLCD_MINOR, 310 296 }; 311 297 312 - static int lcd_probe(struct usb_interface *interface, const struct usb_device_id *id) 298 + static int lcd_probe(struct usb_interface *interface, 299 + const struct usb_device_id *id) 313 300 { 314 301 struct usb_lcd *dev = NULL; 315 302 struct usb_host_interface *iface_desc; ··· 337 322 retval = -ENODEV; 338 323 goto error; 339 324 } 340 - 325 + 341 326 /* set up the endpoint information */ 342 327 /* use only the first bulk-in and bulk-out endpoints */ 343 328 iface_desc = interface->cur_altsetting; ··· 347 332 if (!dev->bulk_in_endpointAddr && 348 333 usb_endpoint_is_bulk_in(endpoint)) { 349 334 /* we found a bulk in endpoint */ 350 - buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 335 + buffer_size = usb_endpoint_maxp(endpoint); 351 336 dev->bulk_in_size = buffer_size; 352 337 dev->bulk_in_endpointAddr = endpoint->bEndpointAddress; 353 338 dev->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); ··· 384 369 385 370 dev_info(&interface->dev, "USBLCD Version %1d%1d.%1d%1d found " 386 371 "at address %d\n", (i & 0xF000)>>12, (i & 0xF00)>>8, 387 - (i & 0xF0)>>4,(i & 0xF), dev->udev->devnum); 372 + (i & 0xF0)>>4, (i & 0xF), dev->udev->devnum); 388 373 389 374 /* let the user know what node this device is now attached to */ 390 375 dev_info(&interface->dev, "USB LCD device now attached to USBLCD-%d\n", ··· 416 401 return 0; 417 402 } 418 403 419 - static int lcd_resume (struct usb_interface *intf) 404 + static int lcd_resume(struct usb_interface *intf) 420 405 { 421 406 return 0; 422 407 } ··· 424 409 static void lcd_disconnect(struct usb_interface *interface) 425 410 { 426 411 struct usb_lcd *dev; 427 - int minor = interface->minor; 412 + int minor = interface->minor; 428 413 429 414 mutex_lock(&open_disc_mutex); 430 - dev = usb_get_intfdata(interface); 431 - usb_set_intfdata(interface, NULL); 415 + dev = usb_get_intfdata(interface); 416 + usb_set_intfdata(interface, NULL); 432 417 mutex_unlock(&open_disc_mutex); 433 418 434 - /* give back our minor */ 435 - usb_deregister_dev(interface, &lcd_class); 436 - 419 + /* give back our minor */ 420 + usb_deregister_dev(interface, &lcd_class); 421 + 437 422 /* decrement our usage count */ 438 423 kref_put(&dev->kref, lcd_delete); 439 424 ··· 453 438 static int __init usb_lcd_init(void) 454 439 { 455 440 int result; 456 - 441 + 457 442 result = usb_register(&lcd_driver); 458 443 if (result) 459 444 err("usb_register failed. Error number %d", result);
+14 -11
drivers/usb/misc/usbled.c
··· 33 33 .driver_info = DREAM_CHEEKY_WEBMAIL_NOTIFIER }, 34 34 { }, 35 35 }; 36 - MODULE_DEVICE_TABLE (usb, id_table); 36 + MODULE_DEVICE_TABLE(usb, id_table); 37 37 38 38 struct usb_led { 39 - struct usb_device * udev; 39 + struct usb_device *udev; 40 40 unsigned char blue; 41 41 unsigned char red; 42 42 unsigned char green; ··· 113 113 } 114 114 115 115 #define show_set(value) \ 116 - static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ 116 + static ssize_t show_##value(struct device *dev, struct device_attribute *attr,\ 117 + char *buf) \ 117 118 { \ 118 119 struct usb_interface *intf = to_usb_interface(dev); \ 119 120 struct usb_led *led = usb_get_intfdata(intf); \ 120 121 \ 121 122 return sprintf(buf, "%d\n", led->value); \ 122 123 } \ 123 - static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ 124 + static ssize_t set_##value(struct device *dev, struct device_attribute *attr,\ 125 + const char *buf, size_t count) \ 124 126 { \ 125 127 struct usb_interface *intf = to_usb_interface(dev); \ 126 128 struct usb_led *led = usb_get_intfdata(intf); \ ··· 137 135 show_set(red); 138 136 show_set(green); 139 137 140 - static int led_probe(struct usb_interface *interface, const struct usb_device_id *id) 138 + static int led_probe(struct usb_interface *interface, 139 + const struct usb_device_id *id) 141 140 { 142 141 struct usb_device *udev = interface_to_usbdev(interface); 143 142 struct usb_led *dev = NULL; ··· 153 150 dev->udev = usb_get_dev(udev); 154 151 dev->type = id->driver_info; 155 152 156 - usb_set_intfdata (interface, dev); 153 + usb_set_intfdata(interface, dev); 157 154 158 155 retval = device_create_file(&interface->dev, &dev_attr_blue); 159 156 if (retval) ··· 197 194 device_remove_file(&interface->dev, &dev_attr_blue); 198 195 device_remove_file(&interface->dev, &dev_attr_red); 199 196 device_remove_file(&interface->dev, &dev_attr_green); 200 - usb_set_intfdata (interface, NULL); 197 + usb_set_intfdata(interface, NULL); 201 198 usb_put_dev(dev->udev); 202 199 kfree(dev); 203 200 error_mem: ··· 208 205 { 209 206 struct usb_led *dev; 210 207 211 - dev = usb_get_intfdata (interface); 208 + dev = usb_get_intfdata(interface); 212 209 213 210 device_remove_file(&interface->dev, &dev_attr_blue); 214 211 device_remove_file(&interface->dev, &dev_attr_red); 215 212 device_remove_file(&interface->dev, &dev_attr_green); 216 213 217 214 /* first remove the files, then set the pointer to NULL */ 218 - usb_set_intfdata (interface, NULL); 215 + usb_set_intfdata(interface, NULL); 219 216 220 217 usb_put_dev(dev->udev); 221 218 ··· 246 243 usb_deregister(&led_driver); 247 244 } 248 245 249 - module_init (usb_led_init); 250 - module_exit (usb_led_exit); 246 + module_init(usb_led_init); 247 + module_exit(usb_led_exit); 251 248 252 249 MODULE_AUTHOR(DRIVER_AUTHOR); 253 250 MODULE_DESCRIPTION(DRIVER_DESC);
+6 -4
drivers/usb/misc/usbtest.c
··· 359 359 urb->context = &completion; 360 360 while (retval == 0 && iterations-- > 0) { 361 361 init_completion(&completion); 362 - if (usb_pipeout(urb->pipe)) 362 + if (usb_pipeout(urb->pipe)) { 363 363 simple_fill_buf(urb); 364 + urb->transfer_flags |= URB_ZERO_PACKET; 365 + } 364 366 retval = usb_submit_urb(urb, GFP_KERNEL); 365 367 if (retval != 0) 366 368 break; ··· 1585 1583 1586 1584 if (bytes < 0 || !desc) 1587 1585 return NULL; 1588 - maxp = 0x7ff & le16_to_cpu(desc->wMaxPacketSize); 1589 - maxp *= 1 + (0x3 & (le16_to_cpu(desc->wMaxPacketSize) >> 11)); 1586 + maxp = 0x7ff & usb_endpoint_maxp(desc); 1587 + maxp *= 1 + (0x3 & (usb_endpoint_maxp(desc) >> 11)); 1590 1588 packets = DIV_ROUND_UP(bytes, maxp); 1591 1589 1592 1590 urb = usb_alloc_urb(packets, GFP_KERNEL); ··· 1656 1654 "... iso period %d %sframes, wMaxPacket %04x\n", 1657 1655 1 << (desc->bInterval - 1), 1658 1656 (udev->speed == USB_SPEED_HIGH) ? "micro" : "", 1659 - le16_to_cpu(desc->wMaxPacketSize)); 1657 + usb_endpoint_maxp(desc)); 1660 1658 1661 1659 for (i = 0; i < param->sglen; i++) { 1662 1660 urbs[i] = iso_alloc_urb(udev, pipe, desc,
+1 -1
drivers/usb/musb/musb_gadget.c
··· 1020 1020 goto fail; 1021 1021 1022 1022 /* REVISIT this rules out high bandwidth periodic transfers */ 1023 - tmp = le16_to_cpu(desc->wMaxPacketSize); 1023 + tmp = usb_endpoint_maxp(desc); 1024 1024 if (tmp & ~0x07ff) { 1025 1025 int ok; 1026 1026
+1 -1
drivers/usb/musb/musb_host.c
··· 1932 1932 INIT_LIST_HEAD(&qh->ring); 1933 1933 qh->is_ready = 1; 1934 1934 1935 - qh->maxpacket = le16_to_cpu(epd->wMaxPacketSize); 1935 + qh->maxpacket = usb_endpoint_maxp(epd); 1936 1936 qh->type = usb_endpoint_type(epd); 1937 1937 1938 1938 /* Bits 11 & 12 of wMaxPacketSize encode high bandwidth multiplier.
-16
drivers/usb/otg/twl6030-usb.c
··· 137 137 return ret; 138 138 } 139 139 140 - /*-------------------------------------------------------------------------*/ 141 - static int twl6030_set_phy_clk(struct otg_transceiver *x, int on) 142 - { 143 - struct twl6030_usb *twl; 144 - struct device *dev; 145 - struct twl4030_usb_data *pdata; 146 - 147 - twl = xceiv_to_twl(x); 148 - dev = twl->dev; 149 - pdata = dev->platform_data; 150 - 151 - pdata->phy_set_clock(twl->dev, on); 152 - 153 - return 0; 154 - } 155 - 156 140 static int twl6030_phy_init(struct otg_transceiver *x) 157 141 { 158 142 struct twl6030_usb *twl;
+1 -1
drivers/usb/renesas_usbhs/pipe.c
··· 392 392 /* host should set DEVSEL */ 393 393 394 394 /* reutn MXPS */ 395 - return PIPE_MAXP_MASK & le16_to_cpu(desc->wMaxPacketSize); 395 + return PIPE_MAXP_MASK & usb_endpoint_maxp(desc); 396 396 } 397 397 398 398 static u16 usbhsp_setup_pipebuff(struct usbhs_pipe *pipe,
+1
drivers/usb/serial/Kconfig
··· 252 252 253 253 config USB_SERIAL_IPW 254 254 tristate "USB IPWireless (3G UMTS TDD) Driver" 255 + select USB_SERIAL_WWAN 255 256 help 256 257 Say Y here if you want to use a IPWireless USB modem such as 257 258 the ones supplied by Axity3G/Sentech South Africa.
+1 -1
drivers/usb/serial/ftdi_sio.c
··· 1486 1486 } 1487 1487 1488 1488 /* set max packet size based on descriptor */ 1489 - priv->max_packet_size = le16_to_cpu(ep_desc->wMaxPacketSize); 1489 + priv->max_packet_size = usb_endpoint_maxp(ep_desc); 1490 1490 1491 1491 dev_info(&udev->dev, "Setting MaxPacketSize %d\n", priv->max_packet_size); 1492 1492 }
+2 -2
drivers/usb/serial/io_edgeport.c
··· 3042 3042 3043 3043 endpoint = &serial->interface->altsetting[0]. 3044 3044 endpoint[i].desc; 3045 - buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 3045 + buffer_size = usb_endpoint_maxp(endpoint); 3046 3046 if (!interrupt_in_found && 3047 3047 (usb_endpoint_is_int_in(endpoint))) { 3048 3048 /* we found a interrupt in endpoint */ ··· 3107 3107 usb_rcvbulkpipe(dev, 3108 3108 endpoint->bEndpointAddress), 3109 3109 edge_serial->bulk_in_buffer, 3110 - le16_to_cpu(endpoint->wMaxPacketSize), 3110 + usb_endpoint_maxp(endpoint), 3111 3111 edge_bulk_in_callback, 3112 3112 edge_serial); 3113 3113 bulk_in_found = true;
+31 -2
drivers/usb/serial/ipw.c
··· 47 47 #include <linux/usb.h> 48 48 #include <linux/usb/serial.h> 49 49 #include <linux/uaccess.h> 50 + #include "usb-wwan.h" 50 51 51 52 /* 52 53 * Version Information ··· 186 185 187 186 /*--2: Start reading from the device */ 188 187 dbg("%s: setting up bulk read callback", __func__); 189 - usb_serial_generic_open(tty, port); 188 + usb_wwan_open(tty, port); 190 189 191 190 /*--3: Tell the modem to open the floodgates on the rx bulk channel */ 192 191 dbg("%s:asking modem for RxRead (RXBULK_ON)", __func__); ··· 218 217 219 218 kfree(buf_flow_init); 220 219 return 0; 220 + } 221 + 222 + /* fake probe - only to allocate data structures */ 223 + static int ipw_probe(struct usb_serial *serial, const struct usb_device_id *id) 224 + { 225 + struct usb_wwan_intf_private *data; 226 + 227 + data = kzalloc(sizeof(struct usb_wwan_intf_private), GFP_KERNEL); 228 + if (!data) 229 + return -ENOMEM; 230 + 231 + spin_lock_init(&data->susp_lock); 232 + usb_set_serial_data(serial, data); 233 + return 0; 234 + } 235 + 236 + static void ipw_release(struct usb_serial *serial) 237 + { 238 + struct usb_wwan_intf_private *data = usb_get_serial_data(serial); 239 + 240 + usb_wwan_release(serial); 241 + usb_set_serial_data(serial, NULL); 242 + kfree(data); 221 243 } 222 244 223 245 static void ipw_dtr_rts(struct usb_serial_port *port, int on) ··· 309 285 dev_err(&port->dev, 310 286 "Disabling bulk RxRead failed (error = %d)\n", result); 311 287 312 - usb_serial_generic_close(port); 288 + usb_wwan_close(port); 313 289 } 314 290 315 291 static struct usb_serial_driver ipw_device = { ··· 321 297 .usb_driver = &usb_ipw_driver, 322 298 .id_table = usb_ipw_ids, 323 299 .num_ports = 1, 300 + .disconnect = usb_wwan_disconnect, 324 301 .open = ipw_open, 325 302 .close = ipw_close, 303 + .probe = ipw_probe, 304 + .attach = usb_wwan_startup, 305 + .release = ipw_release, 326 306 .dtr_rts = ipw_dtr_rts, 307 + .write = usb_wwan_write, 327 308 }; 328 309 329 310
+1 -1
drivers/usb/serial/opticon.c
··· 523 523 goto error; 524 524 } 525 525 526 - priv->buffer_size = le16_to_cpu(endpoint->wMaxPacketSize) * 2; 526 + priv->buffer_size = usb_endpoint_maxp(endpoint) * 2; 527 527 priv->bulk_in_buffer = kmalloc(priv->buffer_size, GFP_KERNEL); 528 528 if (!priv->bulk_in_buffer) { 529 529 dev_err(&priv->udev->dev, "out of memory\n");
-3
drivers/usb/serial/pl2303.c
··· 360 360 tmp >>= 2; 361 361 buf[1] <<= 1; 362 362 } 363 - if (tmp > 256) { 364 - tmp %= 256; 365 - } 366 363 buf[0] = tmp; 367 364 } 368 365 }
+1 -1
drivers/usb/serial/symbolserial.c
··· 226 226 goto error; 227 227 } 228 228 229 - priv->buffer_size = le16_to_cpu(endpoint->wMaxPacketSize) * 2; 229 + priv->buffer_size = usb_endpoint_maxp(endpoint) * 2; 230 230 priv->int_buffer = kmalloc(priv->buffer_size, GFP_KERNEL); 231 231 if (!priv->int_buffer) { 232 232 dev_err(&priv->udev->dev, "out of memory\n");
+4 -4
drivers/usb/serial/usb-serial.c
··· 912 912 goto probe_error; 913 913 } 914 914 buffer_size = max_t(int, serial->type->bulk_in_size, 915 - le16_to_cpu(endpoint->wMaxPacketSize)); 915 + usb_endpoint_maxp(endpoint)); 916 916 port->bulk_in_size = buffer_size; 917 917 port->bulk_in_endpointAddress = endpoint->bEndpointAddress; 918 918 port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); ··· 942 942 goto probe_error; 943 943 buffer_size = serial->type->bulk_out_size; 944 944 if (!buffer_size) 945 - buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 945 + buffer_size = usb_endpoint_maxp(endpoint); 946 946 port->bulk_out_size = buffer_size; 947 947 port->bulk_out_endpointAddress = endpoint->bEndpointAddress; 948 948 port->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL); ··· 990 990 "No free urbs available\n"); 991 991 goto probe_error; 992 992 } 993 - buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 993 + buffer_size = usb_endpoint_maxp(endpoint); 994 994 port->interrupt_in_endpointAddress = 995 995 endpoint->bEndpointAddress; 996 996 port->interrupt_in_buffer = kmalloc(buffer_size, ··· 1021 1021 "No free urbs available\n"); 1022 1022 goto probe_error; 1023 1023 } 1024 - buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 1024 + buffer_size = usb_endpoint_maxp(endpoint); 1025 1025 port->interrupt_out_size = buffer_size; 1026 1026 port->interrupt_out_endpointAddress = 1027 1027 endpoint->bEndpointAddress;
+30 -5
drivers/usb/storage/realtek_cr.c
··· 320 320 { 321 321 int retval; 322 322 u8 cmnd[12] = { 0 }; 323 + u8 *buf; 324 + 325 + buf = kmalloc(len, GFP_NOIO); 326 + if (buf == NULL) 327 + return USB_STOR_TRANSPORT_ERROR; 323 328 324 329 US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len); 325 330 ··· 336 331 cmnd[5] = (u8) len; 337 332 338 333 retval = rts51x_bulk_transport(us, 0, cmnd, 12, 339 - data, len, DMA_FROM_DEVICE, NULL); 340 - if (retval != USB_STOR_TRANSPORT_GOOD) 334 + buf, len, DMA_FROM_DEVICE, NULL); 335 + if (retval != USB_STOR_TRANSPORT_GOOD) { 336 + kfree(buf); 341 337 return -EIO; 338 + } 342 339 340 + memcpy(data, buf, len); 341 + kfree(buf); 343 342 return 0; 344 343 } 345 344 ··· 351 342 { 352 343 int retval; 353 344 u8 cmnd[12] = { 0 }; 345 + u8 *buf; 346 + 347 + buf = kmalloc(len, GFP_NOIO); 348 + if (buf == NULL) 349 + return USB_STOR_TRANSPORT_ERROR; 350 + memcpy(buf, data, len); 354 351 355 352 US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len); 356 353 ··· 368 353 cmnd[5] = (u8) len; 369 354 370 355 retval = rts51x_bulk_transport(us, 0, cmnd, 12, 371 - data, len, DMA_TO_DEVICE, NULL); 356 + buf, len, DMA_TO_DEVICE, NULL); 357 + kfree(buf); 372 358 if (retval != USB_STOR_TRANSPORT_GOOD) 373 359 return -EIO; 374 360 ··· 381 365 { 382 366 int retval; 383 367 u8 cmnd[12] = { 0 }; 368 + u8 *buf; 369 + 370 + buf = kmalloc(len, GFP_NOIO); 371 + if (buf == NULL) 372 + return USB_STOR_TRANSPORT_ERROR; 384 373 385 374 US_DEBUGP("%s, lun = %d\n", __func__, lun); 386 375 ··· 393 372 cmnd[1] = 0x09; 394 373 395 374 retval = rts51x_bulk_transport(us, lun, cmnd, 12, 396 - status, len, DMA_FROM_DEVICE, actlen); 397 - if (retval != USB_STOR_TRANSPORT_GOOD) 375 + buf, len, DMA_FROM_DEVICE, actlen); 376 + if (retval != USB_STOR_TRANSPORT_GOOD) { 377 + kfree(buf); 398 378 return -EIO; 379 + } 399 380 381 + memcpy(status, buf, len); 382 + kfree(buf); 400 383 return 0; 401 384 } 402 385
+13 -3
drivers/usb/storage/usb.c
··· 831 831 832 832 dev_dbg(dev, "device found\n"); 833 833 834 - set_freezable(); 835 - /* Wait for the timeout to expire or for a disconnect */ 834 + set_freezable_with_signal(); 835 + /* 836 + * Wait for the timeout to expire or for a disconnect 837 + * 838 + * We can't freeze in this thread or we risk causing khubd to 839 + * fail to freeze, but we can't be non-freezable either. Nor can 840 + * khubd freeze while waiting for scanning to complete as it may 841 + * hold the device lock, causing a hang when suspending devices. 842 + * So we request a fake signal when freezing and use 843 + * interruptible sleep to kick us out of our wait early when 844 + * freezing happens. 845 + */ 836 846 if (delay_use > 0) { 837 847 dev_dbg(dev, "waiting for device to settle " 838 848 "before scanning\n"); 839 - wait_event_freezable_timeout(us->delay_wait, 849 + wait_event_interruptible_timeout(us->delay_wait, 840 850 test_bit(US_FLIDX_DONT_SCAN, &us->dflags), 841 851 delay_use * HZ); 842 852 }
+1 -1
drivers/usb/usb-skeleton.c
··· 555 555 if (!dev->bulk_in_endpointAddr && 556 556 usb_endpoint_is_bulk_in(endpoint)) { 557 557 /* we found a bulk in endpoint */ 558 - buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 558 + buffer_size = usb_endpoint_maxp(endpoint); 559 559 dev->bulk_in_size = buffer_size; 560 560 dev->bulk_in_endpointAddr = endpoint->bEndpointAddress; 561 561 dev->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
+1 -1
drivers/usb/wusbcore/wa-hc.c
··· 43 43 /* Fill up Data Transfer EP pointers */ 44 44 wa->dti_epd = &iface->cur_altsetting->endpoint[1].desc; 45 45 wa->dto_epd = &iface->cur_altsetting->endpoint[2].desc; 46 - wa->xfer_result_size = le16_to_cpu(wa->dti_epd->wMaxPacketSize); 46 + wa->xfer_result_size = usb_endpoint_maxp(wa->dti_epd); 47 47 wa->xfer_result = kmalloc(wa->xfer_result_size, GFP_KERNEL); 48 48 if (wa->xfer_result == NULL) 49 49 goto error_xfer_result_alloc;
+1 -1
include/linux/usb.h
··· 1574 1574 return 0; 1575 1575 1576 1576 /* NOTE: only 0x07ff bits are for packet size... */ 1577 - return le16_to_cpu(ep->desc.wMaxPacketSize); 1577 + return usb_endpoint_maxp(&ep->desc); 1578 1578 } 1579 1579 1580 1580 /* ----------------------------------------------------------------------- */
+17
include/linux/usb/ch9.h
··· 34 34 #define __LINUX_USB_CH9_H 35 35 36 36 #include <linux/types.h> /* __u8 etc */ 37 + #include <asm/byteorder.h> /* le16_to_cpu */ 37 38 38 39 /*-------------------------------------------------------------------------*/ 39 40 ··· 144 143 #define USB_INTRF_FUNC_SUSPEND 0 /* function suspend */ 145 144 146 145 #define USB_INTR_FUNC_SUSPEND_OPT_MASK 0xFF00 146 + /* 147 + * Suspend Options, Table 9-7 USB 3.0 spec 148 + */ 149 + #define USB_INTRF_FUNC_SUSPEND_LP (1 << (8 + 0)) 150 + #define USB_INTRF_FUNC_SUSPEND_RW (1 << (8 + 1)) 147 151 148 152 #define USB_ENDPOINT_HALT 0 /* IN/OUT will STALL */ 149 153 ··· 574 568 const struct usb_endpoint_descriptor *epd) 575 569 { 576 570 return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd); 571 + } 572 + 573 + /** 574 + * usb_endpoint_maxp - get endpoint's max packet size 575 + * @epd: endpoint to be checked 576 + * 577 + * Returns @epd's max packet 578 + */ 579 + static inline int usb_endpoint_maxp(const struct usb_endpoint_descriptor *epd) 580 + { 581 + return le16_to_cpu(epd->wMaxPacketSize); 577 582 } 578 583 579 584 /*-------------------------------------------------------------------------*/