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