Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * omap_udc.c -- for OMAP full speed udc; most chips support OTG. |
| 3 | * |
| 4 | * Copyright (C) 2004 Texas Instruments, Inc. |
| 5 | * Copyright (C) 2004-2005 David Brownell |
| 6 | * |
Kyungmin Park | 527ea73 | 2007-11-21 15:13:15 -0800 | [diff] [blame] | 7 | * OMAP2 & DMA support by Kyungmin Park <kyungmin.park@samsung.com> |
| 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #undef DEBUG |
| 16 | #undef VERBOSE |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/module.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/ioport.h> |
| 21 | #include <linux/types.h> |
| 22 | #include <linux/errno.h> |
| 23 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/slab.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/timer.h> |
| 27 | #include <linux/list.h> |
| 28 | #include <linux/interrupt.h> |
| 29 | #include <linux/proc_fs.h> |
| 30 | #include <linux/mm.h> |
| 31 | #include <linux/moduleparam.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
David Brownell | 5f84813 | 2006-12-16 15:34:53 -0800 | [diff] [blame] | 33 | #include <linux/usb/ch9.h> |
David Brownell | 9454a57 | 2007-10-04 18:05:17 -0700 | [diff] [blame] | 34 | #include <linux/usb/gadget.h> |
David Brownell | 3a16f7b | 2006-06-29 12:27:23 -0700 | [diff] [blame] | 35 | #include <linux/usb/otg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/dma-mapping.h> |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 37 | #include <linux/clk.h> |
Linus Torvalds | 268bb0c | 2011-05-20 12:50:29 -0700 | [diff] [blame] | 38 | #include <linux/prefetch.h> |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 39 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | #include <asm/byteorder.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <asm/unaligned.h> |
| 44 | #include <asm/mach-types.h> |
| 45 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 46 | #include <plat/dma.h> |
| 47 | #include <plat/usb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #include "omap_udc.h" |
| 50 | |
| 51 | #undef USB_TRACE |
| 52 | |
| 53 | /* bulk DMA seems to be behaving for both IN and OUT */ |
| 54 | #define USE_DMA |
| 55 | |
| 56 | /* ISO too */ |
| 57 | #define USE_ISO |
| 58 | |
| 59 | #define DRIVER_DESC "OMAP UDC driver" |
| 60 | #define DRIVER_VERSION "4 October 2004" |
| 61 | |
| 62 | #define DMA_ADDR_INVALID (~(dma_addr_t)0) |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | /* |
| 65 | * The OMAP UDC needs _very_ early endpoint setup: before enabling the |
| 66 | * D+ pullup to allow enumeration. That's too early for the gadget |
| 67 | * framework to use from usb_endpoint_enable(), which happens after |
| 68 | * enumeration as part of activating an interface. (But if we add an |
| 69 | * optional new "UDC not yet running" state to the gadget driver model, |
| 70 | * even just during driver binding, the endpoint autoconfig logic is the |
| 71 | * natural spot to manufacture new endpoints.) |
| 72 | * |
| 73 | * So instead of using endpoint enable calls to control the hardware setup, |
| 74 | * this driver defines a "fifo mode" parameter. It's used during driver |
| 75 | * initialization to choose among a set of pre-defined endpoint configs. |
| 76 | * See omap_udc_setup() for available modes, or to add others. That code |
| 77 | * lives in an init section, so use this driver as a module if you need |
| 78 | * to change the fifo mode after the kernel boots. |
| 79 | * |
| 80 | * Gadget drivers normally ignore endpoints they don't care about, and |
| 81 | * won't include them in configuration descriptors. That means only |
| 82 | * misbehaving hosts would even notice they exist. |
| 83 | */ |
| 84 | #ifdef USE_ISO |
| 85 | static unsigned fifo_mode = 3; |
| 86 | #else |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 87 | static unsigned fifo_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #endif |
| 89 | |
| 90 | /* "modprobe omap_udc fifo_mode=42", or else as a kernel |
| 91 | * boot parameter "omap_udc:fifo_mode=42" |
| 92 | */ |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 93 | module_param(fifo_mode, uint, 0); |
| 94 | MODULE_PARM_DESC(fifo_mode, "endpoint configuration"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | #ifdef USE_DMA |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 97 | static bool use_dma = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | /* "modprobe omap_udc use_dma=y", or else as a kernel |
| 100 | * boot parameter "omap_udc:use_dma=y" |
| 101 | */ |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 102 | module_param(use_dma, bool, 0); |
| 103 | MODULE_PARM_DESC(use_dma, "enable/disable DMA"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | #else /* !USE_DMA */ |
| 105 | |
| 106 | /* save a bit of code */ |
| 107 | #define use_dma 0 |
| 108 | #endif /* !USE_DMA */ |
| 109 | |
| 110 | |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 111 | static const char driver_name[] = "omap_udc"; |
| 112 | static const char driver_desc[] = DRIVER_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | /*-------------------------------------------------------------------------*/ |
| 115 | |
| 116 | /* there's a notion of "current endpoint" for modifying endpoint |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 117 | * state, and PIO access to its FIFO. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | */ |
| 119 | |
| 120 | static void use_ep(struct omap_ep *ep, u16 select) |
| 121 | { |
| 122 | u16 num = ep->bEndpointAddress & 0x0f; |
| 123 | |
| 124 | if (ep->bEndpointAddress & USB_DIR_IN) |
| 125 | num |= UDC_EP_DIR; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 126 | omap_writew(num | select, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | /* when select, MUST deselect later !! */ |
| 128 | } |
| 129 | |
| 130 | static inline void deselect_ep(void) |
| 131 | { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 132 | u16 w; |
| 133 | |
| 134 | w = omap_readw(UDC_EP_NUM); |
| 135 | w &= ~UDC_EP_SEL; |
| 136 | omap_writew(w, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | /* 6 wait states before TX will happen */ |
| 138 | } |
| 139 | |
| 140 | static void dma_channel_claim(struct omap_ep *ep, unsigned preferred); |
| 141 | |
| 142 | /*-------------------------------------------------------------------------*/ |
| 143 | |
| 144 | static int omap_ep_enable(struct usb_ep *_ep, |
| 145 | const struct usb_endpoint_descriptor *desc) |
| 146 | { |
| 147 | struct omap_ep *ep = container_of(_ep, struct omap_ep, ep); |
| 148 | struct omap_udc *udc; |
| 149 | unsigned long flags; |
| 150 | u16 maxp; |
| 151 | |
| 152 | /* catch various bogus parameters */ |
Ido Shayevitz | f8bdae0 | 2012-03-12 20:25:35 +0200 | [diff] [blame] | 153 | if (!_ep || !desc || ep->ep.desc |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | || desc->bDescriptorType != USB_DT_ENDPOINT |
| 155 | || ep->bEndpointAddress != desc->bEndpointAddress |
Kuninori Morimoto | 29cc889 | 2011-08-23 03:12:03 -0700 | [diff] [blame] | 156 | || ep->maxpacket < usb_endpoint_maxp(desc)) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 157 | DBG("%s, bad ep or descriptor\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | return -EINVAL; |
| 159 | } |
Kuninori Morimoto | 29cc889 | 2011-08-23 03:12:03 -0700 | [diff] [blame] | 160 | maxp = usb_endpoint_maxp(desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK |
| 162 | && maxp != ep->maxpacket) |
Kuninori Morimoto | 29cc889 | 2011-08-23 03:12:03 -0700 | [diff] [blame] | 163 | || usb_endpoint_maxp(desc) > ep->maxpacket |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | || !desc->wMaxPacketSize) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 165 | DBG("%s, bad %s maxpacket\n", __func__, _ep->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | return -ERANGE; |
| 167 | } |
| 168 | |
| 169 | #ifdef USE_ISO |
| 170 | if ((desc->bmAttributes == USB_ENDPOINT_XFER_ISOC |
| 171 | && desc->bInterval != 1)) { |
| 172 | /* hardware wants period = 1; USB allows 2^(Interval-1) */ |
| 173 | DBG("%s, unsupported ISO period %dms\n", _ep->name, |
| 174 | 1 << (desc->bInterval - 1)); |
| 175 | return -EDOM; |
| 176 | } |
| 177 | #else |
| 178 | if (desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { |
| 179 | DBG("%s, ISO nyet\n", _ep->name); |
| 180 | return -EDOM; |
| 181 | } |
| 182 | #endif |
| 183 | |
| 184 | /* xfer types must match, except that interrupt ~= bulk */ |
| 185 | if (ep->bmAttributes != desc->bmAttributes |
| 186 | && ep->bmAttributes != USB_ENDPOINT_XFER_BULK |
| 187 | && desc->bmAttributes != USB_ENDPOINT_XFER_INT) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 188 | DBG("%s, %s type mismatch\n", __func__, _ep->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | return -EINVAL; |
| 190 | } |
| 191 | |
| 192 | udc = ep->udc; |
| 193 | if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 194 | DBG("%s, bogus device state\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | return -ESHUTDOWN; |
| 196 | } |
| 197 | |
| 198 | spin_lock_irqsave(&udc->lock, flags); |
| 199 | |
Ido Shayevitz | f8bdae0 | 2012-03-12 20:25:35 +0200 | [diff] [blame] | 200 | ep->ep.desc = desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | ep->irqs = 0; |
| 202 | ep->stopped = 0; |
| 203 | ep->ep.maxpacket = maxp; |
| 204 | |
| 205 | /* set endpoint to initial state */ |
| 206 | ep->dma_channel = 0; |
| 207 | ep->has_dma = 0; |
| 208 | ep->lch = -1; |
| 209 | use_ep(ep, UDC_EP_SEL); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 210 | omap_writew(udc->clr_halt, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | ep->ackwait = 0; |
| 212 | deselect_ep(); |
| 213 | |
| 214 | if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) |
| 215 | list_add(&ep->iso, &udc->iso); |
| 216 | |
| 217 | /* maybe assign a DMA channel to this endpoint */ |
| 218 | if (use_dma && desc->bmAttributes == USB_ENDPOINT_XFER_BULK) |
| 219 | /* FIXME ISO can dma, but prefers first channel */ |
| 220 | dma_channel_claim(ep, 0); |
| 221 | |
| 222 | /* PIO OUT may RX packets */ |
| 223 | if (desc->bmAttributes != USB_ENDPOINT_XFER_ISOC |
| 224 | && !ep->has_dma |
| 225 | && !(ep->bEndpointAddress & USB_DIR_IN)) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 226 | omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | ep->ackwait = 1 + ep->double_buf; |
| 228 | } |
| 229 | |
| 230 | spin_unlock_irqrestore(&udc->lock, flags); |
| 231 | VDBG("%s enabled\n", _ep->name); |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | static void nuke(struct omap_ep *, int status); |
| 236 | |
| 237 | static int omap_ep_disable(struct usb_ep *_ep) |
| 238 | { |
| 239 | struct omap_ep *ep = container_of(_ep, struct omap_ep, ep); |
| 240 | unsigned long flags; |
| 241 | |
Ido Shayevitz | f8bdae0 | 2012-03-12 20:25:35 +0200 | [diff] [blame] | 242 | if (!_ep || !ep->ep.desc) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 243 | DBG("%s, %s not enabled\n", __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | _ep ? ep->ep.name : NULL); |
| 245 | return -EINVAL; |
| 246 | } |
| 247 | |
| 248 | spin_lock_irqsave(&ep->udc->lock, flags); |
Ido Shayevitz | f9c56cd | 2012-02-08 13:56:48 +0200 | [diff] [blame] | 249 | ep->ep.desc = NULL; |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 250 | nuke(ep, -ESHUTDOWN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | ep->ep.maxpacket = ep->maxpacket; |
| 252 | ep->has_dma = 0; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 253 | omap_writew(UDC_SET_HALT, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | list_del_init(&ep->iso); |
| 255 | del_timer(&ep->timer); |
| 256 | |
| 257 | spin_unlock_irqrestore(&ep->udc->lock, flags); |
| 258 | |
| 259 | VDBG("%s disabled\n", _ep->name); |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | /*-------------------------------------------------------------------------*/ |
| 264 | |
| 265 | static struct usb_request * |
Al Viro | 55016f1 | 2005-10-21 03:21:58 -0400 | [diff] [blame] | 266 | omap_alloc_request(struct usb_ep *ep, gfp_t gfp_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | { |
| 268 | struct omap_req *req; |
| 269 | |
Eric Sesterhenn | 7039f42 | 2006-02-27 13:34:10 -0800 | [diff] [blame] | 270 | req = kzalloc(sizeof(*req), gfp_flags); |
Felipe Balbi | 70617db | 2012-05-29 14:36:42 +0300 | [diff] [blame] | 271 | if (!req) |
| 272 | return NULL; |
| 273 | |
| 274 | req->req.dma = DMA_ADDR_INVALID; |
| 275 | INIT_LIST_HEAD(&req->queue); |
| 276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | return &req->req; |
| 278 | } |
| 279 | |
| 280 | static void |
| 281 | omap_free_request(struct usb_ep *ep, struct usb_request *_req) |
| 282 | { |
| 283 | struct omap_req *req = container_of(_req, struct omap_req, req); |
| 284 | |
Felipe Balbi | 23673d7 | 2012-05-29 14:38:32 +0300 | [diff] [blame^] | 285 | kfree(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /*-------------------------------------------------------------------------*/ |
| 289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | static void |
| 291 | done(struct omap_ep *ep, struct omap_req *req, int status) |
| 292 | { |
| 293 | unsigned stopped = ep->stopped; |
| 294 | |
| 295 | list_del_init(&req->queue); |
| 296 | |
| 297 | if (req->req.status == -EINPROGRESS) |
| 298 | req->req.status = status; |
| 299 | else |
| 300 | status = req->req.status; |
| 301 | |
| 302 | if (use_dma && ep->has_dma) { |
| 303 | if (req->mapped) { |
| 304 | dma_unmap_single(ep->udc->gadget.dev.parent, |
| 305 | req->req.dma, req->req.length, |
| 306 | (ep->bEndpointAddress & USB_DIR_IN) |
| 307 | ? DMA_TO_DEVICE |
| 308 | : DMA_FROM_DEVICE); |
| 309 | req->req.dma = DMA_ADDR_INVALID; |
| 310 | req->mapped = 0; |
| 311 | } else |
| 312 | dma_sync_single_for_cpu(ep->udc->gadget.dev.parent, |
| 313 | req->req.dma, req->req.length, |
| 314 | (ep->bEndpointAddress & USB_DIR_IN) |
| 315 | ? DMA_TO_DEVICE |
| 316 | : DMA_FROM_DEVICE); |
| 317 | } |
| 318 | |
| 319 | #ifndef USB_TRACE |
| 320 | if (status && status != -ESHUTDOWN) |
| 321 | #endif |
| 322 | VDBG("complete %s req %p stat %d len %u/%u\n", |
| 323 | ep->ep.name, &req->req, status, |
| 324 | req->req.actual, req->req.length); |
| 325 | |
| 326 | /* don't modify queue heads during completion callback */ |
| 327 | ep->stopped = 1; |
| 328 | spin_unlock(&ep->udc->lock); |
| 329 | req->req.complete(&ep->ep, &req->req); |
| 330 | spin_lock(&ep->udc->lock); |
| 331 | ep->stopped = stopped; |
| 332 | } |
| 333 | |
| 334 | /*-------------------------------------------------------------------------*/ |
| 335 | |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 336 | #define UDC_FIFO_FULL (UDC_NON_ISO_FIFO_FULL | UDC_ISO_FIFO_FULL) |
| 337 | #define UDC_FIFO_UNWRITABLE (UDC_EP_HALTED | UDC_FIFO_FULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | #define FIFO_EMPTY (UDC_NON_ISO_FIFO_EMPTY | UDC_ISO_FIFO_EMPTY) |
| 340 | #define FIFO_UNREADABLE (UDC_EP_HALTED | FIFO_EMPTY) |
| 341 | |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 342 | static inline int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | write_packet(u8 *buf, struct omap_req *req, unsigned max) |
| 344 | { |
| 345 | unsigned len; |
| 346 | u16 *wp; |
| 347 | |
| 348 | len = min(req->req.length - req->req.actual, max); |
| 349 | req->req.actual += len; |
| 350 | |
| 351 | max = len; |
| 352 | if (likely((((int)buf) & 1) == 0)) { |
| 353 | wp = (u16 *)buf; |
| 354 | while (max >= 2) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 355 | omap_writew(*wp++, UDC_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | max -= 2; |
| 357 | } |
| 358 | buf = (u8 *)wp; |
| 359 | } |
| 360 | while (max--) |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 361 | omap_writeb(*buf++, UDC_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | return len; |
| 363 | } |
| 364 | |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 365 | /* FIXME change r/w fifo calling convention */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
| 367 | |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 368 | /* return: 0 = still running, 1 = completed, negative = errno */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | static int write_fifo(struct omap_ep *ep, struct omap_req *req) |
| 370 | { |
| 371 | u8 *buf; |
| 372 | unsigned count; |
| 373 | int is_last; |
| 374 | u16 ep_stat; |
| 375 | |
| 376 | buf = req->req.buf + req->req.actual; |
| 377 | prefetch(buf); |
| 378 | |
| 379 | /* PIO-IN isn't double buffered except for iso */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 380 | ep_stat = omap_readw(UDC_STAT_FLG); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 381 | if (ep_stat & UDC_FIFO_UNWRITABLE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | return 0; |
| 383 | |
| 384 | count = ep->ep.maxpacket; |
| 385 | count = write_packet(buf, req, count); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 386 | omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | ep->ackwait = 1; |
| 388 | |
| 389 | /* last packet is often short (sometimes a zlp) */ |
| 390 | if (count != ep->ep.maxpacket) |
| 391 | is_last = 1; |
| 392 | else if (req->req.length == req->req.actual |
| 393 | && !req->req.zero) |
| 394 | is_last = 1; |
| 395 | else |
| 396 | is_last = 0; |
| 397 | |
| 398 | /* NOTE: requests complete when all IN data is in a |
| 399 | * FIFO (or sometimes later, if a zlp was needed). |
| 400 | * Use usb_ep_fifo_status() where needed. |
| 401 | */ |
| 402 | if (is_last) |
| 403 | done(ep, req, 0); |
| 404 | return is_last; |
| 405 | } |
| 406 | |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 407 | static inline int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | read_packet(u8 *buf, struct omap_req *req, unsigned avail) |
| 409 | { |
| 410 | unsigned len; |
| 411 | u16 *wp; |
| 412 | |
| 413 | len = min(req->req.length - req->req.actual, avail); |
| 414 | req->req.actual += len; |
| 415 | avail = len; |
| 416 | |
| 417 | if (likely((((int)buf) & 1) == 0)) { |
| 418 | wp = (u16 *)buf; |
| 419 | while (avail >= 2) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 420 | *wp++ = omap_readw(UDC_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | avail -= 2; |
| 422 | } |
| 423 | buf = (u8 *)wp; |
| 424 | } |
| 425 | while (avail--) |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 426 | *buf++ = omap_readb(UDC_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | return len; |
| 428 | } |
| 429 | |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 430 | /* return: 0 = still running, 1 = queue empty, negative = errno */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | static int read_fifo(struct omap_ep *ep, struct omap_req *req) |
| 432 | { |
| 433 | u8 *buf; |
| 434 | unsigned count, avail; |
| 435 | int is_last; |
| 436 | |
| 437 | buf = req->req.buf + req->req.actual; |
| 438 | prefetchw(buf); |
| 439 | |
| 440 | for (;;) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 441 | u16 ep_stat = omap_readw(UDC_STAT_FLG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
| 443 | is_last = 0; |
| 444 | if (ep_stat & FIFO_EMPTY) { |
| 445 | if (!ep->double_buf) |
| 446 | break; |
| 447 | ep->fnf = 1; |
| 448 | } |
| 449 | if (ep_stat & UDC_EP_HALTED) |
| 450 | break; |
| 451 | |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 452 | if (ep_stat & UDC_FIFO_FULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | avail = ep->ep.maxpacket; |
| 454 | else { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 455 | avail = omap_readw(UDC_RXFSTAT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | ep->fnf = ep->double_buf; |
| 457 | } |
| 458 | count = read_packet(buf, req, avail); |
| 459 | |
| 460 | /* partial packet reads may not be errors */ |
| 461 | if (count < ep->ep.maxpacket) { |
| 462 | is_last = 1; |
| 463 | /* overflowed this request? flush extra data */ |
| 464 | if (count != avail) { |
| 465 | req->req.status = -EOVERFLOW; |
| 466 | avail -= count; |
| 467 | while (avail--) |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 468 | omap_readw(UDC_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | } |
| 470 | } else if (req->req.length == req->req.actual) |
| 471 | is_last = 1; |
| 472 | else |
| 473 | is_last = 0; |
| 474 | |
| 475 | if (!ep->bEndpointAddress) |
| 476 | break; |
| 477 | if (is_last) |
| 478 | done(ep, req, 0); |
| 479 | break; |
| 480 | } |
| 481 | return is_last; |
| 482 | } |
| 483 | |
| 484 | /*-------------------------------------------------------------------------*/ |
| 485 | |
| 486 | static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start) |
| 487 | { |
| 488 | dma_addr_t end; |
| 489 | |
| 490 | /* IN-DMA needs this on fault/cancel paths, so 15xx misreports |
| 491 | * the last transfer's bytecount by more than a FIFO's worth. |
| 492 | */ |
| 493 | if (cpu_is_omap15xx()) |
| 494 | return 0; |
| 495 | |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 496 | end = omap_get_dma_src_pos(ep->lch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | if (end == ep->dma_counter) |
| 498 | return 0; |
| 499 | |
| 500 | end |= start & (0xffff << 16); |
| 501 | if (end < start) |
| 502 | end += 0x10000; |
| 503 | return end - start; |
| 504 | } |
| 505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start) |
| 507 | { |
| 508 | dma_addr_t end; |
| 509 | |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 510 | end = omap_get_dma_dst_pos(ep->lch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | if (end == ep->dma_counter) |
| 512 | return 0; |
| 513 | |
| 514 | end |= start & (0xffff << 16); |
| 515 | if (cpu_is_omap15xx()) |
| 516 | end++; |
| 517 | if (end < start) |
| 518 | end += 0x10000; |
| 519 | return end - start; |
| 520 | } |
| 521 | |
| 522 | |
| 523 | /* Each USB transfer request using DMA maps to one or more DMA transfers. |
| 524 | * When DMA completion isn't request completion, the UDC continues with |
| 525 | * the next DMA transfer for that USB transfer. |
| 526 | */ |
| 527 | |
| 528 | static void next_in_dma(struct omap_ep *ep, struct omap_req *req) |
| 529 | { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 530 | u16 txdma_ctrl, w; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | unsigned length = req->req.length - req->req.actual; |
| 532 | const int sync_mode = cpu_is_omap15xx() |
| 533 | ? OMAP_DMA_SYNC_FRAME |
| 534 | : OMAP_DMA_SYNC_ELEMENT; |
Kyungmin Park | 527ea73 | 2007-11-21 15:13:15 -0800 | [diff] [blame] | 535 | int dma_trigger = 0; |
| 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | /* measure length in either bytes or packets */ |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 538 | if ((cpu_is_omap16xx() && length <= UDC_TXN_TSC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | || (cpu_is_omap15xx() && length < ep->maxpacket)) { |
| 540 | txdma_ctrl = UDC_TXN_EOT | length; |
| 541 | omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, |
Kyungmin Park | 527ea73 | 2007-11-21 15:13:15 -0800 | [diff] [blame] | 542 | length, 1, sync_mode, dma_trigger, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | } else { |
| 544 | length = min(length / ep->maxpacket, |
| 545 | (unsigned) UDC_TXN_TSC + 1); |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 546 | txdma_ctrl = length; |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 547 | omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 548 | ep->ep.maxpacket >> 1, length, sync_mode, |
Kyungmin Park | 527ea73 | 2007-11-21 15:13:15 -0800 | [diff] [blame] | 549 | dma_trigger, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | length *= ep->maxpacket; |
| 551 | } |
| 552 | omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF, |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 553 | OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual, |
| 554 | 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
| 556 | omap_start_dma(ep->lch); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 557 | ep->dma_counter = omap_get_dma_src_pos(ep->lch); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 558 | w = omap_readw(UDC_DMA_IRQ_EN); |
| 559 | w |= UDC_TX_DONE_IE(ep->dma_channel); |
| 560 | omap_writew(w, UDC_DMA_IRQ_EN); |
| 561 | omap_writew(UDC_TXN_START | txdma_ctrl, UDC_TXDMA(ep->dma_channel)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | req->dma_bytes = length; |
| 563 | } |
| 564 | |
| 565 | static void finish_in_dma(struct omap_ep *ep, struct omap_req *req, int status) |
| 566 | { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 567 | u16 w; |
| 568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | if (status == 0) { |
| 570 | req->req.actual += req->dma_bytes; |
| 571 | |
| 572 | /* return if this request needs to send data or zlp */ |
| 573 | if (req->req.actual < req->req.length) |
| 574 | return; |
| 575 | if (req->req.zero |
| 576 | && req->dma_bytes != 0 |
| 577 | && (req->req.actual % ep->maxpacket) == 0) |
| 578 | return; |
| 579 | } else |
| 580 | req->req.actual += dma_src_len(ep, req->req.dma |
| 581 | + req->req.actual); |
| 582 | |
| 583 | /* tx completion */ |
| 584 | omap_stop_dma(ep->lch); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 585 | w = omap_readw(UDC_DMA_IRQ_EN); |
| 586 | w &= ~UDC_TX_DONE_IE(ep->dma_channel); |
| 587 | omap_writew(w, UDC_DMA_IRQ_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | done(ep, req, status); |
| 589 | } |
| 590 | |
| 591 | static void next_out_dma(struct omap_ep *ep, struct omap_req *req) |
| 592 | { |
Kyungmin Park | 527ea73 | 2007-11-21 15:13:15 -0800 | [diff] [blame] | 593 | unsigned packets = req->req.length - req->req.actual; |
| 594 | int dma_trigger = 0; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 595 | u16 w; |
Kyungmin Park | 527ea73 | 2007-11-21 15:13:15 -0800 | [diff] [blame] | 596 | |
Tony Lindgren | ae37257 | 2012-05-21 12:01:11 -0700 | [diff] [blame] | 597 | /* set up this DMA transfer, enable the fifo, start */ |
| 598 | packets /= ep->ep.maxpacket; |
| 599 | packets = min(packets, (unsigned)UDC_RXN_TC + 1); |
| 600 | req->dma_bytes = packets * ep->ep.maxpacket; |
| 601 | omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, |
| 602 | ep->ep.maxpacket >> 1, packets, |
| 603 | OMAP_DMA_SYNC_ELEMENT, |
| 604 | dma_trigger, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 606 | OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual, |
| 607 | 0, 0); |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 608 | ep->dma_counter = omap_get_dma_dst_pos(ep->lch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 610 | omap_writew(UDC_RXN_STOP | (packets - 1), UDC_RXDMA(ep->dma_channel)); |
| 611 | w = omap_readw(UDC_DMA_IRQ_EN); |
| 612 | w |= UDC_RX_EOT_IE(ep->dma_channel); |
| 613 | omap_writew(w, UDC_DMA_IRQ_EN); |
| 614 | omap_writew(ep->bEndpointAddress & 0xf, UDC_EP_NUM); |
| 615 | omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
| 617 | omap_start_dma(ep->lch); |
| 618 | } |
| 619 | |
| 620 | static void |
David Brownell | cb97c5c | 2005-10-16 15:06:51 -0700 | [diff] [blame] | 621 | finish_out_dma(struct omap_ep *ep, struct omap_req *req, int status, int one) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 623 | u16 count, w; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
| 625 | if (status == 0) |
| 626 | ep->dma_counter = (u16) (req->req.dma + req->req.actual); |
| 627 | count = dma_dest_len(ep, req->req.dma + req->req.actual); |
| 628 | count += req->req.actual; |
David Brownell | cb97c5c | 2005-10-16 15:06:51 -0700 | [diff] [blame] | 629 | if (one) |
| 630 | count--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | if (count <= req->req.length) |
| 632 | req->req.actual = count; |
| 633 | |
| 634 | if (count != req->dma_bytes || status) |
| 635 | omap_stop_dma(ep->lch); |
| 636 | |
| 637 | /* if this wasn't short, request may need another transfer */ |
| 638 | else if (req->req.actual < req->req.length) |
| 639 | return; |
| 640 | |
| 641 | /* rx completion */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 642 | w = omap_readw(UDC_DMA_IRQ_EN); |
| 643 | w &= ~UDC_RX_EOT_IE(ep->dma_channel); |
| 644 | omap_writew(w, UDC_DMA_IRQ_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | done(ep, req, status); |
| 646 | } |
| 647 | |
| 648 | static void dma_irq(struct omap_udc *udc, u16 irq_src) |
| 649 | { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 650 | u16 dman_stat = omap_readw(UDC_DMAN_STAT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | struct omap_ep *ep; |
| 652 | struct omap_req *req; |
| 653 | |
| 654 | /* IN dma: tx to host */ |
| 655 | if (irq_src & UDC_TXN_DONE) { |
| 656 | ep = &udc->ep[16 + UDC_DMA_TX_SRC(dman_stat)]; |
| 657 | ep->irqs++; |
| 658 | /* can see TXN_DONE after dma abort */ |
| 659 | if (!list_empty(&ep->queue)) { |
| 660 | req = container_of(ep->queue.next, |
| 661 | struct omap_req, queue); |
| 662 | finish_in_dma(ep, req, 0); |
| 663 | } |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 664 | omap_writew(UDC_TXN_DONE, UDC_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 666 | if (!list_empty(&ep->queue)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | req = container_of(ep->queue.next, |
| 668 | struct omap_req, queue); |
| 669 | next_in_dma(ep, req); |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | /* OUT dma: rx from host */ |
| 674 | if (irq_src & UDC_RXN_EOT) { |
| 675 | ep = &udc->ep[UDC_DMA_RX_SRC(dman_stat)]; |
| 676 | ep->irqs++; |
| 677 | /* can see RXN_EOT after dma abort */ |
| 678 | if (!list_empty(&ep->queue)) { |
| 679 | req = container_of(ep->queue.next, |
| 680 | struct omap_req, queue); |
David Brownell | cb97c5c | 2005-10-16 15:06:51 -0700 | [diff] [blame] | 681 | finish_out_dma(ep, req, 0, dman_stat & UDC_DMA_RX_SB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 683 | omap_writew(UDC_RXN_EOT, UDC_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 685 | if (!list_empty(&ep->queue)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | req = container_of(ep->queue.next, |
| 687 | struct omap_req, queue); |
| 688 | next_out_dma(ep, req); |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | if (irq_src & UDC_RXN_CNT) { |
| 693 | ep = &udc->ep[UDC_DMA_RX_SRC(dman_stat)]; |
| 694 | ep->irqs++; |
| 695 | /* omap15xx does this unasked... */ |
| 696 | VDBG("%s, RX_CNT irq?\n", ep->ep.name); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 697 | omap_writew(UDC_RXN_CNT, UDC_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | |
| 701 | static void dma_error(int lch, u16 ch_status, void *data) |
| 702 | { |
| 703 | struct omap_ep *ep = data; |
| 704 | |
| 705 | /* if ch_status & OMAP_DMA_DROP_IRQ ... */ |
Tony Lindgren | 7ff879d | 2006-06-26 16:16:15 -0700 | [diff] [blame] | 706 | /* if ch_status & OMAP1_DMA_TOUT_IRQ ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | ERR("%s dma error, lch %d status %02x\n", ep->ep.name, lch, ch_status); |
| 708 | |
| 709 | /* complete current transfer ... */ |
| 710 | } |
| 711 | |
| 712 | static void dma_channel_claim(struct omap_ep *ep, unsigned channel) |
| 713 | { |
| 714 | u16 reg; |
| 715 | int status, restart, is_in; |
Kyungmin Park | 527ea73 | 2007-11-21 15:13:15 -0800 | [diff] [blame] | 716 | int dma_channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | |
| 718 | is_in = ep->bEndpointAddress & USB_DIR_IN; |
| 719 | if (is_in) |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 720 | reg = omap_readw(UDC_TXDMA_CFG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | else |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 722 | reg = omap_readw(UDC_RXDMA_CFG); |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 723 | reg |= UDC_DMA_REQ; /* "pulse" activated */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | |
| 725 | ep->dma_channel = 0; |
| 726 | ep->lch = -1; |
| 727 | if (channel == 0 || channel > 3) { |
| 728 | if ((reg & 0x0f00) == 0) |
| 729 | channel = 3; |
| 730 | else if ((reg & 0x00f0) == 0) |
| 731 | channel = 2; |
| 732 | else if ((reg & 0x000f) == 0) /* preferred for ISO */ |
| 733 | channel = 1; |
| 734 | else { |
| 735 | status = -EMLINK; |
| 736 | goto just_restart; |
| 737 | } |
| 738 | } |
| 739 | reg |= (0x0f & ep->bEndpointAddress) << (4 * (channel - 1)); |
| 740 | ep->dma_channel = channel; |
| 741 | |
| 742 | if (is_in) { |
Tony Lindgren | ae37257 | 2012-05-21 12:01:11 -0700 | [diff] [blame] | 743 | dma_channel = OMAP_DMA_USB_W2FC_TX0 - 1 + channel; |
Kyungmin Park | 527ea73 | 2007-11-21 15:13:15 -0800 | [diff] [blame] | 744 | status = omap_request_dma(dma_channel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | ep->ep.name, dma_error, ep, &ep->lch); |
| 746 | if (status == 0) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 747 | omap_writew(reg, UDC_TXDMA_CFG); |
Kyungmin Park | 527ea73 | 2007-11-21 15:13:15 -0800 | [diff] [blame] | 748 | /* EMIFF or SDRC */ |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 749 | omap_set_dma_src_burst_mode(ep->lch, |
| 750 | OMAP_DMA_DATA_BURST_4); |
| 751 | omap_set_dma_src_data_pack(ep->lch, 1); |
| 752 | /* TIPB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | omap_set_dma_dest_params(ep->lch, |
| 754 | OMAP_DMA_PORT_TIPB, |
| 755 | OMAP_DMA_AMODE_CONSTANT, |
David Brownell | c3e3208 | 2008-08-31 18:04:27 -0700 | [diff] [blame] | 756 | UDC_DATA_DMA, |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 757 | 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | } |
| 759 | } else { |
Tony Lindgren | ae37257 | 2012-05-21 12:01:11 -0700 | [diff] [blame] | 760 | dma_channel = OMAP_DMA_USB_W2FC_RX0 - 1 + channel; |
Kyungmin Park | 527ea73 | 2007-11-21 15:13:15 -0800 | [diff] [blame] | 761 | status = omap_request_dma(dma_channel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | ep->ep.name, dma_error, ep, &ep->lch); |
| 763 | if (status == 0) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 764 | omap_writew(reg, UDC_RXDMA_CFG); |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 765 | /* TIPB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | omap_set_dma_src_params(ep->lch, |
| 767 | OMAP_DMA_PORT_TIPB, |
| 768 | OMAP_DMA_AMODE_CONSTANT, |
David Brownell | c3e3208 | 2008-08-31 18:04:27 -0700 | [diff] [blame] | 769 | UDC_DATA_DMA, |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 770 | 0, 0); |
Kyungmin Park | 527ea73 | 2007-11-21 15:13:15 -0800 | [diff] [blame] | 771 | /* EMIFF or SDRC */ |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 772 | omap_set_dma_dest_burst_mode(ep->lch, |
| 773 | OMAP_DMA_DATA_BURST_4); |
| 774 | omap_set_dma_dest_data_pack(ep->lch, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | if (status) |
| 778 | ep->dma_channel = 0; |
| 779 | else { |
| 780 | ep->has_dma = 1; |
| 781 | omap_disable_dma_irq(ep->lch, OMAP_DMA_BLOCK_IRQ); |
| 782 | |
| 783 | /* channel type P: hw synch (fifo) */ |
Tony Lindgren | ae37257 | 2012-05-21 12:01:11 -0700 | [diff] [blame] | 784 | if (!cpu_is_omap15xx()) |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 785 | omap_set_dma_channel_mode(ep->lch, OMAP_DMA_LCH_P); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | just_restart: |
| 789 | /* restart any queue, even if the claim failed */ |
| 790 | restart = !ep->stopped && !list_empty(&ep->queue); |
| 791 | |
| 792 | if (status) |
| 793 | DBG("%s no dma channel: %d%s\n", ep->ep.name, status, |
| 794 | restart ? " (restart)" : ""); |
| 795 | else |
| 796 | DBG("%s claimed %cxdma%d lch %d%s\n", ep->ep.name, |
| 797 | is_in ? 't' : 'r', |
| 798 | ep->dma_channel - 1, ep->lch, |
| 799 | restart ? " (restart)" : ""); |
| 800 | |
| 801 | if (restart) { |
| 802 | struct omap_req *req; |
| 803 | req = container_of(ep->queue.next, struct omap_req, queue); |
| 804 | if (ep->has_dma) |
| 805 | (is_in ? next_in_dma : next_out_dma)(ep, req); |
| 806 | else { |
| 807 | use_ep(ep, UDC_EP_SEL); |
| 808 | (is_in ? write_fifo : read_fifo)(ep, req); |
| 809 | deselect_ep(); |
| 810 | if (!is_in) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 811 | omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | ep->ackwait = 1 + ep->double_buf; |
| 813 | } |
| 814 | /* IN: 6 wait states before it'll tx */ |
| 815 | } |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | static void dma_channel_release(struct omap_ep *ep) |
| 820 | { |
| 821 | int shift = 4 * (ep->dma_channel - 1); |
| 822 | u16 mask = 0x0f << shift; |
| 823 | struct omap_req *req; |
| 824 | int active; |
| 825 | |
| 826 | /* abort any active usb transfer request */ |
| 827 | if (!list_empty(&ep->queue)) |
| 828 | req = container_of(ep->queue.next, struct omap_req, queue); |
| 829 | else |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 830 | req = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | |
Tony Lindgren | 0499bde | 2008-07-03 12:24:36 +0300 | [diff] [blame] | 832 | active = omap_get_dma_active_status(ep->lch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | |
| 834 | DBG("%s release %s %cxdma%d %p\n", ep->ep.name, |
| 835 | active ? "active" : "idle", |
| 836 | (ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r', |
| 837 | ep->dma_channel - 1, req); |
| 838 | |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 839 | /* NOTE: re-setting RX_REQ/TX_REQ because of a chip bug (before |
| 840 | * OMAP 1710 ES2.0) where reading the DMA_CFG can clear them. |
| 841 | */ |
| 842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | /* wait till current packet DMA finishes, and fifo empties */ |
| 844 | if (ep->bEndpointAddress & USB_DIR_IN) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 845 | omap_writew((omap_readw(UDC_TXDMA_CFG) & ~mask) | UDC_DMA_REQ, |
| 846 | UDC_TXDMA_CFG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | |
| 848 | if (req) { |
| 849 | finish_in_dma(ep, req, -ECONNRESET); |
| 850 | |
| 851 | /* clear FIFO; hosts probably won't empty it */ |
| 852 | use_ep(ep, UDC_EP_SEL); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 853 | omap_writew(UDC_CLR_EP, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | deselect_ep(); |
| 855 | } |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 856 | while (omap_readw(UDC_TXDMA_CFG) & mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | udelay(10); |
| 858 | } else { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 859 | omap_writew((omap_readw(UDC_RXDMA_CFG) & ~mask) | UDC_DMA_REQ, |
| 860 | UDC_RXDMA_CFG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | |
| 862 | /* dma empties the fifo */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 863 | while (omap_readw(UDC_RXDMA_CFG) & mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | udelay(10); |
| 865 | if (req) |
David Brownell | cb97c5c | 2005-10-16 15:06:51 -0700 | [diff] [blame] | 866 | finish_out_dma(ep, req, -ECONNRESET, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | } |
| 868 | omap_free_dma(ep->lch); |
| 869 | ep->dma_channel = 0; |
| 870 | ep->lch = -1; |
| 871 | /* has_dma still set, till endpoint is fully quiesced */ |
| 872 | } |
| 873 | |
| 874 | |
| 875 | /*-------------------------------------------------------------------------*/ |
| 876 | |
| 877 | static int |
Al Viro | 55016f1 | 2005-10-21 03:21:58 -0400 | [diff] [blame] | 878 | omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | { |
| 880 | struct omap_ep *ep = container_of(_ep, struct omap_ep, ep); |
| 881 | struct omap_req *req = container_of(_req, struct omap_req, req); |
| 882 | struct omap_udc *udc; |
| 883 | unsigned long flags; |
| 884 | int is_iso = 0; |
| 885 | |
| 886 | /* catch various bogus parameters */ |
| 887 | if (!_req || !req->req.complete || !req->req.buf |
| 888 | || !list_empty(&req->queue)) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 889 | DBG("%s, bad params\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | return -EINVAL; |
| 891 | } |
Ido Shayevitz | f8bdae0 | 2012-03-12 20:25:35 +0200 | [diff] [blame] | 892 | if (!_ep || (!ep->ep.desc && ep->bEndpointAddress)) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 893 | DBG("%s, bad ep\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | return -EINVAL; |
| 895 | } |
| 896 | if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) { |
| 897 | if (req->req.length > ep->ep.maxpacket) |
| 898 | return -EMSGSIZE; |
| 899 | is_iso = 1; |
| 900 | } |
| 901 | |
| 902 | /* this isn't bogus, but OMAP DMA isn't the only hardware to |
| 903 | * have a hard time with partial packet reads... reject it. |
| 904 | */ |
| 905 | if (use_dma |
| 906 | && ep->has_dma |
| 907 | && ep->bEndpointAddress != 0 |
| 908 | && (ep->bEndpointAddress & USB_DIR_IN) == 0 |
| 909 | && (req->req.length % ep->ep.maxpacket) != 0) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 910 | DBG("%s, no partial packet OUT reads\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | return -EMSGSIZE; |
| 912 | } |
| 913 | |
| 914 | udc = ep->udc; |
| 915 | if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) |
| 916 | return -ESHUTDOWN; |
| 917 | |
| 918 | if (use_dma && ep->has_dma) { |
| 919 | if (req->req.dma == DMA_ADDR_INVALID) { |
| 920 | req->req.dma = dma_map_single( |
| 921 | ep->udc->gadget.dev.parent, |
| 922 | req->req.buf, |
| 923 | req->req.length, |
| 924 | (ep->bEndpointAddress & USB_DIR_IN) |
| 925 | ? DMA_TO_DEVICE |
| 926 | : DMA_FROM_DEVICE); |
| 927 | req->mapped = 1; |
| 928 | } else { |
| 929 | dma_sync_single_for_device( |
| 930 | ep->udc->gadget.dev.parent, |
| 931 | req->req.dma, req->req.length, |
| 932 | (ep->bEndpointAddress & USB_DIR_IN) |
| 933 | ? DMA_TO_DEVICE |
| 934 | : DMA_FROM_DEVICE); |
| 935 | req->mapped = 0; |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | VDBG("%s queue req %p, len %d buf %p\n", |
| 940 | ep->ep.name, _req, _req->length, _req->buf); |
| 941 | |
| 942 | spin_lock_irqsave(&udc->lock, flags); |
| 943 | |
| 944 | req->req.status = -EINPROGRESS; |
| 945 | req->req.actual = 0; |
| 946 | |
| 947 | /* maybe kickstart non-iso i/o queues */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 948 | if (is_iso) { |
| 949 | u16 w; |
| 950 | |
| 951 | w = omap_readw(UDC_IRQ_EN); |
| 952 | w |= UDC_SOF_IE; |
| 953 | omap_writew(w, UDC_IRQ_EN); |
| 954 | } else if (list_empty(&ep->queue) && !ep->stopped && !ep->ackwait) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | int is_in; |
| 956 | |
| 957 | if (ep->bEndpointAddress == 0) { |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 958 | if (!udc->ep0_pending || !list_empty(&ep->queue)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | spin_unlock_irqrestore(&udc->lock, flags); |
| 960 | return -EL2HLT; |
| 961 | } |
| 962 | |
| 963 | /* empty DATA stage? */ |
| 964 | is_in = udc->ep0_in; |
| 965 | if (!req->req.length) { |
| 966 | |
| 967 | /* chip became CONFIGURED or ADDRESSED |
| 968 | * earlier; drivers may already have queued |
| 969 | * requests to non-control endpoints |
| 970 | */ |
| 971 | if (udc->ep0_set_config) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 972 | u16 irq_en = omap_readw(UDC_IRQ_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | |
| 974 | irq_en |= UDC_DS_CHG_IE | UDC_EP0_IE; |
| 975 | if (!udc->ep0_reset_config) |
| 976 | irq_en |= UDC_EPN_RX_IE |
| 977 | | UDC_EPN_TX_IE; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 978 | omap_writew(irq_en, UDC_IRQ_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | } |
| 980 | |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 981 | /* STATUS for zero length DATA stages is |
| 982 | * always an IN ... even for IN transfers, |
Joe Perches | dc0d5c1 | 2007-12-17 11:40:18 -0800 | [diff] [blame] | 983 | * a weird case which seem to stall OMAP. |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 984 | */ |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 985 | omap_writew(UDC_EP_SEL | UDC_EP_DIR, |
| 986 | UDC_EP_NUM); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 987 | omap_writew(UDC_CLR_EP, UDC_CTRL); |
| 988 | omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); |
| 989 | omap_writew(UDC_EP_DIR, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | |
| 991 | /* cleanup */ |
| 992 | udc->ep0_pending = 0; |
| 993 | done(ep, req, 0); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 994 | req = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | |
| 996 | /* non-empty DATA stage */ |
| 997 | } else if (is_in) { |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 998 | omap_writew(UDC_EP_SEL | UDC_EP_DIR, |
| 999 | UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | } else { |
| 1001 | if (udc->ep0_setup) |
| 1002 | goto irq_wait; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1003 | omap_writew(UDC_EP_SEL, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | } |
| 1005 | } else { |
| 1006 | is_in = ep->bEndpointAddress & USB_DIR_IN; |
| 1007 | if (!ep->has_dma) |
| 1008 | use_ep(ep, UDC_EP_SEL); |
| 1009 | /* if ISO: SOF IRQs must be enabled/disabled! */ |
| 1010 | } |
| 1011 | |
| 1012 | if (ep->has_dma) |
| 1013 | (is_in ? next_in_dma : next_out_dma)(ep, req); |
| 1014 | else if (req) { |
| 1015 | if ((is_in ? write_fifo : read_fifo)(ep, req) == 1) |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 1016 | req = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | deselect_ep(); |
| 1018 | if (!is_in) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1019 | omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | ep->ackwait = 1 + ep->double_buf; |
| 1021 | } |
| 1022 | /* IN: 6 wait states before it'll tx */ |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | irq_wait: |
| 1027 | /* irq handler advances the queue */ |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 1028 | if (req != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | list_add_tail(&req->queue, &ep->queue); |
| 1030 | spin_unlock_irqrestore(&udc->lock, flags); |
| 1031 | |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
| 1035 | static int omap_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) |
| 1036 | { |
| 1037 | struct omap_ep *ep = container_of(_ep, struct omap_ep, ep); |
| 1038 | struct omap_req *req; |
| 1039 | unsigned long flags; |
| 1040 | |
| 1041 | if (!_ep || !_req) |
| 1042 | return -EINVAL; |
| 1043 | |
| 1044 | spin_lock_irqsave(&ep->udc->lock, flags); |
| 1045 | |
| 1046 | /* make sure it's actually queued on this endpoint */ |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 1047 | list_for_each_entry(req, &ep->queue, queue) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | if (&req->req == _req) |
| 1049 | break; |
| 1050 | } |
| 1051 | if (&req->req != _req) { |
| 1052 | spin_unlock_irqrestore(&ep->udc->lock, flags); |
| 1053 | return -EINVAL; |
| 1054 | } |
| 1055 | |
| 1056 | if (use_dma && ep->dma_channel && ep->queue.next == &req->queue) { |
| 1057 | int channel = ep->dma_channel; |
| 1058 | |
| 1059 | /* releasing the channel cancels the request, |
| 1060 | * reclaiming the channel restarts the queue |
| 1061 | */ |
| 1062 | dma_channel_release(ep); |
| 1063 | dma_channel_claim(ep, channel); |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 1064 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | done(ep, req, -ECONNRESET); |
| 1066 | spin_unlock_irqrestore(&ep->udc->lock, flags); |
| 1067 | return 0; |
| 1068 | } |
| 1069 | |
| 1070 | /*-------------------------------------------------------------------------*/ |
| 1071 | |
| 1072 | static int omap_ep_set_halt(struct usb_ep *_ep, int value) |
| 1073 | { |
| 1074 | struct omap_ep *ep = container_of(_ep, struct omap_ep, ep); |
| 1075 | unsigned long flags; |
| 1076 | int status = -EOPNOTSUPP; |
| 1077 | |
| 1078 | spin_lock_irqsave(&ep->udc->lock, flags); |
| 1079 | |
| 1080 | /* just use protocol stalls for ep0; real halts are annoying */ |
| 1081 | if (ep->bEndpointAddress == 0) { |
| 1082 | if (!ep->udc->ep0_pending) |
| 1083 | status = -EINVAL; |
| 1084 | else if (value) { |
| 1085 | if (ep->udc->ep0_set_config) { |
Arjan van de Ven | b6c6393 | 2008-07-25 01:45:52 -0700 | [diff] [blame] | 1086 | WARNING("error changing config?\n"); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1087 | omap_writew(UDC_CLR_CFG, UDC_SYSCON2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | } |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1089 | omap_writew(UDC_STALL_CMD, UDC_SYSCON2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | ep->udc->ep0_pending = 0; |
| 1091 | status = 0; |
| 1092 | } else /* NOP */ |
| 1093 | status = 0; |
| 1094 | |
| 1095 | /* otherwise, all active non-ISO endpoints can halt */ |
Ido Shayevitz | f8bdae0 | 2012-03-12 20:25:35 +0200 | [diff] [blame] | 1096 | } else if (ep->bmAttributes != USB_ENDPOINT_XFER_ISOC && ep->ep.desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | |
| 1098 | /* IN endpoints must already be idle */ |
| 1099 | if ((ep->bEndpointAddress & USB_DIR_IN) |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 1100 | && !list_empty(&ep->queue)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | status = -EAGAIN; |
| 1102 | goto done; |
| 1103 | } |
| 1104 | |
| 1105 | if (value) { |
| 1106 | int channel; |
| 1107 | |
| 1108 | if (use_dma && ep->dma_channel |
| 1109 | && !list_empty(&ep->queue)) { |
| 1110 | channel = ep->dma_channel; |
| 1111 | dma_channel_release(ep); |
| 1112 | } else |
| 1113 | channel = 0; |
| 1114 | |
| 1115 | use_ep(ep, UDC_EP_SEL); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1116 | if (omap_readw(UDC_STAT_FLG) & UDC_NON_ISO_FIFO_EMPTY) { |
| 1117 | omap_writew(UDC_SET_HALT, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | status = 0; |
| 1119 | } else |
| 1120 | status = -EAGAIN; |
| 1121 | deselect_ep(); |
| 1122 | |
| 1123 | if (channel) |
| 1124 | dma_channel_claim(ep, channel); |
| 1125 | } else { |
| 1126 | use_ep(ep, 0); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1127 | omap_writew(ep->udc->clr_halt, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | ep->ackwait = 0; |
| 1129 | if (!(ep->bEndpointAddress & USB_DIR_IN)) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1130 | omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | ep->ackwait = 1 + ep->double_buf; |
| 1132 | } |
| 1133 | } |
| 1134 | } |
| 1135 | done: |
| 1136 | VDBG("%s %s halt stat %d\n", ep->ep.name, |
| 1137 | value ? "set" : "clear", status); |
| 1138 | |
| 1139 | spin_unlock_irqrestore(&ep->udc->lock, flags); |
| 1140 | return status; |
| 1141 | } |
| 1142 | |
| 1143 | static struct usb_ep_ops omap_ep_ops = { |
| 1144 | .enable = omap_ep_enable, |
| 1145 | .disable = omap_ep_disable, |
| 1146 | |
| 1147 | .alloc_request = omap_alloc_request, |
| 1148 | .free_request = omap_free_request, |
| 1149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | .queue = omap_ep_queue, |
| 1151 | .dequeue = omap_ep_dequeue, |
| 1152 | |
| 1153 | .set_halt = omap_ep_set_halt, |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 1154 | /* fifo_status ... report bytes in fifo */ |
| 1155 | /* fifo_flush ... flush fifo */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | }; |
| 1157 | |
| 1158 | /*-------------------------------------------------------------------------*/ |
| 1159 | |
| 1160 | static int omap_get_frame(struct usb_gadget *gadget) |
| 1161 | { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1162 | u16 sof = omap_readw(UDC_SOF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | return (sof & UDC_TS_OK) ? (sof & UDC_TS) : -EL2NSYNC; |
| 1164 | } |
| 1165 | |
| 1166 | static int omap_wakeup(struct usb_gadget *gadget) |
| 1167 | { |
| 1168 | struct omap_udc *udc; |
| 1169 | unsigned long flags; |
| 1170 | int retval = -EHOSTUNREACH; |
| 1171 | |
| 1172 | udc = container_of(gadget, struct omap_udc, gadget); |
| 1173 | |
| 1174 | spin_lock_irqsave(&udc->lock, flags); |
| 1175 | if (udc->devstat & UDC_SUS) { |
| 1176 | /* NOTE: OTG spec erratum says that OTG devices may |
| 1177 | * issue wakeups without host enable. |
| 1178 | */ |
| 1179 | if (udc->devstat & (UDC_B_HNP_ENABLE|UDC_R_WK_OK)) { |
| 1180 | DBG("remote wakeup...\n"); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1181 | omap_writew(UDC_RMT_WKP, UDC_SYSCON2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | retval = 0; |
| 1183 | } |
| 1184 | |
| 1185 | /* NOTE: non-OTG systems may use SRP TOO... */ |
| 1186 | } else if (!(udc->devstat & UDC_ATT)) { |
| 1187 | if (udc->transceiver) |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 1188 | retval = otg_start_srp(udc->transceiver->otg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | } |
| 1190 | spin_unlock_irqrestore(&udc->lock, flags); |
| 1191 | |
| 1192 | return retval; |
| 1193 | } |
| 1194 | |
| 1195 | static int |
| 1196 | omap_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered) |
| 1197 | { |
| 1198 | struct omap_udc *udc; |
| 1199 | unsigned long flags; |
| 1200 | u16 syscon1; |
| 1201 | |
| 1202 | udc = container_of(gadget, struct omap_udc, gadget); |
| 1203 | spin_lock_irqsave(&udc->lock, flags); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1204 | syscon1 = omap_readw(UDC_SYSCON1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | if (is_selfpowered) |
| 1206 | syscon1 |= UDC_SELF_PWR; |
| 1207 | else |
| 1208 | syscon1 &= ~UDC_SELF_PWR; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1209 | omap_writew(syscon1, UDC_SYSCON1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | spin_unlock_irqrestore(&udc->lock, flags); |
| 1211 | |
| 1212 | return 0; |
| 1213 | } |
| 1214 | |
| 1215 | static int can_pullup(struct omap_udc *udc) |
| 1216 | { |
| 1217 | return udc->driver && udc->softconnect && udc->vbus_active; |
| 1218 | } |
| 1219 | |
| 1220 | static void pullup_enable(struct omap_udc *udc) |
| 1221 | { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1222 | u16 w; |
| 1223 | |
| 1224 | w = omap_readw(UDC_SYSCON1); |
| 1225 | w |= UDC_PULLUP_EN; |
| 1226 | omap_writew(w, UDC_SYSCON1); |
| 1227 | if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx()) { |
| 1228 | u32 l; |
| 1229 | |
| 1230 | l = omap_readl(OTG_CTRL); |
| 1231 | l |= OTG_BSESSVLD; |
| 1232 | omap_writel(l, OTG_CTRL); |
| 1233 | } |
| 1234 | omap_writew(UDC_DS_CHG_IE, UDC_IRQ_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | static void pullup_disable(struct omap_udc *udc) |
| 1238 | { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1239 | u16 w; |
| 1240 | |
| 1241 | if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx()) { |
| 1242 | u32 l; |
| 1243 | |
| 1244 | l = omap_readl(OTG_CTRL); |
| 1245 | l &= ~OTG_BSESSVLD; |
| 1246 | omap_writel(l, OTG_CTRL); |
| 1247 | } |
| 1248 | omap_writew(UDC_DS_CHG_IE, UDC_IRQ_EN); |
| 1249 | w = omap_readw(UDC_SYSCON1); |
| 1250 | w &= ~UDC_PULLUP_EN; |
| 1251 | omap_writew(w, UDC_SYSCON1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | } |
| 1253 | |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 1254 | static struct omap_udc *udc; |
| 1255 | |
| 1256 | static void omap_udc_enable_clock(int enable) |
| 1257 | { |
| 1258 | if (udc == NULL || udc->dc_clk == NULL || udc->hhc_clk == NULL) |
| 1259 | return; |
| 1260 | |
| 1261 | if (enable) { |
| 1262 | clk_enable(udc->dc_clk); |
| 1263 | clk_enable(udc->hhc_clk); |
| 1264 | udelay(100); |
| 1265 | } else { |
| 1266 | clk_disable(udc->hhc_clk); |
| 1267 | clk_disable(udc->dc_clk); |
| 1268 | } |
| 1269 | } |
| 1270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | /* |
| 1272 | * Called by whatever detects VBUS sessions: external transceiver |
| 1273 | * driver, or maybe GPIO0 VBUS IRQ. May request 48 MHz clock. |
| 1274 | */ |
| 1275 | static int omap_vbus_session(struct usb_gadget *gadget, int is_active) |
| 1276 | { |
| 1277 | struct omap_udc *udc; |
| 1278 | unsigned long flags; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1279 | u32 l; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | |
| 1281 | udc = container_of(gadget, struct omap_udc, gadget); |
| 1282 | spin_lock_irqsave(&udc->lock, flags); |
| 1283 | VDBG("VBUS %s\n", is_active ? "on" : "off"); |
| 1284 | udc->vbus_active = (is_active != 0); |
| 1285 | if (cpu_is_omap15xx()) { |
| 1286 | /* "software" detect, ignored if !VBUS_MODE_1510 */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1287 | l = omap_readl(FUNC_MUX_CTRL_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | if (is_active) |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1289 | l |= VBUS_CTRL_1510; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | else |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1291 | l &= ~VBUS_CTRL_1510; |
| 1292 | omap_writel(l, FUNC_MUX_CTRL_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | } |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 1294 | if (udc->dc_clk != NULL && is_active) { |
| 1295 | if (!udc->clk_requested) { |
| 1296 | omap_udc_enable_clock(1); |
| 1297 | udc->clk_requested = 1; |
| 1298 | } |
| 1299 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | if (can_pullup(udc)) |
| 1301 | pullup_enable(udc); |
| 1302 | else |
| 1303 | pullup_disable(udc); |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 1304 | if (udc->dc_clk != NULL && !is_active) { |
| 1305 | if (udc->clk_requested) { |
| 1306 | omap_udc_enable_clock(0); |
| 1307 | udc->clk_requested = 0; |
| 1308 | } |
| 1309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | spin_unlock_irqrestore(&udc->lock, flags); |
| 1311 | return 0; |
| 1312 | } |
| 1313 | |
| 1314 | static int omap_vbus_draw(struct usb_gadget *gadget, unsigned mA) |
| 1315 | { |
| 1316 | struct omap_udc *udc; |
| 1317 | |
| 1318 | udc = container_of(gadget, struct omap_udc, gadget); |
| 1319 | if (udc->transceiver) |
Heikki Krogerus | b96d3b0 | 2012-02-13 13:24:18 +0200 | [diff] [blame] | 1320 | return usb_phy_set_power(udc->transceiver, mA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | return -EOPNOTSUPP; |
| 1322 | } |
| 1323 | |
| 1324 | static int omap_pullup(struct usb_gadget *gadget, int is_on) |
| 1325 | { |
| 1326 | struct omap_udc *udc; |
| 1327 | unsigned long flags; |
| 1328 | |
| 1329 | udc = container_of(gadget, struct omap_udc, gadget); |
| 1330 | spin_lock_irqsave(&udc->lock, flags); |
| 1331 | udc->softconnect = (is_on != 0); |
| 1332 | if (can_pullup(udc)) |
| 1333 | pullup_enable(udc); |
| 1334 | else |
| 1335 | pullup_disable(udc); |
| 1336 | spin_unlock_irqrestore(&udc->lock, flags); |
| 1337 | return 0; |
| 1338 | } |
| 1339 | |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 1340 | static int omap_udc_start(struct usb_gadget_driver *driver, |
| 1341 | int (*bind)(struct usb_gadget *)); |
| 1342 | static int omap_udc_stop(struct usb_gadget_driver *driver); |
| 1343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | static struct usb_gadget_ops omap_gadget_ops = { |
| 1345 | .get_frame = omap_get_frame, |
| 1346 | .wakeup = omap_wakeup, |
| 1347 | .set_selfpowered = omap_set_selfpowered, |
| 1348 | .vbus_session = omap_vbus_session, |
| 1349 | .vbus_draw = omap_vbus_draw, |
| 1350 | .pullup = omap_pullup, |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 1351 | .start = omap_udc_start, |
| 1352 | .stop = omap_udc_stop, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | }; |
| 1354 | |
| 1355 | /*-------------------------------------------------------------------------*/ |
| 1356 | |
| 1357 | /* dequeue ALL requests; caller holds udc->lock */ |
| 1358 | static void nuke(struct omap_ep *ep, int status) |
| 1359 | { |
| 1360 | struct omap_req *req; |
| 1361 | |
| 1362 | ep->stopped = 1; |
| 1363 | |
| 1364 | if (use_dma && ep->dma_channel) |
| 1365 | dma_channel_release(ep); |
| 1366 | |
| 1367 | use_ep(ep, 0); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1368 | omap_writew(UDC_CLR_EP, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | if (ep->bEndpointAddress && ep->bmAttributes != USB_ENDPOINT_XFER_ISOC) |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1370 | omap_writew(UDC_SET_HALT, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | |
| 1372 | while (!list_empty(&ep->queue)) { |
| 1373 | req = list_entry(ep->queue.next, struct omap_req, queue); |
| 1374 | done(ep, req, status); |
| 1375 | } |
| 1376 | } |
| 1377 | |
| 1378 | /* caller holds udc->lock */ |
| 1379 | static void udc_quiesce(struct omap_udc *udc) |
| 1380 | { |
| 1381 | struct omap_ep *ep; |
| 1382 | |
| 1383 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
| 1384 | nuke(&udc->ep[0], -ESHUTDOWN); |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 1385 | list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | nuke(ep, -ESHUTDOWN); |
| 1387 | } |
| 1388 | |
| 1389 | /*-------------------------------------------------------------------------*/ |
| 1390 | |
| 1391 | static void update_otg(struct omap_udc *udc) |
| 1392 | { |
| 1393 | u16 devstat; |
| 1394 | |
David Brownell | 9cfbba7 | 2007-10-26 13:42:18 -0700 | [diff] [blame] | 1395 | if (!gadget_is_otg(&udc->gadget)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | return; |
| 1397 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1398 | if (omap_readl(OTG_CTRL) & OTG_ID) |
| 1399 | devstat = omap_readw(UDC_DEVSTAT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | else |
| 1401 | devstat = 0; |
| 1402 | |
| 1403 | udc->gadget.b_hnp_enable = !!(devstat & UDC_B_HNP_ENABLE); |
| 1404 | udc->gadget.a_hnp_support = !!(devstat & UDC_A_HNP_SUPPORT); |
| 1405 | udc->gadget.a_alt_hnp_support = !!(devstat & UDC_A_ALT_HNP_SUPPORT); |
| 1406 | |
| 1407 | /* Enable HNP early, avoiding races on suspend irq path. |
| 1408 | * ASSUMES OTG state machine B_BUS_REQ input is true. |
| 1409 | */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1410 | if (udc->gadget.b_hnp_enable) { |
| 1411 | u32 l; |
| 1412 | |
| 1413 | l = omap_readl(OTG_CTRL); |
| 1414 | l |= OTG_B_HNPEN | OTG_B_BUSREQ; |
| 1415 | l &= ~OTG_PULLUP; |
| 1416 | omap_writel(l, OTG_CTRL); |
| 1417 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | static void ep0_irq(struct omap_udc *udc, u16 irq_src) |
| 1421 | { |
| 1422 | struct omap_ep *ep0 = &udc->ep[0]; |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 1423 | struct omap_req *req = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | |
| 1425 | ep0->irqs++; |
| 1426 | |
| 1427 | /* Clear any pending requests and then scrub any rx/tx state |
| 1428 | * before starting to handle the SETUP request. |
| 1429 | */ |
| 1430 | if (irq_src & UDC_SETUP) { |
| 1431 | u16 ack = irq_src & (UDC_EP0_TX|UDC_EP0_RX); |
| 1432 | |
| 1433 | nuke(ep0, 0); |
| 1434 | if (ack) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1435 | omap_writew(ack, UDC_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | irq_src = UDC_SETUP; |
| 1437 | } |
| 1438 | } |
| 1439 | |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 1440 | /* IN/OUT packets mean we're in the DATA or STATUS stage. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | * This driver uses only uses protocol stalls (ep0 never halts), |
| 1442 | * and if we got this far the gadget driver already had a |
| 1443 | * chance to stall. Tries to be forgiving of host oddities. |
| 1444 | * |
| 1445 | * NOTE: the last chance gadget drivers have to stall control |
| 1446 | * requests is during their request completion callback. |
| 1447 | */ |
| 1448 | if (!list_empty(&ep0->queue)) |
| 1449 | req = container_of(ep0->queue.next, struct omap_req, queue); |
| 1450 | |
| 1451 | /* IN == TX to host */ |
| 1452 | if (irq_src & UDC_EP0_TX) { |
| 1453 | int stat; |
| 1454 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1455 | omap_writew(UDC_EP0_TX, UDC_IRQ_SRC); |
| 1456 | omap_writew(UDC_EP_SEL|UDC_EP_DIR, UDC_EP_NUM); |
| 1457 | stat = omap_readw(UDC_STAT_FLG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | if (stat & UDC_ACK) { |
| 1459 | if (udc->ep0_in) { |
| 1460 | /* write next IN packet from response, |
| 1461 | * or set up the status stage. |
| 1462 | */ |
| 1463 | if (req) |
| 1464 | stat = write_fifo(ep0, req); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1465 | omap_writew(UDC_EP_DIR, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | if (!req && udc->ep0_pending) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1467 | omap_writew(UDC_EP_SEL, UDC_EP_NUM); |
| 1468 | omap_writew(UDC_CLR_EP, UDC_CTRL); |
| 1469 | omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); |
| 1470 | omap_writew(0, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | udc->ep0_pending = 0; |
| 1472 | } /* else: 6 wait states before it'll tx */ |
| 1473 | } else { |
| 1474 | /* ack status stage of OUT transfer */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1475 | omap_writew(UDC_EP_DIR, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | if (req) |
| 1477 | done(ep0, req, 0); |
| 1478 | } |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 1479 | req = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | } else if (stat & UDC_STALL) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1481 | omap_writew(UDC_CLR_HALT, UDC_CTRL); |
| 1482 | omap_writew(UDC_EP_DIR, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | } else { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1484 | omap_writew(UDC_EP_DIR, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | /* OUT == RX from host */ |
| 1489 | if (irq_src & UDC_EP0_RX) { |
| 1490 | int stat; |
| 1491 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1492 | omap_writew(UDC_EP0_RX, UDC_IRQ_SRC); |
| 1493 | omap_writew(UDC_EP_SEL, UDC_EP_NUM); |
| 1494 | stat = omap_readw(UDC_STAT_FLG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | if (stat & UDC_ACK) { |
| 1496 | if (!udc->ep0_in) { |
| 1497 | stat = 0; |
| 1498 | /* read next OUT packet of request, maybe |
| 1499 | * reactiviting the fifo; stall on errors. |
| 1500 | */ |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 1501 | stat = read_fifo(ep0, req); |
| 1502 | if (!req || stat < 0) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1503 | omap_writew(UDC_STALL_CMD, UDC_SYSCON2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | udc->ep0_pending = 0; |
| 1505 | stat = 0; |
| 1506 | } else if (stat == 0) |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1507 | omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); |
| 1508 | omap_writew(0, UDC_EP_NUM); |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 1509 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | /* activate status stage */ |
| 1511 | if (stat == 1) { |
| 1512 | done(ep0, req, 0); |
| 1513 | /* that may have STALLed ep0... */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1514 | omap_writew(UDC_EP_SEL | UDC_EP_DIR, |
| 1515 | UDC_EP_NUM); |
| 1516 | omap_writew(UDC_CLR_EP, UDC_CTRL); |
| 1517 | omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); |
| 1518 | omap_writew(UDC_EP_DIR, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | udc->ep0_pending = 0; |
| 1520 | } |
| 1521 | } else { |
| 1522 | /* ack status stage of IN transfer */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1523 | omap_writew(0, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | if (req) |
| 1525 | done(ep0, req, 0); |
| 1526 | } |
| 1527 | } else if (stat & UDC_STALL) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1528 | omap_writew(UDC_CLR_HALT, UDC_CTRL); |
| 1529 | omap_writew(0, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | } else { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1531 | omap_writew(0, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | /* SETUP starts all control transfers */ |
| 1536 | if (irq_src & UDC_SETUP) { |
| 1537 | union u { |
| 1538 | u16 word[4]; |
| 1539 | struct usb_ctrlrequest r; |
| 1540 | } u; |
| 1541 | int status = -EINVAL; |
| 1542 | struct omap_ep *ep; |
| 1543 | |
| 1544 | /* read the (latest) SETUP message */ |
| 1545 | do { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1546 | omap_writew(UDC_SETUP_SEL, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | /* two bytes at a time */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1548 | u.word[0] = omap_readw(UDC_DATA); |
| 1549 | u.word[1] = omap_readw(UDC_DATA); |
| 1550 | u.word[2] = omap_readw(UDC_DATA); |
| 1551 | u.word[3] = omap_readw(UDC_DATA); |
| 1552 | omap_writew(0, UDC_EP_NUM); |
| 1553 | } while (omap_readw(UDC_IRQ_SRC) & UDC_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | |
David Brownell | 01ee7d7 | 2007-05-25 20:40:14 -0700 | [diff] [blame] | 1555 | #define w_value le16_to_cpu(u.r.wValue) |
| 1556 | #define w_index le16_to_cpu(u.r.wIndex) |
| 1557 | #define w_length le16_to_cpu(u.r.wLength) |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 1558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | /* Delegate almost all control requests to the gadget driver, |
| 1560 | * except for a handful of ch9 status/feature requests that |
| 1561 | * hardware doesn't autodecode _and_ the gadget API hides. |
| 1562 | */ |
| 1563 | udc->ep0_in = (u.r.bRequestType & USB_DIR_IN) != 0; |
| 1564 | udc->ep0_set_config = 0; |
| 1565 | udc->ep0_pending = 1; |
| 1566 | ep0->stopped = 0; |
| 1567 | ep0->ackwait = 0; |
| 1568 | switch (u.r.bRequest) { |
| 1569 | case USB_REQ_SET_CONFIGURATION: |
| 1570 | /* udc needs to know when ep != 0 is valid */ |
| 1571 | if (u.r.bRequestType != USB_RECIP_DEVICE) |
| 1572 | goto delegate; |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 1573 | if (w_length != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | goto do_stall; |
| 1575 | udc->ep0_set_config = 1; |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 1576 | udc->ep0_reset_config = (w_value == 0); |
| 1577 | VDBG("set config %d\n", w_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | |
| 1579 | /* update udc NOW since gadget driver may start |
| 1580 | * queueing requests immediately; clear config |
| 1581 | * later if it fails the request. |
| 1582 | */ |
| 1583 | if (udc->ep0_reset_config) |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1584 | omap_writew(UDC_CLR_CFG, UDC_SYSCON2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | else |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1586 | omap_writew(UDC_DEV_CFG, UDC_SYSCON2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | update_otg(udc); |
| 1588 | goto delegate; |
| 1589 | case USB_REQ_CLEAR_FEATURE: |
| 1590 | /* clear endpoint halt */ |
| 1591 | if (u.r.bRequestType != USB_RECIP_ENDPOINT) |
| 1592 | goto delegate; |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 1593 | if (w_value != USB_ENDPOINT_HALT |
| 1594 | || w_length != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | goto do_stall; |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 1596 | ep = &udc->ep[w_index & 0xf]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | if (ep != ep0) { |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 1598 | if (w_index & USB_DIR_IN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | ep += 16; |
| 1600 | if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC |
Ido Shayevitz | f8bdae0 | 2012-03-12 20:25:35 +0200 | [diff] [blame] | 1601 | || !ep->ep.desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | goto do_stall; |
| 1603 | use_ep(ep, 0); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1604 | omap_writew(udc->clr_halt, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | ep->ackwait = 0; |
| 1606 | if (!(ep->bEndpointAddress & USB_DIR_IN)) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1607 | omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | ep->ackwait = 1 + ep->double_buf; |
| 1609 | } |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 1610 | /* NOTE: assumes the host behaves sanely, |
| 1611 | * only clearing real halts. Else we may |
| 1612 | * need to kill pending transfers and then |
| 1613 | * restart the queue... very messy for DMA! |
| 1614 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | } |
| 1616 | VDBG("%s halt cleared by host\n", ep->name); |
| 1617 | goto ep0out_status_stage; |
| 1618 | case USB_REQ_SET_FEATURE: |
| 1619 | /* set endpoint halt */ |
| 1620 | if (u.r.bRequestType != USB_RECIP_ENDPOINT) |
| 1621 | goto delegate; |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 1622 | if (w_value != USB_ENDPOINT_HALT |
| 1623 | || w_length != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | goto do_stall; |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 1625 | ep = &udc->ep[w_index & 0xf]; |
| 1626 | if (w_index & USB_DIR_IN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | ep += 16; |
| 1628 | if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC |
Ido Shayevitz | f8bdae0 | 2012-03-12 20:25:35 +0200 | [diff] [blame] | 1629 | || ep == ep0 || !ep->ep.desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | goto do_stall; |
| 1631 | if (use_dma && ep->has_dma) { |
| 1632 | /* this has rude side-effects (aborts) and |
| 1633 | * can't really work if DMA-IN is active |
| 1634 | */ |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 1635 | DBG("%s host set_halt, NYET\n", ep->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | goto do_stall; |
| 1637 | } |
| 1638 | use_ep(ep, 0); |
| 1639 | /* can't halt if fifo isn't empty... */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1640 | omap_writew(UDC_CLR_EP, UDC_CTRL); |
| 1641 | omap_writew(UDC_SET_HALT, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | VDBG("%s halted by host\n", ep->name); |
| 1643 | ep0out_status_stage: |
| 1644 | status = 0; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1645 | omap_writew(UDC_EP_SEL|UDC_EP_DIR, UDC_EP_NUM); |
| 1646 | omap_writew(UDC_CLR_EP, UDC_CTRL); |
| 1647 | omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); |
| 1648 | omap_writew(UDC_EP_DIR, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | udc->ep0_pending = 0; |
| 1650 | break; |
| 1651 | case USB_REQ_GET_STATUS: |
David Brownell | 8a3c1f5 | 2007-03-21 12:26:32 -0700 | [diff] [blame] | 1652 | /* USB_ENDPOINT_HALT status? */ |
| 1653 | if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT)) |
| 1654 | goto intf_status; |
| 1655 | |
| 1656 | /* ep0 never stalls */ |
| 1657 | if (!(w_index & 0xf)) |
| 1658 | goto zero_status; |
| 1659 | |
| 1660 | /* only active endpoints count */ |
| 1661 | ep = &udc->ep[w_index & 0xf]; |
| 1662 | if (w_index & USB_DIR_IN) |
| 1663 | ep += 16; |
Ido Shayevitz | f8bdae0 | 2012-03-12 20:25:35 +0200 | [diff] [blame] | 1664 | if (!ep->ep.desc) |
David Brownell | 8a3c1f5 | 2007-03-21 12:26:32 -0700 | [diff] [blame] | 1665 | goto do_stall; |
| 1666 | |
| 1667 | /* iso never stalls */ |
| 1668 | if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) |
| 1669 | goto zero_status; |
| 1670 | |
| 1671 | /* FIXME don't assume non-halted endpoints!! */ |
| 1672 | ERR("%s status, can't report\n", ep->ep.name); |
| 1673 | goto do_stall; |
| 1674 | |
| 1675 | intf_status: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | /* return interface status. if we were pedantic, |
| 1677 | * we'd detect non-existent interfaces, and stall. |
| 1678 | */ |
| 1679 | if (u.r.bRequestType |
| 1680 | != (USB_DIR_IN|USB_RECIP_INTERFACE)) |
| 1681 | goto delegate; |
David Brownell | 8a3c1f5 | 2007-03-21 12:26:32 -0700 | [diff] [blame] | 1682 | |
| 1683 | zero_status: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | /* return two zero bytes */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1685 | omap_writew(UDC_EP_SEL|UDC_EP_DIR, UDC_EP_NUM); |
| 1686 | omap_writew(0, UDC_DATA); |
| 1687 | omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); |
| 1688 | omap_writew(UDC_EP_DIR, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | status = 0; |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 1690 | VDBG("GET_STATUS, interface %d\n", w_index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | /* next, status stage */ |
| 1692 | break; |
| 1693 | default: |
| 1694 | delegate: |
| 1695 | /* activate the ep0out fifo right away */ |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 1696 | if (!udc->ep0_in && w_length) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1697 | omap_writew(0, UDC_EP_NUM); |
| 1698 | omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | /* gadget drivers see class/vendor specific requests, |
| 1702 | * {SET,GET}_{INTERFACE,DESCRIPTOR,CONFIGURATION}, |
| 1703 | * and more |
| 1704 | */ |
| 1705 | VDBG("SETUP %02x.%02x v%04x i%04x l%04x\n", |
| 1706 | u.r.bRequestType, u.r.bRequest, |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 1707 | w_value, w_index, w_length); |
| 1708 | |
| 1709 | #undef w_value |
| 1710 | #undef w_index |
| 1711 | #undef w_length |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | |
| 1713 | /* The gadget driver may return an error here, |
| 1714 | * causing an immediate protocol stall. |
| 1715 | * |
| 1716 | * Else it must issue a response, either queueing a |
| 1717 | * response buffer for the DATA stage, or halting ep0 |
| 1718 | * (causing a protocol stall, not a real halt). A |
| 1719 | * zero length buffer means no DATA stage. |
| 1720 | * |
| 1721 | * It's fine to issue that response after the setup() |
| 1722 | * call returns, and this IRQ was handled. |
| 1723 | */ |
| 1724 | udc->ep0_setup = 1; |
| 1725 | spin_unlock(&udc->lock); |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 1726 | status = udc->driver->setup(&udc->gadget, &u.r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | spin_lock(&udc->lock); |
| 1728 | udc->ep0_setup = 0; |
| 1729 | } |
| 1730 | |
| 1731 | if (status < 0) { |
| 1732 | do_stall: |
| 1733 | VDBG("req %02x.%02x protocol STALL; stat %d\n", |
| 1734 | u.r.bRequestType, u.r.bRequest, status); |
| 1735 | if (udc->ep0_set_config) { |
| 1736 | if (udc->ep0_reset_config) |
Arjan van de Ven | b6c6393 | 2008-07-25 01:45:52 -0700 | [diff] [blame] | 1737 | WARNING("error resetting config?\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | else |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1739 | omap_writew(UDC_CLR_CFG, UDC_SYSCON2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | } |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1741 | omap_writew(UDC_STALL_CMD, UDC_SYSCON2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | udc->ep0_pending = 0; |
| 1743 | } |
| 1744 | } |
| 1745 | } |
| 1746 | |
| 1747 | /*-------------------------------------------------------------------------*/ |
| 1748 | |
| 1749 | #define OTG_FLAGS (UDC_B_HNP_ENABLE|UDC_A_HNP_SUPPORT|UDC_A_ALT_HNP_SUPPORT) |
| 1750 | |
| 1751 | static void devstate_irq(struct omap_udc *udc, u16 irq_src) |
| 1752 | { |
| 1753 | u16 devstat, change; |
| 1754 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1755 | devstat = omap_readw(UDC_DEVSTAT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | change = devstat ^ udc->devstat; |
| 1757 | udc->devstat = devstat; |
| 1758 | |
| 1759 | if (change & (UDC_USB_RESET|UDC_ATT)) { |
| 1760 | udc_quiesce(udc); |
| 1761 | |
| 1762 | if (change & UDC_ATT) { |
| 1763 | /* driver for any external transceiver will |
| 1764 | * have called omap_vbus_session() already |
| 1765 | */ |
| 1766 | if (devstat & UDC_ATT) { |
| 1767 | udc->gadget.speed = USB_SPEED_FULL; |
| 1768 | VDBG("connect\n"); |
| 1769 | if (!udc->transceiver) |
| 1770 | pullup_enable(udc); |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 1771 | /* if (driver->connect) call it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | } else if (udc->gadget.speed != USB_SPEED_UNKNOWN) { |
| 1773 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
| 1774 | if (!udc->transceiver) |
| 1775 | pullup_disable(udc); |
| 1776 | DBG("disconnect, gadget %s\n", |
| 1777 | udc->driver->driver.name); |
| 1778 | if (udc->driver->disconnect) { |
| 1779 | spin_unlock(&udc->lock); |
| 1780 | udc->driver->disconnect(&udc->gadget); |
| 1781 | spin_lock(&udc->lock); |
| 1782 | } |
| 1783 | } |
| 1784 | change &= ~UDC_ATT; |
| 1785 | } |
| 1786 | |
| 1787 | if (change & UDC_USB_RESET) { |
| 1788 | if (devstat & UDC_USB_RESET) { |
| 1789 | VDBG("RESET=1\n"); |
| 1790 | } else { |
| 1791 | udc->gadget.speed = USB_SPEED_FULL; |
| 1792 | INFO("USB reset done, gadget %s\n", |
| 1793 | udc->driver->driver.name); |
| 1794 | /* ep0 traffic is legal from now on */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1795 | omap_writew(UDC_DS_CHG_IE | UDC_EP0_IE, |
| 1796 | UDC_IRQ_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | } |
| 1798 | change &= ~UDC_USB_RESET; |
| 1799 | } |
| 1800 | } |
| 1801 | if (change & UDC_SUS) { |
| 1802 | if (udc->gadget.speed != USB_SPEED_UNKNOWN) { |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 1803 | /* FIXME tell isp1301 to suspend/resume (?) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | if (devstat & UDC_SUS) { |
| 1805 | VDBG("suspend\n"); |
| 1806 | update_otg(udc); |
| 1807 | /* HNP could be under way already */ |
| 1808 | if (udc->gadget.speed == USB_SPEED_FULL |
| 1809 | && udc->driver->suspend) { |
| 1810 | spin_unlock(&udc->lock); |
| 1811 | udc->driver->suspend(&udc->gadget); |
| 1812 | spin_lock(&udc->lock); |
| 1813 | } |
Juha Yrj?l? | 4e67185 | 2005-10-16 15:47:04 -0700 | [diff] [blame] | 1814 | if (udc->transceiver) |
Heikki Krogerus | b96d3b0 | 2012-02-13 13:24:18 +0200 | [diff] [blame] | 1815 | usb_phy_set_suspend( |
| 1816 | udc->transceiver, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | } else { |
| 1818 | VDBG("resume\n"); |
Juha Yrj?l? | 4e67185 | 2005-10-16 15:47:04 -0700 | [diff] [blame] | 1819 | if (udc->transceiver) |
Heikki Krogerus | b96d3b0 | 2012-02-13 13:24:18 +0200 | [diff] [blame] | 1820 | usb_phy_set_suspend( |
| 1821 | udc->transceiver, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | if (udc->gadget.speed == USB_SPEED_FULL |
| 1823 | && udc->driver->resume) { |
| 1824 | spin_unlock(&udc->lock); |
| 1825 | udc->driver->resume(&udc->gadget); |
| 1826 | spin_lock(&udc->lock); |
| 1827 | } |
| 1828 | } |
| 1829 | } |
| 1830 | change &= ~UDC_SUS; |
| 1831 | } |
| 1832 | if (!cpu_is_omap15xx() && (change & OTG_FLAGS)) { |
| 1833 | update_otg(udc); |
| 1834 | change &= ~OTG_FLAGS; |
| 1835 | } |
| 1836 | |
| 1837 | change &= ~(UDC_CFG|UDC_DEF|UDC_ADD); |
| 1838 | if (change) |
| 1839 | VDBG("devstat %03x, ignore change %03x\n", |
| 1840 | devstat, change); |
| 1841 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1842 | omap_writew(UDC_DS_CHG, UDC_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1845 | static irqreturn_t omap_udc_irq(int irq, void *_udc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | { |
| 1847 | struct omap_udc *udc = _udc; |
| 1848 | u16 irq_src; |
| 1849 | irqreturn_t status = IRQ_NONE; |
| 1850 | unsigned long flags; |
| 1851 | |
| 1852 | spin_lock_irqsave(&udc->lock, flags); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1853 | irq_src = omap_readw(UDC_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | |
| 1855 | /* Device state change (usb ch9 stuff) */ |
| 1856 | if (irq_src & UDC_DS_CHG) { |
| 1857 | devstate_irq(_udc, irq_src); |
| 1858 | status = IRQ_HANDLED; |
| 1859 | irq_src &= ~UDC_DS_CHG; |
| 1860 | } |
| 1861 | |
| 1862 | /* EP0 control transfers */ |
| 1863 | if (irq_src & (UDC_EP0_RX|UDC_SETUP|UDC_EP0_TX)) { |
| 1864 | ep0_irq(_udc, irq_src); |
| 1865 | status = IRQ_HANDLED; |
| 1866 | irq_src &= ~(UDC_EP0_RX|UDC_SETUP|UDC_EP0_TX); |
| 1867 | } |
| 1868 | |
| 1869 | /* DMA transfer completion */ |
| 1870 | if (use_dma && (irq_src & (UDC_TXN_DONE|UDC_RXN_CNT|UDC_RXN_EOT))) { |
| 1871 | dma_irq(_udc, irq_src); |
| 1872 | status = IRQ_HANDLED; |
| 1873 | irq_src &= ~(UDC_TXN_DONE|UDC_RXN_CNT|UDC_RXN_EOT); |
| 1874 | } |
| 1875 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1876 | irq_src &= ~(UDC_IRQ_SOF | UDC_EPN_TX|UDC_EPN_RX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | if (irq_src) |
| 1878 | DBG("udc_irq, unhandled %03x\n", irq_src); |
| 1879 | spin_unlock_irqrestore(&udc->lock, flags); |
| 1880 | |
| 1881 | return status; |
| 1882 | } |
| 1883 | |
| 1884 | /* workaround for seemingly-lost IRQs for RX ACKs... */ |
| 1885 | #define PIO_OUT_TIMEOUT (jiffies + HZ/3) |
| 1886 | #define HALF_FULL(f) (!((f)&(UDC_NON_ISO_FIFO_FULL|UDC_NON_ISO_FIFO_EMPTY))) |
| 1887 | |
| 1888 | static void pio_out_timer(unsigned long _ep) |
| 1889 | { |
| 1890 | struct omap_ep *ep = (void *) _ep; |
| 1891 | unsigned long flags; |
| 1892 | u16 stat_flg; |
| 1893 | |
| 1894 | spin_lock_irqsave(&ep->udc->lock, flags); |
| 1895 | if (!list_empty(&ep->queue) && ep->ackwait) { |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 1896 | use_ep(ep, UDC_EP_SEL); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1897 | stat_flg = omap_readw(UDC_STAT_FLG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | |
| 1899 | if ((stat_flg & UDC_ACK) && (!(stat_flg & UDC_FIFO_EN) |
| 1900 | || (ep->double_buf && HALF_FULL(stat_flg)))) { |
| 1901 | struct omap_req *req; |
| 1902 | |
| 1903 | VDBG("%s: lose, %04x\n", ep->ep.name, stat_flg); |
| 1904 | req = container_of(ep->queue.next, |
| 1905 | struct omap_req, queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | (void) read_fifo(ep, req); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1907 | omap_writew(ep->bEndpointAddress, UDC_EP_NUM); |
| 1908 | omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | ep->ackwait = 1 + ep->double_buf; |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 1910 | } else |
| 1911 | deselect_ep(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | } |
| 1913 | mod_timer(&ep->timer, PIO_OUT_TIMEOUT); |
| 1914 | spin_unlock_irqrestore(&ep->udc->lock, flags); |
| 1915 | } |
| 1916 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1917 | static irqreturn_t omap_udc_pio_irq(int irq, void *_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | { |
| 1919 | u16 epn_stat, irq_src; |
| 1920 | irqreturn_t status = IRQ_NONE; |
| 1921 | struct omap_ep *ep; |
| 1922 | int epnum; |
| 1923 | struct omap_udc *udc = _dev; |
| 1924 | struct omap_req *req; |
| 1925 | unsigned long flags; |
| 1926 | |
| 1927 | spin_lock_irqsave(&udc->lock, flags); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1928 | epn_stat = omap_readw(UDC_EPN_STAT); |
| 1929 | irq_src = omap_readw(UDC_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | |
| 1931 | /* handle OUT first, to avoid some wasteful NAKs */ |
| 1932 | if (irq_src & UDC_EPN_RX) { |
| 1933 | epnum = (epn_stat >> 8) & 0x0f; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1934 | omap_writew(UDC_EPN_RX, UDC_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | status = IRQ_HANDLED; |
| 1936 | ep = &udc->ep[epnum]; |
| 1937 | ep->irqs++; |
| 1938 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1939 | omap_writew(epnum | UDC_EP_SEL, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | ep->fnf = 0; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1941 | if (omap_readw(UDC_STAT_FLG) & UDC_ACK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | ep->ackwait--; |
| 1943 | if (!list_empty(&ep->queue)) { |
| 1944 | int stat; |
| 1945 | req = container_of(ep->queue.next, |
| 1946 | struct omap_req, queue); |
| 1947 | stat = read_fifo(ep, req); |
| 1948 | if (!ep->double_buf) |
| 1949 | ep->fnf = 1; |
| 1950 | } |
| 1951 | } |
| 1952 | /* min 6 clock delay before clearing EP_SEL ... */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1953 | epn_stat = omap_readw(UDC_EPN_STAT); |
| 1954 | epn_stat = omap_readw(UDC_EPN_STAT); |
| 1955 | omap_writew(epnum, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | |
| 1957 | /* enabling fifo _after_ clearing ACK, contrary to docs, |
| 1958 | * reduces lossage; timer still needed though (sigh). |
| 1959 | */ |
| 1960 | if (ep->fnf) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1961 | omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | ep->ackwait = 1 + ep->double_buf; |
| 1963 | } |
| 1964 | mod_timer(&ep->timer, PIO_OUT_TIMEOUT); |
| 1965 | } |
| 1966 | |
| 1967 | /* then IN transfers */ |
| 1968 | else if (irq_src & UDC_EPN_TX) { |
| 1969 | epnum = epn_stat & 0x0f; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1970 | omap_writew(UDC_EPN_TX, UDC_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | status = IRQ_HANDLED; |
| 1972 | ep = &udc->ep[16 + epnum]; |
| 1973 | ep->irqs++; |
| 1974 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1975 | omap_writew(epnum | UDC_EP_DIR | UDC_EP_SEL, UDC_EP_NUM); |
| 1976 | if (omap_readw(UDC_STAT_FLG) & UDC_ACK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | ep->ackwait = 0; |
| 1978 | if (!list_empty(&ep->queue)) { |
| 1979 | req = container_of(ep->queue.next, |
| 1980 | struct omap_req, queue); |
| 1981 | (void) write_fifo(ep, req); |
| 1982 | } |
| 1983 | } |
| 1984 | /* min 6 clock delay before clearing EP_SEL ... */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 1985 | epn_stat = omap_readw(UDC_EPN_STAT); |
| 1986 | epn_stat = omap_readw(UDC_EPN_STAT); |
| 1987 | omap_writew(epnum | UDC_EP_DIR, UDC_EP_NUM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | /* then 6 clocks before it'd tx */ |
| 1989 | } |
| 1990 | |
| 1991 | spin_unlock_irqrestore(&udc->lock, flags); |
| 1992 | return status; |
| 1993 | } |
| 1994 | |
| 1995 | #ifdef USE_ISO |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1996 | static irqreturn_t omap_udc_iso_irq(int irq, void *_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | { |
| 1998 | struct omap_udc *udc = _dev; |
| 1999 | struct omap_ep *ep; |
| 2000 | int pending = 0; |
| 2001 | unsigned long flags; |
| 2002 | |
| 2003 | spin_lock_irqsave(&udc->lock, flags); |
| 2004 | |
| 2005 | /* handle all non-DMA ISO transfers */ |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2006 | list_for_each_entry(ep, &udc->iso, iso) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | u16 stat; |
| 2008 | struct omap_req *req; |
| 2009 | |
| 2010 | if (ep->has_dma || list_empty(&ep->queue)) |
| 2011 | continue; |
| 2012 | req = list_entry(ep->queue.next, struct omap_req, queue); |
| 2013 | |
| 2014 | use_ep(ep, UDC_EP_SEL); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2015 | stat = omap_readw(UDC_STAT_FLG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | |
| 2017 | /* NOTE: like the other controller drivers, this isn't |
| 2018 | * currently reporting lost or damaged frames. |
| 2019 | */ |
| 2020 | if (ep->bEndpointAddress & USB_DIR_IN) { |
| 2021 | if (stat & UDC_MISS_IN) |
| 2022 | /* done(ep, req, -EPROTO) */; |
| 2023 | else |
| 2024 | write_fifo(ep, req); |
| 2025 | } else { |
| 2026 | int status = 0; |
| 2027 | |
| 2028 | if (stat & UDC_NO_RXPACKET) |
| 2029 | status = -EREMOTEIO; |
| 2030 | else if (stat & UDC_ISO_ERR) |
| 2031 | status = -EILSEQ; |
| 2032 | else if (stat & UDC_DATA_FLUSH) |
| 2033 | status = -ENOSR; |
| 2034 | |
| 2035 | if (status) |
| 2036 | /* done(ep, req, status) */; |
| 2037 | else |
| 2038 | read_fifo(ep, req); |
| 2039 | } |
| 2040 | deselect_ep(); |
| 2041 | /* 6 wait states before next EP */ |
| 2042 | |
| 2043 | ep->irqs++; |
| 2044 | if (!list_empty(&ep->queue)) |
| 2045 | pending = 1; |
| 2046 | } |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2047 | if (!pending) { |
| 2048 | u16 w; |
| 2049 | |
| 2050 | w = omap_readw(UDC_IRQ_EN); |
| 2051 | w &= ~UDC_SOF_IE; |
| 2052 | omap_writew(w, UDC_IRQ_EN); |
| 2053 | } |
| 2054 | omap_writew(UDC_IRQ_SOF, UDC_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | |
| 2056 | spin_unlock_irqrestore(&udc->lock, flags); |
| 2057 | return IRQ_HANDLED; |
| 2058 | } |
| 2059 | #endif |
| 2060 | |
| 2061 | /*-------------------------------------------------------------------------*/ |
| 2062 | |
David Brownell | 8a3c1f5 | 2007-03-21 12:26:32 -0700 | [diff] [blame] | 2063 | static inline int machine_without_vbus_sense(void) |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2064 | { |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2065 | return machine_is_omap_innovator() |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2066 | || machine_is_omap_osk() |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2067 | || machine_is_sx1() |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2068 | /* No known omap7xx boards with vbus sense */ |
| 2069 | || cpu_is_omap7xx(); |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2070 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 2072 | static int omap_udc_start(struct usb_gadget_driver *driver, |
Uwe Kleine-König | b0fca50 | 2010-08-12 17:43:53 +0200 | [diff] [blame] | 2073 | int (*bind)(struct usb_gadget *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | { |
| 2075 | int status = -ENODEV; |
| 2076 | struct omap_ep *ep; |
| 2077 | unsigned long flags; |
| 2078 | |
| 2079 | /* basic sanity tests */ |
| 2080 | if (!udc) |
| 2081 | return -ENODEV; |
| 2082 | if (!driver |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2083 | /* FIXME if otg, check: driver->is_otg */ |
Michal Nazarewicz | 7177aed | 2011-11-19 18:27:38 +0100 | [diff] [blame] | 2084 | || driver->max_speed < USB_SPEED_FULL |
Uwe Kleine-König | b0fca50 | 2010-08-12 17:43:53 +0200 | [diff] [blame] | 2085 | || !bind || !driver->setup) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | return -EINVAL; |
| 2087 | |
| 2088 | spin_lock_irqsave(&udc->lock, flags); |
| 2089 | if (udc->driver) { |
| 2090 | spin_unlock_irqrestore(&udc->lock, flags); |
| 2091 | return -EBUSY; |
| 2092 | } |
| 2093 | |
| 2094 | /* reset state */ |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2095 | list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | ep->irqs = 0; |
| 2097 | if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) |
| 2098 | continue; |
| 2099 | use_ep(ep, 0); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2100 | omap_writew(UDC_SET_HALT, UDC_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | } |
| 2102 | udc->ep0_pending = 0; |
| 2103 | udc->ep[0].irqs = 0; |
| 2104 | udc->softconnect = 1; |
| 2105 | |
| 2106 | /* hook up the driver */ |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2107 | driver->driver.bus = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | udc->driver = driver; |
| 2109 | udc->gadget.dev.driver = &driver->driver; |
| 2110 | spin_unlock_irqrestore(&udc->lock, flags); |
| 2111 | |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2112 | if (udc->dc_clk != NULL) |
| 2113 | omap_udc_enable_clock(1); |
| 2114 | |
Uwe Kleine-König | b0fca50 | 2010-08-12 17:43:53 +0200 | [diff] [blame] | 2115 | status = bind(&udc->gadget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | if (status) { |
| 2117 | DBG("bind to %s --> %d\n", driver->driver.name, status); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2118 | udc->gadget.dev.driver = NULL; |
| 2119 | udc->driver = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | goto done; |
| 2121 | } |
| 2122 | DBG("bound to driver %s\n", driver->driver.name); |
| 2123 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2124 | omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | |
| 2126 | /* connect to bus through transceiver */ |
| 2127 | if (udc->transceiver) { |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 2128 | status = otg_set_peripheral(udc->transceiver->otg, |
| 2129 | &udc->gadget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | if (status < 0) { |
| 2131 | ERR("can't bind to transceiver\n"); |
David Brownell | 6bea476 | 2006-12-05 03:15:33 -0800 | [diff] [blame] | 2132 | if (driver->unbind) { |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2133 | driver->unbind(&udc->gadget); |
David Brownell | 6bea476 | 2006-12-05 03:15:33 -0800 | [diff] [blame] | 2134 | udc->gadget.dev.driver = NULL; |
| 2135 | udc->driver = NULL; |
| 2136 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | goto done; |
| 2138 | } |
| 2139 | } else { |
| 2140 | if (can_pullup(udc)) |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2141 | pullup_enable(udc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | else |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2143 | pullup_disable(udc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | /* boards that don't have VBUS sensing can't autogate 48MHz; |
| 2147 | * can't enter deep sleep while a gadget driver is active. |
| 2148 | */ |
David Brownell | 8a3c1f5 | 2007-03-21 12:26:32 -0700 | [diff] [blame] | 2149 | if (machine_without_vbus_sense()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | omap_vbus_session(&udc->gadget, 1); |
| 2151 | |
| 2152 | done: |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2153 | if (udc->dc_clk != NULL) |
| 2154 | omap_udc_enable_clock(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | return status; |
| 2156 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 2158 | static int omap_udc_stop(struct usb_gadget_driver *driver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | { |
| 2160 | unsigned long flags; |
| 2161 | int status = -ENODEV; |
| 2162 | |
| 2163 | if (!udc) |
| 2164 | return -ENODEV; |
David Brownell | 6bea476 | 2006-12-05 03:15:33 -0800 | [diff] [blame] | 2165 | if (!driver || driver != udc->driver || !driver->unbind) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | return -EINVAL; |
| 2167 | |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2168 | if (udc->dc_clk != NULL) |
| 2169 | omap_udc_enable_clock(1); |
| 2170 | |
David Brownell | 8a3c1f5 | 2007-03-21 12:26:32 -0700 | [diff] [blame] | 2171 | if (machine_without_vbus_sense()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | omap_vbus_session(&udc->gadget, 0); |
| 2173 | |
| 2174 | if (udc->transceiver) |
Heikki Krogerus | 6e13c65 | 2012-02-13 13:24:20 +0200 | [diff] [blame] | 2175 | (void) otg_set_peripheral(udc->transceiver->otg, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | else |
| 2177 | pullup_disable(udc); |
| 2178 | |
| 2179 | spin_lock_irqsave(&udc->lock, flags); |
| 2180 | udc_quiesce(udc); |
| 2181 | spin_unlock_irqrestore(&udc->lock, flags); |
| 2182 | |
| 2183 | driver->unbind(&udc->gadget); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2184 | udc->gadget.dev.driver = NULL; |
| 2185 | udc->driver = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2187 | if (udc->dc_clk != NULL) |
| 2188 | omap_udc_enable_clock(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | DBG("unregistered driver '%s'\n", driver->driver.name); |
| 2190 | return status; |
| 2191 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | |
| 2193 | /*-------------------------------------------------------------------------*/ |
| 2194 | |
| 2195 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
| 2196 | |
| 2197 | #include <linux/seq_file.h> |
| 2198 | |
| 2199 | static const char proc_filename[] = "driver/udc"; |
| 2200 | |
| 2201 | #define FOURBITS "%s%s%s%s" |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2202 | #define EIGHTBITS "%s%s%s%s%s%s%s%s" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | |
| 2204 | static void proc_ep_show(struct seq_file *s, struct omap_ep *ep) |
| 2205 | { |
| 2206 | u16 stat_flg; |
| 2207 | struct omap_req *req; |
| 2208 | char buf[20]; |
| 2209 | |
| 2210 | use_ep(ep, 0); |
| 2211 | |
| 2212 | if (use_dma && ep->has_dma) |
| 2213 | snprintf(buf, sizeof buf, "(%cxdma%d lch%d) ", |
| 2214 | (ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r', |
| 2215 | ep->dma_channel - 1, ep->lch); |
| 2216 | else |
| 2217 | buf[0] = 0; |
| 2218 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2219 | stat_flg = omap_readw(UDC_STAT_FLG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | seq_printf(s, |
| 2221 | "\n%s %s%s%sirqs %ld stat %04x " EIGHTBITS FOURBITS "%s\n", |
| 2222 | ep->name, buf, |
| 2223 | ep->double_buf ? "dbuf " : "", |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2224 | ({ char *s; |
| 2225 | switch (ep->ackwait) { |
| 2226 | case 0: |
| 2227 | s = ""; |
| 2228 | break; |
| 2229 | case 1: |
| 2230 | s = "(ackw) "; |
| 2231 | break; |
| 2232 | case 2: |
| 2233 | s = "(ackw2) "; |
| 2234 | break; |
| 2235 | default: |
| 2236 | s = "(?) "; |
| 2237 | break; |
| 2238 | } s; }), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | ep->irqs, stat_flg, |
| 2240 | (stat_flg & UDC_NO_RXPACKET) ? "no_rxpacket " : "", |
| 2241 | (stat_flg & UDC_MISS_IN) ? "miss_in " : "", |
| 2242 | (stat_flg & UDC_DATA_FLUSH) ? "data_flush " : "", |
| 2243 | (stat_flg & UDC_ISO_ERR) ? "iso_err " : "", |
| 2244 | (stat_flg & UDC_ISO_FIFO_EMPTY) ? "iso_fifo_empty " : "", |
| 2245 | (stat_flg & UDC_ISO_FIFO_FULL) ? "iso_fifo_full " : "", |
| 2246 | (stat_flg & UDC_EP_HALTED) ? "HALT " : "", |
| 2247 | (stat_flg & UDC_STALL) ? "STALL " : "", |
| 2248 | (stat_flg & UDC_NAK) ? "NAK " : "", |
| 2249 | (stat_flg & UDC_ACK) ? "ACK " : "", |
| 2250 | (stat_flg & UDC_FIFO_EN) ? "fifo_en " : "", |
| 2251 | (stat_flg & UDC_NON_ISO_FIFO_EMPTY) ? "fifo_empty " : "", |
| 2252 | (stat_flg & UDC_NON_ISO_FIFO_FULL) ? "fifo_full " : ""); |
| 2253 | |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2254 | if (list_empty(&ep->queue)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | seq_printf(s, "\t(queue empty)\n"); |
| 2256 | else |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2257 | list_for_each_entry(req, &ep->queue, queue) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | unsigned length = req->req.actual; |
| 2259 | |
| 2260 | if (use_dma && buf[0]) { |
| 2261 | length += ((ep->bEndpointAddress & USB_DIR_IN) |
| 2262 | ? dma_src_len : dma_dest_len) |
| 2263 | (ep, req->req.dma + length); |
| 2264 | buf[0] = 0; |
| 2265 | } |
| 2266 | seq_printf(s, "\treq %p len %d/%d buf %p\n", |
| 2267 | &req->req, length, |
| 2268 | req->req.length, req->req.buf); |
| 2269 | } |
| 2270 | } |
| 2271 | |
| 2272 | static char *trx_mode(unsigned m, int enabled) |
| 2273 | { |
| 2274 | switch (m) { |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2275 | case 0: |
| 2276 | return enabled ? "*6wire" : "unused"; |
| 2277 | case 1: |
| 2278 | return "4wire"; |
| 2279 | case 2: |
| 2280 | return "3wire"; |
| 2281 | case 3: |
| 2282 | return "6wire"; |
| 2283 | default: |
| 2284 | return "unknown"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | } |
| 2286 | } |
| 2287 | |
| 2288 | static int proc_otg_show(struct seq_file *s) |
| 2289 | { |
| 2290 | u32 tmp; |
Paul Walmsley | 4814ced | 2010-10-08 11:40:20 -0600 | [diff] [blame] | 2291 | u32 trans = 0; |
| 2292 | char *ctrl_name = "(UNKNOWN)"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | |
Dmitry Baryshkov | e12cc34 | 2008-08-07 16:29:25 +0400 | [diff] [blame] | 2294 | tmp = omap_readl(OTG_REV); |
Tony Lindgren | ae37257 | 2012-05-21 12:01:11 -0700 | [diff] [blame] | 2295 | ctrl_name = "tranceiver_ctrl"; |
| 2296 | trans = omap_readw(USB_TRANSCEIVER_CTRL); |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2297 | seq_printf(s, "\nOTG rev %d.%d, %s %05x\n", |
| 2298 | tmp >> 4, tmp & 0xf, ctrl_name, trans); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2299 | tmp = omap_readw(OTG_SYSCON_1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s," |
| 2301 | FOURBITS "\n", tmp, |
| 2302 | trx_mode(USB2_TRX_MODE(tmp), trans & CONF_USB2_UNI_R), |
| 2303 | trx_mode(USB1_TRX_MODE(tmp), trans & CONF_USB1_UNI_R), |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 2304 | (USB0_TRX_MODE(tmp) == 0 && !cpu_is_omap1710()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | ? "internal" |
| 2306 | : trx_mode(USB0_TRX_MODE(tmp), 1), |
| 2307 | (tmp & OTG_IDLE_EN) ? " !otg" : "", |
| 2308 | (tmp & HST_IDLE_EN) ? " !host" : "", |
| 2309 | (tmp & DEV_IDLE_EN) ? " !dev" : "", |
| 2310 | (tmp & OTG_RESET_DONE) ? " reset_done" : " reset_active"); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2311 | tmp = omap_readl(OTG_SYSCON_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | seq_printf(s, "otg_syscon2 %08x%s" EIGHTBITS |
| 2313 | " b_ase_brst=%d hmc=%d\n", tmp, |
| 2314 | (tmp & OTG_EN) ? " otg_en" : "", |
| 2315 | (tmp & USBX_SYNCHRO) ? " synchro" : "", |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2316 | /* much more SRP stuff */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | (tmp & SRP_DATA) ? " srp_data" : "", |
| 2318 | (tmp & SRP_VBUS) ? " srp_vbus" : "", |
| 2319 | (tmp & OTG_PADEN) ? " otg_paden" : "", |
| 2320 | (tmp & HMC_PADEN) ? " hmc_paden" : "", |
| 2321 | (tmp & UHOST_EN) ? " uhost_en" : "", |
| 2322 | (tmp & HMC_TLLSPEED) ? " tllspeed" : "", |
| 2323 | (tmp & HMC_TLLATTACH) ? " tllattach" : "", |
| 2324 | B_ASE_BRST(tmp), |
| 2325 | OTG_HMC(tmp)); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2326 | tmp = omap_readl(OTG_CTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | seq_printf(s, "otg_ctrl %06x" EIGHTBITS EIGHTBITS "%s\n", tmp, |
| 2328 | (tmp & OTG_ASESSVLD) ? " asess" : "", |
| 2329 | (tmp & OTG_BSESSEND) ? " bsess_end" : "", |
| 2330 | (tmp & OTG_BSESSVLD) ? " bsess" : "", |
| 2331 | (tmp & OTG_VBUSVLD) ? " vbus" : "", |
| 2332 | (tmp & OTG_ID) ? " id" : "", |
| 2333 | (tmp & OTG_DRIVER_SEL) ? " DEVICE" : " HOST", |
| 2334 | (tmp & OTG_A_SETB_HNPEN) ? " a_setb_hnpen" : "", |
| 2335 | (tmp & OTG_A_BUSREQ) ? " a_bus" : "", |
| 2336 | (tmp & OTG_B_HNPEN) ? " b_hnpen" : "", |
| 2337 | (tmp & OTG_B_BUSREQ) ? " b_bus" : "", |
| 2338 | (tmp & OTG_BUSDROP) ? " busdrop" : "", |
| 2339 | (tmp & OTG_PULLDOWN) ? " down" : "", |
| 2340 | (tmp & OTG_PULLUP) ? " up" : "", |
| 2341 | (tmp & OTG_DRV_VBUS) ? " drv" : "", |
| 2342 | (tmp & OTG_PD_VBUS) ? " pd_vb" : "", |
| 2343 | (tmp & OTG_PU_VBUS) ? " pu_vb" : "", |
| 2344 | (tmp & OTG_PU_ID) ? " pu_id" : "" |
| 2345 | ); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2346 | tmp = omap_readw(OTG_IRQ_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | seq_printf(s, "otg_irq_en %04x" "\n", tmp); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2348 | tmp = omap_readw(OTG_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | seq_printf(s, "otg_irq_src %04x" "\n", tmp); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2350 | tmp = omap_readw(OTG_OUTCTRL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | seq_printf(s, "otg_outctrl %04x" "\n", tmp); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2352 | tmp = omap_readw(OTG_TEST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | seq_printf(s, "otg_test %04x" "\n", tmp); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2354 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | static int proc_udc_show(struct seq_file *s, void *_) |
| 2358 | { |
| 2359 | u32 tmp; |
| 2360 | struct omap_ep *ep; |
| 2361 | unsigned long flags; |
| 2362 | |
| 2363 | spin_lock_irqsave(&udc->lock, flags); |
| 2364 | |
| 2365 | seq_printf(s, "%s, version: " DRIVER_VERSION |
| 2366 | #ifdef USE_ISO |
| 2367 | " (iso)" |
| 2368 | #endif |
| 2369 | "%s\n", |
| 2370 | driver_desc, |
| 2371 | use_dma ? " (dma)" : ""); |
| 2372 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2373 | tmp = omap_readw(UDC_REV) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | seq_printf(s, |
| 2375 | "UDC rev %d.%d, fifo mode %d, gadget %s\n" |
| 2376 | "hmc %d, transceiver %s\n", |
| 2377 | tmp >> 4, tmp & 0xf, |
| 2378 | fifo_mode, |
| 2379 | udc->driver ? udc->driver->driver.name : "(none)", |
| 2380 | HMC, |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2381 | udc->transceiver |
| 2382 | ? udc->transceiver->label |
Tony Lindgren | ae37257 | 2012-05-21 12:01:11 -0700 | [diff] [blame] | 2383 | : (cpu_is_omap1710() |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2384 | ? "external" : "(none)")); |
Tony Lindgren | ae37257 | 2012-05-21 12:01:11 -0700 | [diff] [blame] | 2385 | seq_printf(s, "ULPD control %04x req %04x status %04x\n", |
| 2386 | omap_readw(ULPD_CLOCK_CTRL), |
| 2387 | omap_readw(ULPD_SOFT_REQ), |
| 2388 | omap_readw(ULPD_STATUS_REQ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | |
| 2390 | /* OTG controller registers */ |
| 2391 | if (!cpu_is_omap15xx()) |
| 2392 | proc_otg_show(s); |
| 2393 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2394 | tmp = omap_readw(UDC_SYSCON1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | seq_printf(s, "\nsyscon1 %04x" EIGHTBITS "\n", tmp, |
| 2396 | (tmp & UDC_CFG_LOCK) ? " cfg_lock" : "", |
| 2397 | (tmp & UDC_DATA_ENDIAN) ? " data_endian" : "", |
| 2398 | (tmp & UDC_DMA_ENDIAN) ? " dma_endian" : "", |
| 2399 | (tmp & UDC_NAK_EN) ? " nak" : "", |
| 2400 | (tmp & UDC_AUTODECODE_DIS) ? " autodecode_dis" : "", |
| 2401 | (tmp & UDC_SELF_PWR) ? " self_pwr" : "", |
| 2402 | (tmp & UDC_SOFF_DIS) ? " soff_dis" : "", |
| 2403 | (tmp & UDC_PULLUP_EN) ? " PULLUP" : ""); |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2404 | /* syscon2 is write-only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | |
| 2406 | /* UDC controller registers */ |
| 2407 | if (!(tmp & UDC_PULLUP_EN)) { |
| 2408 | seq_printf(s, "(suspended)\n"); |
| 2409 | spin_unlock_irqrestore(&udc->lock, flags); |
| 2410 | return 0; |
| 2411 | } |
| 2412 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2413 | tmp = omap_readw(UDC_DEVSTAT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | seq_printf(s, "devstat %04x" EIGHTBITS "%s%s\n", tmp, |
| 2415 | (tmp & UDC_B_HNP_ENABLE) ? " b_hnp" : "", |
| 2416 | (tmp & UDC_A_HNP_SUPPORT) ? " a_hnp" : "", |
| 2417 | (tmp & UDC_A_ALT_HNP_SUPPORT) ? " a_alt_hnp" : "", |
| 2418 | (tmp & UDC_R_WK_OK) ? " r_wk_ok" : "", |
| 2419 | (tmp & UDC_USB_RESET) ? " usb_reset" : "", |
| 2420 | (tmp & UDC_SUS) ? " SUS" : "", |
| 2421 | (tmp & UDC_CFG) ? " CFG" : "", |
| 2422 | (tmp & UDC_ADD) ? " ADD" : "", |
| 2423 | (tmp & UDC_DEF) ? " DEF" : "", |
| 2424 | (tmp & UDC_ATT) ? " ATT" : ""); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2425 | seq_printf(s, "sof %04x\n", omap_readw(UDC_SOF)); |
| 2426 | tmp = omap_readw(UDC_IRQ_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | seq_printf(s, "irq_en %04x" FOURBITS "%s\n", tmp, |
| 2428 | (tmp & UDC_SOF_IE) ? " sof" : "", |
| 2429 | (tmp & UDC_EPN_RX_IE) ? " epn_rx" : "", |
| 2430 | (tmp & UDC_EPN_TX_IE) ? " epn_tx" : "", |
| 2431 | (tmp & UDC_DS_CHG_IE) ? " ds_chg" : "", |
| 2432 | (tmp & UDC_EP0_IE) ? " ep0" : ""); |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2433 | tmp = omap_readw(UDC_IRQ_SRC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | seq_printf(s, "irq_src %04x" EIGHTBITS "%s%s\n", tmp, |
| 2435 | (tmp & UDC_TXN_DONE) ? " txn_done" : "", |
| 2436 | (tmp & UDC_RXN_CNT) ? " rxn_cnt" : "", |
| 2437 | (tmp & UDC_RXN_EOT) ? " rxn_eot" : "", |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2438 | (tmp & UDC_IRQ_SOF) ? " sof" : "", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | (tmp & UDC_EPN_RX) ? " epn_rx" : "", |
| 2440 | (tmp & UDC_EPN_TX) ? " epn_tx" : "", |
| 2441 | (tmp & UDC_DS_CHG) ? " ds_chg" : "", |
| 2442 | (tmp & UDC_SETUP) ? " setup" : "", |
| 2443 | (tmp & UDC_EP0_RX) ? " ep0out" : "", |
| 2444 | (tmp & UDC_EP0_TX) ? " ep0in" : ""); |
| 2445 | if (use_dma) { |
| 2446 | unsigned i; |
| 2447 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2448 | tmp = omap_readw(UDC_DMA_IRQ_EN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | seq_printf(s, "dma_irq_en %04x%s" EIGHTBITS "\n", tmp, |
| 2450 | (tmp & UDC_TX_DONE_IE(3)) ? " tx2_done" : "", |
| 2451 | (tmp & UDC_RX_CNT_IE(3)) ? " rx2_cnt" : "", |
| 2452 | (tmp & UDC_RX_EOT_IE(3)) ? " rx2_eot" : "", |
| 2453 | |
| 2454 | (tmp & UDC_TX_DONE_IE(2)) ? " tx1_done" : "", |
| 2455 | (tmp & UDC_RX_CNT_IE(2)) ? " rx1_cnt" : "", |
| 2456 | (tmp & UDC_RX_EOT_IE(2)) ? " rx1_eot" : "", |
| 2457 | |
| 2458 | (tmp & UDC_TX_DONE_IE(1)) ? " tx0_done" : "", |
| 2459 | (tmp & UDC_RX_CNT_IE(1)) ? " rx0_cnt" : "", |
| 2460 | (tmp & UDC_RX_EOT_IE(1)) ? " rx0_eot" : ""); |
| 2461 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2462 | tmp = omap_readw(UDC_RXDMA_CFG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | seq_printf(s, "rxdma_cfg %04x\n", tmp); |
| 2464 | if (tmp) { |
| 2465 | for (i = 0; i < 3; i++) { |
| 2466 | if ((tmp & (0x0f << (i * 4))) == 0) |
| 2467 | continue; |
| 2468 | seq_printf(s, "rxdma[%d] %04x\n", i, |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2469 | omap_readw(UDC_RXDMA(i + 1))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | } |
| 2471 | } |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2472 | tmp = omap_readw(UDC_TXDMA_CFG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | seq_printf(s, "txdma_cfg %04x\n", tmp); |
| 2474 | if (tmp) { |
| 2475 | for (i = 0; i < 3; i++) { |
| 2476 | if (!(tmp & (0x0f << (i * 4)))) |
| 2477 | continue; |
| 2478 | seq_printf(s, "txdma[%d] %04x\n", i, |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2479 | omap_readw(UDC_TXDMA(i + 1))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | } |
| 2481 | } |
| 2482 | } |
| 2483 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2484 | tmp = omap_readw(UDC_DEVSTAT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | if (tmp & UDC_ATT) { |
| 2486 | proc_ep_show(s, &udc->ep[0]); |
| 2487 | if (tmp & UDC_ADD) { |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2488 | list_for_each_entry(ep, &udc->gadget.ep_list, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | ep.ep_list) { |
Ido Shayevitz | f8bdae0 | 2012-03-12 20:25:35 +0200 | [diff] [blame] | 2490 | if (ep->ep.desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | proc_ep_show(s, ep); |
| 2492 | } |
| 2493 | } |
| 2494 | } |
| 2495 | spin_unlock_irqrestore(&udc->lock, flags); |
| 2496 | return 0; |
| 2497 | } |
| 2498 | |
| 2499 | static int proc_udc_open(struct inode *inode, struct file *file) |
| 2500 | { |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2501 | return single_open(file, proc_udc_show, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2502 | } |
| 2503 | |
Luiz Fernando N. Capitulino | 066202d | 2006-08-05 20:37:11 -0300 | [diff] [blame] | 2504 | static const struct file_operations proc_ops = { |
Denis V. Lunev | cdefa18 | 2008-04-29 01:02:19 -0700 | [diff] [blame] | 2505 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | .open = proc_udc_open, |
| 2507 | .read = seq_read, |
| 2508 | .llseek = seq_lseek, |
| 2509 | .release = single_release, |
| 2510 | }; |
| 2511 | |
| 2512 | static void create_proc_file(void) |
| 2513 | { |
Denis V. Lunev | cdefa18 | 2008-04-29 01:02:19 -0700 | [diff] [blame] | 2514 | proc_create(proc_filename, 0, NULL, &proc_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | static void remove_proc_file(void) |
| 2518 | { |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2519 | remove_proc_entry(proc_filename, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
| 2522 | #else |
| 2523 | |
| 2524 | static inline void create_proc_file(void) {} |
| 2525 | static inline void remove_proc_file(void) {} |
| 2526 | |
| 2527 | #endif |
| 2528 | |
| 2529 | /*-------------------------------------------------------------------------*/ |
| 2530 | |
| 2531 | /* Before this controller can enumerate, we need to pick an endpoint |
| 2532 | * configuration, or "fifo_mode" That involves allocating 2KB of packet |
| 2533 | * buffer space among the endpoints we'll be operating. |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 2534 | * |
| 2535 | * NOTE: as of OMAP 1710 ES2.0, writing a new endpoint config when |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2536 | * UDC_SYSCON_1.CFG_LOCK is set can now work. We won't use that |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 2537 | * capability yet though. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | */ |
Felipe Balbi | dc1737c | 2012-05-29 14:33:30 +0300 | [diff] [blame] | 2539 | static unsigned __devinit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | omap_ep_setup(char *name, u8 addr, u8 type, |
| 2541 | unsigned buf, unsigned maxp, int dbuf) |
| 2542 | { |
| 2543 | struct omap_ep *ep; |
| 2544 | u16 epn_rxtx = 0; |
| 2545 | |
| 2546 | /* OUT endpoints first, then IN */ |
| 2547 | ep = &udc->ep[addr & 0xf]; |
| 2548 | if (addr & USB_DIR_IN) |
| 2549 | ep += 16; |
| 2550 | |
| 2551 | /* in case of ep init table bugs */ |
| 2552 | BUG_ON(ep->name[0]); |
| 2553 | |
| 2554 | /* chip setup ... bit values are same for IN, OUT */ |
| 2555 | if (type == USB_ENDPOINT_XFER_ISOC) { |
| 2556 | switch (maxp) { |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2557 | case 8: |
| 2558 | epn_rxtx = 0 << 12; |
| 2559 | break; |
| 2560 | case 16: |
| 2561 | epn_rxtx = 1 << 12; |
| 2562 | break; |
| 2563 | case 32: |
| 2564 | epn_rxtx = 2 << 12; |
| 2565 | break; |
| 2566 | case 64: |
| 2567 | epn_rxtx = 3 << 12; |
| 2568 | break; |
| 2569 | case 128: |
| 2570 | epn_rxtx = 4 << 12; |
| 2571 | break; |
| 2572 | case 256: |
| 2573 | epn_rxtx = 5 << 12; |
| 2574 | break; |
| 2575 | case 512: |
| 2576 | epn_rxtx = 6 << 12; |
| 2577 | break; |
| 2578 | default: |
| 2579 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | } |
| 2581 | epn_rxtx |= UDC_EPN_RX_ISO; |
| 2582 | dbuf = 1; |
| 2583 | } else { |
| 2584 | /* double-buffering "not supported" on 15xx, |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2585 | * and ignored for PIO-IN on newer chips |
| 2586 | * (for more reliable behavior) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | */ |
Tony Lindgren | ae37257 | 2012-05-21 12:01:11 -0700 | [diff] [blame] | 2588 | if (!use_dma || cpu_is_omap15xx()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2589 | dbuf = 0; |
| 2590 | |
| 2591 | switch (maxp) { |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2592 | case 8: |
| 2593 | epn_rxtx = 0 << 12; |
| 2594 | break; |
| 2595 | case 16: |
| 2596 | epn_rxtx = 1 << 12; |
| 2597 | break; |
| 2598 | case 32: |
| 2599 | epn_rxtx = 2 << 12; |
| 2600 | break; |
| 2601 | case 64: |
| 2602 | epn_rxtx = 3 << 12; |
| 2603 | break; |
| 2604 | default: |
| 2605 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | } |
| 2607 | if (dbuf && addr) |
| 2608 | epn_rxtx |= UDC_EPN_RX_DB; |
| 2609 | init_timer(&ep->timer); |
| 2610 | ep->timer.function = pio_out_timer; |
| 2611 | ep->timer.data = (unsigned long) ep; |
| 2612 | } |
| 2613 | if (addr) |
| 2614 | epn_rxtx |= UDC_EPN_RX_VALID; |
| 2615 | BUG_ON(buf & 0x07); |
| 2616 | epn_rxtx |= buf >> 3; |
| 2617 | |
| 2618 | DBG("%s addr %02x rxtx %04x maxp %d%s buf %d\n", |
| 2619 | name, addr, epn_rxtx, maxp, dbuf ? "x2" : "", buf); |
| 2620 | |
| 2621 | if (addr & USB_DIR_IN) |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2622 | omap_writew(epn_rxtx, UDC_EP_TX(addr & 0xf)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2623 | else |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2624 | omap_writew(epn_rxtx, UDC_EP_RX(addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2625 | |
| 2626 | /* next endpoint's buffer starts after this one's */ |
| 2627 | buf += maxp; |
| 2628 | if (dbuf) |
| 2629 | buf += maxp; |
| 2630 | BUG_ON(buf > 2048); |
| 2631 | |
| 2632 | /* set up driver data structures */ |
| 2633 | BUG_ON(strlen(name) >= sizeof ep->name); |
| 2634 | strlcpy(ep->name, name, sizeof ep->name); |
| 2635 | INIT_LIST_HEAD(&ep->queue); |
| 2636 | INIT_LIST_HEAD(&ep->iso); |
| 2637 | ep->bEndpointAddress = addr; |
| 2638 | ep->bmAttributes = type; |
| 2639 | ep->double_buf = dbuf; |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2640 | ep->udc = udc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | |
| 2642 | ep->ep.name = ep->name; |
| 2643 | ep->ep.ops = &omap_ep_ops; |
| 2644 | ep->ep.maxpacket = ep->maxpacket = maxp; |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2645 | list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | |
| 2647 | return buf; |
| 2648 | } |
| 2649 | |
| 2650 | static void omap_udc_release(struct device *dev) |
| 2651 | { |
| 2652 | complete(udc->done); |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2653 | kfree(udc); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2654 | udc = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | } |
| 2656 | |
Felipe Balbi | dc1737c | 2012-05-29 14:33:30 +0300 | [diff] [blame] | 2657 | static int __devinit |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame] | 2658 | omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | { |
| 2660 | unsigned tmp, buf; |
| 2661 | |
| 2662 | /* abolish any previous hardware state */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2663 | omap_writew(0, UDC_SYSCON1); |
| 2664 | omap_writew(0, UDC_IRQ_EN); |
| 2665 | omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC); |
| 2666 | omap_writew(0, UDC_DMA_IRQ_EN); |
| 2667 | omap_writew(0, UDC_RXDMA_CFG); |
| 2668 | omap_writew(0, UDC_TXDMA_CFG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | |
| 2670 | /* UDC_PULLUP_EN gates the chip clock */ |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2671 | /* OTG_SYSCON_1 |= DEV_IDLE_EN; */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 2673 | udc = kzalloc(sizeof(*udc), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | if (!udc) |
| 2675 | return -ENOMEM; |
| 2676 | |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2677 | spin_lock_init(&udc->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | |
| 2679 | udc->gadget.ops = &omap_gadget_ops; |
| 2680 | udc->gadget.ep0 = &udc->ep[0].ep; |
| 2681 | INIT_LIST_HEAD(&udc->gadget.ep_list); |
| 2682 | INIT_LIST_HEAD(&udc->iso); |
| 2683 | udc->gadget.speed = USB_SPEED_UNKNOWN; |
Michal Nazarewicz | d327ab5 | 2011-11-19 18:27:37 +0100 | [diff] [blame] | 2684 | udc->gadget.max_speed = USB_SPEED_FULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | udc->gadget.name = driver_name; |
| 2686 | |
| 2687 | device_initialize(&udc->gadget.dev); |
Kay Sievers | 0031a06 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 2688 | dev_set_name(&udc->gadget.dev, "gadget"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | udc->gadget.dev.release = omap_udc_release; |
| 2690 | udc->gadget.dev.parent = &odev->dev; |
| 2691 | if (use_dma) |
| 2692 | udc->gadget.dev.dma_mask = odev->dev.dma_mask; |
| 2693 | |
| 2694 | udc->transceiver = xceiv; |
| 2695 | |
| 2696 | /* ep0 is special; put it right after the SETUP buffer */ |
| 2697 | buf = omap_ep_setup("ep0", 0, USB_ENDPOINT_XFER_CONTROL, |
| 2698 | 8 /* after SETUP */, 64 /* maxpacket */, 0); |
| 2699 | list_del_init(&udc->ep[0].ep.ep_list); |
| 2700 | |
| 2701 | /* initially disable all non-ep0 endpoints */ |
| 2702 | for (tmp = 1; tmp < 15; tmp++) { |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2703 | omap_writew(0, UDC_EP_RX(tmp)); |
| 2704 | omap_writew(0, UDC_EP_TX(tmp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | } |
| 2706 | |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2707 | #define OMAP_BULK_EP(name, addr) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2708 | buf = omap_ep_setup(name "-bulk", addr, \ |
| 2709 | USB_ENDPOINT_XFER_BULK, buf, 64, 1); |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2710 | #define OMAP_INT_EP(name, addr, maxp) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | buf = omap_ep_setup(name "-int", addr, \ |
| 2712 | USB_ENDPOINT_XFER_INT, buf, maxp, 0); |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2713 | #define OMAP_ISO_EP(name, addr, maxp) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | buf = omap_ep_setup(name "-iso", addr, \ |
| 2715 | USB_ENDPOINT_XFER_ISOC, buf, maxp, 1); |
| 2716 | |
| 2717 | switch (fifo_mode) { |
| 2718 | case 0: |
| 2719 | OMAP_BULK_EP("ep1in", USB_DIR_IN | 1); |
| 2720 | OMAP_BULK_EP("ep2out", USB_DIR_OUT | 2); |
| 2721 | OMAP_INT_EP("ep3in", USB_DIR_IN | 3, 16); |
| 2722 | break; |
| 2723 | case 1: |
| 2724 | OMAP_BULK_EP("ep1in", USB_DIR_IN | 1); |
| 2725 | OMAP_BULK_EP("ep2out", USB_DIR_OUT | 2); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2726 | OMAP_INT_EP("ep9in", USB_DIR_IN | 9, 16); |
| 2727 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | OMAP_BULK_EP("ep3in", USB_DIR_IN | 3); |
| 2729 | OMAP_BULK_EP("ep4out", USB_DIR_OUT | 4); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2730 | OMAP_INT_EP("ep10in", USB_DIR_IN | 10, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | |
| 2732 | OMAP_BULK_EP("ep5in", USB_DIR_IN | 5); |
| 2733 | OMAP_BULK_EP("ep5out", USB_DIR_OUT | 5); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2734 | OMAP_INT_EP("ep11in", USB_DIR_IN | 11, 16); |
| 2735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | OMAP_BULK_EP("ep6in", USB_DIR_IN | 6); |
| 2737 | OMAP_BULK_EP("ep6out", USB_DIR_OUT | 6); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2738 | OMAP_INT_EP("ep12in", USB_DIR_IN | 12, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | |
| 2740 | OMAP_BULK_EP("ep7in", USB_DIR_IN | 7); |
| 2741 | OMAP_BULK_EP("ep7out", USB_DIR_OUT | 7); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2742 | OMAP_INT_EP("ep13in", USB_DIR_IN | 13, 16); |
| 2743 | OMAP_INT_EP("ep13out", USB_DIR_OUT | 13, 16); |
| 2744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | OMAP_BULK_EP("ep8in", USB_DIR_IN | 8); |
| 2746 | OMAP_BULK_EP("ep8out", USB_DIR_OUT | 8); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2747 | OMAP_INT_EP("ep14in", USB_DIR_IN | 14, 16); |
| 2748 | OMAP_INT_EP("ep14out", USB_DIR_OUT | 14, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2750 | OMAP_BULK_EP("ep15in", USB_DIR_IN | 15); |
| 2751 | OMAP_BULK_EP("ep15out", USB_DIR_OUT | 15); |
| 2752 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | break; |
| 2754 | |
| 2755 | #ifdef USE_ISO |
| 2756 | case 2: /* mixed iso/bulk */ |
| 2757 | OMAP_ISO_EP("ep1in", USB_DIR_IN | 1, 256); |
| 2758 | OMAP_ISO_EP("ep2out", USB_DIR_OUT | 2, 256); |
| 2759 | OMAP_ISO_EP("ep3in", USB_DIR_IN | 3, 128); |
| 2760 | OMAP_ISO_EP("ep4out", USB_DIR_OUT | 4, 128); |
| 2761 | |
| 2762 | OMAP_INT_EP("ep5in", USB_DIR_IN | 5, 16); |
| 2763 | |
| 2764 | OMAP_BULK_EP("ep6in", USB_DIR_IN | 6); |
| 2765 | OMAP_BULK_EP("ep7out", USB_DIR_OUT | 7); |
| 2766 | OMAP_INT_EP("ep8in", USB_DIR_IN | 8, 16); |
| 2767 | break; |
| 2768 | case 3: /* mixed bulk/iso */ |
| 2769 | OMAP_BULK_EP("ep1in", USB_DIR_IN | 1); |
| 2770 | OMAP_BULK_EP("ep2out", USB_DIR_OUT | 2); |
| 2771 | OMAP_INT_EP("ep3in", USB_DIR_IN | 3, 16); |
| 2772 | |
| 2773 | OMAP_BULK_EP("ep4in", USB_DIR_IN | 4); |
| 2774 | OMAP_BULK_EP("ep5out", USB_DIR_OUT | 5); |
| 2775 | OMAP_INT_EP("ep6in", USB_DIR_IN | 6, 16); |
| 2776 | |
| 2777 | OMAP_ISO_EP("ep7in", USB_DIR_IN | 7, 256); |
| 2778 | OMAP_ISO_EP("ep8out", USB_DIR_OUT | 8, 256); |
| 2779 | OMAP_INT_EP("ep9in", USB_DIR_IN | 9, 16); |
| 2780 | break; |
| 2781 | #endif |
| 2782 | |
| 2783 | /* add more modes as needed */ |
| 2784 | |
| 2785 | default: |
| 2786 | ERR("unsupported fifo_mode #%d\n", fifo_mode); |
| 2787 | return -ENODEV; |
| 2788 | } |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2789 | omap_writew(UDC_CFG_LOCK|UDC_SELF_PWR, UDC_SYSCON1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | INFO("fifo mode %d, %d bytes not used\n", fifo_mode, 2048 - buf); |
| 2791 | return 0; |
| 2792 | } |
| 2793 | |
Felipe Balbi | dc1737c | 2012-05-29 14:33:30 +0300 | [diff] [blame] | 2794 | static int __devinit omap_udc_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | int status = -ENODEV; |
| 2797 | int hmc; |
Heikki Krogerus | 8675381 | 2012-02-13 13:24:02 +0200 | [diff] [blame] | 2798 | struct usb_phy *xceiv = NULL; |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2799 | const char *type = NULL; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2800 | struct omap_usb_config *config = pdev->dev.platform_data; |
Tony Lindgren | ae37257 | 2012-05-21 12:01:11 -0700 | [diff] [blame] | 2801 | struct clk *dc_clk = NULL; |
| 2802 | struct clk *hhc_clk = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | |
Felipe Balbi | 5b6d84b | 2012-05-29 14:27:52 +0300 | [diff] [blame] | 2804 | if (cpu_is_omap7xx()) |
| 2805 | use_dma = 0; |
| 2806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | /* NOTE: "knows" the order of the resources! */ |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2808 | if (!request_mem_region(pdev->resource[0].start, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2809 | pdev->resource[0].end - pdev->resource[0].start + 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | driver_name)) { |
| 2811 | DBG("request_mem_region failed\n"); |
| 2812 | return -EBUSY; |
| 2813 | } |
| 2814 | |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2815 | if (cpu_is_omap16xx()) { |
| 2816 | dc_clk = clk_get(&pdev->dev, "usb_dc_ck"); |
| 2817 | hhc_clk = clk_get(&pdev->dev, "usb_hhc_ck"); |
| 2818 | BUG_ON(IS_ERR(dc_clk) || IS_ERR(hhc_clk)); |
| 2819 | /* can't use omap_udc_enable_clock yet */ |
| 2820 | clk_enable(dc_clk); |
| 2821 | clk_enable(hhc_clk); |
| 2822 | udelay(100); |
| 2823 | } |
| 2824 | |
Cory Maccarrone | 45f780a | 2009-11-22 10:10:52 -0800 | [diff] [blame] | 2825 | if (cpu_is_omap7xx()) { |
| 2826 | dc_clk = clk_get(&pdev->dev, "usb_dc_ck"); |
| 2827 | hhc_clk = clk_get(&pdev->dev, "l3_ocpi_ck"); |
| 2828 | BUG_ON(IS_ERR(dc_clk) || IS_ERR(hhc_clk)); |
| 2829 | /* can't use omap_udc_enable_clock yet */ |
| 2830 | clk_enable(dc_clk); |
| 2831 | clk_enable(hhc_clk); |
| 2832 | udelay(100); |
| 2833 | } |
| 2834 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | INFO("OMAP UDC rev %d.%d%s\n", |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2836 | omap_readw(UDC_REV) >> 4, omap_readw(UDC_REV) & 0xf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | config->otg ? ", Mini-AB" : ""); |
| 2838 | |
| 2839 | /* use the mode given to us by board init code */ |
| 2840 | if (cpu_is_omap15xx()) { |
| 2841 | hmc = HMC_1510; |
| 2842 | type = "(unknown)"; |
| 2843 | |
David Brownell | 8a3c1f5 | 2007-03-21 12:26:32 -0700 | [diff] [blame] | 2844 | if (machine_without_vbus_sense()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | /* just set up software VBUS detect, and then |
| 2846 | * later rig it so we always report VBUS. |
| 2847 | * FIXME without really sensing VBUS, we can't |
| 2848 | * know when to turn PULLUP_EN on/off; and that |
| 2849 | * means we always "need" the 48MHz clock. |
| 2850 | */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2851 | u32 tmp = omap_readl(FUNC_MUX_CTRL_0); |
| 2852 | tmp &= ~VBUS_CTRL_1510; |
| 2853 | omap_writel(tmp, FUNC_MUX_CTRL_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | tmp |= VBUS_MODE_1510; |
| 2855 | tmp &= ~VBUS_CTRL_1510; |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2856 | omap_writel(tmp, FUNC_MUX_CTRL_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | } |
| 2858 | } else { |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 2859 | /* The transceiver may package some GPIO logic or handle |
| 2860 | * loopback and/or transceiverless setup; if we find one, |
| 2861 | * use it. Except for OTG, we don't _need_ to talk to one; |
| 2862 | * but not having one probably means no VBUS detection. |
| 2863 | */ |
Heikki Krogerus | b96d3b0 | 2012-02-13 13:24:18 +0200 | [diff] [blame] | 2864 | xceiv = usb_get_transceiver(); |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 2865 | if (xceiv) |
| 2866 | type = xceiv->label; |
| 2867 | else if (config->otg) { |
| 2868 | DBG("OTG requires external transceiver!\n"); |
| 2869 | goto cleanup0; |
| 2870 | } |
| 2871 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | hmc = HMC_1610; |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | switch (hmc) { |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2875 | case 0: /* POWERUP DEFAULT == 0 */ |
| 2876 | case 4: |
| 2877 | case 12: |
| 2878 | case 20: |
| 2879 | if (!cpu_is_omap1710()) { |
| 2880 | type = "integrated"; |
| 2881 | break; |
| 2882 | } |
| 2883 | /* FALL THROUGH */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | case 3: |
| 2885 | case 11: |
| 2886 | case 16: |
| 2887 | case 19: |
| 2888 | case 25: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | if (!xceiv) { |
| 2890 | DBG("external transceiver not registered!\n"); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2891 | type = "unknown"; |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 2892 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | case 21: /* internal loopback */ |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2895 | type = "loopback"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | break; |
| 2897 | case 14: /* transceiverless */ |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 2898 | if (cpu_is_omap1710()) |
| 2899 | goto bad_on_1710; |
| 2900 | /* FALL THROUGH */ |
| 2901 | case 13: |
| 2902 | case 15: |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2903 | type = "no"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | break; |
| 2905 | |
| 2906 | default: |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 2907 | bad_on_1710: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2908 | ERR("unrecognized UDC HMC mode %d\n", hmc); |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 2909 | goto cleanup0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | } |
| 2911 | } |
Tony Lindgren | ae37257 | 2012-05-21 12:01:11 -0700 | [diff] [blame] | 2912 | |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2913 | INFO("hmc mode %d, %s transceiver\n", hmc, type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | |
| 2915 | /* a "gadget" abstracts/virtualizes the controller */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2916 | status = omap_udc_setup(pdev, xceiv); |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2917 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | goto cleanup0; |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2919 | |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2920 | xceiv = NULL; |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2921 | /* "udc" is now valid */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | pullup_disable(udc); |
| 2923 | #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) |
| 2924 | udc->gadget.is_otg = (config->otg != 0); |
| 2925 | #endif |
| 2926 | |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 2927 | /* starting with omap1710 es2.0, clear toggle is a separate bit */ |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 2928 | if (omap_readw(UDC_REV) >= 0x61) |
David Brownell | 6511108 | 2005-04-28 13:52:31 -0700 | [diff] [blame] | 2929 | udc->clr_halt = UDC_RESET_EP | UDC_CLRDATA_TOGGLE; |
| 2930 | else |
| 2931 | udc->clr_halt = UDC_RESET_EP; |
| 2932 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | /* USB general purpose IRQ: ep0, state changes, dma, etc */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2934 | status = request_irq(pdev->resource[1].start, omap_udc_irq, |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2935 | 0, driver_name, udc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | if (status != 0) { |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2937 | ERR("can't get irq %d, err %d\n", |
| 2938 | (int) pdev->resource[1].start, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | goto cleanup1; |
| 2940 | } |
| 2941 | |
| 2942 | /* USB "non-iso" IRQ (PIO for all but ep0) */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2943 | status = request_irq(pdev->resource[2].start, omap_udc_pio_irq, |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2944 | 0, "omap_udc pio", udc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 | if (status != 0) { |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2946 | ERR("can't get irq %d, err %d\n", |
| 2947 | (int) pdev->resource[2].start, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | goto cleanup2; |
| 2949 | } |
| 2950 | #ifdef USE_ISO |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2951 | status = request_irq(pdev->resource[3].start, omap_udc_iso_irq, |
Yong Zhang | b5dd18d | 2011-09-07 16:10:52 +0800 | [diff] [blame] | 2952 | 0, "omap_udc iso", udc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | if (status != 0) { |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2954 | ERR("can't get irq %d, err %d\n", |
| 2955 | (int) pdev->resource[3].start, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | goto cleanup3; |
| 2957 | } |
| 2958 | #endif |
Cory Maccarrone | 45f780a | 2009-11-22 10:10:52 -0800 | [diff] [blame] | 2959 | if (cpu_is_omap16xx() || cpu_is_omap7xx()) { |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2960 | udc->dc_clk = dc_clk; |
| 2961 | udc->hhc_clk = hhc_clk; |
| 2962 | clk_disable(hhc_clk); |
| 2963 | clk_disable(dc_clk); |
| 2964 | } |
| 2965 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | create_proc_file(); |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2967 | status = device_add(&udc->gadget.dev); |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 2968 | if (status) |
| 2969 | goto cleanup4; |
| 2970 | |
| 2971 | status = usb_add_gadget_udc(&pdev->dev, &udc->gadget); |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2972 | if (!status) |
| 2973 | return status; |
| 2974 | /* If fail, fall through */ |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 2975 | cleanup4: |
| 2976 | remove_proc_file(); |
| 2977 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | #ifdef USE_ISO |
| 2979 | cleanup3: |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2980 | free_irq(pdev->resource[2].start, udc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | #endif |
| 2982 | |
| 2983 | cleanup2: |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 2984 | free_irq(pdev->resource[1].start, udc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | |
| 2986 | cleanup1: |
Felipe Balbi | 80dd135 | 2012-05-29 14:26:09 +0300 | [diff] [blame] | 2987 | kfree(udc); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 2988 | udc = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | |
| 2990 | cleanup0: |
| 2991 | if (xceiv) |
Heikki Krogerus | b96d3b0 | 2012-02-13 13:24:18 +0200 | [diff] [blame] | 2992 | usb_put_transceiver(xceiv); |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2993 | |
Tony Lindgren | ae37257 | 2012-05-21 12:01:11 -0700 | [diff] [blame] | 2994 | if (cpu_is_omap16xx() || cpu_is_omap7xx()) { |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 2995 | clk_disable(hhc_clk); |
| 2996 | clk_disable(dc_clk); |
| 2997 | clk_put(hhc_clk); |
| 2998 | clk_put(dc_clk); |
| 2999 | } |
| 3000 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3001 | release_mem_region(pdev->resource[0].start, |
| 3002 | pdev->resource[0].end - pdev->resource[0].start + 1); |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 3003 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | return status; |
| 3005 | } |
| 3006 | |
Felipe Balbi | dc1737c | 2012-05-29 14:33:30 +0300 | [diff] [blame] | 3007 | static int __devexit omap_udc_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | { |
Peter Zijlstra | 6e9a473 | 2006-09-30 23:28:10 -0700 | [diff] [blame] | 3009 | DECLARE_COMPLETION_ONSTACK(done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | |
| 3011 | if (!udc) |
| 3012 | return -ENODEV; |
Sebastian Andrzej Siewior | 0f91349 | 2011-06-28 16:33:47 +0300 | [diff] [blame] | 3013 | |
| 3014 | usb_del_gadget_udc(&udc->gadget); |
David Brownell | 6bea476 | 2006-12-05 03:15:33 -0800 | [diff] [blame] | 3015 | if (udc->driver) |
| 3016 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | |
| 3018 | udc->done = &done; |
| 3019 | |
| 3020 | pullup_disable(udc); |
| 3021 | if (udc->transceiver) { |
Heikki Krogerus | b96d3b0 | 2012-02-13 13:24:18 +0200 | [diff] [blame] | 3022 | usb_put_transceiver(udc->transceiver); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 3023 | udc->transceiver = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | } |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 3025 | omap_writew(0, UDC_SYSCON1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | |
| 3027 | remove_proc_file(); |
| 3028 | |
| 3029 | #ifdef USE_ISO |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3030 | free_irq(pdev->resource[3].start, udc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3031 | #endif |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3032 | free_irq(pdev->resource[2].start, udc); |
| 3033 | free_irq(pdev->resource[1].start, udc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | |
David Brownell | e6a6e47 | 2006-12-10 11:47:04 -0800 | [diff] [blame] | 3035 | if (udc->dc_clk) { |
| 3036 | if (udc->clk_requested) |
| 3037 | omap_udc_enable_clock(0); |
| 3038 | clk_put(udc->hhc_clk); |
| 3039 | clk_put(udc->dc_clk); |
| 3040 | } |
| 3041 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3042 | release_mem_region(pdev->resource[0].start, |
| 3043 | pdev->resource[0].end - pdev->resource[0].start + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | |
| 3045 | device_unregister(&udc->gadget.dev); |
| 3046 | wait_for_completion(&done); |
| 3047 | |
| 3048 | return 0; |
| 3049 | } |
| 3050 | |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 3051 | /* suspend/resume/wakeup from sysfs (echo > power/state) or when the |
| 3052 | * system is forced into deep sleep |
| 3053 | * |
| 3054 | * REVISIT we should probably reject suspend requests when there's a host |
| 3055 | * session active, rather than disconnecting, at least on boards that can |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 3056 | * report VBUS irqs (UDC_DEVSTAT.UDC_ATT). And in any case, we need to |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 3057 | * make host resumes and VBUS detection trigger OMAP wakeup events; that |
| 3058 | * may involve talking to an external transceiver (e.g. isp1301). |
| 3059 | */ |
david-b@pacbell.net | 1d7beee | 2005-06-29 07:00:56 -0700 | [diff] [blame] | 3060 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3061 | static int omap_udc_suspend(struct platform_device *dev, pm_message_t message) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | { |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 3063 | u32 devstat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | |
Tony Lindgren | f35ae63 | 2008-07-03 12:24:43 +0300 | [diff] [blame] | 3065 | devstat = omap_readw(UDC_DEVSTAT); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 3066 | |
| 3067 | /* we're requesting 48 MHz clock if the pullup is enabled |
| 3068 | * (== we're attached to the host) and we're not suspended, |
| 3069 | * which would prevent entry to deep sleep... |
| 3070 | */ |
| 3071 | if ((devstat & UDC_ATT) != 0 && (devstat & UDC_SUS) == 0) { |
Arjan van de Ven | b6c6393 | 2008-07-25 01:45:52 -0700 | [diff] [blame] | 3072 | WARNING("session active; suspend requires disconnect\n"); |
David Brownell | 313980c | 2005-04-11 15:38:25 -0700 | [diff] [blame] | 3073 | omap_pullup(&udc->gadget, 0); |
| 3074 | } |
| 3075 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | return 0; |
| 3077 | } |
| 3078 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3079 | static int omap_udc_resume(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | DBG("resume + wakeup/SRP\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | omap_pullup(&udc->gadget, 1); |
| 3083 | |
| 3084 | /* maybe the host would enumerate us if we nudged it */ |
| 3085 | msleep(100); |
| 3086 | return omap_wakeup(&udc->gadget); |
| 3087 | } |
| 3088 | |
| 3089 | /*-------------------------------------------------------------------------*/ |
| 3090 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3091 | static struct platform_driver udc_driver = { |
Felipe Balbi | dc1737c | 2012-05-29 14:33:30 +0300 | [diff] [blame] | 3092 | .probe = omap_udc_probe, |
| 3093 | .remove = __devexit_p(omap_udc_remove), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3094 | .suspend = omap_udc_suspend, |
| 3095 | .resume = omap_udc_resume, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 3096 | .driver = { |
| 3097 | .owner = THIS_MODULE, |
| 3098 | .name = (char *) driver_name, |
| 3099 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | }; |
| 3101 | |
Felipe Balbi | dc1737c | 2012-05-29 14:33:30 +0300 | [diff] [blame] | 3102 | module_platform_driver(udc_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | |
| 3104 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 3105 | MODULE_LICENSE("GPL"); |
Kay Sievers | f34c32f | 2008-04-10 21:29:21 -0700 | [diff] [blame] | 3106 | MODULE_ALIAS("platform:omap_udc"); |