| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * omap_udc.c -- for OMAP full speed udc; most chips support OTG. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 2004 Texas Instruments, Inc. | 
					
						
							|  |  |  |  * Copyright (C) 2004-2005 David Brownell | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2007-11-21 15:13:15 -08:00
										 |  |  |  * OMAP2 & DMA support by Kyungmin Park <kyungmin.park@samsung.com> | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation; either version 2 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef	DEBUG
 | 
					
						
							|  |  |  | #undef	VERBOSE
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/module.h>
 | 
					
						
							|  |  |  | #include <linux/kernel.h>
 | 
					
						
							|  |  |  | #include <linux/ioport.h>
 | 
					
						
							|  |  |  | #include <linux/types.h>
 | 
					
						
							|  |  |  | #include <linux/errno.h>
 | 
					
						
							|  |  |  | #include <linux/delay.h>
 | 
					
						
							|  |  |  | #include <linux/slab.h>
 | 
					
						
							|  |  |  | #include <linux/timer.h>
 | 
					
						
							|  |  |  | #include <linux/list.h>
 | 
					
						
							|  |  |  | #include <linux/interrupt.h>
 | 
					
						
							|  |  |  | #include <linux/proc_fs.h>
 | 
					
						
							|  |  |  | #include <linux/mm.h>
 | 
					
						
							|  |  |  | #include <linux/moduleparam.h>
 | 
					
						
							| 
									
										
										
										
											2005-10-29 19:07:23 +01:00
										 |  |  | #include <linux/platform_device.h>
 | 
					
						
							| 
									
										
										
										
											2006-12-16 15:34:53 -08:00
										 |  |  | #include <linux/usb/ch9.h>
 | 
					
						
							| 
									
										
										
										
											2007-10-04 18:05:17 -07:00
										 |  |  | #include <linux/usb/gadget.h>
 | 
					
						
							| 
									
										
										
										
											2006-06-29 12:27:23 -07:00
										 |  |  | #include <linux/usb/otg.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #include <linux/dma-mapping.h>
 | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | #include <linux/clk.h>
 | 
					
						
							| 
									
										
										
										
											2012-06-26 17:40:32 +05:30
										 |  |  | #include <linux/err.h>
 | 
					
						
							| 
									
										
										
										
											2011-05-20 12:50:29 -07:00
										 |  |  | #include <linux/prefetch.h>
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | #include <linux/io.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <asm/byteorder.h>
 | 
					
						
							|  |  |  | #include <asm/irq.h>
 | 
					
						
							|  |  |  | #include <asm/unaligned.h>
 | 
					
						
							|  |  |  | #include <asm/mach-types.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-30 08:41:50 -08:00
										 |  |  | #include <linux/omap-dma.h>
 | 
					
						
							| 
									
										
										
										
											2012-06-04 00:56:15 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <mach/usb.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "omap_udc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef	USB_TRACE
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* bulk DMA seems to be behaving for both IN and OUT */ | 
					
						
							|  |  |  | #define	USE_DMA
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ISO too */ | 
					
						
							|  |  |  | #define	USE_ISO
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define	DRIVER_DESC	"OMAP UDC driver"
 | 
					
						
							|  |  |  | #define	DRIVER_VERSION	"4 October 2004"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-15 14:01:01 -07:00
										 |  |  | #define OMAP_DMA_USB_W2FC_TX0		29
 | 
					
						
							| 
									
										
										
										
											2013-03-05 23:16:44 +01:00
										 |  |  | #define OMAP_DMA_USB_W2FC_RX0		26
 | 
					
						
							| 
									
										
										
										
											2012-10-15 14:01:01 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * The OMAP UDC needs _very_ early endpoint setup:  before enabling the | 
					
						
							|  |  |  |  * D+ pullup to allow enumeration.  That's too early for the gadget | 
					
						
							|  |  |  |  * framework to use from usb_endpoint_enable(), which happens after | 
					
						
							|  |  |  |  * enumeration as part of activating an interface.  (But if we add an | 
					
						
							|  |  |  |  * optional new "UDC not yet running" state to the gadget driver model, | 
					
						
							|  |  |  |  * even just during driver binding, the endpoint autoconfig logic is the | 
					
						
							|  |  |  |  * natural spot to manufacture new endpoints.) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * So instead of using endpoint enable calls to control the hardware setup, | 
					
						
							|  |  |  |  * this driver defines a "fifo mode" parameter.  It's used during driver | 
					
						
							|  |  |  |  * initialization to choose among a set of pre-defined endpoint configs. | 
					
						
							|  |  |  |  * See omap_udc_setup() for available modes, or to add others.  That code | 
					
						
							|  |  |  |  * lives in an init section, so use this driver as a module if you need | 
					
						
							|  |  |  |  * to change the fifo mode after the kernel boots. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Gadget drivers normally ignore endpoints they don't care about, and | 
					
						
							|  |  |  |  * won't include them in configuration descriptors.  That means only | 
					
						
							|  |  |  |  * misbehaving hosts would even notice they exist. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #ifdef	USE_ISO
 | 
					
						
							|  |  |  | static unsigned fifo_mode = 3; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | static unsigned fifo_mode; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* "modprobe omap_udc fifo_mode=42", or else as a kernel
 | 
					
						
							|  |  |  |  * boot parameter "omap_udc:fifo_mode=42" | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | module_param(fifo_mode, uint, 0); | 
					
						
							|  |  |  | MODULE_PARM_DESC(fifo_mode, "endpoint configuration"); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef	USE_DMA
 | 
					
						
							| 
									
										
										
										
											2012-01-13 09:32:20 +10:30
										 |  |  | static bool use_dma = 1; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* "modprobe omap_udc use_dma=y", or else as a kernel
 | 
					
						
							|  |  |  |  * boot parameter "omap_udc:use_dma=y" | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | module_param(use_dma, bool, 0); | 
					
						
							|  |  |  | MODULE_PARM_DESC(use_dma, "enable/disable DMA"); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #else	/* !USE_DMA */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* save a bit of code */ | 
					
						
							|  |  |  | #define	use_dma		0
 | 
					
						
							|  |  |  | #endif	/* !USE_DMA */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | static const char driver_name[] = "omap_udc"; | 
					
						
							|  |  |  | static const char driver_desc[] = DRIVER_DESC; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* there's a notion of "current endpoint" for modifying endpoint
 | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  |  * state, and PIO access to its FIFO. | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void use_ep(struct omap_ep *ep, u16 select) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u16	num = ep->bEndpointAddress & 0x0f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ep->bEndpointAddress & USB_DIR_IN) | 
					
						
							|  |  |  | 		num |= UDC_EP_DIR; | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	omap_writew(num | select, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	/* when select, MUST deselect later !! */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void deselect_ep(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	u16 w; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	w = omap_readw(UDC_EP_NUM); | 
					
						
							|  |  |  | 	w &= ~UDC_EP_SEL; | 
					
						
							|  |  |  | 	omap_writew(w, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	/* 6 wait states before TX will happen */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dma_channel_claim(struct omap_ep *ep, unsigned preferred); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int omap_ep_enable(struct usb_ep *_ep, | 
					
						
							|  |  |  | 		const struct usb_endpoint_descriptor *desc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct omap_ep	*ep = container_of(_ep, struct omap_ep, ep); | 
					
						
							|  |  |  | 	struct omap_udc	*udc; | 
					
						
							|  |  |  | 	unsigned long	flags; | 
					
						
							|  |  |  | 	u16		maxp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* catch various bogus parameters */ | 
					
						
							| 
									
										
										
										
											2012-06-04 13:35:25 +03:00
										 |  |  | 	if (!_ep || !desc | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			|| desc->bDescriptorType != USB_DT_ENDPOINT | 
					
						
							|  |  |  | 			|| ep->bEndpointAddress != desc->bEndpointAddress | 
					
						
							| 
									
										
										
										
											2011-08-23 03:12:03 -07:00
										 |  |  | 			|| ep->maxpacket < usb_endpoint_maxp(desc)) { | 
					
						
							| 
									
										
										
										
											2008-03-03 16:08:34 -08:00
										 |  |  | 		DBG("%s, bad ep or descriptor\n", __func__); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-08-23 03:12:03 -07:00
										 |  |  | 	maxp = usb_endpoint_maxp(desc); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK | 
					
						
							|  |  |  | 				&& maxp != ep->maxpacket) | 
					
						
							| 
									
										
										
										
											2011-08-23 03:12:03 -07:00
										 |  |  | 			|| usb_endpoint_maxp(desc) > ep->maxpacket | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			|| !desc->wMaxPacketSize) { | 
					
						
							| 
									
										
										
										
											2008-03-03 16:08:34 -08:00
										 |  |  | 		DBG("%s, bad %s maxpacket\n", __func__, _ep->name); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return -ERANGE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef	USE_ISO
 | 
					
						
							|  |  |  | 	if ((desc->bmAttributes == USB_ENDPOINT_XFER_ISOC | 
					
						
							|  |  |  | 				&& desc->bInterval != 1)) { | 
					
						
							|  |  |  | 		/* hardware wants period = 1; USB allows 2^(Interval-1) */ | 
					
						
							|  |  |  | 		DBG("%s, unsupported ISO period %dms\n", _ep->name, | 
					
						
							|  |  |  | 				1 << (desc->bInterval - 1)); | 
					
						
							|  |  |  | 		return -EDOM; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 	if (desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { | 
					
						
							|  |  |  | 		DBG("%s, ISO nyet\n", _ep->name); | 
					
						
							|  |  |  | 		return -EDOM; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* xfer types must match, except that interrupt ~= bulk */ | 
					
						
							|  |  |  | 	if (ep->bmAttributes != desc->bmAttributes | 
					
						
							|  |  |  | 			&& ep->bmAttributes != USB_ENDPOINT_XFER_BULK | 
					
						
							|  |  |  | 			&& desc->bmAttributes != USB_ENDPOINT_XFER_INT) { | 
					
						
							| 
									
										
										
										
											2008-03-03 16:08:34 -08:00
										 |  |  | 		DBG("%s, %s type mismatch\n", __func__, _ep->name); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	udc = ep->udc; | 
					
						
							|  |  |  | 	if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { | 
					
						
							| 
									
										
										
										
											2008-03-03 16:08:34 -08:00
										 |  |  | 		DBG("%s, bogus device state\n", __func__); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return -ESHUTDOWN; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&udc->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-12 20:25:35 +02:00
										 |  |  | 	ep->ep.desc = desc; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	ep->irqs = 0; | 
					
						
							|  |  |  | 	ep->stopped = 0; | 
					
						
							|  |  |  | 	ep->ep.maxpacket = maxp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* set endpoint to initial state */ | 
					
						
							|  |  |  | 	ep->dma_channel = 0; | 
					
						
							|  |  |  | 	ep->has_dma = 0; | 
					
						
							|  |  |  | 	ep->lch = -1; | 
					
						
							|  |  |  | 	use_ep(ep, UDC_EP_SEL); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	omap_writew(udc->clr_halt, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	ep->ackwait = 0; | 
					
						
							|  |  |  | 	deselect_ep(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) | 
					
						
							|  |  |  | 		list_add(&ep->iso, &udc->iso); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* maybe assign a DMA channel to this endpoint */ | 
					
						
							|  |  |  | 	if (use_dma && desc->bmAttributes == USB_ENDPOINT_XFER_BULK) | 
					
						
							|  |  |  | 		/* FIXME ISO can dma, but prefers first channel */ | 
					
						
							|  |  |  | 		dma_channel_claim(ep, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* PIO OUT may RX packets */ | 
					
						
							|  |  |  | 	if (desc->bmAttributes != USB_ENDPOINT_XFER_ISOC | 
					
						
							|  |  |  | 			&& !ep->has_dma | 
					
						
							|  |  |  | 			&& !(ep->bEndpointAddress & USB_DIR_IN)) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		ep->ackwait = 1 + ep->double_buf; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&udc->lock, flags); | 
					
						
							|  |  |  | 	VDBG("%s enabled\n", _ep->name); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void nuke(struct omap_ep *, int status); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int omap_ep_disable(struct usb_ep *_ep) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct omap_ep	*ep = container_of(_ep, struct omap_ep, ep); | 
					
						
							|  |  |  | 	unsigned long	flags; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-12 20:25:35 +02:00
										 |  |  | 	if (!_ep || !ep->ep.desc) { | 
					
						
							| 
									
										
										
										
											2008-03-03 16:08:34 -08:00
										 |  |  | 		DBG("%s, %s not enabled\n", __func__, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			_ep ? ep->ep.name : NULL); | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&ep->udc->lock, flags); | 
					
						
							| 
									
										
										
										
											2012-02-08 13:56:48 +02:00
										 |  |  | 	ep->ep.desc = NULL; | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	nuke(ep, -ESHUTDOWN); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	ep->ep.maxpacket = ep->maxpacket; | 
					
						
							|  |  |  | 	ep->has_dma = 0; | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	omap_writew(UDC_SET_HALT, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	list_del_init(&ep->iso); | 
					
						
							|  |  |  | 	del_timer(&ep->timer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&ep->udc->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	VDBG("%s disabled\n", _ep->name); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct usb_request * | 
					
						
							| 
									
										
										
										
											2005-10-21 03:21:58 -04:00
										 |  |  | omap_alloc_request(struct usb_ep *ep, gfp_t gfp_flags) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct omap_req	*req; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-27 13:34:10 -08:00
										 |  |  | 	req = kzalloc(sizeof(*req), gfp_flags); | 
					
						
							| 
									
										
										
										
											2012-05-29 14:36:42 +03:00
										 |  |  | 	if (!req) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&req->queue); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	return &req->req; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | omap_free_request(struct usb_ep *ep, struct usb_request *_req) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct omap_req	*req = container_of(_req, struct omap_req, req); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:38:32 +03:00
										 |  |  | 	kfree(req); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | done(struct omap_ep *ep, struct omap_req *req, int status) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-29 14:42:56 +03:00
										 |  |  | 	struct omap_udc		*udc = ep->udc; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	unsigned		stopped = ep->stopped; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	list_del_init(&req->queue); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (req->req.status == -EINPROGRESS) | 
					
						
							|  |  |  | 		req->req.status = status; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		status = req->req.status; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:42:56 +03:00
										 |  |  | 	if (use_dma && ep->has_dma) | 
					
						
							|  |  |  | 		usb_gadget_unmap_request(&udc->gadget, &req->req, | 
					
						
							|  |  |  | 				(ep->bEndpointAddress & USB_DIR_IN)); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifndef	USB_TRACE
 | 
					
						
							|  |  |  | 	if (status && status != -ESHUTDOWN) | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 		VDBG("complete %s req %p stat %d len %u/%u\n", | 
					
						
							|  |  |  | 			ep->ep.name, &req->req, status, | 
					
						
							|  |  |  | 			req->req.actual, req->req.length); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* don't modify queue heads during completion callback */ | 
					
						
							|  |  |  | 	ep->stopped = 1; | 
					
						
							|  |  |  | 	spin_unlock(&ep->udc->lock); | 
					
						
							| 
									
										
										
										
											2014-09-24 22:43:19 +02:00
										 |  |  | 	usb_gadget_giveback_request(&ep->ep, &req->req); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	spin_lock(&ep->udc->lock); | 
					
						
							|  |  |  | 	ep->stopped = stopped; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | #define UDC_FIFO_FULL		(UDC_NON_ISO_FIFO_FULL | UDC_ISO_FIFO_FULL)
 | 
					
						
							|  |  |  | #define UDC_FIFO_UNWRITABLE	(UDC_EP_HALTED | UDC_FIFO_FULL)
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define FIFO_EMPTY	(UDC_NON_ISO_FIFO_EMPTY | UDC_ISO_FIFO_EMPTY)
 | 
					
						
							|  |  |  | #define FIFO_UNREADABLE (UDC_EP_HALTED | FIFO_EMPTY)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | static inline int | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | write_packet(u8 *buf, struct omap_req *req, unsigned max) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned	len; | 
					
						
							|  |  |  | 	u16		*wp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	len = min(req->req.length - req->req.actual, max); | 
					
						
							|  |  |  | 	req->req.actual += len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	max = len; | 
					
						
							|  |  |  | 	if (likely((((int)buf) & 1) == 0)) { | 
					
						
							|  |  |  | 		wp = (u16 *)buf; | 
					
						
							|  |  |  | 		while (max >= 2) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(*wp++, UDC_DATA); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			max -= 2; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		buf = (u8 *)wp; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	while (max--) | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writeb(*buf++, UDC_DATA); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	return len; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | /* FIXME change r/w fifo calling convention */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | /* return:  0 = still running, 1 = completed, negative = errno */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | static int write_fifo(struct omap_ep *ep, struct omap_req *req) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u8		*buf; | 
					
						
							|  |  |  | 	unsigned	count; | 
					
						
							|  |  |  | 	int		is_last; | 
					
						
							|  |  |  | 	u16		ep_stat; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	buf = req->req.buf + req->req.actual; | 
					
						
							|  |  |  | 	prefetch(buf); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* PIO-IN isn't double buffered except for iso */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	ep_stat = omap_readw(UDC_STAT_FLG); | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 	if (ep_stat & UDC_FIFO_UNWRITABLE) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	count = ep->ep.maxpacket; | 
					
						
							|  |  |  | 	count = write_packet(buf, req, count); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	ep->ackwait = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* last packet is often short (sometimes a zlp) */ | 
					
						
							|  |  |  | 	if (count != ep->ep.maxpacket) | 
					
						
							|  |  |  | 		is_last = 1; | 
					
						
							|  |  |  | 	else if (req->req.length == req->req.actual | 
					
						
							|  |  |  | 			&& !req->req.zero) | 
					
						
							|  |  |  | 		is_last = 1; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		is_last = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* NOTE:  requests complete when all IN data is in a
 | 
					
						
							|  |  |  | 	 * FIFO (or sometimes later, if a zlp was needed). | 
					
						
							|  |  |  | 	 * Use usb_ep_fifo_status() where needed. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (is_last) | 
					
						
							|  |  |  | 		done(ep, req, 0); | 
					
						
							|  |  |  | 	return is_last; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | static inline int | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | read_packet(u8 *buf, struct omap_req *req, unsigned avail) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned	len; | 
					
						
							|  |  |  | 	u16		*wp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	len = min(req->req.length - req->req.actual, avail); | 
					
						
							|  |  |  | 	req->req.actual += len; | 
					
						
							|  |  |  | 	avail = len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (likely((((int)buf) & 1) == 0)) { | 
					
						
							|  |  |  | 		wp = (u16 *)buf; | 
					
						
							|  |  |  | 		while (avail >= 2) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			*wp++ = omap_readw(UDC_DATA); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			avail -= 2; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		buf = (u8 *)wp; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	while (avail--) | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		*buf++ = omap_readb(UDC_DATA); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	return len; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | /* return:  0 = still running, 1 = queue empty, negative = errno */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | static int read_fifo(struct omap_ep *ep, struct omap_req *req) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u8		*buf; | 
					
						
							|  |  |  | 	unsigned	count, avail; | 
					
						
							|  |  |  | 	int		is_last; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	buf = req->req.buf + req->req.actual; | 
					
						
							|  |  |  | 	prefetchw(buf); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (;;) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		u16	ep_stat = omap_readw(UDC_STAT_FLG); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		is_last = 0; | 
					
						
							|  |  |  | 		if (ep_stat & FIFO_EMPTY) { | 
					
						
							|  |  |  | 			if (!ep->double_buf) | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			ep->fnf = 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (ep_stat & UDC_EP_HALTED) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 		if (ep_stat & UDC_FIFO_FULL) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			avail = ep->ep.maxpacket; | 
					
						
							|  |  |  | 		else  { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			avail = omap_readw(UDC_RXFSTAT); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			ep->fnf = ep->double_buf; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		count = read_packet(buf, req, avail); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* partial packet reads may not be errors */ | 
					
						
							|  |  |  | 		if (count < ep->ep.maxpacket) { | 
					
						
							|  |  |  | 			is_last = 1; | 
					
						
							|  |  |  | 			/* overflowed this request?  flush extra data */ | 
					
						
							|  |  |  | 			if (count != avail) { | 
					
						
							|  |  |  | 				req->req.status = -EOVERFLOW; | 
					
						
							|  |  |  | 				avail -= count; | 
					
						
							|  |  |  | 				while (avail--) | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 					omap_readw(UDC_DATA); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} else if (req->req.length == req->req.actual) | 
					
						
							|  |  |  | 			is_last = 1; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			is_last = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!ep->bEndpointAddress) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		if (is_last) | 
					
						
							|  |  |  | 			done(ep, req, 0); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return is_last; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	dma_addr_t	end; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* IN-DMA needs this on fault/cancel paths, so 15xx misreports
 | 
					
						
							|  |  |  | 	 * the last transfer's bytecount by more than a FIFO's worth. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (cpu_is_omap15xx()) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:36 +03:00
										 |  |  | 	end = omap_get_dma_src_pos(ep->lch); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (end == ep->dma_counter) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	end |= start & (0xffff << 16); | 
					
						
							|  |  |  | 	if (end < start) | 
					
						
							|  |  |  | 		end += 0x10000; | 
					
						
							|  |  |  | 	return end - start; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	dma_addr_t	end; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:36 +03:00
										 |  |  | 	end = omap_get_dma_dst_pos(ep->lch); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (end == ep->dma_counter) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	end |= start & (0xffff << 16); | 
					
						
							|  |  |  | 	if (cpu_is_omap15xx()) | 
					
						
							|  |  |  | 		end++; | 
					
						
							|  |  |  | 	if (end < start) | 
					
						
							|  |  |  | 		end += 0x10000; | 
					
						
							|  |  |  | 	return end - start; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Each USB transfer request using DMA maps to one or more DMA transfers.
 | 
					
						
							|  |  |  |  * When DMA completion isn't request completion, the UDC continues with | 
					
						
							|  |  |  |  * the next DMA transfer for that USB transfer. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void next_in_dma(struct omap_ep *ep, struct omap_req *req) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	u16		txdma_ctrl, w; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	unsigned	length = req->req.length - req->req.actual; | 
					
						
							|  |  |  | 	const int	sync_mode = cpu_is_omap15xx() | 
					
						
							|  |  |  | 				? OMAP_DMA_SYNC_FRAME | 
					
						
							|  |  |  | 				: OMAP_DMA_SYNC_ELEMENT; | 
					
						
							| 
									
										
										
										
											2007-11-21 15:13:15 -08:00
										 |  |  | 	int		dma_trigger = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	/* measure length in either bytes or packets */ | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 	if ((cpu_is_omap16xx() && length <= UDC_TXN_TSC) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			|| (cpu_is_omap15xx() && length < ep->maxpacket)) { | 
					
						
							|  |  |  | 		txdma_ctrl = UDC_TXN_EOT | length; | 
					
						
							|  |  |  | 		omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, | 
					
						
							| 
									
										
										
										
											2007-11-21 15:13:15 -08:00
										 |  |  | 				length, 1, sync_mode, dma_trigger, 0); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		length = min(length / ep->maxpacket, | 
					
						
							|  |  |  | 				(unsigned) UDC_TXN_TSC + 1); | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 		txdma_ctrl = length; | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 		omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 				ep->ep.maxpacket >> 1, length, sync_mode, | 
					
						
							| 
									
										
										
										
											2007-11-21 15:13:15 -08:00
										 |  |  | 				dma_trigger, 0); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		length *= ep->maxpacket; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF, | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 		OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual, | 
					
						
							|  |  |  | 		0, 0); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	omap_start_dma(ep->lch); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:36 +03:00
										 |  |  | 	ep->dma_counter = omap_get_dma_src_pos(ep->lch); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	w = omap_readw(UDC_DMA_IRQ_EN); | 
					
						
							|  |  |  | 	w |= UDC_TX_DONE_IE(ep->dma_channel); | 
					
						
							|  |  |  | 	omap_writew(w, UDC_DMA_IRQ_EN); | 
					
						
							|  |  |  | 	omap_writew(UDC_TXN_START | txdma_ctrl, UDC_TXDMA(ep->dma_channel)); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	req->dma_bytes = length; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void finish_in_dma(struct omap_ep *ep, struct omap_req *req, int status) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	u16 w; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (status == 0) { | 
					
						
							|  |  |  | 		req->req.actual += req->dma_bytes; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* return if this request needs to send data or zlp */ | 
					
						
							|  |  |  | 		if (req->req.actual < req->req.length) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		if (req->req.zero | 
					
						
							|  |  |  | 				&& req->dma_bytes != 0 | 
					
						
							|  |  |  | 				&& (req->req.actual % ep->maxpacket) == 0) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		req->req.actual += dma_src_len(ep, req->req.dma | 
					
						
							|  |  |  | 							+ req->req.actual); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* tx completion */ | 
					
						
							|  |  |  | 	omap_stop_dma(ep->lch); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	w = omap_readw(UDC_DMA_IRQ_EN); | 
					
						
							|  |  |  | 	w &= ~UDC_TX_DONE_IE(ep->dma_channel); | 
					
						
							|  |  |  | 	omap_writew(w, UDC_DMA_IRQ_EN); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	done(ep, req, status); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void next_out_dma(struct omap_ep *ep, struct omap_req *req) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-11-21 15:13:15 -08:00
										 |  |  | 	unsigned packets = req->req.length - req->req.actual; | 
					
						
							|  |  |  | 	int dma_trigger = 0; | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	u16 w; | 
					
						
							| 
									
										
										
										
											2007-11-21 15:13:15 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-21 12:01:11 -07:00
										 |  |  | 	/* set up this DMA transfer, enable the fifo, start */ | 
					
						
							|  |  |  | 	packets /= ep->ep.maxpacket; | 
					
						
							|  |  |  | 	packets = min(packets, (unsigned)UDC_RXN_TC + 1); | 
					
						
							|  |  |  | 	req->dma_bytes = packets * ep->ep.maxpacket; | 
					
						
							|  |  |  | 	omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, | 
					
						
							|  |  |  | 			ep->ep.maxpacket >> 1, packets, | 
					
						
							|  |  |  | 			OMAP_DMA_SYNC_ELEMENT, | 
					
						
							|  |  |  | 			dma_trigger, 0); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 		OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual, | 
					
						
							|  |  |  | 		0, 0); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:36 +03:00
										 |  |  | 	ep->dma_counter = omap_get_dma_dst_pos(ep->lch); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	omap_writew(UDC_RXN_STOP | (packets - 1), UDC_RXDMA(ep->dma_channel)); | 
					
						
							|  |  |  | 	w = omap_readw(UDC_DMA_IRQ_EN); | 
					
						
							|  |  |  | 	w |= UDC_RX_EOT_IE(ep->dma_channel); | 
					
						
							|  |  |  | 	omap_writew(w, UDC_DMA_IRQ_EN); | 
					
						
							|  |  |  | 	omap_writew(ep->bEndpointAddress & 0xf, UDC_EP_NUM); | 
					
						
							|  |  |  | 	omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	omap_start_dma(ep->lch); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2005-10-16 15:06:51 -07:00
										 |  |  | finish_out_dma(struct omap_ep *ep, struct omap_req *req, int status, int one) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	u16	count, w; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (status == 0) | 
					
						
							|  |  |  | 		ep->dma_counter = (u16) (req->req.dma + req->req.actual); | 
					
						
							|  |  |  | 	count = dma_dest_len(ep, req->req.dma + req->req.actual); | 
					
						
							|  |  |  | 	count += req->req.actual; | 
					
						
							| 
									
										
										
										
											2005-10-16 15:06:51 -07:00
										 |  |  | 	if (one) | 
					
						
							|  |  |  | 		count--; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (count <= req->req.length) | 
					
						
							|  |  |  | 		req->req.actual = count; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (count != req->dma_bytes || status) | 
					
						
							|  |  |  | 		omap_stop_dma(ep->lch); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* if this wasn't short, request may need another transfer */ | 
					
						
							|  |  |  | 	else if (req->req.actual < req->req.length) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* rx completion */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	w = omap_readw(UDC_DMA_IRQ_EN); | 
					
						
							|  |  |  | 	w &= ~UDC_RX_EOT_IE(ep->dma_channel); | 
					
						
							|  |  |  | 	omap_writew(w, UDC_DMA_IRQ_EN); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	done(ep, req, status); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dma_irq(struct omap_udc *udc, u16 irq_src) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	u16		dman_stat = omap_readw(UDC_DMAN_STAT); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	struct omap_ep	*ep; | 
					
						
							|  |  |  | 	struct omap_req	*req; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* IN dma: tx to host */ | 
					
						
							|  |  |  | 	if (irq_src & UDC_TXN_DONE) { | 
					
						
							|  |  |  | 		ep = &udc->ep[16 + UDC_DMA_TX_SRC(dman_stat)]; | 
					
						
							|  |  |  | 		ep->irqs++; | 
					
						
							|  |  |  | 		/* can see TXN_DONE after dma abort */ | 
					
						
							|  |  |  | 		if (!list_empty(&ep->queue)) { | 
					
						
							|  |  |  | 			req = container_of(ep->queue.next, | 
					
						
							|  |  |  | 						struct omap_req, queue); | 
					
						
							|  |  |  | 			finish_in_dma(ep, req, 0); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew(UDC_TXN_DONE, UDC_IRQ_SRC); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 		if (!list_empty(&ep->queue)) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			req = container_of(ep->queue.next, | 
					
						
							|  |  |  | 					struct omap_req, queue); | 
					
						
							|  |  |  | 			next_in_dma(ep, req); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* OUT dma: rx from host */ | 
					
						
							|  |  |  | 	if (irq_src & UDC_RXN_EOT) { | 
					
						
							|  |  |  | 		ep = &udc->ep[UDC_DMA_RX_SRC(dman_stat)]; | 
					
						
							|  |  |  | 		ep->irqs++; | 
					
						
							|  |  |  | 		/* can see RXN_EOT after dma abort */ | 
					
						
							|  |  |  | 		if (!list_empty(&ep->queue)) { | 
					
						
							|  |  |  | 			req = container_of(ep->queue.next, | 
					
						
							|  |  |  | 					struct omap_req, queue); | 
					
						
							| 
									
										
										
										
											2005-10-16 15:06:51 -07:00
										 |  |  | 			finish_out_dma(ep, req, 0, dman_stat & UDC_DMA_RX_SB); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew(UDC_RXN_EOT, UDC_IRQ_SRC); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 		if (!list_empty(&ep->queue)) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			req = container_of(ep->queue.next, | 
					
						
							|  |  |  | 					struct omap_req, queue); | 
					
						
							|  |  |  | 			next_out_dma(ep, req); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (irq_src & UDC_RXN_CNT) { | 
					
						
							|  |  |  | 		ep = &udc->ep[UDC_DMA_RX_SRC(dman_stat)]; | 
					
						
							|  |  |  | 		ep->irqs++; | 
					
						
							|  |  |  | 		/* omap15xx does this unasked... */ | 
					
						
							|  |  |  | 		VDBG("%s, RX_CNT irq?\n", ep->ep.name); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew(UDC_RXN_CNT, UDC_IRQ_SRC); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dma_error(int lch, u16 ch_status, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct omap_ep	*ep = data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* if ch_status & OMAP_DMA_DROP_IRQ ... */ | 
					
						
							| 
									
										
										
										
											2006-06-26 16:16:15 -07:00
										 |  |  | 	/* if ch_status & OMAP1_DMA_TOUT_IRQ ... */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	ERR("%s dma error, lch %d status %02x\n", ep->ep.name, lch, ch_status); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* complete current transfer ... */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dma_channel_claim(struct omap_ep *ep, unsigned channel) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u16	reg; | 
					
						
							|  |  |  | 	int	status, restart, is_in; | 
					
						
							| 
									
										
										
										
											2007-11-21 15:13:15 -08:00
										 |  |  | 	int	dma_channel; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	is_in = ep->bEndpointAddress & USB_DIR_IN; | 
					
						
							|  |  |  | 	if (is_in) | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		reg = omap_readw(UDC_TXDMA_CFG); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		reg = omap_readw(UDC_RXDMA_CFG); | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 	reg |= UDC_DMA_REQ;		/* "pulse" activated */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ep->dma_channel = 0; | 
					
						
							|  |  |  | 	ep->lch = -1; | 
					
						
							|  |  |  | 	if (channel == 0 || channel > 3) { | 
					
						
							|  |  |  | 		if ((reg & 0x0f00) == 0) | 
					
						
							|  |  |  | 			channel = 3; | 
					
						
							|  |  |  | 		else if ((reg & 0x00f0) == 0) | 
					
						
							|  |  |  | 			channel = 2; | 
					
						
							|  |  |  | 		else if ((reg & 0x000f) == 0)	/* preferred for ISO */ | 
					
						
							|  |  |  | 			channel = 1; | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			status = -EMLINK; | 
					
						
							|  |  |  | 			goto just_restart; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	reg |= (0x0f & ep->bEndpointAddress) << (4 * (channel - 1)); | 
					
						
							|  |  |  | 	ep->dma_channel = channel; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (is_in) { | 
					
						
							| 
									
										
										
										
											2012-05-21 12:01:11 -07:00
										 |  |  | 		dma_channel = OMAP_DMA_USB_W2FC_TX0 - 1 + channel; | 
					
						
							| 
									
										
										
										
											2007-11-21 15:13:15 -08:00
										 |  |  | 		status = omap_request_dma(dma_channel, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			ep->ep.name, dma_error, ep, &ep->lch); | 
					
						
							|  |  |  | 		if (status == 0) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(reg, UDC_TXDMA_CFG); | 
					
						
							| 
									
										
										
										
											2007-11-21 15:13:15 -08:00
										 |  |  | 			/* EMIFF or SDRC */ | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 			omap_set_dma_src_burst_mode(ep->lch, | 
					
						
							|  |  |  | 						OMAP_DMA_DATA_BURST_4); | 
					
						
							|  |  |  | 			omap_set_dma_src_data_pack(ep->lch, 1); | 
					
						
							|  |  |  | 			/* TIPB */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			omap_set_dma_dest_params(ep->lch, | 
					
						
							|  |  |  | 				OMAP_DMA_PORT_TIPB, | 
					
						
							|  |  |  | 				OMAP_DMA_AMODE_CONSTANT, | 
					
						
							| 
									
										
										
										
											2008-08-31 18:04:27 -07:00
										 |  |  | 				UDC_DATA_DMA, | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 				0, 0); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2012-05-21 12:01:11 -07:00
										 |  |  | 		dma_channel = OMAP_DMA_USB_W2FC_RX0 - 1 + channel; | 
					
						
							| 
									
										
										
										
											2007-11-21 15:13:15 -08:00
										 |  |  | 		status = omap_request_dma(dma_channel, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			ep->ep.name, dma_error, ep, &ep->lch); | 
					
						
							|  |  |  | 		if (status == 0) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(reg, UDC_RXDMA_CFG); | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 			/* TIPB */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			omap_set_dma_src_params(ep->lch, | 
					
						
							|  |  |  | 				OMAP_DMA_PORT_TIPB, | 
					
						
							|  |  |  | 				OMAP_DMA_AMODE_CONSTANT, | 
					
						
							| 
									
										
										
										
											2008-08-31 18:04:27 -07:00
										 |  |  | 				UDC_DATA_DMA, | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 				0, 0); | 
					
						
							| 
									
										
										
										
											2007-11-21 15:13:15 -08:00
										 |  |  | 			/* EMIFF or SDRC */ | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 			omap_set_dma_dest_burst_mode(ep->lch, | 
					
						
							|  |  |  | 						OMAP_DMA_DATA_BURST_4); | 
					
						
							|  |  |  | 			omap_set_dma_dest_data_pack(ep->lch, 1); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (status) | 
					
						
							|  |  |  | 		ep->dma_channel = 0; | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		ep->has_dma = 1; | 
					
						
							|  |  |  | 		omap_disable_dma_irq(ep->lch, OMAP_DMA_BLOCK_IRQ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* channel type P: hw synch (fifo) */ | 
					
						
							| 
									
										
										
										
											2012-05-21 12:01:11 -07:00
										 |  |  | 		if (!cpu_is_omap15xx()) | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:36 +03:00
										 |  |  | 			omap_set_dma_channel_mode(ep->lch, OMAP_DMA_LCH_P); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | just_restart: | 
					
						
							|  |  |  | 	/* restart any queue, even if the claim failed  */ | 
					
						
							|  |  |  | 	restart = !ep->stopped && !list_empty(&ep->queue); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (status) | 
					
						
							|  |  |  | 		DBG("%s no dma channel: %d%s\n", ep->ep.name, status, | 
					
						
							|  |  |  | 			restart ? " (restart)" : ""); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		DBG("%s claimed %cxdma%d lch %d%s\n", ep->ep.name, | 
					
						
							|  |  |  | 			is_in ? 't' : 'r', | 
					
						
							|  |  |  | 			ep->dma_channel - 1, ep->lch, | 
					
						
							|  |  |  | 			restart ? " (restart)" : ""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (restart) { | 
					
						
							|  |  |  | 		struct omap_req	*req; | 
					
						
							|  |  |  | 		req = container_of(ep->queue.next, struct omap_req, queue); | 
					
						
							|  |  |  | 		if (ep->has_dma) | 
					
						
							|  |  |  | 			(is_in ? next_in_dma : next_out_dma)(ep, req); | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			use_ep(ep, UDC_EP_SEL); | 
					
						
							|  |  |  | 			(is_in ? write_fifo : read_fifo)(ep, req); | 
					
						
							|  |  |  | 			deselect_ep(); | 
					
						
							|  |  |  | 			if (!is_in) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 				omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				ep->ackwait = 1 + ep->double_buf; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			/* IN: 6 wait states before it'll tx */ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dma_channel_release(struct omap_ep *ep) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int		shift = 4 * (ep->dma_channel - 1); | 
					
						
							|  |  |  | 	u16		mask = 0x0f << shift; | 
					
						
							|  |  |  | 	struct omap_req	*req; | 
					
						
							|  |  |  | 	int		active; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* abort any active usb transfer request */ | 
					
						
							|  |  |  | 	if (!list_empty(&ep->queue)) | 
					
						
							|  |  |  | 		req = container_of(ep->queue.next, struct omap_req, queue); | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 		req = NULL; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:36 +03:00
										 |  |  | 	active = omap_get_dma_active_status(ep->lch); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	DBG("%s release %s %cxdma%d %p\n", ep->ep.name, | 
					
						
							|  |  |  | 			active ? "active" : "idle", | 
					
						
							|  |  |  | 			(ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r', | 
					
						
							|  |  |  | 			ep->dma_channel - 1, req); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 	/* NOTE: re-setting RX_REQ/TX_REQ because of a chip bug (before
 | 
					
						
							|  |  |  | 	 * OMAP 1710 ES2.0) where reading the DMA_CFG can clear them. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	/* wait till current packet DMA finishes, and fifo empties */ | 
					
						
							|  |  |  | 	if (ep->bEndpointAddress & USB_DIR_IN) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew((omap_readw(UDC_TXDMA_CFG) & ~mask) | UDC_DMA_REQ, | 
					
						
							|  |  |  | 					UDC_TXDMA_CFG); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (req) { | 
					
						
							|  |  |  | 			finish_in_dma(ep, req, -ECONNRESET); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* clear FIFO; hosts probably won't empty it */ | 
					
						
							|  |  |  | 			use_ep(ep, UDC_EP_SEL); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(UDC_CLR_EP, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			deselect_ep(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		while (omap_readw(UDC_TXDMA_CFG) & mask) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			udelay(10); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew((omap_readw(UDC_RXDMA_CFG) & ~mask) | UDC_DMA_REQ, | 
					
						
							|  |  |  | 					UDC_RXDMA_CFG); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* dma empties the fifo */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		while (omap_readw(UDC_RXDMA_CFG) & mask) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			udelay(10); | 
					
						
							|  |  |  | 		if (req) | 
					
						
							| 
									
										
										
										
											2005-10-16 15:06:51 -07:00
										 |  |  | 			finish_out_dma(ep, req, -ECONNRESET, 0); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	omap_free_dma(ep->lch); | 
					
						
							|  |  |  | 	ep->dma_channel = 0; | 
					
						
							|  |  |  | 	ep->lch = -1; | 
					
						
							|  |  |  | 	/* has_dma still set, till endpoint is fully quiesced */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							| 
									
										
										
										
											2005-10-21 03:21:58 -04:00
										 |  |  | omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct omap_ep	*ep = container_of(_ep, struct omap_ep, ep); | 
					
						
							|  |  |  | 	struct omap_req	*req = container_of(_req, struct omap_req, req); | 
					
						
							|  |  |  | 	struct omap_udc	*udc; | 
					
						
							|  |  |  | 	unsigned long	flags; | 
					
						
							|  |  |  | 	int		is_iso = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* catch various bogus parameters */ | 
					
						
							|  |  |  | 	if (!_req || !req->req.complete || !req->req.buf | 
					
						
							|  |  |  | 			|| !list_empty(&req->queue)) { | 
					
						
							| 
									
										
										
										
											2008-03-03 16:08:34 -08:00
										 |  |  | 		DBG("%s, bad params\n", __func__); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-12 20:25:35 +02:00
										 |  |  | 	if (!_ep || (!ep->ep.desc && ep->bEndpointAddress)) { | 
					
						
							| 
									
										
										
										
											2008-03-03 16:08:34 -08:00
										 |  |  | 		DBG("%s, bad ep\n", __func__); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) { | 
					
						
							|  |  |  | 		if (req->req.length > ep->ep.maxpacket) | 
					
						
							|  |  |  | 			return -EMSGSIZE; | 
					
						
							|  |  |  | 		is_iso = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* this isn't bogus, but OMAP DMA isn't the only hardware to
 | 
					
						
							|  |  |  | 	 * have a hard time with partial packet reads...  reject it. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (use_dma | 
					
						
							|  |  |  | 			&& ep->has_dma | 
					
						
							|  |  |  | 			&& ep->bEndpointAddress != 0 | 
					
						
							|  |  |  | 			&& (ep->bEndpointAddress & USB_DIR_IN) == 0 | 
					
						
							|  |  |  | 			&& (req->req.length % ep->ep.maxpacket) != 0) { | 
					
						
							| 
									
										
										
										
											2008-03-03 16:08:34 -08:00
										 |  |  | 		DBG("%s, no partial packet OUT reads\n", __func__); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return -EMSGSIZE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	udc = ep->udc; | 
					
						
							|  |  |  | 	if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) | 
					
						
							|  |  |  | 		return -ESHUTDOWN; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:42:56 +03:00
										 |  |  | 	if (use_dma && ep->has_dma) | 
					
						
							|  |  |  | 		usb_gadget_map_request(&udc->gadget, &req->req, | 
					
						
							|  |  |  | 				(ep->bEndpointAddress & USB_DIR_IN)); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	VDBG("%s queue req %p, len %d buf %p\n", | 
					
						
							|  |  |  | 		ep->ep.name, _req, _req->length, _req->buf); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&udc->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	req->req.status = -EINPROGRESS; | 
					
						
							|  |  |  | 	req->req.actual = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* maybe kickstart non-iso i/o queues */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	if (is_iso) { | 
					
						
							|  |  |  | 		u16 w; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		w = omap_readw(UDC_IRQ_EN); | 
					
						
							|  |  |  | 		w |= UDC_SOF_IE; | 
					
						
							|  |  |  | 		omap_writew(w, UDC_IRQ_EN); | 
					
						
							|  |  |  | 	} else if (list_empty(&ep->queue) && !ep->stopped && !ep->ackwait) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		int	is_in; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (ep->bEndpointAddress == 0) { | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 			if (!udc->ep0_pending || !list_empty(&ep->queue)) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				spin_unlock_irqrestore(&udc->lock, flags); | 
					
						
							|  |  |  | 				return -EL2HLT; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* empty DATA stage? */ | 
					
						
							|  |  |  | 			is_in = udc->ep0_in; | 
					
						
							|  |  |  | 			if (!req->req.length) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				/* chip became CONFIGURED or ADDRESSED
 | 
					
						
							|  |  |  | 				 * earlier; drivers may already have queued | 
					
						
							|  |  |  | 				 * requests to non-control endpoints | 
					
						
							|  |  |  | 				 */ | 
					
						
							|  |  |  | 				if (udc->ep0_set_config) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 					u16	irq_en = omap_readw(UDC_IRQ_EN); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					irq_en |= UDC_DS_CHG_IE | UDC_EP0_IE; | 
					
						
							|  |  |  | 					if (!udc->ep0_reset_config) | 
					
						
							|  |  |  | 						irq_en |= UDC_EPN_RX_IE | 
					
						
							|  |  |  | 							| UDC_EPN_TX_IE; | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 					omap_writew(irq_en, UDC_IRQ_EN); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 				/* STATUS for zero length DATA stages is
 | 
					
						
							|  |  |  | 				 * always an IN ... even for IN transfers, | 
					
						
							| 
									
										
										
										
											2007-12-17 11:40:18 -08:00
										 |  |  | 				 * a weird case which seem to stall OMAP. | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 				 */ | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 				omap_writew(UDC_EP_SEL | UDC_EP_DIR, | 
					
						
							|  |  |  | 						UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 				omap_writew(UDC_CLR_EP, UDC_CTRL); | 
					
						
							|  |  |  | 				omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); | 
					
						
							|  |  |  | 				omap_writew(UDC_EP_DIR, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				/* cleanup */ | 
					
						
							|  |  |  | 				udc->ep0_pending = 0; | 
					
						
							|  |  |  | 				done(ep, req, 0); | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 				req = NULL; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			/* non-empty DATA stage */ | 
					
						
							|  |  |  | 			} else if (is_in) { | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 				omap_writew(UDC_EP_SEL | UDC_EP_DIR, | 
					
						
							|  |  |  | 						UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				if (udc->ep0_setup) | 
					
						
							|  |  |  | 					goto irq_wait; | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 				omap_writew(UDC_EP_SEL, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			is_in = ep->bEndpointAddress & USB_DIR_IN; | 
					
						
							|  |  |  | 			if (!ep->has_dma) | 
					
						
							|  |  |  | 				use_ep(ep, UDC_EP_SEL); | 
					
						
							|  |  |  | 			/* if ISO: SOF IRQs must be enabled/disabled! */ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (ep->has_dma) | 
					
						
							|  |  |  | 			(is_in ? next_in_dma : next_out_dma)(ep, req); | 
					
						
							|  |  |  | 		else if (req) { | 
					
						
							|  |  |  | 			if ((is_in ? write_fifo : read_fifo)(ep, req) == 1) | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 				req = NULL; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			deselect_ep(); | 
					
						
							|  |  |  | 			if (!is_in) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 				omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				ep->ackwait = 1 + ep->double_buf; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			/* IN: 6 wait states before it'll tx */ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | irq_wait: | 
					
						
							|  |  |  | 	/* irq handler advances the queue */ | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 	if (req != NULL) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		list_add_tail(&req->queue, &ep->queue); | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&udc->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int omap_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct omap_ep	*ep = container_of(_ep, struct omap_ep, ep); | 
					
						
							|  |  |  | 	struct omap_req	*req; | 
					
						
							|  |  |  | 	unsigned long	flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!_ep || !_req) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&ep->udc->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* make sure it's actually queued on this endpoint */ | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	list_for_each_entry(req, &ep->queue, queue) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		if (&req->req == _req) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (&req->req != _req) { | 
					
						
							|  |  |  | 		spin_unlock_irqrestore(&ep->udc->lock, flags); | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (use_dma && ep->dma_channel && ep->queue.next == &req->queue) { | 
					
						
							|  |  |  | 		int channel = ep->dma_channel; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* releasing the channel cancels the request,
 | 
					
						
							|  |  |  | 		 * reclaiming the channel restarts the queue | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		dma_channel_release(ep); | 
					
						
							|  |  |  | 		dma_channel_claim(ep, channel); | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 	} else | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		done(ep, req, -ECONNRESET); | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&ep->udc->lock, flags); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int omap_ep_set_halt(struct usb_ep *_ep, int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct omap_ep	*ep = container_of(_ep, struct omap_ep, ep); | 
					
						
							|  |  |  | 	unsigned long	flags; | 
					
						
							|  |  |  | 	int		status = -EOPNOTSUPP; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&ep->udc->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* just use protocol stalls for ep0; real halts are annoying */ | 
					
						
							|  |  |  | 	if (ep->bEndpointAddress == 0) { | 
					
						
							|  |  |  | 		if (!ep->udc->ep0_pending) | 
					
						
							|  |  |  | 			status = -EINVAL; | 
					
						
							|  |  |  | 		else if (value) { | 
					
						
							|  |  |  | 			if (ep->udc->ep0_set_config) { | 
					
						
							| 
									
										
										
										
											2008-07-25 01:45:52 -07:00
										 |  |  | 				WARNING("error changing config?\n"); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 				omap_writew(UDC_CLR_CFG, UDC_SYSCON2); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(UDC_STALL_CMD, UDC_SYSCON2); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			ep->udc->ep0_pending = 0; | 
					
						
							|  |  |  | 			status = 0; | 
					
						
							|  |  |  | 		} else /* NOP */ | 
					
						
							|  |  |  | 			status = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* otherwise, all active non-ISO endpoints can halt */ | 
					
						
							| 
									
										
										
										
											2012-03-12 20:25:35 +02:00
										 |  |  | 	} else if (ep->bmAttributes != USB_ENDPOINT_XFER_ISOC && ep->ep.desc) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* IN endpoints must already be idle */ | 
					
						
							|  |  |  | 		if ((ep->bEndpointAddress & USB_DIR_IN) | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 				&& !list_empty(&ep->queue)) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			status = -EAGAIN; | 
					
						
							|  |  |  | 			goto done; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (value) { | 
					
						
							|  |  |  | 			int	channel; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (use_dma && ep->dma_channel | 
					
						
							|  |  |  | 					&& !list_empty(&ep->queue)) { | 
					
						
							|  |  |  | 				channel = ep->dma_channel; | 
					
						
							|  |  |  | 				dma_channel_release(ep); | 
					
						
							|  |  |  | 			} else | 
					
						
							|  |  |  | 				channel = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			use_ep(ep, UDC_EP_SEL); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			if (omap_readw(UDC_STAT_FLG) & UDC_NON_ISO_FIFO_EMPTY) { | 
					
						
							|  |  |  | 				omap_writew(UDC_SET_HALT, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				status = 0; | 
					
						
							|  |  |  | 			} else | 
					
						
							|  |  |  | 				status = -EAGAIN; | 
					
						
							|  |  |  | 			deselect_ep(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (channel) | 
					
						
							|  |  |  | 				dma_channel_claim(ep, channel); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			use_ep(ep, 0); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(ep->udc->clr_halt, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			ep->ackwait = 0; | 
					
						
							|  |  |  | 			if (!(ep->bEndpointAddress & USB_DIR_IN)) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 				omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				ep->ackwait = 1 + ep->double_buf; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | done: | 
					
						
							|  |  |  | 	VDBG("%s %s halt stat %d\n", ep->ep.name, | 
					
						
							|  |  |  | 		value ? "set" : "clear", status); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&ep->udc->lock, flags); | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct usb_ep_ops omap_ep_ops = { | 
					
						
							|  |  |  | 	.enable		= omap_ep_enable, | 
					
						
							|  |  |  | 	.disable	= omap_ep_disable, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	.alloc_request	= omap_alloc_request, | 
					
						
							|  |  |  | 	.free_request	= omap_free_request, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	.queue		= omap_ep_queue, | 
					
						
							|  |  |  | 	.dequeue	= omap_ep_dequeue, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	.set_halt	= omap_ep_set_halt, | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	/* fifo_status ... report bytes in fifo */ | 
					
						
							|  |  |  | 	/* fifo_flush ... flush fifo */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int omap_get_frame(struct usb_gadget *gadget) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	u16	sof = omap_readw(UDC_SOF); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	return (sof & UDC_TS_OK) ? (sof & UDC_TS) : -EL2NSYNC; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int omap_wakeup(struct usb_gadget *gadget) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct omap_udc	*udc; | 
					
						
							|  |  |  | 	unsigned long	flags; | 
					
						
							|  |  |  | 	int		retval = -EHOSTUNREACH; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	udc = container_of(gadget, struct omap_udc, gadget); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&udc->lock, flags); | 
					
						
							|  |  |  | 	if (udc->devstat & UDC_SUS) { | 
					
						
							|  |  |  | 		/* NOTE:  OTG spec erratum says that OTG devices may
 | 
					
						
							|  |  |  | 		 * issue wakeups without host enable. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if (udc->devstat & (UDC_B_HNP_ENABLE|UDC_R_WK_OK)) { | 
					
						
							|  |  |  | 			DBG("remote wakeup...\n"); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(UDC_RMT_WKP, UDC_SYSCON2); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			retval = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* NOTE:  non-OTG systems may use SRP TOO... */ | 
					
						
							|  |  |  | 	} else if (!(udc->devstat & UDC_ATT)) { | 
					
						
							| 
									
										
										
										
											2012-06-26 17:40:32 +05:30
										 |  |  | 		if (!IS_ERR_OR_NULL(udc->transceiver)) | 
					
						
							| 
									
										
										
										
											2012-02-13 13:24:20 +02:00
										 |  |  | 			retval = otg_start_srp(udc->transceiver->otg); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&udc->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return retval; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | omap_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct omap_udc	*udc; | 
					
						
							|  |  |  | 	unsigned long	flags; | 
					
						
							|  |  |  | 	u16		syscon1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	udc = container_of(gadget, struct omap_udc, gadget); | 
					
						
							|  |  |  | 	spin_lock_irqsave(&udc->lock, flags); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	syscon1 = omap_readw(UDC_SYSCON1); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (is_selfpowered) | 
					
						
							|  |  |  | 		syscon1 |= UDC_SELF_PWR; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		syscon1 &= ~UDC_SELF_PWR; | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	omap_writew(syscon1, UDC_SYSCON1); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	spin_unlock_irqrestore(&udc->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int can_pullup(struct omap_udc *udc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return udc->driver && udc->softconnect && udc->vbus_active; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void pullup_enable(struct omap_udc *udc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	u16 w; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	w = omap_readw(UDC_SYSCON1); | 
					
						
							|  |  |  | 	w |= UDC_PULLUP_EN; | 
					
						
							|  |  |  | 	omap_writew(w, UDC_SYSCON1); | 
					
						
							|  |  |  | 	if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx()) { | 
					
						
							|  |  |  | 		u32 l; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		l = omap_readl(OTG_CTRL); | 
					
						
							|  |  |  | 		l |= OTG_BSESSVLD; | 
					
						
							|  |  |  | 		omap_writel(l, OTG_CTRL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	omap_writew(UDC_DS_CHG_IE, UDC_IRQ_EN); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void pullup_disable(struct omap_udc *udc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	u16 w; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx()) { | 
					
						
							|  |  |  | 		u32 l; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		l = omap_readl(OTG_CTRL); | 
					
						
							|  |  |  | 		l &= ~OTG_BSESSVLD; | 
					
						
							|  |  |  | 		omap_writel(l, OTG_CTRL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	omap_writew(UDC_DS_CHG_IE, UDC_IRQ_EN); | 
					
						
							|  |  |  | 	w = omap_readw(UDC_SYSCON1); | 
					
						
							|  |  |  | 	w &= ~UDC_PULLUP_EN; | 
					
						
							|  |  |  | 	omap_writew(w, UDC_SYSCON1); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | static struct omap_udc *udc; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void omap_udc_enable_clock(int enable) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (udc == NULL || udc->dc_clk == NULL || udc->hhc_clk == NULL) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (enable) { | 
					
						
							|  |  |  | 		clk_enable(udc->dc_clk); | 
					
						
							|  |  |  | 		clk_enable(udc->hhc_clk); | 
					
						
							|  |  |  | 		udelay(100); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		clk_disable(udc->hhc_clk); | 
					
						
							|  |  |  | 		clk_disable(udc->dc_clk); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Called by whatever detects VBUS sessions:  external transceiver | 
					
						
							|  |  |  |  * driver, or maybe GPIO0 VBUS IRQ.  May request 48 MHz clock. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static int omap_vbus_session(struct usb_gadget *gadget, int is_active) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct omap_udc	*udc; | 
					
						
							|  |  |  | 	unsigned long	flags; | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	u32 l; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	udc = container_of(gadget, struct omap_udc, gadget); | 
					
						
							|  |  |  | 	spin_lock_irqsave(&udc->lock, flags); | 
					
						
							|  |  |  | 	VDBG("VBUS %s\n", is_active ? "on" : "off"); | 
					
						
							|  |  |  | 	udc->vbus_active = (is_active != 0); | 
					
						
							|  |  |  | 	if (cpu_is_omap15xx()) { | 
					
						
							|  |  |  | 		/* "software" detect, ignored if !VBUS_MODE_1510 */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		l = omap_readl(FUNC_MUX_CTRL_0); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		if (is_active) | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			l |= VBUS_CTRL_1510; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			l &= ~VBUS_CTRL_1510; | 
					
						
							|  |  |  | 		omap_writel(l, FUNC_MUX_CTRL_0); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 	if (udc->dc_clk != NULL && is_active) { | 
					
						
							|  |  |  | 		if (!udc->clk_requested) { | 
					
						
							|  |  |  | 			omap_udc_enable_clock(1); | 
					
						
							|  |  |  | 			udc->clk_requested = 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (can_pullup(udc)) | 
					
						
							|  |  |  | 		pullup_enable(udc); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		pullup_disable(udc); | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 	if (udc->dc_clk != NULL && !is_active) { | 
					
						
							|  |  |  | 		if (udc->clk_requested) { | 
					
						
							|  |  |  | 			omap_udc_enable_clock(0); | 
					
						
							|  |  |  | 			udc->clk_requested = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	spin_unlock_irqrestore(&udc->lock, flags); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int omap_vbus_draw(struct usb_gadget *gadget, unsigned mA) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct omap_udc	*udc; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	udc = container_of(gadget, struct omap_udc, gadget); | 
					
						
							| 
									
										
										
										
											2012-06-26 17:40:32 +05:30
										 |  |  | 	if (!IS_ERR_OR_NULL(udc->transceiver)) | 
					
						
							| 
									
										
										
										
											2012-02-13 13:24:18 +02:00
										 |  |  | 		return usb_phy_set_power(udc->transceiver, mA); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	return -EOPNOTSUPP; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int omap_pullup(struct usb_gadget *gadget, int is_on) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct omap_udc	*udc; | 
					
						
							|  |  |  | 	unsigned long	flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	udc = container_of(gadget, struct omap_udc, gadget); | 
					
						
							|  |  |  | 	spin_lock_irqsave(&udc->lock, flags); | 
					
						
							|  |  |  | 	udc->softconnect = (is_on != 0); | 
					
						
							|  |  |  | 	if (can_pullup(udc)) | 
					
						
							|  |  |  | 		pullup_enable(udc); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		pullup_disable(udc); | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&udc->lock, flags); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-24 10:52:52 +02:00
										 |  |  | static int omap_udc_start(struct usb_gadget *g, | 
					
						
							| 
									
										
										
										
											2013-03-05 23:16:44 +01:00
										 |  |  | 		struct usb_gadget_driver *driver); | 
					
						
							| 
									
										
										
										
											2013-01-24 10:52:52 +02:00
										 |  |  | static int omap_udc_stop(struct usb_gadget *g, | 
					
						
							|  |  |  | 		struct usb_gadget_driver *driver); | 
					
						
							| 
									
										
										
										
											2011-06-28 16:33:47 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-24 17:58:16 +02:00
										 |  |  | static const struct usb_gadget_ops omap_gadget_ops = { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	.get_frame		= omap_get_frame, | 
					
						
							|  |  |  | 	.wakeup			= omap_wakeup, | 
					
						
							|  |  |  | 	.set_selfpowered	= omap_set_selfpowered, | 
					
						
							|  |  |  | 	.vbus_session		= omap_vbus_session, | 
					
						
							|  |  |  | 	.vbus_draw		= omap_vbus_draw, | 
					
						
							|  |  |  | 	.pullup			= omap_pullup, | 
					
						
							| 
									
										
										
										
											2013-01-24 10:52:52 +02:00
										 |  |  | 	.udc_start		= omap_udc_start, | 
					
						
							|  |  |  | 	.udc_stop		= omap_udc_stop, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* dequeue ALL requests; caller holds udc->lock */ | 
					
						
							|  |  |  | static void nuke(struct omap_ep *ep, int status) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct omap_req	*req; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ep->stopped = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (use_dma && ep->dma_channel) | 
					
						
							|  |  |  | 		dma_channel_release(ep); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	use_ep(ep, 0); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	omap_writew(UDC_CLR_EP, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (ep->bEndpointAddress && ep->bmAttributes != USB_ENDPOINT_XFER_ISOC) | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew(UDC_SET_HALT, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while (!list_empty(&ep->queue)) { | 
					
						
							|  |  |  | 		req = list_entry(ep->queue.next, struct omap_req, queue); | 
					
						
							|  |  |  | 		done(ep, req, status); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* caller holds udc->lock */ | 
					
						
							|  |  |  | static void udc_quiesce(struct omap_udc *udc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct omap_ep	*ep; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	udc->gadget.speed = USB_SPEED_UNKNOWN; | 
					
						
							|  |  |  | 	nuke(&udc->ep[0], -ESHUTDOWN); | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		nuke(ep, -ESHUTDOWN); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void update_otg(struct omap_udc *udc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u16	devstat; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-26 13:42:18 -07:00
										 |  |  | 	if (!gadget_is_otg(&udc->gadget)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	if (omap_readl(OTG_CTRL) & OTG_ID) | 
					
						
							|  |  |  | 		devstat = omap_readw(UDC_DEVSTAT); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		devstat = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	udc->gadget.b_hnp_enable = !!(devstat & UDC_B_HNP_ENABLE); | 
					
						
							|  |  |  | 	udc->gadget.a_hnp_support = !!(devstat & UDC_A_HNP_SUPPORT); | 
					
						
							|  |  |  | 	udc->gadget.a_alt_hnp_support = !!(devstat & UDC_A_ALT_HNP_SUPPORT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Enable HNP early, avoiding races on suspend irq path.
 | 
					
						
							|  |  |  | 	 * ASSUMES OTG state machine B_BUS_REQ input is true. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	if (udc->gadget.b_hnp_enable) { | 
					
						
							|  |  |  | 		u32 l; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		l = omap_readl(OTG_CTRL); | 
					
						
							|  |  |  | 		l |= OTG_B_HNPEN | OTG_B_BUSREQ; | 
					
						
							|  |  |  | 		l &= ~OTG_PULLUP; | 
					
						
							|  |  |  | 		omap_writel(l, OTG_CTRL); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void ep0_irq(struct omap_udc *udc, u16 irq_src) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct omap_ep	*ep0 = &udc->ep[0]; | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 	struct omap_req	*req = NULL; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ep0->irqs++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Clear any pending requests and then scrub any rx/tx state
 | 
					
						
							|  |  |  | 	 * before starting to handle the SETUP request. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (irq_src & UDC_SETUP) { | 
					
						
							|  |  |  | 		u16	ack = irq_src & (UDC_EP0_TX|UDC_EP0_RX); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		nuke(ep0, 0); | 
					
						
							|  |  |  | 		if (ack) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(ack, UDC_IRQ_SRC); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			irq_src = UDC_SETUP; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 	/* IN/OUT packets mean we're in the DATA or STATUS stage.
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	 * This driver uses only uses protocol stalls (ep0 never halts), | 
					
						
							|  |  |  | 	 * and if we got this far the gadget driver already had a | 
					
						
							|  |  |  | 	 * chance to stall.  Tries to be forgiving of host oddities. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * NOTE:  the last chance gadget drivers have to stall control | 
					
						
							|  |  |  | 	 * requests is during their request completion callback. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (!list_empty(&ep0->queue)) | 
					
						
							|  |  |  | 		req = container_of(ep0->queue.next, struct omap_req, queue); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* IN == TX to host */ | 
					
						
							|  |  |  | 	if (irq_src & UDC_EP0_TX) { | 
					
						
							|  |  |  | 		int	stat; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew(UDC_EP0_TX, UDC_IRQ_SRC); | 
					
						
							|  |  |  | 		omap_writew(UDC_EP_SEL|UDC_EP_DIR, UDC_EP_NUM); | 
					
						
							|  |  |  | 		stat = omap_readw(UDC_STAT_FLG); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		if (stat & UDC_ACK) { | 
					
						
							|  |  |  | 			if (udc->ep0_in) { | 
					
						
							|  |  |  | 				/* write next IN packet from response,
 | 
					
						
							|  |  |  | 				 * or set up the status stage. | 
					
						
							|  |  |  | 				 */ | 
					
						
							|  |  |  | 				if (req) | 
					
						
							|  |  |  | 					stat = write_fifo(ep0, req); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 				omap_writew(UDC_EP_DIR, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				if (!req && udc->ep0_pending) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 					omap_writew(UDC_EP_SEL, UDC_EP_NUM); | 
					
						
							|  |  |  | 					omap_writew(UDC_CLR_EP, UDC_CTRL); | 
					
						
							|  |  |  | 					omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); | 
					
						
							|  |  |  | 					omap_writew(0, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 					udc->ep0_pending = 0; | 
					
						
							|  |  |  | 				} /* else:  6 wait states before it'll tx */ | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				/* ack status stage of OUT transfer */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 				omap_writew(UDC_EP_DIR, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				if (req) | 
					
						
							|  |  |  | 					done(ep0, req, 0); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 			req = NULL; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		} else if (stat & UDC_STALL) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(UDC_CLR_HALT, UDC_CTRL); | 
					
						
							|  |  |  | 			omap_writew(UDC_EP_DIR, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(UDC_EP_DIR, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* OUT == RX from host */ | 
					
						
							|  |  |  | 	if (irq_src & UDC_EP0_RX) { | 
					
						
							|  |  |  | 		int	stat; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew(UDC_EP0_RX, UDC_IRQ_SRC); | 
					
						
							|  |  |  | 		omap_writew(UDC_EP_SEL, UDC_EP_NUM); | 
					
						
							|  |  |  | 		stat = omap_readw(UDC_STAT_FLG); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		if (stat & UDC_ACK) { | 
					
						
							|  |  |  | 			if (!udc->ep0_in) { | 
					
						
							|  |  |  | 				stat = 0; | 
					
						
							|  |  |  | 				/* read next OUT packet of request, maybe
 | 
					
						
							|  |  |  | 				 * reactiviting the fifo; stall on errors. | 
					
						
							|  |  |  | 				 */ | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 				stat = read_fifo(ep0, req); | 
					
						
							|  |  |  | 				if (!req || stat < 0) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 					omap_writew(UDC_STALL_CMD, UDC_SYSCON2); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 					udc->ep0_pending = 0; | 
					
						
							|  |  |  | 					stat = 0; | 
					
						
							|  |  |  | 				} else if (stat == 0) | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 					omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); | 
					
						
							|  |  |  | 				omap_writew(0, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				/* activate status stage */ | 
					
						
							|  |  |  | 				if (stat == 1) { | 
					
						
							|  |  |  | 					done(ep0, req, 0); | 
					
						
							|  |  |  | 					/* that may have STALLed ep0... */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 					omap_writew(UDC_EP_SEL | UDC_EP_DIR, | 
					
						
							|  |  |  | 							UDC_EP_NUM); | 
					
						
							|  |  |  | 					omap_writew(UDC_CLR_EP, UDC_CTRL); | 
					
						
							|  |  |  | 					omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); | 
					
						
							|  |  |  | 					omap_writew(UDC_EP_DIR, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 					udc->ep0_pending = 0; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				/* ack status stage of IN transfer */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 				omap_writew(0, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				if (req) | 
					
						
							|  |  |  | 					done(ep0, req, 0); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else if (stat & UDC_STALL) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(UDC_CLR_HALT, UDC_CTRL); | 
					
						
							|  |  |  | 			omap_writew(0, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(0, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* SETUP starts all control transfers */ | 
					
						
							|  |  |  | 	if (irq_src & UDC_SETUP) { | 
					
						
							|  |  |  | 		union u { | 
					
						
							|  |  |  | 			u16			word[4]; | 
					
						
							|  |  |  | 			struct usb_ctrlrequest	r; | 
					
						
							|  |  |  | 		} u; | 
					
						
							|  |  |  | 		int			status = -EINVAL; | 
					
						
							|  |  |  | 		struct omap_ep		*ep; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* read the (latest) SETUP message */ | 
					
						
							|  |  |  | 		do { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(UDC_SETUP_SEL, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			/* two bytes at a time */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			u.word[0] = omap_readw(UDC_DATA); | 
					
						
							|  |  |  | 			u.word[1] = omap_readw(UDC_DATA); | 
					
						
							|  |  |  | 			u.word[2] = omap_readw(UDC_DATA); | 
					
						
							|  |  |  | 			u.word[3] = omap_readw(UDC_DATA); | 
					
						
							|  |  |  | 			omap_writew(0, UDC_EP_NUM); | 
					
						
							|  |  |  | 		} while (omap_readw(UDC_IRQ_SRC) & UDC_SETUP); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-25 20:40:14 -07:00
										 |  |  | #define	w_value		le16_to_cpu(u.r.wValue)
 | 
					
						
							|  |  |  | #define	w_index		le16_to_cpu(u.r.wIndex)
 | 
					
						
							|  |  |  | #define	w_length	le16_to_cpu(u.r.wLength)
 | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		/* Delegate almost all control requests to the gadget driver,
 | 
					
						
							|  |  |  | 		 * except for a handful of ch9 status/feature requests that | 
					
						
							|  |  |  | 		 * hardware doesn't autodecode _and_ the gadget API hides. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		udc->ep0_in = (u.r.bRequestType & USB_DIR_IN) != 0; | 
					
						
							|  |  |  | 		udc->ep0_set_config = 0; | 
					
						
							|  |  |  | 		udc->ep0_pending = 1; | 
					
						
							|  |  |  | 		ep0->stopped = 0; | 
					
						
							|  |  |  | 		ep0->ackwait = 0; | 
					
						
							|  |  |  | 		switch (u.r.bRequest) { | 
					
						
							|  |  |  | 		case USB_REQ_SET_CONFIGURATION: | 
					
						
							|  |  |  | 			/* udc needs to know when ep != 0 is valid */ | 
					
						
							|  |  |  | 			if (u.r.bRequestType != USB_RECIP_DEVICE) | 
					
						
							|  |  |  | 				goto delegate; | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 			if (w_length != 0) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				goto do_stall; | 
					
						
							|  |  |  | 			udc->ep0_set_config = 1; | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 			udc->ep0_reset_config = (w_value == 0); | 
					
						
							|  |  |  | 			VDBG("set config %d\n", w_value); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			/* update udc NOW since gadget driver may start
 | 
					
						
							|  |  |  | 			 * queueing requests immediately; clear config | 
					
						
							|  |  |  | 			 * later if it fails the request. | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			if (udc->ep0_reset_config) | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 				omap_writew(UDC_CLR_CFG, UDC_SYSCON2); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 				omap_writew(UDC_DEV_CFG, UDC_SYSCON2); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			update_otg(udc); | 
					
						
							|  |  |  | 			goto delegate; | 
					
						
							|  |  |  | 		case USB_REQ_CLEAR_FEATURE: | 
					
						
							|  |  |  | 			/* clear endpoint halt */ | 
					
						
							|  |  |  | 			if (u.r.bRequestType != USB_RECIP_ENDPOINT) | 
					
						
							|  |  |  | 				goto delegate; | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 			if (w_value != USB_ENDPOINT_HALT | 
					
						
							|  |  |  | 					|| w_length != 0) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				goto do_stall; | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 			ep = &udc->ep[w_index & 0xf]; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			if (ep != ep0) { | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 				if (w_index & USB_DIR_IN) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 					ep += 16; | 
					
						
							|  |  |  | 				if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC | 
					
						
							| 
									
										
										
										
											2012-03-12 20:25:35 +02:00
										 |  |  | 						|| !ep->ep.desc) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 					goto do_stall; | 
					
						
							|  |  |  | 				use_ep(ep, 0); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 				omap_writew(udc->clr_halt, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				ep->ackwait = 0; | 
					
						
							|  |  |  | 				if (!(ep->bEndpointAddress & USB_DIR_IN)) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 					omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 					ep->ackwait = 1 + ep->double_buf; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 				/* NOTE:  assumes the host behaves sanely,
 | 
					
						
							|  |  |  | 				 * only clearing real halts.  Else we may | 
					
						
							|  |  |  | 				 * need to kill pending transfers and then | 
					
						
							|  |  |  | 				 * restart the queue... very messy for DMA! | 
					
						
							|  |  |  | 				 */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			VDBG("%s halt cleared by host\n", ep->name); | 
					
						
							|  |  |  | 			goto ep0out_status_stage; | 
					
						
							|  |  |  | 		case USB_REQ_SET_FEATURE: | 
					
						
							|  |  |  | 			/* set endpoint halt */ | 
					
						
							|  |  |  | 			if (u.r.bRequestType != USB_RECIP_ENDPOINT) | 
					
						
							|  |  |  | 				goto delegate; | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 			if (w_value != USB_ENDPOINT_HALT | 
					
						
							|  |  |  | 					|| w_length != 0) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				goto do_stall; | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 			ep = &udc->ep[w_index & 0xf]; | 
					
						
							|  |  |  | 			if (w_index & USB_DIR_IN) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				ep += 16; | 
					
						
							|  |  |  | 			if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC | 
					
						
							| 
									
										
										
										
											2012-03-12 20:25:35 +02:00
										 |  |  | 					|| ep == ep0 || !ep->ep.desc) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				goto do_stall; | 
					
						
							|  |  |  | 			if (use_dma && ep->has_dma) { | 
					
						
							|  |  |  | 				/* this has rude side-effects (aborts) and
 | 
					
						
							|  |  |  | 				 * can't really work if DMA-IN is active | 
					
						
							|  |  |  | 				 */ | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 				DBG("%s host set_halt, NYET\n", ep->name); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				goto do_stall; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			use_ep(ep, 0); | 
					
						
							|  |  |  | 			/* can't halt if fifo isn't empty... */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(UDC_CLR_EP, UDC_CTRL); | 
					
						
							|  |  |  | 			omap_writew(UDC_SET_HALT, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			VDBG("%s halted by host\n", ep->name); | 
					
						
							|  |  |  | ep0out_status_stage: | 
					
						
							|  |  |  | 			status = 0; | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(UDC_EP_SEL|UDC_EP_DIR, UDC_EP_NUM); | 
					
						
							|  |  |  | 			omap_writew(UDC_CLR_EP, UDC_CTRL); | 
					
						
							|  |  |  | 			omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); | 
					
						
							|  |  |  | 			omap_writew(UDC_EP_DIR, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			udc->ep0_pending = 0; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case USB_REQ_GET_STATUS: | 
					
						
							| 
									
										
										
										
											2007-03-21 12:26:32 -07:00
										 |  |  | 			/* USB_ENDPOINT_HALT status? */ | 
					
						
							|  |  |  | 			if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT)) | 
					
						
							|  |  |  | 				goto intf_status; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* ep0 never stalls */ | 
					
						
							|  |  |  | 			if (!(w_index & 0xf)) | 
					
						
							|  |  |  | 				goto zero_status; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* only active endpoints count */ | 
					
						
							|  |  |  | 			ep = &udc->ep[w_index & 0xf]; | 
					
						
							|  |  |  | 			if (w_index & USB_DIR_IN) | 
					
						
							|  |  |  | 				ep += 16; | 
					
						
							| 
									
										
										
										
											2012-03-12 20:25:35 +02:00
										 |  |  | 			if (!ep->ep.desc) | 
					
						
							| 
									
										
										
										
											2007-03-21 12:26:32 -07:00
										 |  |  | 				goto do_stall; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* iso never stalls */ | 
					
						
							|  |  |  | 			if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) | 
					
						
							|  |  |  | 				goto zero_status; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* FIXME don't assume non-halted endpoints!! */ | 
					
						
							|  |  |  | 			ERR("%s status, can't report\n", ep->ep.name); | 
					
						
							|  |  |  | 			goto do_stall; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | intf_status: | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			/* return interface status.  if we were pedantic,
 | 
					
						
							|  |  |  | 			 * we'd detect non-existent interfaces, and stall. | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			if (u.r.bRequestType | 
					
						
							|  |  |  | 					!= (USB_DIR_IN|USB_RECIP_INTERFACE)) | 
					
						
							|  |  |  | 				goto delegate; | 
					
						
							| 
									
										
										
										
											2007-03-21 12:26:32 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | zero_status: | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			/* return two zero bytes */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(UDC_EP_SEL|UDC_EP_DIR, UDC_EP_NUM); | 
					
						
							|  |  |  | 			omap_writew(0, UDC_DATA); | 
					
						
							|  |  |  | 			omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); | 
					
						
							|  |  |  | 			omap_writew(UDC_EP_DIR, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			status = 0; | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 			VDBG("GET_STATUS, interface %d\n", w_index); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			/* next, status stage */ | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | delegate: | 
					
						
							|  |  |  | 			/* activate the ep0out fifo right away */ | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 			if (!udc->ep0_in && w_length) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 				omap_writew(0, UDC_EP_NUM); | 
					
						
							|  |  |  | 				omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* gadget drivers see class/vendor specific requests,
 | 
					
						
							|  |  |  | 			 * {SET,GET}_{INTERFACE,DESCRIPTOR,CONFIGURATION}, | 
					
						
							|  |  |  | 			 * and more | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			VDBG("SETUP %02x.%02x v%04x i%04x l%04x\n", | 
					
						
							|  |  |  | 				u.r.bRequestType, u.r.bRequest, | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 				w_value, w_index, w_length); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef	w_value
 | 
					
						
							|  |  |  | #undef	w_index
 | 
					
						
							|  |  |  | #undef	w_length
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			/* The gadget driver may return an error here,
 | 
					
						
							|  |  |  | 			 * causing an immediate protocol stall. | 
					
						
							|  |  |  | 			 * | 
					
						
							|  |  |  | 			 * Else it must issue a response, either queueing a | 
					
						
							|  |  |  | 			 * response buffer for the DATA stage, or halting ep0 | 
					
						
							|  |  |  | 			 * (causing a protocol stall, not a real halt).  A | 
					
						
							|  |  |  | 			 * zero length buffer means no DATA stage. | 
					
						
							|  |  |  | 			 * | 
					
						
							|  |  |  | 			 * It's fine to issue that response after the setup() | 
					
						
							|  |  |  | 			 * call returns, and this IRQ was handled. | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			udc->ep0_setup = 1; | 
					
						
							|  |  |  | 			spin_unlock(&udc->lock); | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 			status = udc->driver->setup(&udc->gadget, &u.r); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			spin_lock(&udc->lock); | 
					
						
							|  |  |  | 			udc->ep0_setup = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (status < 0) { | 
					
						
							|  |  |  | do_stall: | 
					
						
							|  |  |  | 			VDBG("req %02x.%02x protocol STALL; stat %d\n", | 
					
						
							|  |  |  | 					u.r.bRequestType, u.r.bRequest, status); | 
					
						
							|  |  |  | 			if (udc->ep0_set_config) { | 
					
						
							|  |  |  | 				if (udc->ep0_reset_config) | 
					
						
							| 
									
										
										
										
											2008-07-25 01:45:52 -07:00
										 |  |  | 					WARNING("error resetting config?\n"); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				else | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 					omap_writew(UDC_CLR_CFG, UDC_SYSCON2); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(UDC_STALL_CMD, UDC_SYSCON2); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			udc->ep0_pending = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define OTG_FLAGS (UDC_B_HNP_ENABLE|UDC_A_HNP_SUPPORT|UDC_A_ALT_HNP_SUPPORT)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void devstate_irq(struct omap_udc *udc, u16 irq_src) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u16	devstat, change; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	devstat = omap_readw(UDC_DEVSTAT); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	change = devstat ^ udc->devstat; | 
					
						
							|  |  |  | 	udc->devstat = devstat; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (change & (UDC_USB_RESET|UDC_ATT)) { | 
					
						
							|  |  |  | 		udc_quiesce(udc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (change & UDC_ATT) { | 
					
						
							|  |  |  | 			/* driver for any external transceiver will
 | 
					
						
							|  |  |  | 			 * have called omap_vbus_session() already | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			if (devstat & UDC_ATT) { | 
					
						
							|  |  |  | 				udc->gadget.speed = USB_SPEED_FULL; | 
					
						
							|  |  |  | 				VDBG("connect\n"); | 
					
						
							| 
									
										
										
										
											2012-06-26 17:40:32 +05:30
										 |  |  | 				if (IS_ERR_OR_NULL(udc->transceiver)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 					pullup_enable(udc); | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 				/* if (driver->connect) call it */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			} else if (udc->gadget.speed != USB_SPEED_UNKNOWN) { | 
					
						
							|  |  |  | 				udc->gadget.speed = USB_SPEED_UNKNOWN; | 
					
						
							| 
									
										
										
										
											2012-06-26 17:40:32 +05:30
										 |  |  | 				if (IS_ERR_OR_NULL(udc->transceiver)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 					pullup_disable(udc); | 
					
						
							|  |  |  | 				DBG("disconnect, gadget %s\n", | 
					
						
							|  |  |  | 					udc->driver->driver.name); | 
					
						
							|  |  |  | 				if (udc->driver->disconnect) { | 
					
						
							|  |  |  | 					spin_unlock(&udc->lock); | 
					
						
							|  |  |  | 					udc->driver->disconnect(&udc->gadget); | 
					
						
							|  |  |  | 					spin_lock(&udc->lock); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			change &= ~UDC_ATT; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (change & UDC_USB_RESET) { | 
					
						
							|  |  |  | 			if (devstat & UDC_USB_RESET) { | 
					
						
							|  |  |  | 				VDBG("RESET=1\n"); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				udc->gadget.speed = USB_SPEED_FULL; | 
					
						
							|  |  |  | 				INFO("USB reset done, gadget %s\n", | 
					
						
							|  |  |  | 					udc->driver->driver.name); | 
					
						
							|  |  |  | 				/* ep0 traffic is legal from now on */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 				omap_writew(UDC_DS_CHG_IE | UDC_EP0_IE, | 
					
						
							|  |  |  | 						UDC_IRQ_EN); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			change &= ~UDC_USB_RESET; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (change & UDC_SUS) { | 
					
						
							|  |  |  | 		if (udc->gadget.speed != USB_SPEED_UNKNOWN) { | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 			/* FIXME tell isp1301 to suspend/resume (?) */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			if (devstat & UDC_SUS) { | 
					
						
							|  |  |  | 				VDBG("suspend\n"); | 
					
						
							|  |  |  | 				update_otg(udc); | 
					
						
							|  |  |  | 				/* HNP could be under way already */ | 
					
						
							|  |  |  | 				if (udc->gadget.speed == USB_SPEED_FULL | 
					
						
							|  |  |  | 						&& udc->driver->suspend) { | 
					
						
							|  |  |  | 					spin_unlock(&udc->lock); | 
					
						
							|  |  |  | 					udc->driver->suspend(&udc->gadget); | 
					
						
							|  |  |  | 					spin_lock(&udc->lock); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-06-26 17:40:32 +05:30
										 |  |  | 				if (!IS_ERR_OR_NULL(udc->transceiver)) | 
					
						
							| 
									
										
										
										
											2012-02-13 13:24:18 +02:00
										 |  |  | 					usb_phy_set_suspend( | 
					
						
							|  |  |  | 							udc->transceiver, 1); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				VDBG("resume\n"); | 
					
						
							| 
									
										
										
										
											2012-06-26 17:40:32 +05:30
										 |  |  | 				if (!IS_ERR_OR_NULL(udc->transceiver)) | 
					
						
							| 
									
										
										
										
											2012-02-13 13:24:18 +02:00
										 |  |  | 					usb_phy_set_suspend( | 
					
						
							|  |  |  | 							udc->transceiver, 0); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				if (udc->gadget.speed == USB_SPEED_FULL | 
					
						
							|  |  |  | 						&& udc->driver->resume) { | 
					
						
							|  |  |  | 					spin_unlock(&udc->lock); | 
					
						
							|  |  |  | 					udc->driver->resume(&udc->gadget); | 
					
						
							|  |  |  | 					spin_lock(&udc->lock); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		change &= ~UDC_SUS; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (!cpu_is_omap15xx() && (change & OTG_FLAGS)) { | 
					
						
							|  |  |  | 		update_otg(udc); | 
					
						
							|  |  |  | 		change &= ~OTG_FLAGS; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	change &= ~(UDC_CFG|UDC_DEF|UDC_ADD); | 
					
						
							|  |  |  | 	if (change) | 
					
						
							|  |  |  | 		VDBG("devstat %03x, ignore change %03x\n", | 
					
						
							|  |  |  | 			devstat,  change); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	omap_writew(UDC_DS_CHG, UDC_IRQ_SRC); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around.  On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable.  On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions.  Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller.  A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386.  I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs.  Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
	struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
	set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
	-	update_process_times(user_mode(regs));
	-	profile_tick(CPU_PROFILING, regs);
	+	update_process_times(user_mode(get_irq_regs()));
	+	profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
 (*) input_dev() is now gone entirely.  The regs pointer is no longer stored in
     the input_dev struct.
 (*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking.  It does
     something different depending on whether it's been supplied with a regs
     pointer or not.
 (*) Various IRQ handler function pointers have been moved to type
     irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
											
										 
											2006-10-05 14:55:46 +01:00
										 |  |  | static irqreturn_t omap_udc_irq(int irq, void *_udc) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct omap_udc	*udc = _udc; | 
					
						
							|  |  |  | 	u16		irq_src; | 
					
						
							|  |  |  | 	irqreturn_t	status = IRQ_NONE; | 
					
						
							|  |  |  | 	unsigned long	flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&udc->lock, flags); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	irq_src = omap_readw(UDC_IRQ_SRC); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Device state change (usb ch9 stuff) */ | 
					
						
							|  |  |  | 	if (irq_src & UDC_DS_CHG) { | 
					
						
							|  |  |  | 		devstate_irq(_udc, irq_src); | 
					
						
							|  |  |  | 		status = IRQ_HANDLED; | 
					
						
							|  |  |  | 		irq_src &= ~UDC_DS_CHG; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* EP0 control transfers */ | 
					
						
							|  |  |  | 	if (irq_src & (UDC_EP0_RX|UDC_SETUP|UDC_EP0_TX)) { | 
					
						
							|  |  |  | 		ep0_irq(_udc, irq_src); | 
					
						
							|  |  |  | 		status = IRQ_HANDLED; | 
					
						
							|  |  |  | 		irq_src &= ~(UDC_EP0_RX|UDC_SETUP|UDC_EP0_TX); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* DMA transfer completion */ | 
					
						
							|  |  |  | 	if (use_dma && (irq_src & (UDC_TXN_DONE|UDC_RXN_CNT|UDC_RXN_EOT))) { | 
					
						
							|  |  |  | 		dma_irq(_udc, irq_src); | 
					
						
							|  |  |  | 		status = IRQ_HANDLED; | 
					
						
							|  |  |  | 		irq_src &= ~(UDC_TXN_DONE|UDC_RXN_CNT|UDC_RXN_EOT); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	irq_src &= ~(UDC_IRQ_SOF | UDC_EPN_TX|UDC_EPN_RX); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (irq_src) | 
					
						
							|  |  |  | 		DBG("udc_irq, unhandled %03x\n", irq_src); | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&udc->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* workaround for seemingly-lost IRQs for RX ACKs... */ | 
					
						
							|  |  |  | #define PIO_OUT_TIMEOUT	(jiffies + HZ/3)
 | 
					
						
							|  |  |  | #define HALF_FULL(f)	(!((f)&(UDC_NON_ISO_FIFO_FULL|UDC_NON_ISO_FIFO_EMPTY)))
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void pio_out_timer(unsigned long _ep) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct omap_ep	*ep = (void *) _ep; | 
					
						
							|  |  |  | 	unsigned long	flags; | 
					
						
							|  |  |  | 	u16		stat_flg; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&ep->udc->lock, flags); | 
					
						
							|  |  |  | 	if (!list_empty(&ep->queue) && ep->ackwait) { | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 		use_ep(ep, UDC_EP_SEL); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		stat_flg = omap_readw(UDC_STAT_FLG); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if ((stat_flg & UDC_ACK) && (!(stat_flg & UDC_FIFO_EN) | 
					
						
							|  |  |  | 				|| (ep->double_buf && HALF_FULL(stat_flg)))) { | 
					
						
							|  |  |  | 			struct omap_req	*req; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			VDBG("%s: lose, %04x\n", ep->ep.name, stat_flg); | 
					
						
							|  |  |  | 			req = container_of(ep->queue.next, | 
					
						
							|  |  |  | 					struct omap_req, queue); | 
					
						
							|  |  |  | 			(void) read_fifo(ep, req); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(ep->bEndpointAddress, UDC_EP_NUM); | 
					
						
							|  |  |  | 			omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			ep->ackwait = 1 + ep->double_buf; | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 		} else | 
					
						
							|  |  |  | 			deselect_ep(); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	mod_timer(&ep->timer, PIO_OUT_TIMEOUT); | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&ep->udc->lock, flags); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around.  On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable.  On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions.  Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller.  A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386.  I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs.  Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
	struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
	set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
	-	update_process_times(user_mode(regs));
	-	profile_tick(CPU_PROFILING, regs);
	+	update_process_times(user_mode(get_irq_regs()));
	+	profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
 (*) input_dev() is now gone entirely.  The regs pointer is no longer stored in
     the input_dev struct.
 (*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking.  It does
     something different depending on whether it's been supplied with a regs
     pointer or not.
 (*) Various IRQ handler function pointers have been moved to type
     irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
											
										 
											2006-10-05 14:55:46 +01:00
										 |  |  | static irqreturn_t omap_udc_pio_irq(int irq, void *_dev) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	u16		epn_stat, irq_src; | 
					
						
							|  |  |  | 	irqreturn_t	status = IRQ_NONE; | 
					
						
							|  |  |  | 	struct omap_ep	*ep; | 
					
						
							|  |  |  | 	int		epnum; | 
					
						
							|  |  |  | 	struct omap_udc	*udc = _dev; | 
					
						
							|  |  |  | 	struct omap_req	*req; | 
					
						
							|  |  |  | 	unsigned long	flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&udc->lock, flags); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	epn_stat = omap_readw(UDC_EPN_STAT); | 
					
						
							|  |  |  | 	irq_src = omap_readw(UDC_IRQ_SRC); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* handle OUT first, to avoid some wasteful NAKs */ | 
					
						
							|  |  |  | 	if (irq_src & UDC_EPN_RX) { | 
					
						
							|  |  |  | 		epnum = (epn_stat >> 8) & 0x0f; | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew(UDC_EPN_RX, UDC_IRQ_SRC); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		status = IRQ_HANDLED; | 
					
						
							|  |  |  | 		ep = &udc->ep[epnum]; | 
					
						
							|  |  |  | 		ep->irqs++; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew(epnum | UDC_EP_SEL, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		ep->fnf = 0; | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		if (omap_readw(UDC_STAT_FLG) & UDC_ACK) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			ep->ackwait--; | 
					
						
							|  |  |  | 			if (!list_empty(&ep->queue)) { | 
					
						
							|  |  |  | 				int stat; | 
					
						
							|  |  |  | 				req = container_of(ep->queue.next, | 
					
						
							|  |  |  | 						struct omap_req, queue); | 
					
						
							|  |  |  | 				stat = read_fifo(ep, req); | 
					
						
							|  |  |  | 				if (!ep->double_buf) | 
					
						
							|  |  |  | 					ep->fnf = 1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/* min 6 clock delay before clearing EP_SEL ... */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		epn_stat = omap_readw(UDC_EPN_STAT); | 
					
						
							|  |  |  | 		epn_stat = omap_readw(UDC_EPN_STAT); | 
					
						
							|  |  |  | 		omap_writew(epnum, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* enabling fifo _after_ clearing ACK, contrary to docs,
 | 
					
						
							|  |  |  | 		 * reduces lossage; timer still needed though (sigh). | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if (ep->fnf) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writew(UDC_SET_FIFO_EN, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			ep->ackwait = 1 + ep->double_buf; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		mod_timer(&ep->timer, PIO_OUT_TIMEOUT); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* then IN transfers */ | 
					
						
							|  |  |  | 	else if (irq_src & UDC_EPN_TX) { | 
					
						
							|  |  |  | 		epnum = epn_stat & 0x0f; | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew(UDC_EPN_TX, UDC_IRQ_SRC); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		status = IRQ_HANDLED; | 
					
						
							|  |  |  | 		ep = &udc->ep[16 + epnum]; | 
					
						
							|  |  |  | 		ep->irqs++; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew(epnum | UDC_EP_DIR | UDC_EP_SEL, UDC_EP_NUM); | 
					
						
							|  |  |  | 		if (omap_readw(UDC_STAT_FLG) & UDC_ACK) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			ep->ackwait = 0; | 
					
						
							|  |  |  | 			if (!list_empty(&ep->queue)) { | 
					
						
							|  |  |  | 				req = container_of(ep->queue.next, | 
					
						
							|  |  |  | 						struct omap_req, queue); | 
					
						
							|  |  |  | 				(void) write_fifo(ep, req); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/* min 6 clock delay before clearing EP_SEL ... */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		epn_stat = omap_readw(UDC_EPN_STAT); | 
					
						
							|  |  |  | 		epn_stat = omap_readw(UDC_EPN_STAT); | 
					
						
							|  |  |  | 		omap_writew(epnum | UDC_EP_DIR, UDC_EP_NUM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		/* then 6 clocks before it'd tx */ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&udc->lock, flags); | 
					
						
							|  |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef	USE_ISO
 | 
					
						
							| 
									
										
											  
											
												IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around.  On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable.  On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions.  Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller.  A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386.  I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs.  Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
	struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
	set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
	-	update_process_times(user_mode(regs));
	-	profile_tick(CPU_PROFILING, regs);
	+	update_process_times(user_mode(get_irq_regs()));
	+	profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
 (*) input_dev() is now gone entirely.  The regs pointer is no longer stored in
     the input_dev struct.
 (*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking.  It does
     something different depending on whether it's been supplied with a regs
     pointer or not.
 (*) Various IRQ handler function pointers have been moved to type
     irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
											
										 
											2006-10-05 14:55:46 +01:00
										 |  |  | static irqreturn_t omap_udc_iso_irq(int irq, void *_dev) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct omap_udc	*udc = _dev; | 
					
						
							|  |  |  | 	struct omap_ep	*ep; | 
					
						
							|  |  |  | 	int		pending = 0; | 
					
						
							|  |  |  | 	unsigned long	flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&udc->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* handle all non-DMA ISO transfers */ | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	list_for_each_entry(ep, &udc->iso, iso) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		u16		stat; | 
					
						
							|  |  |  | 		struct omap_req	*req; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (ep->has_dma || list_empty(&ep->queue)) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		req = list_entry(ep->queue.next, struct omap_req, queue); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		use_ep(ep, UDC_EP_SEL); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		stat = omap_readw(UDC_STAT_FLG); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* NOTE: like the other controller drivers, this isn't
 | 
					
						
							|  |  |  | 		 * currently reporting lost or damaged frames. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if (ep->bEndpointAddress & USB_DIR_IN) { | 
					
						
							|  |  |  | 			if (stat & UDC_MISS_IN) | 
					
						
							|  |  |  | 				/* done(ep, req, -EPROTO) */; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				write_fifo(ep, req); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			int	status = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (stat & UDC_NO_RXPACKET) | 
					
						
							|  |  |  | 				status = -EREMOTEIO; | 
					
						
							|  |  |  | 			else if (stat & UDC_ISO_ERR) | 
					
						
							|  |  |  | 				status = -EILSEQ; | 
					
						
							|  |  |  | 			else if (stat & UDC_DATA_FLUSH) | 
					
						
							|  |  |  | 				status = -ENOSR; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (status) | 
					
						
							|  |  |  | 				/* done(ep, req, status) */; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				read_fifo(ep, req); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		deselect_ep(); | 
					
						
							|  |  |  | 		/* 6 wait states before next EP */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ep->irqs++; | 
					
						
							|  |  |  | 		if (!list_empty(&ep->queue)) | 
					
						
							|  |  |  | 			pending = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	if (!pending) { | 
					
						
							|  |  |  | 		u16 w; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		w = omap_readw(UDC_IRQ_EN); | 
					
						
							|  |  |  | 		w &= ~UDC_SOF_IE; | 
					
						
							|  |  |  | 		omap_writew(w, UDC_IRQ_EN); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	omap_writew(UDC_IRQ_SOF, UDC_IRQ_SRC); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&udc->lock, flags); | 
					
						
							|  |  |  | 	return IRQ_HANDLED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-03-21 12:26:32 -07:00
										 |  |  | static inline int machine_without_vbus_sense(void) | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	return machine_is_omap_innovator() | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 		|| machine_is_omap_osk() | 
					
						
							|  |  |  | 		|| machine_is_sx1() | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 		/* No known omap7xx boards with vbus sense */ | 
					
						
							|  |  |  | 		|| cpu_is_omap7xx(); | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-24 10:52:52 +02:00
										 |  |  | static int omap_udc_start(struct usb_gadget *g, | 
					
						
							|  |  |  | 		struct usb_gadget_driver *driver) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	int		status = -ENODEV; | 
					
						
							|  |  |  | 	struct omap_ep	*ep; | 
					
						
							|  |  |  | 	unsigned long	flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&udc->lock, flags); | 
					
						
							|  |  |  | 	/* reset state */ | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		ep->irqs = 0; | 
					
						
							|  |  |  | 		if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		use_ep(ep, 0); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew(UDC_SET_HALT, UDC_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	udc->ep0_pending = 0; | 
					
						
							|  |  |  | 	udc->ep[0].irqs = 0; | 
					
						
							|  |  |  | 	udc->softconnect = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* hook up the driver */ | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 	driver->driver.bus = NULL; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	udc->driver = driver; | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&udc->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 	if (udc->dc_clk != NULL) | 
					
						
							|  |  |  | 		omap_udc_enable_clock(1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* connect to bus through transceiver */ | 
					
						
							| 
									
										
										
										
											2012-06-26 17:40:32 +05:30
										 |  |  | 	if (!IS_ERR_OR_NULL(udc->transceiver)) { | 
					
						
							| 
									
										
										
										
											2012-02-13 13:24:20 +02:00
										 |  |  | 		status = otg_set_peripheral(udc->transceiver->otg, | 
					
						
							|  |  |  | 						&udc->gadget); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		if (status < 0) { | 
					
						
							|  |  |  | 			ERR("can't bind to transceiver\n"); | 
					
						
							| 
									
										
										
										
											2014-05-21 09:04:21 +08:00
										 |  |  | 			udc->driver = NULL; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			goto done; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		if (can_pullup(udc)) | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 			pullup_enable(udc); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 			pullup_disable(udc); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* boards that don't have VBUS sensing can't autogate 48MHz;
 | 
					
						
							|  |  |  | 	 * can't enter deep sleep while a gadget driver is active. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2007-03-21 12:26:32 -07:00
										 |  |  | 	if (machine_without_vbus_sense()) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		omap_vbus_session(&udc->gadget, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | done: | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 	if (udc->dc_clk != NULL) | 
					
						
							|  |  |  | 		omap_udc_enable_clock(0); | 
					
						
							| 
									
										
										
										
											2013-01-24 10:52:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-24 10:52:52 +02:00
										 |  |  | static int omap_udc_stop(struct usb_gadget *g, | 
					
						
							|  |  |  | 		struct usb_gadget_driver *driver) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	unsigned long	flags; | 
					
						
							|  |  |  | 	int		status = -ENODEV; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 	if (udc->dc_clk != NULL) | 
					
						
							|  |  |  | 		omap_udc_enable_clock(1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-03-21 12:26:32 -07:00
										 |  |  | 	if (machine_without_vbus_sense()) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		omap_vbus_session(&udc->gadget, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-26 17:40:32 +05:30
										 |  |  | 	if (!IS_ERR_OR_NULL(udc->transceiver)) | 
					
						
							| 
									
										
										
										
											2012-02-13 13:24:20 +02:00
										 |  |  | 		(void) otg_set_peripheral(udc->transceiver->otg, NULL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		pullup_disable(udc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&udc->lock, flags); | 
					
						
							|  |  |  | 	udc_quiesce(udc); | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&udc->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 	udc->driver = NULL; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 	if (udc->dc_clk != NULL) | 
					
						
							|  |  |  | 		omap_udc_enable_clock(0); | 
					
						
							| 
									
										
										
										
											2013-01-24 10:52:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_USB_GADGET_DEBUG_FILES
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/seq_file.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const char proc_filename[] = "driver/udc"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FOURBITS "%s%s%s%s"
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | #define EIGHTBITS "%s%s%s%s%s%s%s%s"
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void proc_ep_show(struct seq_file *s, struct omap_ep *ep) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u16		stat_flg; | 
					
						
							|  |  |  | 	struct omap_req	*req; | 
					
						
							|  |  |  | 	char		buf[20]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	use_ep(ep, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (use_dma && ep->has_dma) | 
					
						
							|  |  |  | 		snprintf(buf, sizeof buf, "(%cxdma%d lch%d) ", | 
					
						
							|  |  |  | 			(ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r', | 
					
						
							|  |  |  | 			ep->dma_channel - 1, ep->lch); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		buf[0] = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	stat_flg = omap_readw(UDC_STAT_FLG); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	seq_printf(s, | 
					
						
							|  |  |  | 		"\n%s %s%s%sirqs %ld stat %04x " EIGHTBITS FOURBITS "%s\n", | 
					
						
							|  |  |  | 		ep->name, buf, | 
					
						
							|  |  |  | 		ep->double_buf ? "dbuf " : "", | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 		({ char *s; | 
					
						
							|  |  |  | 		switch (ep->ackwait) { | 
					
						
							|  |  |  | 		case 0: | 
					
						
							|  |  |  | 			s = ""; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 1: | 
					
						
							|  |  |  | 			s = "(ackw) "; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 2: | 
					
						
							|  |  |  | 			s = "(ackw2) "; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			s = "(?) "; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} s; }), | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		ep->irqs, stat_flg, | 
					
						
							|  |  |  | 		(stat_flg & UDC_NO_RXPACKET) ? "no_rxpacket " : "", | 
					
						
							|  |  |  | 		(stat_flg & UDC_MISS_IN) ? "miss_in " : "", | 
					
						
							|  |  |  | 		(stat_flg & UDC_DATA_FLUSH) ? "data_flush " : "", | 
					
						
							|  |  |  | 		(stat_flg & UDC_ISO_ERR) ? "iso_err " : "", | 
					
						
							|  |  |  | 		(stat_flg & UDC_ISO_FIFO_EMPTY) ? "iso_fifo_empty " : "", | 
					
						
							|  |  |  | 		(stat_flg & UDC_ISO_FIFO_FULL) ? "iso_fifo_full " : "", | 
					
						
							|  |  |  | 		(stat_flg & UDC_EP_HALTED) ? "HALT " : "", | 
					
						
							|  |  |  | 		(stat_flg & UDC_STALL) ? "STALL " : "", | 
					
						
							|  |  |  | 		(stat_flg & UDC_NAK) ? "NAK " : "", | 
					
						
							|  |  |  | 		(stat_flg & UDC_ACK) ? "ACK " : "", | 
					
						
							|  |  |  | 		(stat_flg & UDC_FIFO_EN) ? "fifo_en " : "", | 
					
						
							|  |  |  | 		(stat_flg & UDC_NON_ISO_FIFO_EMPTY) ? "fifo_empty " : "", | 
					
						
							|  |  |  | 		(stat_flg & UDC_NON_ISO_FIFO_FULL) ? "fifo_full " : ""); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	if (list_empty(&ep->queue)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		seq_printf(s, "\t(queue empty)\n"); | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 		list_for_each_entry(req, &ep->queue, queue) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			unsigned	length = req->req.actual; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (use_dma && buf[0]) { | 
					
						
							|  |  |  | 				length += ((ep->bEndpointAddress & USB_DIR_IN) | 
					
						
							|  |  |  | 						? dma_src_len : dma_dest_len) | 
					
						
							|  |  |  | 					(ep, req->req.dma + length); | 
					
						
							|  |  |  | 				buf[0] = 0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			seq_printf(s, "\treq %p len %d/%d buf %p\n", | 
					
						
							|  |  |  | 					&req->req, length, | 
					
						
							|  |  |  | 					req->req.length, req->req.buf); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char *trx_mode(unsigned m, int enabled) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	switch (m) { | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	case 0: | 
					
						
							|  |  |  | 		return enabled ? "*6wire" : "unused"; | 
					
						
							|  |  |  | 	case 1: | 
					
						
							|  |  |  | 		return "4wire"; | 
					
						
							|  |  |  | 	case 2: | 
					
						
							|  |  |  | 		return "3wire"; | 
					
						
							|  |  |  | 	case 3: | 
					
						
							|  |  |  | 		return "6wire"; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return "unknown"; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int proc_otg_show(struct seq_file *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32		tmp; | 
					
						
							| 
									
										
										
										
											2010-10-08 11:40:20 -06:00
										 |  |  | 	u32		trans = 0; | 
					
						
							|  |  |  | 	char		*ctrl_name = "(UNKNOWN)"; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-07 16:29:25 +04:00
										 |  |  | 	tmp = omap_readl(OTG_REV); | 
					
						
							| 
									
										
										
										
											2012-05-21 12:01:11 -07:00
										 |  |  | 	ctrl_name = "tranceiver_ctrl"; | 
					
						
							|  |  |  | 	trans = omap_readw(USB_TRANSCEIVER_CTRL); | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 	seq_printf(s, "\nOTG rev %d.%d, %s %05x\n", | 
					
						
							|  |  |  | 		tmp >> 4, tmp & 0xf, ctrl_name, trans); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	tmp = omap_readw(OTG_SYSCON_1); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	seq_printf(s, "otg_syscon1 %08x usb2 %s, usb1 %s, usb0 %s," | 
					
						
							|  |  |  | 			FOURBITS "\n", tmp, | 
					
						
							|  |  |  | 		trx_mode(USB2_TRX_MODE(tmp), trans & CONF_USB2_UNI_R), | 
					
						
							|  |  |  | 		trx_mode(USB1_TRX_MODE(tmp), trans & CONF_USB1_UNI_R), | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 		(USB0_TRX_MODE(tmp) == 0 && !cpu_is_omap1710()) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			? "internal" | 
					
						
							|  |  |  | 			: trx_mode(USB0_TRX_MODE(tmp), 1), | 
					
						
							|  |  |  | 		(tmp & OTG_IDLE_EN) ? " !otg" : "", | 
					
						
							|  |  |  | 		(tmp & HST_IDLE_EN) ? " !host" : "", | 
					
						
							|  |  |  | 		(tmp & DEV_IDLE_EN) ? " !dev" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_RESET_DONE) ? " reset_done" : " reset_active"); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	tmp = omap_readl(OTG_SYSCON_2); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	seq_printf(s, "otg_syscon2 %08x%s" EIGHTBITS | 
					
						
							|  |  |  | 			" b_ase_brst=%d hmc=%d\n", tmp, | 
					
						
							|  |  |  | 		(tmp & OTG_EN) ? " otg_en" : "", | 
					
						
							|  |  |  | 		(tmp & USBX_SYNCHRO) ? " synchro" : "", | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 		/* much more SRP stuff */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		(tmp & SRP_DATA) ? " srp_data" : "", | 
					
						
							|  |  |  | 		(tmp & SRP_VBUS) ? " srp_vbus" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_PADEN) ? " otg_paden" : "", | 
					
						
							|  |  |  | 		(tmp & HMC_PADEN) ? " hmc_paden" : "", | 
					
						
							|  |  |  | 		(tmp & UHOST_EN) ? " uhost_en" : "", | 
					
						
							|  |  |  | 		(tmp & HMC_TLLSPEED) ? " tllspeed" : "", | 
					
						
							|  |  |  | 		(tmp & HMC_TLLATTACH) ? " tllattach" : "", | 
					
						
							|  |  |  | 		B_ASE_BRST(tmp), | 
					
						
							|  |  |  | 		OTG_HMC(tmp)); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	tmp = omap_readl(OTG_CTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	seq_printf(s, "otg_ctrl    %06x" EIGHTBITS EIGHTBITS "%s\n", tmp, | 
					
						
							|  |  |  | 		(tmp & OTG_ASESSVLD) ? " asess" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_BSESSEND) ? " bsess_end" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_BSESSVLD) ? " bsess" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_VBUSVLD) ? " vbus" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_ID) ? " id" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_DRIVER_SEL) ? " DEVICE" : " HOST", | 
					
						
							|  |  |  | 		(tmp & OTG_A_SETB_HNPEN) ? " a_setb_hnpen" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_A_BUSREQ) ? " a_bus" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_B_HNPEN) ? " b_hnpen" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_B_BUSREQ) ? " b_bus" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_BUSDROP) ? " busdrop" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_PULLDOWN) ? " down" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_PULLUP) ? " up" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_DRV_VBUS) ? " drv" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_PD_VBUS) ? " pd_vb" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_PU_VBUS) ? " pu_vb" : "", | 
					
						
							|  |  |  | 		(tmp & OTG_PU_ID) ? " pu_id" : "" | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	tmp = omap_readw(OTG_IRQ_EN); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	seq_printf(s, "otg_irq_en  %04x" "\n", tmp); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	tmp = omap_readw(OTG_IRQ_SRC); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	seq_printf(s, "otg_irq_src %04x" "\n", tmp); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	tmp = omap_readw(OTG_OUTCTRL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	seq_printf(s, "otg_outctrl %04x" "\n", tmp); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	tmp = omap_readw(OTG_TEST); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	seq_printf(s, "otg_test    %04x" "\n", tmp); | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int proc_udc_show(struct seq_file *s, void *_) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u32		tmp; | 
					
						
							|  |  |  | 	struct omap_ep	*ep; | 
					
						
							|  |  |  | 	unsigned long	flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&udc->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	seq_printf(s, "%s, version: " DRIVER_VERSION | 
					
						
							|  |  |  | #ifdef	USE_ISO
 | 
					
						
							|  |  |  | 		" (iso)" | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 		"%s\n", | 
					
						
							|  |  |  | 		driver_desc, | 
					
						
							|  |  |  | 		use_dma ?  " (dma)" : ""); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	tmp = omap_readw(UDC_REV) & 0xff; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	seq_printf(s, | 
					
						
							|  |  |  | 		"UDC rev %d.%d, fifo mode %d, gadget %s\n" | 
					
						
							|  |  |  | 		"hmc %d, transceiver %s\n", | 
					
						
							|  |  |  | 		tmp >> 4, tmp & 0xf, | 
					
						
							|  |  |  | 		fifo_mode, | 
					
						
							|  |  |  | 		udc->driver ? udc->driver->driver.name : "(none)", | 
					
						
							|  |  |  | 		HMC, | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 		udc->transceiver | 
					
						
							|  |  |  | 			? udc->transceiver->label | 
					
						
							| 
									
										
										
										
											2012-05-21 12:01:11 -07:00
										 |  |  | 			: (cpu_is_omap1710() | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 				? "external" : "(none)")); | 
					
						
							| 
									
										
										
										
											2012-05-21 12:01:11 -07:00
										 |  |  | 	seq_printf(s, "ULPD control %04x req %04x status %04x\n", | 
					
						
							|  |  |  | 		omap_readw(ULPD_CLOCK_CTRL), | 
					
						
							|  |  |  | 		omap_readw(ULPD_SOFT_REQ), | 
					
						
							|  |  |  | 		omap_readw(ULPD_STATUS_REQ)); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* OTG controller registers */ | 
					
						
							|  |  |  | 	if (!cpu_is_omap15xx()) | 
					
						
							|  |  |  | 		proc_otg_show(s); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	tmp = omap_readw(UDC_SYSCON1); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	seq_printf(s, "\nsyscon1     %04x" EIGHTBITS "\n", tmp, | 
					
						
							|  |  |  | 		(tmp & UDC_CFG_LOCK) ? " cfg_lock" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_DATA_ENDIAN) ? " data_endian" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_DMA_ENDIAN) ? " dma_endian" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_NAK_EN) ? " nak" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_AUTODECODE_DIS) ? " autodecode_dis" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_SELF_PWR) ? " self_pwr" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_SOFF_DIS) ? " soff_dis" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_PULLUP_EN) ? " PULLUP" : ""); | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	/* syscon2 is write-only */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* UDC controller registers */ | 
					
						
							|  |  |  | 	if (!(tmp & UDC_PULLUP_EN)) { | 
					
						
							|  |  |  | 		seq_printf(s, "(suspended)\n"); | 
					
						
							|  |  |  | 		spin_unlock_irqrestore(&udc->lock, flags); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	tmp = omap_readw(UDC_DEVSTAT); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	seq_printf(s, "devstat     %04x" EIGHTBITS "%s%s\n", tmp, | 
					
						
							|  |  |  | 		(tmp & UDC_B_HNP_ENABLE) ? " b_hnp" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_A_HNP_SUPPORT) ? " a_hnp" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_A_ALT_HNP_SUPPORT) ? " a_alt_hnp" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_R_WK_OK) ? " r_wk_ok" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_USB_RESET) ? " usb_reset" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_SUS) ? " SUS" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_CFG) ? " CFG" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_ADD) ? " ADD" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_DEF) ? " DEF" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_ATT) ? " ATT" : ""); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	seq_printf(s, "sof         %04x\n", omap_readw(UDC_SOF)); | 
					
						
							|  |  |  | 	tmp = omap_readw(UDC_IRQ_EN); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	seq_printf(s, "irq_en      %04x" FOURBITS "%s\n", tmp, | 
					
						
							|  |  |  | 		(tmp & UDC_SOF_IE) ? " sof" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_EPN_RX_IE) ? " epn_rx" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_EPN_TX_IE) ? " epn_tx" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_DS_CHG_IE) ? " ds_chg" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_EP0_IE) ? " ep0" : ""); | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	tmp = omap_readw(UDC_IRQ_SRC); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	seq_printf(s, "irq_src     %04x" EIGHTBITS "%s%s\n", tmp, | 
					
						
							|  |  |  | 		(tmp & UDC_TXN_DONE) ? " txn_done" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_RXN_CNT) ? " rxn_cnt" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_RXN_EOT) ? " rxn_eot" : "", | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		(tmp & UDC_IRQ_SOF) ? " sof" : "", | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		(tmp & UDC_EPN_RX) ? " epn_rx" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_EPN_TX) ? " epn_tx" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_DS_CHG) ? " ds_chg" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_SETUP) ? " setup" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_EP0_RX) ? " ep0out" : "", | 
					
						
							|  |  |  | 		(tmp & UDC_EP0_TX) ? " ep0in" : ""); | 
					
						
							|  |  |  | 	if (use_dma) { | 
					
						
							|  |  |  | 		unsigned i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		tmp = omap_readw(UDC_DMA_IRQ_EN); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		seq_printf(s, "dma_irq_en  %04x%s" EIGHTBITS "\n", tmp, | 
					
						
							|  |  |  | 			(tmp & UDC_TX_DONE_IE(3)) ? " tx2_done" : "", | 
					
						
							|  |  |  | 			(tmp & UDC_RX_CNT_IE(3)) ? " rx2_cnt" : "", | 
					
						
							|  |  |  | 			(tmp & UDC_RX_EOT_IE(3)) ? " rx2_eot" : "", | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			(tmp & UDC_TX_DONE_IE(2)) ? " tx1_done" : "", | 
					
						
							|  |  |  | 			(tmp & UDC_RX_CNT_IE(2)) ? " rx1_cnt" : "", | 
					
						
							|  |  |  | 			(tmp & UDC_RX_EOT_IE(2)) ? " rx1_eot" : "", | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			(tmp & UDC_TX_DONE_IE(1)) ? " tx0_done" : "", | 
					
						
							|  |  |  | 			(tmp & UDC_RX_CNT_IE(1)) ? " rx0_cnt" : "", | 
					
						
							|  |  |  | 			(tmp & UDC_RX_EOT_IE(1)) ? " rx0_eot" : ""); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		tmp = omap_readw(UDC_RXDMA_CFG); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		seq_printf(s, "rxdma_cfg   %04x\n", tmp); | 
					
						
							|  |  |  | 		if (tmp) { | 
					
						
							|  |  |  | 			for (i = 0; i < 3; i++) { | 
					
						
							|  |  |  | 				if ((tmp & (0x0f << (i * 4))) == 0) | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				seq_printf(s, "rxdma[%d]    %04x\n", i, | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 						omap_readw(UDC_RXDMA(i + 1))); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		tmp = omap_readw(UDC_TXDMA_CFG); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		seq_printf(s, "txdma_cfg   %04x\n", tmp); | 
					
						
							|  |  |  | 		if (tmp) { | 
					
						
							|  |  |  | 			for (i = 0; i < 3; i++) { | 
					
						
							|  |  |  | 				if (!(tmp & (0x0f << (i * 4)))) | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				seq_printf(s, "txdma[%d]    %04x\n", i, | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 						omap_readw(UDC_TXDMA(i + 1))); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	tmp = omap_readw(UDC_DEVSTAT); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (tmp & UDC_ATT) { | 
					
						
							|  |  |  | 		proc_ep_show(s, &udc->ep[0]); | 
					
						
							|  |  |  | 		if (tmp & UDC_ADD) { | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 			list_for_each_entry(ep, &udc->gadget.ep_list, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 					ep.ep_list) { | 
					
						
							| 
									
										
										
										
											2012-03-12 20:25:35 +02:00
										 |  |  | 				if (ep->ep.desc) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 					proc_ep_show(s, ep); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&udc->lock, flags); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int proc_udc_open(struct inode *inode, struct file *file) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 	return single_open(file, proc_udc_show, NULL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-05 20:37:11 -03:00
										 |  |  | static const struct file_operations proc_ops = { | 
					
						
							| 
									
										
										
										
											2008-04-29 01:02:19 -07:00
										 |  |  | 	.owner		= THIS_MODULE, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	.open		= proc_udc_open, | 
					
						
							|  |  |  | 	.read		= seq_read, | 
					
						
							|  |  |  | 	.llseek		= seq_lseek, | 
					
						
							|  |  |  | 	.release	= single_release, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void create_proc_file(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-04-29 01:02:19 -07:00
										 |  |  | 	proc_create(proc_filename, 0, NULL, &proc_ops); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void remove_proc_file(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 	remove_proc_entry(proc_filename, NULL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void create_proc_file(void) {} | 
					
						
							|  |  |  | static inline void remove_proc_file(void) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Before this controller can enumerate, we need to pick an endpoint
 | 
					
						
							|  |  |  |  * configuration, or "fifo_mode"  That involves allocating 2KB of packet | 
					
						
							|  |  |  |  * buffer space among the endpoints we'll be operating. | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * NOTE: as of OMAP 1710 ES2.0, writing a new endpoint config when | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  |  * UDC_SYSCON_1.CFG_LOCK is set can now work.  We won't use that | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  |  * capability yet though. | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-11-19 13:21:48 -05:00
										 |  |  | static unsigned | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | omap_ep_setup(char *name, u8 addr, u8 type, | 
					
						
							|  |  |  | 		unsigned buf, unsigned maxp, int dbuf) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct omap_ep	*ep; | 
					
						
							|  |  |  | 	u16		epn_rxtx = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* OUT endpoints first, then IN */ | 
					
						
							|  |  |  | 	ep = &udc->ep[addr & 0xf]; | 
					
						
							|  |  |  | 	if (addr & USB_DIR_IN) | 
					
						
							|  |  |  | 		ep += 16; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* in case of ep init table bugs */ | 
					
						
							|  |  |  | 	BUG_ON(ep->name[0]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* chip setup ... bit values are same for IN, OUT */ | 
					
						
							|  |  |  | 	if (type == USB_ENDPOINT_XFER_ISOC) { | 
					
						
							|  |  |  | 		switch (maxp) { | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 		case 8: | 
					
						
							|  |  |  | 			epn_rxtx = 0 << 12; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 16: | 
					
						
							|  |  |  | 			epn_rxtx = 1 << 12; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 32: | 
					
						
							|  |  |  | 			epn_rxtx = 2 << 12; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 64: | 
					
						
							|  |  |  | 			epn_rxtx = 3 << 12; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 128: | 
					
						
							|  |  |  | 			epn_rxtx = 4 << 12; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 256: | 
					
						
							|  |  |  | 			epn_rxtx = 5 << 12; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 512: | 
					
						
							|  |  |  | 			epn_rxtx = 6 << 12; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			BUG(); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		epn_rxtx |= UDC_EPN_RX_ISO; | 
					
						
							|  |  |  | 		dbuf = 1; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		/* double-buffering "not supported" on 15xx,
 | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 		 * and ignored for PIO-IN on newer chips | 
					
						
							|  |  |  | 		 * (for more reliable behavior) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2012-05-21 12:01:11 -07:00
										 |  |  | 		if (!use_dma || cpu_is_omap15xx()) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			dbuf = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		switch (maxp) { | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 		case 8: | 
					
						
							|  |  |  | 			epn_rxtx = 0 << 12; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 16: | 
					
						
							|  |  |  | 			epn_rxtx = 1 << 12; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 32: | 
					
						
							|  |  |  | 			epn_rxtx = 2 << 12; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 64: | 
					
						
							|  |  |  | 			epn_rxtx = 3 << 12; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			BUG(); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (dbuf && addr) | 
					
						
							|  |  |  | 			epn_rxtx |= UDC_EPN_RX_DB; | 
					
						
							|  |  |  | 		init_timer(&ep->timer); | 
					
						
							|  |  |  | 		ep->timer.function = pio_out_timer; | 
					
						
							|  |  |  | 		ep->timer.data = (unsigned long) ep; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (addr) | 
					
						
							|  |  |  | 		epn_rxtx |= UDC_EPN_RX_VALID; | 
					
						
							|  |  |  | 	BUG_ON(buf & 0x07); | 
					
						
							|  |  |  | 	epn_rxtx |= buf >> 3; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	DBG("%s addr %02x rxtx %04x maxp %d%s buf %d\n", | 
					
						
							|  |  |  | 		name, addr, epn_rxtx, maxp, dbuf ? "x2" : "", buf); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (addr & USB_DIR_IN) | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew(epn_rxtx, UDC_EP_TX(addr & 0xf)); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew(epn_rxtx, UDC_EP_RX(addr)); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* next endpoint's buffer starts after this one's */ | 
					
						
							|  |  |  | 	buf += maxp; | 
					
						
							|  |  |  | 	if (dbuf) | 
					
						
							|  |  |  | 		buf += maxp; | 
					
						
							|  |  |  | 	BUG_ON(buf > 2048); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* set up driver data structures */ | 
					
						
							|  |  |  | 	BUG_ON(strlen(name) >= sizeof ep->name); | 
					
						
							|  |  |  | 	strlcpy(ep->name, name, sizeof ep->name); | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&ep->queue); | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&ep->iso); | 
					
						
							|  |  |  | 	ep->bEndpointAddress = addr; | 
					
						
							|  |  |  | 	ep->bmAttributes = type; | 
					
						
							|  |  |  | 	ep->double_buf = dbuf; | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 	ep->udc = udc; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ep->ep.name = ep->name; | 
					
						
							|  |  |  | 	ep->ep.ops = &omap_ep_ops; | 
					
						
							| 
									
										
										
										
											2013-12-13 12:23:38 +01:00
										 |  |  | 	ep->maxpacket = maxp; | 
					
						
							|  |  |  | 	usb_ep_set_maxpacket_limit(&ep->ep, ep->maxpacket); | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return buf; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void omap_udc_release(struct device *dev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	complete(udc->done); | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	kfree(udc); | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 	udc = NULL; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-19 13:21:48 -05:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2012-02-13 13:24:02 +02:00
										 |  |  | omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	unsigned	tmp, buf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* abolish any previous hardware state */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	omap_writew(0, UDC_SYSCON1); | 
					
						
							|  |  |  | 	omap_writew(0, UDC_IRQ_EN); | 
					
						
							|  |  |  | 	omap_writew(UDC_IRQ_SRC_MASK, UDC_IRQ_SRC); | 
					
						
							|  |  |  | 	omap_writew(0, UDC_DMA_IRQ_EN); | 
					
						
							|  |  |  | 	omap_writew(0, UDC_RXDMA_CFG); | 
					
						
							|  |  |  | 	omap_writew(0, UDC_TXDMA_CFG); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* UDC_PULLUP_EN gates the chip clock */ | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	/* OTG_SYSCON_1 |= DEV_IDLE_EN; */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-06 20:33:17 -08:00
										 |  |  | 	udc = kzalloc(sizeof(*udc), GFP_KERNEL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (!udc) | 
					
						
							|  |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	spin_lock_init(&udc->lock); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	udc->gadget.ops = &omap_gadget_ops; | 
					
						
							|  |  |  | 	udc->gadget.ep0 = &udc->ep[0].ep; | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&udc->gadget.ep_list); | 
					
						
							|  |  |  | 	INIT_LIST_HEAD(&udc->iso); | 
					
						
							|  |  |  | 	udc->gadget.speed = USB_SPEED_UNKNOWN; | 
					
						
							| 
									
										
										
										
											2011-11-19 18:27:37 +01:00
										 |  |  | 	udc->gadget.max_speed = USB_SPEED_FULL; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	udc->gadget.name = driver_name; | 
					
						
							|  |  |  | 	udc->transceiver = xceiv; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ep0 is special; put it right after the SETUP buffer */ | 
					
						
							|  |  |  | 	buf = omap_ep_setup("ep0", 0, USB_ENDPOINT_XFER_CONTROL, | 
					
						
							|  |  |  | 			8 /* after SETUP */, 64 /* maxpacket */, 0); | 
					
						
							|  |  |  | 	list_del_init(&udc->ep[0].ep.ep_list); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* initially disable all non-ep0 endpoints */ | 
					
						
							|  |  |  | 	for (tmp = 1; tmp < 15; tmp++) { | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_writew(0, UDC_EP_RX(tmp)); | 
					
						
							|  |  |  | 		omap_writew(0, UDC_EP_TX(tmp)); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | #define OMAP_BULK_EP(name, addr) \
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	buf = omap_ep_setup(name "-bulk", addr, \ | 
					
						
							|  |  |  | 			USB_ENDPOINT_XFER_BULK, buf, 64, 1); | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | #define OMAP_INT_EP(name, addr, maxp) \
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	buf = omap_ep_setup(name "-int", addr, \ | 
					
						
							|  |  |  | 			USB_ENDPOINT_XFER_INT, buf, maxp, 0); | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | #define OMAP_ISO_EP(name, addr, maxp) \
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	buf = omap_ep_setup(name "-iso", addr, \ | 
					
						
							|  |  |  | 			USB_ENDPOINT_XFER_ISOC, buf, maxp, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (fifo_mode) { | 
					
						
							|  |  |  | 	case 0: | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep1in",  USB_DIR_IN  | 1); | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep2out", USB_DIR_OUT | 2); | 
					
						
							|  |  |  | 		OMAP_INT_EP("ep3in",   USB_DIR_IN  | 3, 16); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case 1: | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep1in",  USB_DIR_IN  | 1); | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep2out", USB_DIR_OUT | 2); | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 		OMAP_INT_EP("ep9in",   USB_DIR_IN  | 9, 16); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		OMAP_BULK_EP("ep3in",  USB_DIR_IN  | 3); | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep4out", USB_DIR_OUT | 4); | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 		OMAP_INT_EP("ep10in",  USB_DIR_IN  | 10, 16); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep5in",  USB_DIR_IN  | 5); | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep5out", USB_DIR_OUT | 5); | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 		OMAP_INT_EP("ep11in",  USB_DIR_IN  | 11, 16); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		OMAP_BULK_EP("ep6in",  USB_DIR_IN  | 6); | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep6out", USB_DIR_OUT | 6); | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 		OMAP_INT_EP("ep12in",  USB_DIR_IN  | 12, 16); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep7in",  USB_DIR_IN  | 7); | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep7out", USB_DIR_OUT | 7); | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 		OMAP_INT_EP("ep13in",  USB_DIR_IN  | 13, 16); | 
					
						
							|  |  |  | 		OMAP_INT_EP("ep13out", USB_DIR_OUT | 13, 16); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		OMAP_BULK_EP("ep8in",  USB_DIR_IN  | 8); | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep8out", USB_DIR_OUT | 8); | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 		OMAP_INT_EP("ep14in",  USB_DIR_IN  | 14, 16); | 
					
						
							|  |  |  | 		OMAP_INT_EP("ep14out", USB_DIR_OUT | 14, 16); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep15in",  USB_DIR_IN  | 15); | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep15out", USB_DIR_OUT | 15); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef	USE_ISO
 | 
					
						
							|  |  |  | 	case 2:			/* mixed iso/bulk */ | 
					
						
							|  |  |  | 		OMAP_ISO_EP("ep1in",   USB_DIR_IN  | 1, 256); | 
					
						
							|  |  |  | 		OMAP_ISO_EP("ep2out",  USB_DIR_OUT | 2, 256); | 
					
						
							|  |  |  | 		OMAP_ISO_EP("ep3in",   USB_DIR_IN  | 3, 128); | 
					
						
							|  |  |  | 		OMAP_ISO_EP("ep4out",  USB_DIR_OUT | 4, 128); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		OMAP_INT_EP("ep5in",   USB_DIR_IN  | 5, 16); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep6in",  USB_DIR_IN  | 6); | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep7out", USB_DIR_OUT | 7); | 
					
						
							|  |  |  | 		OMAP_INT_EP("ep8in",   USB_DIR_IN  | 8, 16); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case 3:			/* mixed bulk/iso */ | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep1in",  USB_DIR_IN  | 1); | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep2out", USB_DIR_OUT | 2); | 
					
						
							|  |  |  | 		OMAP_INT_EP("ep3in",   USB_DIR_IN  | 3, 16); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep4in",  USB_DIR_IN  | 4); | 
					
						
							|  |  |  | 		OMAP_BULK_EP("ep5out", USB_DIR_OUT | 5); | 
					
						
							|  |  |  | 		OMAP_INT_EP("ep6in",   USB_DIR_IN  | 6, 16); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		OMAP_ISO_EP("ep7in",   USB_DIR_IN  | 7, 256); | 
					
						
							|  |  |  | 		OMAP_ISO_EP("ep8out",  USB_DIR_OUT | 8, 256); | 
					
						
							|  |  |  | 		OMAP_INT_EP("ep9in",   USB_DIR_IN  | 9, 16); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* add more modes as needed */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		ERR("unsupported fifo_mode #%d\n", fifo_mode); | 
					
						
							|  |  |  | 		return -ENODEV; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	omap_writew(UDC_CFG_LOCK|UDC_SELF_PWR, UDC_SYSCON1); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	INFO("fifo mode %d, %d bytes not used\n", fifo_mode, 2048 - buf); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-19 13:21:48 -05:00
										 |  |  | static int omap_udc_probe(struct platform_device *pdev) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	int			status = -ENODEV; | 
					
						
							|  |  |  | 	int			hmc; | 
					
						
							| 
									
										
										
										
											2012-02-13 13:24:02 +02:00
										 |  |  | 	struct usb_phy		*xceiv = NULL; | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 	const char		*type = NULL; | 
					
						
							| 
									
										
										
										
											2013-07-30 17:00:51 +09:00
										 |  |  | 	struct omap_usb_config	*config = dev_get_platdata(&pdev->dev); | 
					
						
							| 
									
										
										
										
											2012-05-21 12:01:11 -07:00
										 |  |  | 	struct clk		*dc_clk = NULL; | 
					
						
							|  |  |  | 	struct clk		*hhc_clk = NULL; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:27:52 +03:00
										 |  |  | 	if (cpu_is_omap7xx()) | 
					
						
							|  |  |  | 		use_dma = 0; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* NOTE:  "knows" the order of the resources! */ | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 	if (!request_mem_region(pdev->resource[0].start, | 
					
						
							| 
									
										
										
										
											2005-11-09 22:32:44 +00:00
										 |  |  | 			pdev->resource[0].end - pdev->resource[0].start + 1, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			driver_name)) { | 
					
						
							|  |  |  | 		DBG("request_mem_region failed\n"); | 
					
						
							|  |  |  | 		return -EBUSY; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 	if (cpu_is_omap16xx()) { | 
					
						
							|  |  |  | 		dc_clk = clk_get(&pdev->dev, "usb_dc_ck"); | 
					
						
							|  |  |  | 		hhc_clk = clk_get(&pdev->dev, "usb_hhc_ck"); | 
					
						
							|  |  |  | 		BUG_ON(IS_ERR(dc_clk) || IS_ERR(hhc_clk)); | 
					
						
							|  |  |  | 		/* can't use omap_udc_enable_clock yet */ | 
					
						
							|  |  |  | 		clk_enable(dc_clk); | 
					
						
							|  |  |  | 		clk_enable(hhc_clk); | 
					
						
							|  |  |  | 		udelay(100); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-22 10:10:52 -08:00
										 |  |  | 	if (cpu_is_omap7xx()) { | 
					
						
							|  |  |  | 		dc_clk = clk_get(&pdev->dev, "usb_dc_ck"); | 
					
						
							|  |  |  | 		hhc_clk = clk_get(&pdev->dev, "l3_ocpi_ck"); | 
					
						
							|  |  |  | 		BUG_ON(IS_ERR(dc_clk) || IS_ERR(hhc_clk)); | 
					
						
							|  |  |  | 		/* can't use omap_udc_enable_clock yet */ | 
					
						
							|  |  |  | 		clk_enable(dc_clk); | 
					
						
							|  |  |  | 		clk_enable(hhc_clk); | 
					
						
							|  |  |  | 		udelay(100); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	INFO("OMAP UDC rev %d.%d%s\n", | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 		omap_readw(UDC_REV) >> 4, omap_readw(UDC_REV) & 0xf, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		config->otg ? ", Mini-AB" : ""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* use the mode given to us by board init code */ | 
					
						
							|  |  |  | 	if (cpu_is_omap15xx()) { | 
					
						
							|  |  |  | 		hmc = HMC_1510; | 
					
						
							|  |  |  | 		type = "(unknown)"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-03-21 12:26:32 -07:00
										 |  |  | 		if (machine_without_vbus_sense()) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			/* just set up software VBUS detect, and then
 | 
					
						
							|  |  |  | 			 * later rig it so we always report VBUS. | 
					
						
							|  |  |  | 			 * FIXME without really sensing VBUS, we can't | 
					
						
							|  |  |  | 			 * know when to turn PULLUP_EN on/off; and that | 
					
						
							|  |  |  | 			 * means we always "need" the 48MHz clock. | 
					
						
							|  |  |  | 			 */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			u32 tmp = omap_readl(FUNC_MUX_CTRL_0); | 
					
						
							|  |  |  | 			tmp &= ~VBUS_CTRL_1510; | 
					
						
							|  |  |  | 			omap_writel(tmp, FUNC_MUX_CTRL_0); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			tmp |= VBUS_MODE_1510; | 
					
						
							|  |  |  | 			tmp &= ~VBUS_CTRL_1510; | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 			omap_writel(tmp, FUNC_MUX_CTRL_0); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 		/* The transceiver may package some GPIO logic or handle
 | 
					
						
							|  |  |  | 		 * loopback and/or transceiverless setup; if we find one, | 
					
						
							|  |  |  | 		 * use it.  Except for OTG, we don't _need_ to talk to one; | 
					
						
							|  |  |  | 		 * but not having one probably means no VBUS detection. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2012-06-22 17:02:46 +05:30
										 |  |  | 		xceiv = usb_get_phy(USB_PHY_TYPE_USB2); | 
					
						
							| 
									
										
										
										
											2012-06-26 17:40:32 +05:30
										 |  |  | 		if (!IS_ERR_OR_NULL(xceiv)) | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 			type = xceiv->label; | 
					
						
							|  |  |  | 		else if (config->otg) { | 
					
						
							|  |  |  | 			DBG("OTG requires external transceiver!\n"); | 
					
						
							|  |  |  | 			goto cleanup0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		hmc = HMC_1610; | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		switch (hmc) { | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 		case 0:			/* POWERUP DEFAULT == 0 */ | 
					
						
							|  |  |  | 		case 4: | 
					
						
							|  |  |  | 		case 12: | 
					
						
							|  |  |  | 		case 20: | 
					
						
							|  |  |  | 			if (!cpu_is_omap1710()) { | 
					
						
							|  |  |  | 				type = "integrated"; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			/* FALL THROUGH */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		case 3: | 
					
						
							|  |  |  | 		case 11: | 
					
						
							|  |  |  | 		case 16: | 
					
						
							|  |  |  | 		case 19: | 
					
						
							|  |  |  | 		case 25: | 
					
						
							| 
									
										
										
										
											2012-06-26 17:40:32 +05:30
										 |  |  | 			if (IS_ERR_OR_NULL(xceiv)) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				DBG("external transceiver not registered!\n"); | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 				type = "unknown"; | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case 21:			/* internal loopback */ | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 			type = "loopback"; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case 14:			/* transceiverless */ | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 			if (cpu_is_omap1710()) | 
					
						
							|  |  |  | 				goto bad_on_1710; | 
					
						
							|  |  |  | 			/* FALL THROUGH */ | 
					
						
							|  |  |  | 		case 13: | 
					
						
							|  |  |  | 		case 15: | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 			type = "no"; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | bad_on_1710: | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			ERR("unrecognized UDC HMC mode %d\n", hmc); | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 			goto cleanup0; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-05-21 12:01:11 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 	INFO("hmc mode %d, %s transceiver\n", hmc, type); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* a "gadget" abstracts/virtualizes the controller */ | 
					
						
							| 
									
										
										
										
											2005-11-09 22:32:44 +00:00
										 |  |  | 	status = omap_udc_setup(pdev, xceiv); | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	if (status) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		goto cleanup0; | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 	xceiv = NULL; | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	/* "udc" is now valid */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	pullup_disable(udc); | 
					
						
							|  |  |  | #if	defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
 | 
					
						
							|  |  |  | 	udc->gadget.is_otg = (config->otg != 0); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 	/* starting with omap1710 es2.0, clear toggle is a separate bit */ | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	if (omap_readw(UDC_REV) >= 0x61) | 
					
						
							| 
									
										
										
										
											2005-04-28 13:52:31 -07:00
										 |  |  | 		udc->clr_halt = UDC_RESET_EP | UDC_CLRDATA_TOGGLE; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		udc->clr_halt = UDC_RESET_EP; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	/* USB general purpose IRQ:  ep0, state changes, dma, etc */ | 
					
						
							| 
									
										
										
										
											2005-11-09 22:32:44 +00:00
										 |  |  | 	status = request_irq(pdev->resource[1].start, omap_udc_irq, | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 			0, driver_name, udc); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (status != 0) { | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 		ERR("can't get irq %d, err %d\n", | 
					
						
							|  |  |  | 			(int) pdev->resource[1].start, status); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		goto cleanup1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* USB "non-iso" IRQ (PIO for all but ep0) */ | 
					
						
							| 
									
										
										
										
											2005-11-09 22:32:44 +00:00
										 |  |  | 	status = request_irq(pdev->resource[2].start, omap_udc_pio_irq, | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 			0, "omap_udc pio", udc); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (status != 0) { | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 		ERR("can't get irq %d, err %d\n", | 
					
						
							|  |  |  | 			(int) pdev->resource[2].start, status); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		goto cleanup2; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #ifdef	USE_ISO
 | 
					
						
							| 
									
										
										
										
											2005-11-09 22:32:44 +00:00
										 |  |  | 	status = request_irq(pdev->resource[3].start, omap_udc_iso_irq, | 
					
						
							| 
									
										
										
										
											2011-09-07 16:10:52 +08:00
										 |  |  | 			0, "omap_udc iso", udc); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (status != 0) { | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 		ERR("can't get irq %d, err %d\n", | 
					
						
							|  |  |  | 			(int) pdev->resource[3].start, status); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		goto cleanup3; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-11-22 10:10:52 -08:00
										 |  |  | 	if (cpu_is_omap16xx() || cpu_is_omap7xx()) { | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 		udc->dc_clk = dc_clk; | 
					
						
							|  |  |  | 		udc->hhc_clk = hhc_clk; | 
					
						
							|  |  |  | 		clk_disable(hhc_clk); | 
					
						
							|  |  |  | 		clk_disable(dc_clk); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	create_proc_file(); | 
					
						
							| 
									
										
										
										
											2013-02-26 15:15:27 +02:00
										 |  |  | 	status = usb_add_gadget_udc_release(&pdev->dev, &udc->gadget, | 
					
						
							|  |  |  | 			omap_udc_release); | 
					
						
							| 
									
										
										
										
											2011-06-28 16:33:47 +03:00
										 |  |  | 	if (status) | 
					
						
							|  |  |  | 		goto cleanup4; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-24 15:07:29 +02:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 16:33:47 +03:00
										 |  |  | cleanup4: | 
					
						
							|  |  |  | 	remove_proc_file(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #ifdef	USE_ISO
 | 
					
						
							|  |  |  | cleanup3: | 
					
						
							| 
									
										
										
										
											2005-11-09 22:32:44 +00:00
										 |  |  | 	free_irq(pdev->resource[2].start, udc); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | cleanup2: | 
					
						
							| 
									
										
										
										
											2005-11-09 22:32:44 +00:00
										 |  |  | 	free_irq(pdev->resource[1].start, udc); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | cleanup1: | 
					
						
							| 
									
										
										
										
											2012-05-29 14:26:09 +03:00
										 |  |  | 	kfree(udc); | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 	udc = NULL; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | cleanup0: | 
					
						
							| 
									
										
										
										
											2012-06-26 17:40:32 +05:30
										 |  |  | 	if (!IS_ERR_OR_NULL(xceiv)) | 
					
						
							| 
									
										
										
										
											2012-06-22 17:02:45 +05:30
										 |  |  | 		usb_put_phy(xceiv); | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-21 12:01:11 -07:00
										 |  |  | 	if (cpu_is_omap16xx() || cpu_is_omap7xx()) { | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 		clk_disable(hhc_clk); | 
					
						
							|  |  |  | 		clk_disable(dc_clk); | 
					
						
							|  |  |  | 		clk_put(hhc_clk); | 
					
						
							|  |  |  | 		clk_put(dc_clk); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-09 22:32:44 +00:00
										 |  |  | 	release_mem_region(pdev->resource[0].start, | 
					
						
							|  |  |  | 			pdev->resource[0].end - pdev->resource[0].start + 1); | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	return status; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-19 13:26:20 -05:00
										 |  |  | static int omap_udc_remove(struct platform_device *pdev) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-09-30 23:28:10 -07:00
										 |  |  | 	DECLARE_COMPLETION_ONSTACK(done); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!udc) | 
					
						
							|  |  |  | 		return -ENODEV; | 
					
						
							| 
									
										
										
										
											2011-06-28 16:33:47 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	usb_del_gadget_udc(&udc->gadget); | 
					
						
							| 
									
										
										
										
											2006-12-05 03:15:33 -08:00
										 |  |  | 	if (udc->driver) | 
					
						
							|  |  |  | 		return -EBUSY; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	udc->done = &done; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pullup_disable(udc); | 
					
						
							| 
									
										
										
										
											2012-06-26 17:40:32 +05:30
										 |  |  | 	if (!IS_ERR_OR_NULL(udc->transceiver)) { | 
					
						
							| 
									
										
										
										
											2012-06-22 17:02:45 +05:30
										 |  |  | 		usb_put_phy(udc->transceiver); | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 		udc->transceiver = NULL; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	omap_writew(0, UDC_SYSCON1); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	remove_proc_file(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef	USE_ISO
 | 
					
						
							| 
									
										
										
										
											2005-11-09 22:32:44 +00:00
										 |  |  | 	free_irq(pdev->resource[3].start, udc); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-11-09 22:32:44 +00:00
										 |  |  | 	free_irq(pdev->resource[2].start, udc); | 
					
						
							|  |  |  | 	free_irq(pdev->resource[1].start, udc); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-10 11:47:04 -08:00
										 |  |  | 	if (udc->dc_clk) { | 
					
						
							|  |  |  | 		if (udc->clk_requested) | 
					
						
							|  |  |  | 			omap_udc_enable_clock(0); | 
					
						
							|  |  |  | 		clk_put(udc->hhc_clk); | 
					
						
							|  |  |  | 		clk_put(udc->dc_clk); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-09 22:32:44 +00:00
										 |  |  | 	release_mem_region(pdev->resource[0].start, | 
					
						
							|  |  |  | 			pdev->resource[0].end - pdev->resource[0].start + 1); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	wait_for_completion(&done); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | /* suspend/resume/wakeup from sysfs (echo > power/state) or when the
 | 
					
						
							|  |  |  |  * system is forced into deep sleep | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * REVISIT we should probably reject suspend requests when there's a host | 
					
						
							|  |  |  |  * session active, rather than disconnecting, at least on boards that can | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  |  * report VBUS irqs (UDC_DEVSTAT.UDC_ATT).  And in any case, we need to | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  |  * make host resumes and VBUS detection trigger OMAP wakeup events; that | 
					
						
							|  |  |  |  * may involve talking to an external transceiver (e.g. isp1301). | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2005-06-29 07:00:56 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-09 22:32:44 +00:00
										 |  |  | static int omap_udc_suspend(struct platform_device *dev, pm_message_t message) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 	u32	devstat; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-03 12:24:43 +03:00
										 |  |  | 	devstat = omap_readw(UDC_DEVSTAT); | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* we're requesting 48 MHz clock if the pullup is enabled
 | 
					
						
							|  |  |  | 	 * (== we're attached to the host) and we're not suspended, | 
					
						
							|  |  |  | 	 * which would prevent entry to deep sleep... | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if ((devstat & UDC_ATT) != 0 && (devstat & UDC_SUS) == 0) { | 
					
						
							| 
									
										
										
										
											2008-07-25 01:45:52 -07:00
										 |  |  | 		WARNING("session active; suspend requires disconnect\n"); | 
					
						
							| 
									
										
										
										
											2005-04-11 15:38:25 -07:00
										 |  |  | 		omap_pullup(&udc->gadget, 0); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-09 22:32:44 +00:00
										 |  |  | static int omap_udc_resume(struct platform_device *dev) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	DBG("resume + wakeup/SRP\n"); | 
					
						
							|  |  |  | 	omap_pullup(&udc->gadget, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* maybe the host would enumerate us if we nudged it */ | 
					
						
							|  |  |  | 	msleep(100); | 
					
						
							|  |  |  | 	return omap_wakeup(&udc->gadget); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*-------------------------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-09 22:32:44 +00:00
										 |  |  | static struct platform_driver udc_driver = { | 
					
						
							| 
									
										
										
										
											2012-05-29 14:33:30 +03:00
										 |  |  | 	.probe		= omap_udc_probe, | 
					
						
							| 
									
										
										
										
											2012-11-19 13:21:08 -05:00
										 |  |  | 	.remove		= omap_udc_remove, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	.suspend	= omap_udc_suspend, | 
					
						
							|  |  |  | 	.resume		= omap_udc_resume, | 
					
						
							| 
									
										
										
										
											2005-11-09 22:32:44 +00:00
										 |  |  | 	.driver		= { | 
					
						
							|  |  |  | 		.owner	= THIS_MODULE, | 
					
						
							|  |  |  | 		.name	= (char *) driver_name, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-29 14:33:30 +03:00
										 |  |  | module_platform_driver(udc_driver); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | MODULE_DESCRIPTION(DRIVER_DESC); | 
					
						
							|  |  |  | MODULE_LICENSE("GPL"); | 
					
						
							| 
									
										
										
										
											2008-04-10 21:29:21 -07:00
										 |  |  | MODULE_ALIAS("platform:omap_udc"); |