Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1 | /** |
| 2 | * ep0.c - DesignWare USB3 DRD Controller Endpoint 0 Handling |
| 3 | * |
| 4 | * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 5 | * |
| 6 | * Authors: Felipe Balbi <balbi@ti.com>, |
| 7 | * Sebastian Andrzej Siewior <bigeasy@linutronix.de> |
| 8 | * |
| 9 | * Redistribution and use in source and binary forms, with or without |
| 10 | * modification, are permitted provided that the following conditions |
| 11 | * are met: |
| 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions, and the following disclaimer, |
| 14 | * without modification. |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in the |
| 17 | * documentation and/or other materials provided with the distribution. |
| 18 | * 3. The names of the above-listed copyright holders may not be used |
| 19 | * to endorse or promote products derived from this software without |
| 20 | * specific prior written permission. |
| 21 | * |
| 22 | * ALTERNATIVELY, this software may be distributed under the terms of the |
| 23 | * GNU General Public License ("GPL") version 2, as published by the Free |
| 24 | * Software Foundation. |
| 25 | * |
| 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 27 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 28 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 29 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 30 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 31 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 32 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 33 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 34 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 35 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 36 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 37 | */ |
| 38 | |
| 39 | #include <linux/kernel.h> |
| 40 | #include <linux/slab.h> |
| 41 | #include <linux/spinlock.h> |
| 42 | #include <linux/platform_device.h> |
| 43 | #include <linux/pm_runtime.h> |
| 44 | #include <linux/interrupt.h> |
| 45 | #include <linux/io.h> |
| 46 | #include <linux/list.h> |
| 47 | #include <linux/dma-mapping.h> |
| 48 | |
| 49 | #include <linux/usb/ch9.h> |
| 50 | #include <linux/usb/gadget.h> |
Sebastian Andrzej Siewior | 5bdb1dc | 2011-11-02 13:30:45 +0100 | [diff] [blame] | 51 | #include <linux/usb/composite.h> |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 52 | |
| 53 | #include "core.h" |
| 54 | #include "gadget.h" |
| 55 | #include "io.h" |
| 56 | |
Felipe Balbi | 9610cd2 | 2012-05-21 14:22:41 +0300 | [diff] [blame] | 57 | static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep); |
Felipe Balbi | db0af40 | 2012-05-04 13:03:54 +0300 | [diff] [blame] | 58 | static void __dwc3_ep0_do_control_data(struct dwc3 *dwc, |
| 59 | struct dwc3_ep *dep, struct dwc3_request *req); |
Sebastian Andrzej Siewior | 5bdb1dc | 2011-11-02 13:30:45 +0100 | [diff] [blame] | 60 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 61 | static const char *dwc3_ep0_state_string(enum dwc3_ep0_state state) |
| 62 | { |
| 63 | switch (state) { |
| 64 | case EP0_UNCONNECTED: |
| 65 | return "Unconnected"; |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 66 | case EP0_SETUP_PHASE: |
| 67 | return "Setup Phase"; |
| 68 | case EP0_DATA_PHASE: |
| 69 | return "Data Phase"; |
| 70 | case EP0_STATUS_PHASE: |
| 71 | return "Status Phase"; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 72 | default: |
| 73 | return "UNKNOWN"; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma, |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 78 | u32 len, u32 type) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 79 | { |
| 80 | struct dwc3_gadget_ep_cmd_params params; |
Felipe Balbi | f6bafc6 | 2012-02-06 11:04:53 +0200 | [diff] [blame] | 81 | struct dwc3_trb *trb; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 82 | struct dwc3_ep *dep; |
| 83 | |
| 84 | int ret; |
| 85 | |
| 86 | dep = dwc->eps[epnum]; |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 87 | if (dep->flags & DWC3_EP_BUSY) { |
| 88 | dev_vdbg(dwc->dev, "%s: still busy\n", dep->name); |
| 89 | return 0; |
| 90 | } |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 91 | |
Felipe Balbi | f6bafc6 | 2012-02-06 11:04:53 +0200 | [diff] [blame] | 92 | trb = dwc->ep0_trb; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 93 | |
Felipe Balbi | f6bafc6 | 2012-02-06 11:04:53 +0200 | [diff] [blame] | 94 | trb->bpl = lower_32_bits(buf_dma); |
| 95 | trb->bph = upper_32_bits(buf_dma); |
| 96 | trb->size = len; |
| 97 | trb->ctrl = type; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 98 | |
Felipe Balbi | f6bafc6 | 2012-02-06 11:04:53 +0200 | [diff] [blame] | 99 | trb->ctrl |= (DWC3_TRB_CTRL_HWO |
| 100 | | DWC3_TRB_CTRL_LST |
| 101 | | DWC3_TRB_CTRL_IOC |
| 102 | | DWC3_TRB_CTRL_ISP_IMI); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 103 | |
| 104 | memset(¶ms, 0, sizeof(params)); |
Felipe Balbi | dc1c70a | 2011-09-30 10:58:51 +0300 | [diff] [blame] | 105 | params.param0 = upper_32_bits(dwc->ep0_trb_addr); |
| 106 | params.param1 = lower_32_bits(dwc->ep0_trb_addr); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 107 | |
| 108 | ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, |
| 109 | DWC3_DEPCMD_STARTTRANSFER, ¶ms); |
| 110 | if (ret < 0) { |
| 111 | dev_dbg(dwc->dev, "failed to send STARTTRANSFER command\n"); |
| 112 | return ret; |
| 113 | } |
| 114 | |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 115 | dep->flags |= DWC3_EP_BUSY; |
Felipe Balbi | 4959cfc | 2012-06-06 12:04:13 +0300 | [diff] [blame] | 116 | dep->resource_index = dwc3_gadget_ep_get_transfer_index(dwc, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 117 | dep->number); |
| 118 | |
Felipe Balbi | 1ddcb21 | 2011-08-30 15:52:17 +0300 | [diff] [blame] | 119 | dwc->ep0_next_event = DWC3_EP0_COMPLETE; |
| 120 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep, |
| 125 | struct dwc3_request *req) |
| 126 | { |
Sebastian Andrzej Siewior | 5bdb1dc | 2011-11-02 13:30:45 +0100 | [diff] [blame] | 127 | struct dwc3 *dwc = dep->dwc; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 128 | |
| 129 | req->request.actual = 0; |
| 130 | req->request.status = -EINPROGRESS; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 131 | req->epnum = dep->number; |
| 132 | |
| 133 | list_add_tail(&req->list, &dep->request_list); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 134 | |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 135 | /* |
| 136 | * Gadget driver might not be quick enough to queue a request |
| 137 | * before we get a Transfer Not Ready event on this endpoint. |
| 138 | * |
| 139 | * In that case, we will set DWC3_EP_PENDING_REQUEST. When that |
| 140 | * flag is set, it's telling us that as soon as Gadget queues the |
| 141 | * required request, we should kick the transfer here because the |
| 142 | * IRQ we were waiting for is long gone. |
| 143 | */ |
| 144 | if (dep->flags & DWC3_EP_PENDING_REQUEST) { |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 145 | unsigned direction; |
Felipe Balbi | a682970 | 2011-08-27 22:18:09 +0300 | [diff] [blame] | 146 | |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 147 | direction = !!(dep->flags & DWC3_EP0_DIR_IN); |
Felipe Balbi | a682970 | 2011-08-27 22:18:09 +0300 | [diff] [blame] | 148 | |
Felipe Balbi | 68d8a78 | 2011-12-29 06:32:29 +0200 | [diff] [blame] | 149 | if (dwc->ep0state != EP0_DATA_PHASE) { |
| 150 | dev_WARN(dwc->dev, "Unexpected pending request\n"); |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 151 | return 0; |
| 152 | } |
Felipe Balbi | a682970 | 2011-08-27 22:18:09 +0300 | [diff] [blame] | 153 | |
Felipe Balbi | db0af40 | 2012-05-04 13:03:54 +0300 | [diff] [blame] | 154 | __dwc3_ep0_do_control_data(dwc, dwc->eps[direction], req); |
| 155 | |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 156 | dep->flags &= ~(DWC3_EP_PENDING_REQUEST | |
| 157 | DWC3_EP0_DIR_IN); |
Felipe Balbi | 929646c | 2012-07-19 08:51:13 +0300 | [diff] [blame] | 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * In case gadget driver asked us to delay the STATUS phase, |
| 164 | * handle it here. |
| 165 | */ |
| 166 | if (dwc->delayed_status) { |
Felipe Balbi | a866ee0 | 2012-07-19 21:05:08 +0300 | [diff] [blame^] | 167 | unsigned direction; |
| 168 | |
| 169 | direction = !dwc->ep0_expect_in; |
Sebastian Andrzej Siewior | 5bdb1dc | 2011-11-02 13:30:45 +0100 | [diff] [blame] | 170 | dwc->delayed_status = false; |
Felipe Balbi | 68d3e66 | 2011-12-08 13:56:27 +0200 | [diff] [blame] | 171 | |
| 172 | if (dwc->ep0state == EP0_STATUS_PHASE) |
Felipe Balbi | a866ee0 | 2012-07-19 21:05:08 +0300 | [diff] [blame^] | 173 | __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]); |
Felipe Balbi | 68d3e66 | 2011-12-08 13:56:27 +0200 | [diff] [blame] | 174 | else |
| 175 | dev_dbg(dwc->dev, "too early for delayed status\n"); |
Felipe Balbi | 929646c | 2012-07-19 08:51:13 +0300 | [diff] [blame] | 176 | |
| 177 | return 0; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 178 | } |
| 179 | |
Felipe Balbi | b6c4acd | 2012-07-19 09:05:35 +0300 | [diff] [blame] | 180 | /* |
| 181 | * Unfortunately we have uncovered a limitation wrt the Data Phase. |
| 182 | * |
| 183 | * Section 9.4 says we can wait for the XferNotReady(DATA) event to |
| 184 | * come before issueing Start Transfer command, but if we do, we will |
| 185 | * miss situations where the host starts another SETUP phase instead of |
| 186 | * the DATA phase. Such cases happen at least on TD.7.6 of the Link |
| 187 | * Layer Compliance Suite. |
| 188 | * |
| 189 | * The problem surfaces due to the fact that in case of back-to-back |
| 190 | * SETUP packets there will be no XferNotReady(DATA) generated and we |
| 191 | * will be stuck waiting for XferNotReady(DATA) forever. |
| 192 | * |
| 193 | * By looking at tables 9-13 and 9-14 of the Databook, we can see that |
| 194 | * it tells us to start Data Phase right away. It also mentions that if |
| 195 | * we receive a SETUP phase instead of the DATA phase, core will issue |
| 196 | * XferComplete for the DATA phase, before actually initiating it in |
| 197 | * the wire, with the TRB's status set to "SETUP_PENDING". Such status |
| 198 | * can only be used to print some debugging logs, as the core expects |
| 199 | * us to go through to the STATUS phase and start a CONTROL_STATUS TRB, |
| 200 | * just so it completes right away, without transferring anything and, |
| 201 | * only then, we can go back to the SETUP phase. |
| 202 | * |
| 203 | * Because of this scenario, SNPS decided to change the programming |
| 204 | * model of control transfers and support on-demand transfers only for |
| 205 | * the STATUS phase. To fix the issue we have now, we will always wait |
| 206 | * for gadget driver to queue the DATA phase's struct usb_request, then |
| 207 | * start it right away. |
| 208 | * |
| 209 | * If we're actually in a 2-stage transfer, we will wait for |
| 210 | * XferNotReady(STATUS). |
| 211 | */ |
| 212 | if (dwc->three_stage_setup) { |
| 213 | unsigned direction; |
| 214 | |
| 215 | direction = dwc->ep0_expect_in; |
| 216 | dwc->ep0state = EP0_DATA_PHASE; |
| 217 | |
| 218 | __dwc3_ep0_do_control_data(dwc, dwc->eps[direction], req); |
| 219 | |
| 220 | dep->flags &= ~DWC3_EP0_DIR_IN; |
| 221 | } |
| 222 | |
Felipe Balbi | 2640f34 | 2012-07-19 08:49:01 +0300 | [diff] [blame] | 223 | return 0; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request, |
| 227 | gfp_t gfp_flags) |
| 228 | { |
| 229 | struct dwc3_request *req = to_dwc3_request(request); |
| 230 | struct dwc3_ep *dep = to_dwc3_ep(ep); |
| 231 | struct dwc3 *dwc = dep->dwc; |
| 232 | |
| 233 | unsigned long flags; |
| 234 | |
| 235 | int ret; |
| 236 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 237 | spin_lock_irqsave(&dwc->lock, flags); |
Ido Shayevitz | 57cdac1 | 2012-03-12 20:25:24 +0200 | [diff] [blame] | 238 | if (!dep->endpoint.desc) { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 239 | dev_dbg(dwc->dev, "trying to queue request %p to disabled %s\n", |
| 240 | request, dep->name); |
| 241 | ret = -ESHUTDOWN; |
| 242 | goto out; |
| 243 | } |
| 244 | |
| 245 | /* we share one TRB for ep0/1 */ |
Sebastian Andrzej Siewior | c2da2ff | 2011-10-20 19:04:16 +0200 | [diff] [blame] | 246 | if (!list_empty(&dep->request_list)) { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 247 | ret = -EBUSY; |
| 248 | goto out; |
| 249 | } |
| 250 | |
| 251 | dev_vdbg(dwc->dev, "queueing request %p to %s length %d, state '%s'\n", |
| 252 | request, dep->name, request->length, |
| 253 | dwc3_ep0_state_string(dwc->ep0state)); |
| 254 | |
| 255 | ret = __dwc3_gadget_ep0_queue(dep, req); |
| 256 | |
| 257 | out: |
| 258 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 259 | |
| 260 | return ret; |
| 261 | } |
| 262 | |
| 263 | static void dwc3_ep0_stall_and_restart(struct dwc3 *dwc) |
| 264 | { |
Felipe Balbi | d742220 | 2011-09-08 18:17:12 +0300 | [diff] [blame] | 265 | struct dwc3_ep *dep = dwc->eps[0]; |
| 266 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 267 | /* stall is always issued on EP0 */ |
Sebastian Andrzej Siewior | c2da2ff | 2011-10-20 19:04:16 +0200 | [diff] [blame] | 268 | __dwc3_gadget_ep_set_halt(dep, 1); |
| 269 | dep->flags = DWC3_EP_ENABLED; |
Sebastian Andrzej Siewior | 5bdb1dc | 2011-11-02 13:30:45 +0100 | [diff] [blame] | 270 | dwc->delayed_status = false; |
Felipe Balbi | d742220 | 2011-09-08 18:17:12 +0300 | [diff] [blame] | 271 | |
| 272 | if (!list_empty(&dep->request_list)) { |
| 273 | struct dwc3_request *req; |
| 274 | |
| 275 | req = next_request(&dep->request_list); |
| 276 | dwc3_gadget_giveback(dep, req, -ECONNRESET); |
| 277 | } |
| 278 | |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 279 | dwc->ep0state = EP0_SETUP_PHASE; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 280 | dwc3_ep0_out_start(dwc); |
| 281 | } |
| 282 | |
Pratyush Anand | eb84075 | 2012-06-25 22:40:43 +0530 | [diff] [blame] | 283 | int dwc3_gadget_ep0_set_halt(struct usb_ep *ep, int value) |
| 284 | { |
| 285 | struct dwc3_ep *dep = to_dwc3_ep(ep); |
| 286 | struct dwc3 *dwc = dep->dwc; |
| 287 | |
| 288 | dwc3_ep0_stall_and_restart(dwc); |
| 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 293 | void dwc3_ep0_out_start(struct dwc3 *dwc) |
| 294 | { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 295 | int ret; |
| 296 | |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 297 | ret = dwc3_ep0_start_trans(dwc, 0, dwc->ctrl_req_addr, 8, |
| 298 | DWC3_TRBCTL_CONTROL_SETUP); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 299 | WARN_ON(ret < 0); |
| 300 | } |
| 301 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 302 | static struct dwc3_ep *dwc3_wIndex_to_dep(struct dwc3 *dwc, __le16 wIndex_le) |
| 303 | { |
| 304 | struct dwc3_ep *dep; |
| 305 | u32 windex = le16_to_cpu(wIndex_le); |
| 306 | u32 epnum; |
| 307 | |
| 308 | epnum = (windex & USB_ENDPOINT_NUMBER_MASK) << 1; |
| 309 | if ((windex & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) |
| 310 | epnum |= 1; |
| 311 | |
| 312 | dep = dwc->eps[epnum]; |
| 313 | if (dep->flags & DWC3_EP_ENABLED) |
| 314 | return dep; |
| 315 | |
| 316 | return NULL; |
| 317 | } |
| 318 | |
Sebastian Andrzej Siewior | 8ee6270 | 2011-10-18 19:13:29 +0200 | [diff] [blame] | 319 | static void dwc3_ep0_status_cmpl(struct usb_ep *ep, struct usb_request *req) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 320 | { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 321 | } |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 322 | /* |
| 323 | * ch 9.4.5 |
| 324 | */ |
Felipe Balbi | 25b8ff6 | 2011-11-04 12:32:47 +0200 | [diff] [blame] | 325 | static int dwc3_ep0_handle_status(struct dwc3 *dwc, |
| 326 | struct usb_ctrlrequest *ctrl) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 327 | { |
| 328 | struct dwc3_ep *dep; |
| 329 | u32 recip; |
Sebastian Andrzej Siewior | bb8b8a3 | 2011-09-13 17:54:39 +0200 | [diff] [blame] | 330 | u32 reg; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 331 | u16 usb_status = 0; |
| 332 | __le16 *response_pkt; |
| 333 | |
| 334 | recip = ctrl->bRequestType & USB_RECIP_MASK; |
| 335 | switch (recip) { |
| 336 | case USB_RECIP_DEVICE: |
| 337 | /* |
Sebastian Andrzej Siewior | bb8b8a3 | 2011-09-13 17:54:39 +0200 | [diff] [blame] | 338 | * LTM will be set once we know how to set this in HW. |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 339 | */ |
| 340 | usb_status |= dwc->is_selfpowered << USB_DEVICE_SELF_POWERED; |
Sebastian Andrzej Siewior | bb8b8a3 | 2011-09-13 17:54:39 +0200 | [diff] [blame] | 341 | |
| 342 | if (dwc->speed == DWC3_DSTS_SUPERSPEED) { |
| 343 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); |
| 344 | if (reg & DWC3_DCTL_INITU1ENA) |
| 345 | usb_status |= 1 << USB_DEV_STAT_U1_ENABLED; |
| 346 | if (reg & DWC3_DCTL_INITU2ENA) |
| 347 | usb_status |= 1 << USB_DEV_STAT_U2_ENABLED; |
| 348 | } |
| 349 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 350 | break; |
| 351 | |
| 352 | case USB_RECIP_INTERFACE: |
| 353 | /* |
| 354 | * Function Remote Wake Capable D0 |
| 355 | * Function Remote Wakeup D1 |
| 356 | */ |
| 357 | break; |
| 358 | |
| 359 | case USB_RECIP_ENDPOINT: |
| 360 | dep = dwc3_wIndex_to_dep(dwc, ctrl->wIndex); |
| 361 | if (!dep) |
Felipe Balbi | 25b8ff6 | 2011-11-04 12:32:47 +0200 | [diff] [blame] | 362 | return -EINVAL; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 363 | |
| 364 | if (dep->flags & DWC3_EP_STALL) |
| 365 | usb_status = 1 << USB_ENDPOINT_HALT; |
| 366 | break; |
| 367 | default: |
| 368 | return -EINVAL; |
| 369 | }; |
| 370 | |
| 371 | response_pkt = (__le16 *) dwc->setup_buf; |
| 372 | *response_pkt = cpu_to_le16(usb_status); |
Felipe Balbi | e261779 | 2011-11-29 10:35:47 +0200 | [diff] [blame] | 373 | |
| 374 | dep = dwc->eps[0]; |
| 375 | dwc->ep0_usb_req.dep = dep; |
Sebastian Andrzej Siewior | e0ce0b0 | 2011-11-25 12:03:46 +0100 | [diff] [blame] | 376 | dwc->ep0_usb_req.request.length = sizeof(*response_pkt); |
Felipe Balbi | 0fc9a1b | 2011-12-19 11:32:34 +0200 | [diff] [blame] | 377 | dwc->ep0_usb_req.request.buf = dwc->setup_buf; |
Sebastian Andrzej Siewior | e0ce0b0 | 2011-11-25 12:03:46 +0100 | [diff] [blame] | 378 | dwc->ep0_usb_req.request.complete = dwc3_ep0_status_cmpl; |
Felipe Balbi | e261779 | 2011-11-29 10:35:47 +0200 | [diff] [blame] | 379 | |
| 380 | return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | static int dwc3_ep0_handle_feature(struct dwc3 *dwc, |
| 384 | struct usb_ctrlrequest *ctrl, int set) |
| 385 | { |
| 386 | struct dwc3_ep *dep; |
| 387 | u32 recip; |
| 388 | u32 wValue; |
| 389 | u32 wIndex; |
Sebastian Andrzej Siewior | bb8b8a3 | 2011-09-13 17:54:39 +0200 | [diff] [blame] | 390 | u32 reg; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 391 | int ret; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 392 | |
| 393 | wValue = le16_to_cpu(ctrl->wValue); |
| 394 | wIndex = le16_to_cpu(ctrl->wIndex); |
| 395 | recip = ctrl->bRequestType & USB_RECIP_MASK; |
| 396 | switch (recip) { |
| 397 | case USB_RECIP_DEVICE: |
| 398 | |
Sebastian Andrzej Siewior | bb8b8a3 | 2011-09-13 17:54:39 +0200 | [diff] [blame] | 399 | switch (wValue) { |
| 400 | case USB_DEVICE_REMOTE_WAKEUP: |
| 401 | break; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 402 | /* |
| 403 | * 9.4.1 says only only for SS, in AddressState only for |
| 404 | * default control pipe |
| 405 | */ |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 406 | case USB_DEVICE_U1_ENABLE: |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 407 | if (dwc->dev_state != DWC3_CONFIGURED_STATE) |
| 408 | return -EINVAL; |
| 409 | if (dwc->speed != DWC3_DSTS_SUPERSPEED) |
| 410 | return -EINVAL; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 411 | |
Sebastian Andrzej Siewior | bb8b8a3 | 2011-09-13 17:54:39 +0200 | [diff] [blame] | 412 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); |
| 413 | if (set) |
| 414 | reg |= DWC3_DCTL_INITU1ENA; |
| 415 | else |
| 416 | reg &= ~DWC3_DCTL_INITU1ENA; |
| 417 | dwc3_writel(dwc->regs, DWC3_DCTL, reg); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 418 | break; |
Sebastian Andrzej Siewior | bb8b8a3 | 2011-09-13 17:54:39 +0200 | [diff] [blame] | 419 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 420 | case USB_DEVICE_U2_ENABLE: |
Sebastian Andrzej Siewior | bb8b8a3 | 2011-09-13 17:54:39 +0200 | [diff] [blame] | 421 | if (dwc->dev_state != DWC3_CONFIGURED_STATE) |
| 422 | return -EINVAL; |
| 423 | if (dwc->speed != DWC3_DSTS_SUPERSPEED) |
| 424 | return -EINVAL; |
| 425 | |
| 426 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); |
| 427 | if (set) |
| 428 | reg |= DWC3_DCTL_INITU2ENA; |
| 429 | else |
| 430 | reg &= ~DWC3_DCTL_INITU2ENA; |
| 431 | dwc3_writel(dwc->regs, DWC3_DCTL, reg); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 432 | break; |
Sebastian Andrzej Siewior | bb8b8a3 | 2011-09-13 17:54:39 +0200 | [diff] [blame] | 433 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 434 | case USB_DEVICE_LTM_ENABLE: |
Sebastian Andrzej Siewior | bb8b8a3 | 2011-09-13 17:54:39 +0200 | [diff] [blame] | 435 | return -EINVAL; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 436 | break; |
| 437 | |
| 438 | case USB_DEVICE_TEST_MODE: |
| 439 | if ((wIndex & 0xff) != 0) |
| 440 | return -EINVAL; |
| 441 | if (!set) |
| 442 | return -EINVAL; |
| 443 | |
Gerard Cauvy | 3b63736 | 2012-02-10 12:21:18 +0200 | [diff] [blame] | 444 | dwc->test_mode_nr = wIndex >> 8; |
| 445 | dwc->test_mode = true; |
Gerard Cauvy | ecb0779 | 2012-03-16 16:20:10 +0200 | [diff] [blame] | 446 | break; |
| 447 | default: |
| 448 | return -EINVAL; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 449 | } |
| 450 | break; |
| 451 | |
| 452 | case USB_RECIP_INTERFACE: |
| 453 | switch (wValue) { |
| 454 | case USB_INTRF_FUNC_SUSPEND: |
| 455 | if (wIndex & USB_INTRF_FUNC_SUSPEND_LP) |
| 456 | /* XXX enable Low power suspend */ |
| 457 | ; |
| 458 | if (wIndex & USB_INTRF_FUNC_SUSPEND_RW) |
| 459 | /* XXX enable remote wakeup */ |
| 460 | ; |
| 461 | break; |
| 462 | default: |
| 463 | return -EINVAL; |
| 464 | } |
| 465 | break; |
| 466 | |
| 467 | case USB_RECIP_ENDPOINT: |
| 468 | switch (wValue) { |
| 469 | case USB_ENDPOINT_HALT: |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 470 | dep = dwc3_wIndex_to_dep(dwc, wIndex); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 471 | if (!dep) |
| 472 | return -EINVAL; |
| 473 | ret = __dwc3_gadget_ep_set_halt(dep, set); |
| 474 | if (ret) |
| 475 | return -EINVAL; |
| 476 | break; |
| 477 | default: |
| 478 | return -EINVAL; |
| 479 | } |
| 480 | break; |
| 481 | |
| 482 | default: |
| 483 | return -EINVAL; |
| 484 | }; |
| 485 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) |
| 490 | { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 491 | u32 addr; |
| 492 | u32 reg; |
| 493 | |
| 494 | addr = le16_to_cpu(ctrl->wValue); |
Felipe Balbi | f96a6ec | 2011-10-15 21:37:35 +0300 | [diff] [blame] | 495 | if (addr > 127) { |
| 496 | dev_dbg(dwc->dev, "invalid device address %d\n", addr); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 497 | return -EINVAL; |
Felipe Balbi | f96a6ec | 2011-10-15 21:37:35 +0300 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | if (dwc->dev_state == DWC3_CONFIGURED_STATE) { |
| 501 | dev_dbg(dwc->dev, "trying to set address when configured\n"); |
| 502 | return -EINVAL; |
| 503 | } |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 504 | |
Felipe Balbi | 2646021 | 2011-09-30 10:58:36 +0300 | [diff] [blame] | 505 | reg = dwc3_readl(dwc->regs, DWC3_DCFG); |
| 506 | reg &= ~(DWC3_DCFG_DEVADDR_MASK); |
| 507 | reg |= DWC3_DCFG_DEVADDR(addr); |
| 508 | dwc3_writel(dwc->regs, DWC3_DCFG, reg); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 509 | |
Felipe Balbi | 2646021 | 2011-09-30 10:58:36 +0300 | [diff] [blame] | 510 | if (addr) |
| 511 | dwc->dev_state = DWC3_ADDRESS_STATE; |
| 512 | else |
| 513 | dwc->dev_state = DWC3_DEFAULT_STATE; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 514 | |
Felipe Balbi | 2646021 | 2011-09-30 10:58:36 +0300 | [diff] [blame] | 515 | return 0; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | static int dwc3_ep0_delegate_req(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) |
| 519 | { |
| 520 | int ret; |
| 521 | |
| 522 | spin_unlock(&dwc->lock); |
| 523 | ret = dwc->gadget_driver->setup(&dwc->gadget, ctrl); |
| 524 | spin_lock(&dwc->lock); |
| 525 | return ret; |
| 526 | } |
| 527 | |
| 528 | static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) |
| 529 | { |
| 530 | u32 cfg; |
| 531 | int ret; |
Pratyush Anand | 49917a4 | 2012-07-02 10:21:54 +0530 | [diff] [blame] | 532 | u32 reg; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 533 | |
Paul Zimmerman | b23c843 | 2011-09-30 10:58:42 +0300 | [diff] [blame] | 534 | dwc->start_config_issued = false; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 535 | cfg = le16_to_cpu(ctrl->wValue); |
| 536 | |
| 537 | switch (dwc->dev_state) { |
| 538 | case DWC3_DEFAULT_STATE: |
| 539 | return -EINVAL; |
| 540 | break; |
| 541 | |
| 542 | case DWC3_ADDRESS_STATE: |
| 543 | ret = dwc3_ep0_delegate_req(dwc, ctrl); |
| 544 | /* if the cfg matches and the cfg is non zero */ |
Felipe Balbi | 457e84b | 2012-01-18 18:04:09 +0200 | [diff] [blame] | 545 | if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 546 | dwc->dev_state = DWC3_CONFIGURED_STATE; |
Pratyush Anand | 49917a4 | 2012-07-02 10:21:54 +0530 | [diff] [blame] | 547 | /* |
| 548 | * Enable transition to U1/U2 state when |
| 549 | * nothing is pending from application. |
| 550 | */ |
| 551 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); |
| 552 | reg |= (DWC3_DCTL_ACCEPTU1ENA | DWC3_DCTL_ACCEPTU2ENA); |
| 553 | dwc3_writel(dwc->regs, DWC3_DCTL, reg); |
| 554 | |
Felipe Balbi | 457e84b | 2012-01-18 18:04:09 +0200 | [diff] [blame] | 555 | dwc->resize_fifos = true; |
| 556 | dev_dbg(dwc->dev, "resize fifos flag SET\n"); |
| 557 | } |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 558 | break; |
| 559 | |
| 560 | case DWC3_CONFIGURED_STATE: |
| 561 | ret = dwc3_ep0_delegate_req(dwc, ctrl); |
| 562 | if (!cfg) |
| 563 | dwc->dev_state = DWC3_ADDRESS_STATE; |
| 564 | break; |
Sebastian Andrzej Siewior | 5bdb1dc | 2011-11-02 13:30:45 +0100 | [diff] [blame] | 565 | default: |
| 566 | ret = -EINVAL; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 567 | } |
Sebastian Andrzej Siewior | 5bdb1dc | 2011-11-02 13:30:45 +0100 | [diff] [blame] | 568 | return ret; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 569 | } |
| 570 | |
Felipe Balbi | 9e788d6 | 2012-04-24 16:19:49 +0300 | [diff] [blame] | 571 | static void dwc3_ep0_set_sel_cmpl(struct usb_ep *ep, struct usb_request *req) |
| 572 | { |
| 573 | struct dwc3_ep *dep = to_dwc3_ep(ep); |
| 574 | struct dwc3 *dwc = dep->dwc; |
| 575 | |
| 576 | u32 param = 0; |
| 577 | u32 reg; |
| 578 | |
| 579 | struct timing { |
| 580 | u8 u1sel; |
| 581 | u8 u1pel; |
| 582 | u16 u2sel; |
| 583 | u16 u2pel; |
| 584 | } __packed timing; |
| 585 | |
| 586 | int ret; |
| 587 | |
| 588 | memcpy(&timing, req->buf, sizeof(timing)); |
| 589 | |
| 590 | dwc->u1sel = timing.u1sel; |
| 591 | dwc->u1pel = timing.u1pel; |
Felipe Balbi | 8761921 | 2012-05-31 11:00:28 +0300 | [diff] [blame] | 592 | dwc->u2sel = le16_to_cpu(timing.u2sel); |
| 593 | dwc->u2pel = le16_to_cpu(timing.u2pel); |
Felipe Balbi | 9e788d6 | 2012-04-24 16:19:49 +0300 | [diff] [blame] | 594 | |
| 595 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); |
| 596 | if (reg & DWC3_DCTL_INITU2ENA) |
| 597 | param = dwc->u2pel; |
| 598 | if (reg & DWC3_DCTL_INITU1ENA) |
| 599 | param = dwc->u1pel; |
| 600 | |
| 601 | /* |
| 602 | * According to Synopsys Databook, if parameter is |
| 603 | * greater than 125, a value of zero should be |
| 604 | * programmed in the register. |
| 605 | */ |
| 606 | if (param > 125) |
| 607 | param = 0; |
| 608 | |
| 609 | /* now that we have the time, issue DGCMD Set Sel */ |
| 610 | ret = dwc3_send_gadget_generic_command(dwc, |
| 611 | DWC3_DGCMD_SET_PERIODIC_PAR, param); |
| 612 | WARN_ON(ret < 0); |
| 613 | } |
| 614 | |
| 615 | static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) |
| 616 | { |
| 617 | struct dwc3_ep *dep; |
| 618 | u16 wLength; |
| 619 | u16 wValue; |
| 620 | |
| 621 | if (dwc->dev_state == DWC3_DEFAULT_STATE) |
| 622 | return -EINVAL; |
| 623 | |
| 624 | wValue = le16_to_cpu(ctrl->wValue); |
| 625 | wLength = le16_to_cpu(ctrl->wLength); |
| 626 | |
| 627 | if (wLength != 6) { |
| 628 | dev_err(dwc->dev, "Set SEL should be 6 bytes, got %d\n", |
| 629 | wLength); |
| 630 | return -EINVAL; |
| 631 | } |
| 632 | |
| 633 | /* |
| 634 | * To handle Set SEL we need to receive 6 bytes from Host. So let's |
| 635 | * queue a usb_request for 6 bytes. |
| 636 | * |
| 637 | * Remember, though, this controller can't handle non-wMaxPacketSize |
| 638 | * aligned transfers on the OUT direction, so we queue a request for |
| 639 | * wMaxPacketSize instead. |
| 640 | */ |
| 641 | dep = dwc->eps[0]; |
| 642 | dwc->ep0_usb_req.dep = dep; |
| 643 | dwc->ep0_usb_req.request.length = dep->endpoint.maxpacket; |
| 644 | dwc->ep0_usb_req.request.buf = dwc->setup_buf; |
| 645 | dwc->ep0_usb_req.request.complete = dwc3_ep0_set_sel_cmpl; |
| 646 | |
| 647 | return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req); |
| 648 | } |
| 649 | |
Felipe Balbi | 395c349 | 2012-04-25 10:45:05 +0300 | [diff] [blame] | 650 | static int dwc3_ep0_set_isoch_delay(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) |
| 651 | { |
| 652 | u16 wLength; |
| 653 | u16 wValue; |
| 654 | u16 wIndex; |
| 655 | |
| 656 | wValue = le16_to_cpu(ctrl->wValue); |
| 657 | wLength = le16_to_cpu(ctrl->wLength); |
| 658 | wIndex = le16_to_cpu(ctrl->wIndex); |
| 659 | |
| 660 | if (wIndex || wLength) |
| 661 | return -EINVAL; |
| 662 | |
| 663 | /* |
| 664 | * REVISIT It's unclear from Databook what to do with this |
| 665 | * value. For now, just cache it. |
| 666 | */ |
| 667 | dwc->isoch_delay = wValue; |
| 668 | |
| 669 | return 0; |
| 670 | } |
| 671 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 672 | static int dwc3_ep0_std_request(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) |
| 673 | { |
| 674 | int ret; |
| 675 | |
| 676 | switch (ctrl->bRequest) { |
| 677 | case USB_REQ_GET_STATUS: |
| 678 | dev_vdbg(dwc->dev, "USB_REQ_GET_STATUS\n"); |
| 679 | ret = dwc3_ep0_handle_status(dwc, ctrl); |
| 680 | break; |
| 681 | case USB_REQ_CLEAR_FEATURE: |
| 682 | dev_vdbg(dwc->dev, "USB_REQ_CLEAR_FEATURE\n"); |
| 683 | ret = dwc3_ep0_handle_feature(dwc, ctrl, 0); |
| 684 | break; |
| 685 | case USB_REQ_SET_FEATURE: |
| 686 | dev_vdbg(dwc->dev, "USB_REQ_SET_FEATURE\n"); |
| 687 | ret = dwc3_ep0_handle_feature(dwc, ctrl, 1); |
| 688 | break; |
| 689 | case USB_REQ_SET_ADDRESS: |
| 690 | dev_vdbg(dwc->dev, "USB_REQ_SET_ADDRESS\n"); |
| 691 | ret = dwc3_ep0_set_address(dwc, ctrl); |
| 692 | break; |
| 693 | case USB_REQ_SET_CONFIGURATION: |
| 694 | dev_vdbg(dwc->dev, "USB_REQ_SET_CONFIGURATION\n"); |
| 695 | ret = dwc3_ep0_set_config(dwc, ctrl); |
| 696 | break; |
Felipe Balbi | 9e788d6 | 2012-04-24 16:19:49 +0300 | [diff] [blame] | 697 | case USB_REQ_SET_SEL: |
| 698 | dev_vdbg(dwc->dev, "USB_REQ_SET_SEL\n"); |
| 699 | ret = dwc3_ep0_set_sel(dwc, ctrl); |
| 700 | break; |
Felipe Balbi | 395c349 | 2012-04-25 10:45:05 +0300 | [diff] [blame] | 701 | case USB_REQ_SET_ISOCH_DELAY: |
| 702 | dev_vdbg(dwc->dev, "USB_REQ_SET_ISOCH_DELAY\n"); |
| 703 | ret = dwc3_ep0_set_isoch_delay(dwc, ctrl); |
| 704 | break; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 705 | default: |
| 706 | dev_vdbg(dwc->dev, "Forwarding to gadget driver\n"); |
| 707 | ret = dwc3_ep0_delegate_req(dwc, ctrl); |
| 708 | break; |
| 709 | }; |
| 710 | |
| 711 | return ret; |
| 712 | } |
| 713 | |
| 714 | static void dwc3_ep0_inspect_setup(struct dwc3 *dwc, |
| 715 | const struct dwc3_event_depevt *event) |
| 716 | { |
| 717 | struct usb_ctrlrequest *ctrl = dwc->ctrl_req; |
Felipe Balbi | 65811b6 | 2012-05-31 10:29:49 +0300 | [diff] [blame] | 718 | int ret = -EINVAL; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 719 | u32 len; |
| 720 | |
| 721 | if (!dwc->gadget_driver) |
Felipe Balbi | 65811b6 | 2012-05-31 10:29:49 +0300 | [diff] [blame] | 722 | goto out; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 723 | |
| 724 | len = le16_to_cpu(ctrl->wLength); |
Felipe Balbi | 1ddcb21 | 2011-08-30 15:52:17 +0300 | [diff] [blame] | 725 | if (!len) { |
Felipe Balbi | d95b09b | 2011-09-30 10:58:37 +0300 | [diff] [blame] | 726 | dwc->three_stage_setup = false; |
| 727 | dwc->ep0_expect_in = false; |
Felipe Balbi | 1ddcb21 | 2011-08-30 15:52:17 +0300 | [diff] [blame] | 728 | dwc->ep0_next_event = DWC3_EP0_NRDY_STATUS; |
| 729 | } else { |
Felipe Balbi | d95b09b | 2011-09-30 10:58:37 +0300 | [diff] [blame] | 730 | dwc->three_stage_setup = true; |
| 731 | dwc->ep0_expect_in = !!(ctrl->bRequestType & USB_DIR_IN); |
Felipe Balbi | 1ddcb21 | 2011-08-30 15:52:17 +0300 | [diff] [blame] | 732 | dwc->ep0_next_event = DWC3_EP0_NRDY_DATA; |
| 733 | } |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 734 | |
| 735 | if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) |
| 736 | ret = dwc3_ep0_std_request(dwc, ctrl); |
| 737 | else |
| 738 | ret = dwc3_ep0_delegate_req(dwc, ctrl); |
| 739 | |
Sebastian Andrzej Siewior | 5bdb1dc | 2011-11-02 13:30:45 +0100 | [diff] [blame] | 740 | if (ret == USB_GADGET_DELAYED_STATUS) |
| 741 | dwc->delayed_status = true; |
| 742 | |
Felipe Balbi | 65811b6 | 2012-05-31 10:29:49 +0300 | [diff] [blame] | 743 | out: |
| 744 | if (ret < 0) |
| 745 | dwc3_ep0_stall_and_restart(dwc); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | static void dwc3_ep0_complete_data(struct dwc3 *dwc, |
| 749 | const struct dwc3_event_depevt *event) |
| 750 | { |
| 751 | struct dwc3_request *r = NULL; |
| 752 | struct usb_request *ur; |
Felipe Balbi | f6bafc6 | 2012-02-06 11:04:53 +0200 | [diff] [blame] | 753 | struct dwc3_trb *trb; |
Sebastian Andrzej Siewior | c2da2ff | 2011-10-20 19:04:16 +0200 | [diff] [blame] | 754 | struct dwc3_ep *ep0; |
Felipe Balbi | c611ccb | 2011-08-27 02:30:33 +0300 | [diff] [blame] | 755 | u32 transferred; |
Felipe Balbi | b6c4acd | 2012-07-19 09:05:35 +0300 | [diff] [blame] | 756 | u32 status; |
Felipe Balbi | f6bafc6 | 2012-02-06 11:04:53 +0200 | [diff] [blame] | 757 | u32 length; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 758 | u8 epnum; |
| 759 | |
| 760 | epnum = event->endpoint_number; |
Sebastian Andrzej Siewior | c2da2ff | 2011-10-20 19:04:16 +0200 | [diff] [blame] | 761 | ep0 = dwc->eps[0]; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 762 | |
Felipe Balbi | 1ddcb21 | 2011-08-30 15:52:17 +0300 | [diff] [blame] | 763 | dwc->ep0_next_event = DWC3_EP0_NRDY_STATUS; |
| 764 | |
Sebastian Andrzej Siewior | c2da2ff | 2011-10-20 19:04:16 +0200 | [diff] [blame] | 765 | r = next_request(&ep0->request_list); |
Sebastian Andrzej Siewior | 8ee6270 | 2011-10-18 19:13:29 +0200 | [diff] [blame] | 766 | ur = &r->request; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 767 | |
Felipe Balbi | f6bafc6 | 2012-02-06 11:04:53 +0200 | [diff] [blame] | 768 | trb = dwc->ep0_trb; |
Felipe Balbi | b6c4acd | 2012-07-19 09:05:35 +0300 | [diff] [blame] | 769 | |
| 770 | status = DWC3_TRB_SIZE_TRBSTS(trb->size); |
| 771 | if (status == DWC3_TRBSTS_SETUP_PENDING) { |
| 772 | dev_dbg(dwc->dev, "Setup Pending received\n"); |
| 773 | |
| 774 | if (r) |
| 775 | dwc3_gadget_giveback(ep0, r, -ECONNRESET); |
| 776 | |
| 777 | return; |
| 778 | } |
| 779 | |
Felipe Balbi | f6bafc6 | 2012-02-06 11:04:53 +0200 | [diff] [blame] | 780 | length = trb->size & DWC3_TRB_SIZE_MASK; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 781 | |
Felipe Balbi | a682970 | 2011-08-27 22:18:09 +0300 | [diff] [blame] | 782 | if (dwc->ep0_bounced) { |
Moiz Sonasath | 566ccdd | 2012-03-14 00:44:56 -0500 | [diff] [blame] | 783 | unsigned transfer_size = ur->length; |
| 784 | unsigned maxp = ep0->endpoint.maxpacket; |
| 785 | |
| 786 | transfer_size += (maxp - (transfer_size % maxp)); |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 787 | transferred = min_t(u32, ur->length, |
Moiz Sonasath | 566ccdd | 2012-03-14 00:44:56 -0500 | [diff] [blame] | 788 | transfer_size - length); |
Felipe Balbi | a682970 | 2011-08-27 22:18:09 +0300 | [diff] [blame] | 789 | memcpy(ur->buf, dwc->ep0_bounce, transferred); |
| 790 | dwc->ep0_bounced = false; |
| 791 | } else { |
Felipe Balbi | f6bafc6 | 2012-02-06 11:04:53 +0200 | [diff] [blame] | 792 | transferred = ur->length - length; |
Felipe Balbi | a682970 | 2011-08-27 22:18:09 +0300 | [diff] [blame] | 793 | } |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 794 | |
Felipe Balbi | cd423dd | 2012-03-21 11:44:00 +0200 | [diff] [blame] | 795 | ur->actual += transferred; |
| 796 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 797 | if ((epnum & 1) && ur->actual < ur->length) { |
| 798 | /* for some reason we did not get everything out */ |
| 799 | |
| 800 | dwc3_ep0_stall_and_restart(dwc); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 801 | } else { |
| 802 | /* |
| 803 | * handle the case where we have to send a zero packet. This |
| 804 | * seems to be case when req.length > maxpacket. Could it be? |
| 805 | */ |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 806 | if (r) |
Sebastian Andrzej Siewior | c2da2ff | 2011-10-20 19:04:16 +0200 | [diff] [blame] | 807 | dwc3_gadget_giveback(ep0, r, 0); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | |
Felipe Balbi | ed8c398 | 2012-05-31 12:32:37 +0300 | [diff] [blame] | 811 | static void dwc3_ep0_complete_status(struct dwc3 *dwc, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 812 | const struct dwc3_event_depevt *event) |
| 813 | { |
| 814 | struct dwc3_request *r; |
| 815 | struct dwc3_ep *dep; |
Felipe Balbi | b6c4acd | 2012-07-19 09:05:35 +0300 | [diff] [blame] | 816 | struct dwc3_trb *trb; |
| 817 | u32 status; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 818 | |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 819 | dep = dwc->eps[0]; |
Felipe Balbi | b6c4acd | 2012-07-19 09:05:35 +0300 | [diff] [blame] | 820 | trb = dwc->ep0_trb; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 821 | |
| 822 | if (!list_empty(&dep->request_list)) { |
| 823 | r = next_request(&dep->request_list); |
| 824 | |
| 825 | dwc3_gadget_giveback(dep, r, 0); |
| 826 | } |
| 827 | |
Gerard Cauvy | 3b63736 | 2012-02-10 12:21:18 +0200 | [diff] [blame] | 828 | if (dwc->test_mode) { |
| 829 | int ret; |
| 830 | |
| 831 | ret = dwc3_gadget_set_test_mode(dwc, dwc->test_mode_nr); |
| 832 | if (ret < 0) { |
| 833 | dev_dbg(dwc->dev, "Invalid Test #%d\n", |
| 834 | dwc->test_mode_nr); |
| 835 | dwc3_ep0_stall_and_restart(dwc); |
Felipe Balbi | 0ed27b1 | 2012-06-25 19:30:49 +0300 | [diff] [blame] | 836 | return; |
Gerard Cauvy | 3b63736 | 2012-02-10 12:21:18 +0200 | [diff] [blame] | 837 | } |
| 838 | } |
| 839 | |
Felipe Balbi | b6c4acd | 2012-07-19 09:05:35 +0300 | [diff] [blame] | 840 | status = DWC3_TRB_SIZE_TRBSTS(trb->size); |
| 841 | if (status == DWC3_TRBSTS_SETUP_PENDING) |
| 842 | dev_dbg(dwc->dev, "Setup Pending received\n"); |
| 843 | |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 844 | dwc->ep0state = EP0_SETUP_PHASE; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 845 | dwc3_ep0_out_start(dwc); |
| 846 | } |
| 847 | |
| 848 | static void dwc3_ep0_xfer_complete(struct dwc3 *dwc, |
| 849 | const struct dwc3_event_depevt *event) |
| 850 | { |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 851 | struct dwc3_ep *dep = dwc->eps[event->endpoint_number]; |
| 852 | |
| 853 | dep->flags &= ~DWC3_EP_BUSY; |
Felipe Balbi | 4959cfc | 2012-06-06 12:04:13 +0300 | [diff] [blame] | 854 | dep->resource_index = 0; |
Felipe Balbi | df62df5 | 2011-10-14 15:11:49 +0300 | [diff] [blame] | 855 | dwc->setup_packet_pending = false; |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 856 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 857 | switch (dwc->ep0state) { |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 858 | case EP0_SETUP_PHASE: |
| 859 | dev_vdbg(dwc->dev, "Inspecting Setup Bytes\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 860 | dwc3_ep0_inspect_setup(dwc, event); |
| 861 | break; |
| 862 | |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 863 | case EP0_DATA_PHASE: |
| 864 | dev_vdbg(dwc->dev, "Data Phase\n"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 865 | dwc3_ep0_complete_data(dwc, event); |
| 866 | break; |
| 867 | |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 868 | case EP0_STATUS_PHASE: |
| 869 | dev_vdbg(dwc->dev, "Status Phase\n"); |
Felipe Balbi | ed8c398 | 2012-05-31 12:32:37 +0300 | [diff] [blame] | 870 | dwc3_ep0_complete_status(dwc, event); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 871 | break; |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 872 | default: |
| 873 | WARN(true, "UNKNOWN ep0state %d\n", dwc->ep0state); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 874 | } |
| 875 | } |
| 876 | |
Felipe Balbi | db0af40 | 2012-05-04 13:03:54 +0300 | [diff] [blame] | 877 | static void __dwc3_ep0_do_control_data(struct dwc3 *dwc, |
| 878 | struct dwc3_ep *dep, struct dwc3_request *req) |
| 879 | { |
| 880 | int ret; |
| 881 | |
| 882 | req->direction = !!dep->number; |
| 883 | |
| 884 | if (req->request.length == 0) { |
| 885 | ret = dwc3_ep0_start_trans(dwc, dep->number, |
| 886 | dwc->ctrl_req_addr, 0, |
| 887 | DWC3_TRBCTL_CONTROL_DATA); |
Felipe Balbi | 0a1730a | 2012-05-04 13:08:22 +0300 | [diff] [blame] | 888 | } else if (!IS_ALIGNED(req->request.length, dep->endpoint.maxpacket) |
Felipe Balbi | db0af40 | 2012-05-04 13:03:54 +0300 | [diff] [blame] | 889 | && (dep->number == 0)) { |
| 890 | u32 transfer_size; |
| 891 | |
| 892 | ret = usb_gadget_map_request(&dwc->gadget, &req->request, |
| 893 | dep->number); |
| 894 | if (ret) { |
| 895 | dev_dbg(dwc->dev, "failed to map request\n"); |
| 896 | return; |
| 897 | } |
| 898 | |
| 899 | WARN_ON(req->request.length > DWC3_EP0_BOUNCE_SIZE); |
| 900 | |
| 901 | transfer_size = roundup(req->request.length, |
| 902 | (u32) dep->endpoint.maxpacket); |
| 903 | |
| 904 | dwc->ep0_bounced = true; |
| 905 | |
| 906 | /* |
| 907 | * REVISIT in case request length is bigger than |
| 908 | * DWC3_EP0_BOUNCE_SIZE we will need two chained |
| 909 | * TRBs to handle the transfer. |
| 910 | */ |
| 911 | ret = dwc3_ep0_start_trans(dwc, dep->number, |
| 912 | dwc->ep0_bounce_addr, transfer_size, |
| 913 | DWC3_TRBCTL_CONTROL_DATA); |
| 914 | } else { |
| 915 | ret = usb_gadget_map_request(&dwc->gadget, &req->request, |
| 916 | dep->number); |
| 917 | if (ret) { |
| 918 | dev_dbg(dwc->dev, "failed to map request\n"); |
| 919 | return; |
| 920 | } |
| 921 | |
| 922 | ret = dwc3_ep0_start_trans(dwc, dep->number, req->request.dma, |
| 923 | req->request.length, DWC3_TRBCTL_CONTROL_DATA); |
| 924 | } |
| 925 | |
| 926 | WARN_ON(ret < 0); |
| 927 | } |
| 928 | |
Sebastian Andrzej Siewior | f0f2b2a | 2011-11-02 13:30:44 +0100 | [diff] [blame] | 929 | static int dwc3_ep0_start_control_status(struct dwc3_ep *dep) |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 930 | { |
Sebastian Andrzej Siewior | f0f2b2a | 2011-11-02 13:30:44 +0100 | [diff] [blame] | 931 | struct dwc3 *dwc = dep->dwc; |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 932 | u32 type; |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 933 | |
| 934 | type = dwc->three_stage_setup ? DWC3_TRBCTL_CONTROL_STATUS3 |
| 935 | : DWC3_TRBCTL_CONTROL_STATUS2; |
| 936 | |
Sebastian Andrzej Siewior | f0f2b2a | 2011-11-02 13:30:44 +0100 | [diff] [blame] | 937 | return dwc3_ep0_start_trans(dwc, dep->number, |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 938 | dwc->ctrl_req_addr, 0, type); |
Sebastian Andrzej Siewior | f0f2b2a | 2011-11-02 13:30:44 +0100 | [diff] [blame] | 939 | } |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 940 | |
Felipe Balbi | 9610cd2 | 2012-05-21 14:22:41 +0300 | [diff] [blame] | 941 | static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep) |
Sebastian Andrzej Siewior | f0f2b2a | 2011-11-02 13:30:44 +0100 | [diff] [blame] | 942 | { |
Felipe Balbi | 457e84b | 2012-01-18 18:04:09 +0200 | [diff] [blame] | 943 | if (dwc->resize_fifos) { |
| 944 | dev_dbg(dwc->dev, "starting to resize fifos\n"); |
| 945 | dwc3_gadget_resize_tx_fifos(dwc); |
| 946 | dwc->resize_fifos = 0; |
| 947 | } |
| 948 | |
Sebastian Andrzej Siewior | f0f2b2a | 2011-11-02 13:30:44 +0100 | [diff] [blame] | 949 | WARN_ON(dwc3_ep0_start_control_status(dep)); |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 950 | } |
| 951 | |
Felipe Balbi | 9610cd2 | 2012-05-21 14:22:41 +0300 | [diff] [blame] | 952 | static void dwc3_ep0_do_control_status(struct dwc3 *dwc, |
| 953 | const struct dwc3_event_depevt *event) |
| 954 | { |
| 955 | struct dwc3_ep *dep = dwc->eps[event->endpoint_number]; |
| 956 | |
| 957 | __dwc3_ep0_do_control_status(dwc, dep); |
| 958 | } |
| 959 | |
Felipe Balbi | a7e8d65 | 2012-07-19 09:26:59 +0300 | [diff] [blame] | 960 | static void dwc3_ep0_end_control_data(struct dwc3 *dwc, struct dwc3_ep *dep) |
| 961 | { |
| 962 | struct dwc3_gadget_ep_cmd_params params; |
| 963 | u32 cmd; |
| 964 | int ret; |
| 965 | |
| 966 | if (!dep->resource_index) |
| 967 | return; |
| 968 | |
| 969 | cmd = DWC3_DEPCMD_ENDTRANSFER; |
| 970 | cmd |= DWC3_DEPCMD_CMDIOC; |
| 971 | cmd |= DWC3_DEPCMD_PARAM(dep->resource_index); |
| 972 | memset(¶ms, 0, sizeof(params)); |
| 973 | ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, cmd, ¶ms); |
| 974 | WARN_ON_ONCE(ret); |
| 975 | dep->resource_index = 0; |
| 976 | } |
| 977 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 978 | static void dwc3_ep0_xfernotready(struct dwc3 *dwc, |
| 979 | const struct dwc3_event_depevt *event) |
| 980 | { |
Felipe Balbi | df62df5 | 2011-10-14 15:11:49 +0300 | [diff] [blame] | 981 | dwc->setup_packet_pending = true; |
| 982 | |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 983 | switch (event->status) { |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 984 | case DEPEVT_STATUS_CONTROL_DATA: |
| 985 | dev_vdbg(dwc->dev, "Control Data\n"); |
Felipe Balbi | 1ddcb21 | 2011-08-30 15:52:17 +0300 | [diff] [blame] | 986 | |
Felipe Balbi | 55f3fba | 2011-09-08 18:27:33 +0300 | [diff] [blame] | 987 | /* |
Felipe Balbi | a7e8d65 | 2012-07-19 09:26:59 +0300 | [diff] [blame] | 988 | * We already have a DATA transfer in the controller's cache, |
| 989 | * if we receive a XferNotReady(DATA) we will ignore it, unless |
| 990 | * it's for the wrong direction. |
Felipe Balbi | 55f3fba | 2011-09-08 18:27:33 +0300 | [diff] [blame] | 991 | * |
Felipe Balbi | a7e8d65 | 2012-07-19 09:26:59 +0300 | [diff] [blame] | 992 | * In that case, we must issue END_TRANSFER command to the Data |
| 993 | * Phase we already have started and issue SetStall on the |
| 994 | * control endpoint. |
Felipe Balbi | 55f3fba | 2011-09-08 18:27:33 +0300 | [diff] [blame] | 995 | */ |
| 996 | if (dwc->ep0_expect_in != event->endpoint_number) { |
Felipe Balbi | a7e8d65 | 2012-07-19 09:26:59 +0300 | [diff] [blame] | 997 | struct dwc3_ep *dep = dwc->eps[dwc->ep0_expect_in]; |
| 998 | |
Felipe Balbi | 55f3fba | 2011-09-08 18:27:33 +0300 | [diff] [blame] | 999 | dev_vdbg(dwc->dev, "Wrong direction for Data phase\n"); |
Felipe Balbi | a7e8d65 | 2012-07-19 09:26:59 +0300 | [diff] [blame] | 1000 | dwc3_ep0_end_control_data(dwc, dep); |
Felipe Balbi | 55f3fba | 2011-09-08 18:27:33 +0300 | [diff] [blame] | 1001 | dwc3_ep0_stall_and_restart(dwc); |
| 1002 | return; |
| 1003 | } |
| 1004 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1005 | break; |
Felipe Balbi | 1ddcb21 | 2011-08-30 15:52:17 +0300 | [diff] [blame] | 1006 | |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 1007 | case DEPEVT_STATUS_CONTROL_STATUS: |
Felipe Balbi | cb84c5e | 2012-07-23 09:09:32 +0300 | [diff] [blame] | 1008 | if (dwc->ep0_next_event != DWC3_EP0_NRDY_STATUS) |
| 1009 | return; |
| 1010 | |
Felipe Balbi | c7fcdeb | 2011-08-27 22:28:36 +0300 | [diff] [blame] | 1011 | dev_vdbg(dwc->dev, "Control Status\n"); |
Felipe Balbi | 1ddcb21 | 2011-08-30 15:52:17 +0300 | [diff] [blame] | 1012 | |
Sebastian Andrzej Siewior | f0f2b2a | 2011-11-02 13:30:44 +0100 | [diff] [blame] | 1013 | dwc->ep0state = EP0_STATUS_PHASE; |
| 1014 | |
Sebastian Andrzej Siewior | 5bdb1dc | 2011-11-02 13:30:45 +0100 | [diff] [blame] | 1015 | if (dwc->delayed_status) { |
| 1016 | WARN_ON_ONCE(event->endpoint_number != 1); |
| 1017 | dev_vdbg(dwc->dev, "Mass Storage delayed status\n"); |
| 1018 | return; |
| 1019 | } |
| 1020 | |
Felipe Balbi | 9610cd2 | 2012-05-21 14:22:41 +0300 | [diff] [blame] | 1021 | dwc3_ep0_do_control_status(dwc, event); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | void dwc3_ep0_interrupt(struct dwc3 *dwc, |
Felipe Balbi | 8becf27 | 2011-11-04 12:40:05 +0200 | [diff] [blame] | 1026 | const struct dwc3_event_depevt *event) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1027 | { |
| 1028 | u8 epnum = event->endpoint_number; |
| 1029 | |
| 1030 | dev_dbg(dwc->dev, "%s while ep%d%s in state '%s'\n", |
| 1031 | dwc3_ep_event_string(event->endpoint_event), |
Sebastian Andrzej Siewior | b147f35 | 2011-09-30 10:58:40 +0300 | [diff] [blame] | 1032 | epnum >> 1, (epnum & 1) ? "in" : "out", |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1033 | dwc3_ep0_state_string(dwc->ep0state)); |
| 1034 | |
| 1035 | switch (event->endpoint_event) { |
| 1036 | case DWC3_DEPEVT_XFERCOMPLETE: |
| 1037 | dwc3_ep0_xfer_complete(dwc, event); |
| 1038 | break; |
| 1039 | |
| 1040 | case DWC3_DEPEVT_XFERNOTREADY: |
| 1041 | dwc3_ep0_xfernotready(dwc, event); |
| 1042 | break; |
| 1043 | |
| 1044 | case DWC3_DEPEVT_XFERINPROGRESS: |
| 1045 | case DWC3_DEPEVT_RXTXFIFOEVT: |
| 1046 | case DWC3_DEPEVT_STREAMEVT: |
| 1047 | case DWC3_DEPEVT_EPCMDCMPLT: |
| 1048 | break; |
| 1049 | } |
| 1050 | } |