2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2005-05-08 04:20:19 +08:00
|
|
|
* Intel PXA25x and IXP4xx on-chip full speed USB device controllers
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Intrinsyc, Inc. (Frank Becker)
|
|
|
|
* Copyright (C) 2003 Robert Schwebel, Pengutronix
|
|
|
|
* Copyright (C) 2003 Benedikt Spranger, Pengutronix
|
|
|
|
* Copyright (C) 2003 David Brownell
|
|
|
|
* Copyright (C) 2003 Joshua Wise
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-12-31 03:56:27 +08:00
|
|
|
/* #define VERBOSE_DEBUG */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-06-30 21:25:35 +08:00
|
|
|
#include <linux/device.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#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/init.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/mm.h>
|
2005-10-30 02:07:23 +08:00
|
|
|
#include <linux/platform_device.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/dma-mapping.h>
|
2006-10-21 05:20:17 +08:00
|
|
|
#include <linux/irq.h>
|
2007-08-20 17:33:35 +08:00
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/err.h>
|
2007-12-31 03:56:27 +08:00
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/debugfs.h>
|
2008-04-21 00:32:16 +08:00
|
|
|
#include <linux/io.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/byteorder.h>
|
|
|
|
#include <asm/dma.h>
|
2007-06-30 21:25:35 +08:00
|
|
|
#include <asm/gpio.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/system.h>
|
|
|
|
#include <asm/mach-types.h>
|
|
|
|
#include <asm/unaligned.h>
|
|
|
|
|
2006-12-17 07:34:53 +08:00
|
|
|
#include <linux/usb/ch9.h>
|
2007-10-05 09:05:17 +08:00
|
|
|
#include <linux/usb/gadget.h>
|
2009-07-01 18:46:25 +08:00
|
|
|
#include <linux/usb/otg.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-21 00:32:16 +08:00
|
|
|
/*
|
|
|
|
* This driver is PXA25x only. Grab the right register definitions.
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_ARCH_PXA
|
2008-08-05 23:14:15 +08:00
|
|
|
#include <mach/pxa25x-udc.h>
|
2008-04-21 00:32:16 +08:00
|
|
|
#endif
|
|
|
|
|
2007-06-30 21:25:35 +08:00
|
|
|
#include <asm/mach/udc_pxa2xx.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2005-05-08 04:20:19 +08:00
|
|
|
* This driver handles the USB Device Controller (UDC) in Intel's PXA 25x
|
2005-04-17 06:20:36 +08:00
|
|
|
* series processors. The UDC for the IXP 4xx series is very similar.
|
|
|
|
* There are fifteen endpoints, in addition to ep0.
|
|
|
|
*
|
|
|
|
* Such controller drivers work with a gadget driver. The gadget driver
|
|
|
|
* returns descriptors, implements configuration and data protocols used
|
|
|
|
* by the host to interact with this device, and allocates endpoints to
|
|
|
|
* the different protocol interfaces. The controller driver virtualizes
|
|
|
|
* usb hardware so that the gadget drivers will be more portable.
|
2007-02-25 04:23:52 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* This UDC hardware wants to implement a bit too much USB protocol, so
|
|
|
|
* it constrains the sorts of USB configuration change events that work.
|
|
|
|
* The errata for these chips are misleading; some "fixed" bugs from
|
|
|
|
* pxa250 a0/a1 b0/b1/b2 sure act like they're still there.
|
2007-06-30 21:30:04 +08:00
|
|
|
*
|
|
|
|
* Note that the UDC hardware supports DMA (except on IXP) but that's
|
|
|
|
* not used here. IN-DMA (to host) is simple enough, when the data is
|
|
|
|
* suitably aligned (16 bytes) ... the network stack doesn't do that,
|
|
|
|
* other software can. OUT-DMA is buggy in most chip versions, as well
|
|
|
|
* as poorly designed (data toggle not automatic). So this driver won't
|
|
|
|
* bother using DMA. (Mostly-working IN-DMA support was available in
|
|
|
|
* kernels before 2.6.23, but was never enabled or well tested.)
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2007-06-30 21:30:04 +08:00
|
|
|
#define DRIVER_VERSION "30-June-2007"
|
2005-05-08 04:20:19 +08:00
|
|
|
#define DRIVER_DESC "PXA 25x USB Device Controller driver"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static const char driver_name [] = "pxa25x_udc";
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static const char ep0name [] = "ep0";
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_IXP4XX
|
|
|
|
|
|
|
|
/* cpu-specific register addresses are compiled in to this code */
|
|
|
|
#ifdef CONFIG_ARCH_PXA
|
|
|
|
#error "Can't configure both IXP and PXA"
|
|
|
|
#endif
|
|
|
|
|
2008-02-23 09:17:19 +08:00
|
|
|
/* IXP doesn't yet support <linux/clk.h> */
|
|
|
|
#define clk_get(dev,name) NULL
|
|
|
|
#define clk_enable(clk) do { } while (0)
|
|
|
|
#define clk_disable(clk) do { } while (0)
|
|
|
|
#define clk_put(clk) do { } while (0)
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
#include "pxa25x_udc.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
#ifdef CONFIG_USB_PXA25X_SMALL
|
2005-04-17 06:20:36 +08:00
|
|
|
#define SIZE_STR " (small)"
|
|
|
|
#else
|
|
|
|
#define SIZE_STR ""
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------
|
2007-02-25 04:23:52 +08:00
|
|
|
* endpoint related parts of the api to the usb controller hardware,
|
2005-04-17 06:20:36 +08:00
|
|
|
* used by gadget driver; and the inner talker-to-hardware core.
|
|
|
|
* ---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static void pxa25x_ep_fifo_flush (struct usb_ep *ep);
|
|
|
|
static void nuke (struct pxa25x_ep *, int status);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 03:25:39 +08:00
|
|
|
/* one GPIO should be used to detect VBUS from the host */
|
|
|
|
static int is_vbus_present(void)
|
|
|
|
{
|
|
|
|
struct pxa2xx_udc_mach_info *mach = the_controller->mach;
|
|
|
|
|
2009-07-01 18:42:45 +08:00
|
|
|
if (gpio_is_valid(mach->gpio_vbus)) {
|
2007-12-07 10:18:03 +08:00
|
|
|
int value = gpio_get_value(mach->gpio_vbus);
|
2008-11-18 09:32:36 +08:00
|
|
|
|
|
|
|
if (mach->gpio_vbus_inverted)
|
|
|
|
return !value;
|
|
|
|
else
|
|
|
|
return !!value;
|
2007-12-07 10:18:03 +08:00
|
|
|
}
|
2006-06-30 03:25:39 +08:00
|
|
|
if (mach->udc_is_connected)
|
|
|
|
return mach->udc_is_connected();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* one GPIO should control a D+ pullup, so host sees this device (or not) */
|
|
|
|
static void pullup_off(void)
|
|
|
|
{
|
|
|
|
struct pxa2xx_udc_mach_info *mach = the_controller->mach;
|
2008-06-26 05:34:51 +08:00
|
|
|
int off_level = mach->gpio_pullup_inverted;
|
2006-06-30 03:25:39 +08:00
|
|
|
|
2009-07-01 18:42:45 +08:00
|
|
|
if (gpio_is_valid(mach->gpio_pullup))
|
2008-06-26 05:34:51 +08:00
|
|
|
gpio_set_value(mach->gpio_pullup, off_level);
|
2006-06-30 03:25:39 +08:00
|
|
|
else if (mach->udc_command)
|
|
|
|
mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pullup_on(void)
|
|
|
|
{
|
|
|
|
struct pxa2xx_udc_mach_info *mach = the_controller->mach;
|
2008-06-26 05:34:51 +08:00
|
|
|
int on_level = !mach->gpio_pullup_inverted;
|
2006-06-30 03:25:39 +08:00
|
|
|
|
2009-07-01 18:42:45 +08:00
|
|
|
if (gpio_is_valid(mach->gpio_pullup))
|
2008-06-26 05:34:51 +08:00
|
|
|
gpio_set_value(mach->gpio_pullup, on_level);
|
2006-06-30 03:25:39 +08:00
|
|
|
else if (mach->udc_command)
|
|
|
|
mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static void pio_irq_enable(int bEndpointAddress)
|
|
|
|
{
|
|
|
|
bEndpointAddress &= 0xf;
|
|
|
|
if (bEndpointAddress < 8)
|
|
|
|
UICR0 &= ~(1 << bEndpointAddress);
|
|
|
|
else {
|
|
|
|
bEndpointAddress -= 8;
|
|
|
|
UICR1 &= ~(1 << bEndpointAddress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pio_irq_disable(int bEndpointAddress)
|
|
|
|
{
|
|
|
|
bEndpointAddress &= 0xf;
|
|
|
|
if (bEndpointAddress < 8)
|
|
|
|
UICR0 |= 1 << bEndpointAddress;
|
|
|
|
else {
|
|
|
|
bEndpointAddress -= 8;
|
|
|
|
UICR1 |= 1 << bEndpointAddress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The UDCCR reg contains mask and interrupt status bits,
|
|
|
|
* so using '|=' isn't safe as it may ack an interrupt.
|
|
|
|
*/
|
|
|
|
#define UDCCR_MASK_BITS (UDCCR_REM | UDCCR_SRM | UDCCR_UDE)
|
|
|
|
|
|
|
|
static inline void udc_set_mask_UDCCR(int mask)
|
|
|
|
{
|
|
|
|
UDCCR = (UDCCR & UDCCR_MASK_BITS) | (mask & UDCCR_MASK_BITS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void udc_clear_mask_UDCCR(int mask)
|
|
|
|
{
|
|
|
|
UDCCR = (UDCCR & UDCCR_MASK_BITS) & ~(mask & UDCCR_MASK_BITS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void udc_ack_int_UDCCR(int mask)
|
|
|
|
{
|
|
|
|
/* udccr contains the bits we dont want to change */
|
|
|
|
__u32 udccr = UDCCR & UDCCR_MASK_BITS;
|
|
|
|
|
|
|
|
UDCCR = udccr | (mask & ~UDCCR_MASK_BITS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* endpoint enable/disable
|
|
|
|
*
|
2008-06-23 06:36:39 +08:00
|
|
|
* we need to verify the descriptors used to enable endpoints. since pxa25x
|
2005-04-17 06:20:36 +08:00
|
|
|
* endpoint configurations are fixed, and are pretty much always enabled,
|
|
|
|
* there's not a lot to manage here.
|
|
|
|
*
|
2008-06-23 06:36:39 +08:00
|
|
|
* because pxa25x can't selectively initialize bulk (or interrupt) endpoints,
|
2005-04-17 06:20:36 +08:00
|
|
|
* (resetting endpoint halt and toggle), SET_INTERFACE is unusable except
|
|
|
|
* for a single interface (with only the default altsetting) and for gadget
|
|
|
|
* drivers that don't halt endpoints (not reset by set_interface). that also
|
|
|
|
* means that if you use ISO, you must violate the USB spec rule that all
|
|
|
|
* iso endpoints must be in non-default altsettings.
|
|
|
|
*/
|
2008-06-23 06:36:39 +08:00
|
|
|
static int pxa25x_ep_enable (struct usb_ep *_ep,
|
2005-04-17 06:20:36 +08:00
|
|
|
const struct usb_endpoint_descriptor *desc)
|
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_ep *ep;
|
|
|
|
struct pxa25x_udc *dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
ep = container_of (_ep, struct pxa25x_ep, ep);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!_ep || !desc || ep->desc || _ep->name == ep0name
|
|
|
|
|| desc->bDescriptorType != USB_DT_ENDPOINT
|
|
|
|
|| ep->bEndpointAddress != desc->bEndpointAddress
|
|
|
|
|| ep->fifo_size < le16_to_cpu
|
|
|
|
(desc->wMaxPacketSize)) {
|
2008-03-04 08:08:34 +08:00
|
|
|
DMSG("%s, bad ep or descriptor\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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-04 08:08:34 +08:00
|
|
|
DMSG("%s, %s type mismatch\n", __func__, _ep->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hardware _could_ do smaller, but driver doesn't */
|
|
|
|
if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK
|
|
|
|
&& le16_to_cpu (desc->wMaxPacketSize)
|
|
|
|
!= BULK_FIFO_SIZE)
|
|
|
|
|| !desc->wMaxPacketSize) {
|
2008-03-04 08:08:34 +08:00
|
|
|
DMSG("%s, bad %s maxpacket\n", __func__, _ep->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev = ep->dev;
|
|
|
|
if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
|
2008-03-04 08:08:34 +08:00
|
|
|
DMSG("%s, bogus device state\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ESHUTDOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
ep->desc = desc;
|
|
|
|
ep->stopped = 0;
|
2007-06-30 21:30:04 +08:00
|
|
|
ep->pio_irqs = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
ep->ep.maxpacket = le16_to_cpu (desc->wMaxPacketSize);
|
|
|
|
|
|
|
|
/* flush fifo (mostly for OUT buffers) */
|
2008-06-23 06:36:39 +08:00
|
|
|
pxa25x_ep_fifo_flush (_ep);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* ... reset halt state too, if we could ... */
|
|
|
|
|
|
|
|
DBG(DBG_VERBOSE, "enabled %s\n", _ep->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static int pxa25x_ep_disable (struct usb_ep *_ep)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_ep *ep;
|
2005-05-08 04:20:19 +08:00
|
|
|
unsigned long flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
ep = container_of (_ep, struct pxa25x_ep, ep);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!_ep || !ep->desc) {
|
2008-03-04 08:08:34 +08:00
|
|
|
DMSG("%s, %s not enabled\n", __func__,
|
2005-04-17 06:20:36 +08:00
|
|
|
_ep ? ep->ep.name : NULL);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2005-05-08 04:20:19 +08:00
|
|
|
local_irq_save(flags);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
nuke (ep, -ESHUTDOWN);
|
|
|
|
|
|
|
|
/* flush fifo (mostly for IN buffers) */
|
2008-06-23 06:36:39 +08:00
|
|
|
pxa25x_ep_fifo_flush (_ep);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ep->desc = NULL;
|
|
|
|
ep->stopped = 1;
|
|
|
|
|
2005-05-08 04:20:19 +08:00
|
|
|
local_irq_restore(flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
DBG(DBG_VERBOSE, "%s disabled\n", _ep->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
/* for the pxa25x, these can just wrap kmalloc/kfree. gadget drivers
|
2005-04-17 06:20:36 +08:00
|
|
|
* must still pass correctly initialized endpoints, since other controller
|
|
|
|
* drivers may care about how it's currently set up (dma issues etc).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2008-06-23 06:36:39 +08:00
|
|
|
* pxa25x_ep_alloc_request - allocate a request data structure
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
static struct usb_request *
|
2008-06-23 06:36:39 +08:00
|
|
|
pxa25x_ep_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_request *req;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-02-28 05:34:10 +08:00
|
|
|
req = kzalloc(sizeof(*req), gfp_flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!req)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD (&req->queue);
|
|
|
|
return &req->req;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2008-06-23 06:36:39 +08:00
|
|
|
* pxa25x_ep_free_request - deallocate a request data structure
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
static void
|
2008-06-23 06:36:39 +08:00
|
|
|
pxa25x_ep_free_request (struct usb_ep *_ep, struct usb_request *_req)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_request *req;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
req = container_of (_req, struct pxa25x_request, req);
|
2008-07-25 16:45:52 +08:00
|
|
|
WARN_ON(!list_empty (&req->queue));
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* done - retire a request; caller blocked irqs
|
|
|
|
*/
|
2008-06-23 06:36:39 +08:00
|
|
|
static void done(struct pxa25x_ep *ep, struct pxa25x_request *req, int status)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned stopped = ep->stopped;
|
|
|
|
|
|
|
|
list_del_init(&req->queue);
|
|
|
|
|
|
|
|
if (likely (req->req.status == -EINPROGRESS))
|
|
|
|
req->req.status = status;
|
|
|
|
else
|
|
|
|
status = req->req.status;
|
|
|
|
|
|
|
|
if (status && status != -ESHUTDOWN)
|
|
|
|
DBG(DBG_VERBOSE, "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;
|
|
|
|
req->req.complete(&ep->ep, &req->req);
|
|
|
|
ep->stopped = stopped;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static inline void ep0_idle (struct pxa25x_udc *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
dev->ep0state = EP0_IDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-06-23 06:36:39 +08:00
|
|
|
write_packet(volatile u32 *uddr, struct pxa25x_request *req, unsigned max)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
u8 *buf;
|
|
|
|
unsigned length, count;
|
|
|
|
|
|
|
|
buf = req->req.buf + req->req.actual;
|
|
|
|
prefetch(buf);
|
|
|
|
|
|
|
|
/* how big will this packet be? */
|
|
|
|
length = min(req->req.length - req->req.actual, max);
|
|
|
|
req->req.actual += length;
|
|
|
|
|
|
|
|
count = length;
|
|
|
|
while (likely(count--))
|
|
|
|
*uddr = *buf++;
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* write to an IN endpoint fifo, as many packets as possible.
|
|
|
|
* irqs will use this to write the rest later.
|
|
|
|
* caller guarantees at least one packet buffer is ready (or a zlp).
|
|
|
|
*/
|
|
|
|
static int
|
2008-06-23 06:36:39 +08:00
|
|
|
write_fifo (struct pxa25x_ep *ep, struct pxa25x_request *req)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned max;
|
|
|
|
|
|
|
|
max = le16_to_cpu(ep->desc->wMaxPacketSize);
|
|
|
|
do {
|
|
|
|
unsigned count;
|
|
|
|
int is_last, is_short;
|
|
|
|
|
|
|
|
count = write_packet(ep->reg_uddr, req, max);
|
|
|
|
|
|
|
|
/* last packet is usually short (or a zlp) */
|
|
|
|
if (unlikely (count != max))
|
|
|
|
is_last = is_short = 1;
|
|
|
|
else {
|
|
|
|
if (likely(req->req.length != req->req.actual)
|
|
|
|
|| req->req.zero)
|
|
|
|
is_last = 0;
|
|
|
|
else
|
|
|
|
is_last = 1;
|
|
|
|
/* interrupt/iso maxpacket may not fill the fifo */
|
|
|
|
is_short = unlikely (max < ep->fifo_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG(DBG_VERY_NOISY, "wrote %s %d bytes%s%s %d left %p\n",
|
|
|
|
ep->ep.name, count,
|
|
|
|
is_last ? "/L" : "", is_short ? "/S" : "",
|
|
|
|
req->req.length - req->req.actual, req);
|
|
|
|
|
|
|
|
/* let loose that packet. maybe try writing another one,
|
|
|
|
* double buffering might work. TSP, TPC, and TFS
|
|
|
|
* bit values are the same for all normal IN endpoints.
|
|
|
|
*/
|
|
|
|
*ep->reg_udccs = UDCCS_BI_TPC;
|
|
|
|
if (is_short)
|
|
|
|
*ep->reg_udccs = UDCCS_BI_TSP;
|
|
|
|
|
|
|
|
/* requests complete when all IN data is in the FIFO */
|
|
|
|
if (is_last) {
|
|
|
|
done (ep, req, 0);
|
2007-06-30 21:30:04 +08:00
|
|
|
if (list_empty(&ep->queue))
|
2005-04-17 06:20:36 +08:00
|
|
|
pio_irq_disable (ep->bEndpointAddress);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO experiment: how robust can fifo mode tweaking be?
|
|
|
|
// double buffering is off in the default fifo mode, which
|
|
|
|
// prevents TFS from being set here.
|
|
|
|
|
|
|
|
} while (*ep->reg_udccs & UDCCS_BI_TFS);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* caller asserts req->pending (ep0 irq status nyet cleared); starts
|
|
|
|
* ep0 data stage. these chips want very simple state transitions.
|
|
|
|
*/
|
|
|
|
static inline
|
2008-06-23 06:36:39 +08:00
|
|
|
void ep0start(struct pxa25x_udc *dev, u32 flags, const char *tag)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
UDCCS0 = flags|UDCCS0_SA|UDCCS0_OPR;
|
|
|
|
USIR0 = USIR0_IR0;
|
|
|
|
dev->req_pending = 0;
|
|
|
|
DBG(DBG_VERY_NOISY, "%s %s, %02x/%02x\n",
|
2008-03-04 08:08:34 +08:00
|
|
|
__func__, tag, UDCCS0, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-06-23 06:36:39 +08:00
|
|
|
write_ep0_fifo (struct pxa25x_ep *ep, struct pxa25x_request *req)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned count;
|
|
|
|
int is_short;
|
|
|
|
|
|
|
|
count = write_packet(&UDDR0, req, EP0_FIFO_SIZE);
|
|
|
|
ep->dev->stats.write.bytes += count;
|
|
|
|
|
|
|
|
/* last packet "must be" short (or a zlp) */
|
|
|
|
is_short = (count != EP0_FIFO_SIZE);
|
|
|
|
|
|
|
|
DBG(DBG_VERY_NOISY, "ep0in %d bytes %d left %p\n", count,
|
|
|
|
req->req.length - req->req.actual, req);
|
|
|
|
|
|
|
|
if (unlikely (is_short)) {
|
|
|
|
if (ep->dev->req_pending)
|
|
|
|
ep0start(ep->dev, UDCCS0_IPR, "short IN");
|
|
|
|
else
|
|
|
|
UDCCS0 = UDCCS0_IPR;
|
|
|
|
|
|
|
|
count = req->req.length;
|
|
|
|
done (ep, req, 0);
|
|
|
|
ep0_idle(ep->dev);
|
2006-05-29 18:34:00 +08:00
|
|
|
#ifndef CONFIG_ARCH_IXP4XX
|
2005-04-17 06:20:36 +08:00
|
|
|
#if 1
|
|
|
|
/* This seems to get rid of lost status irqs in some cases:
|
|
|
|
* host responds quickly, or next request involves config
|
|
|
|
* change automagic, or should have been hidden, or ...
|
|
|
|
*
|
|
|
|
* FIXME get rid of all udelays possible...
|
|
|
|
*/
|
|
|
|
if (count >= EP0_FIFO_SIZE) {
|
|
|
|
count = 100;
|
|
|
|
do {
|
|
|
|
if ((UDCCS0 & UDCCS0_OPR) != 0) {
|
|
|
|
/* clear OPR, generate ack */
|
|
|
|
UDCCS0 = UDCCS0_OPR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count--;
|
|
|
|
udelay(1);
|
|
|
|
} while (count);
|
|
|
|
}
|
2006-05-29 18:34:00 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
} else if (ep->dev->req_pending)
|
|
|
|
ep0start(ep->dev, 0, "IN");
|
|
|
|
return is_short;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read_fifo - unload packet(s) from the fifo we use for usb OUT
|
|
|
|
* transfers and put them into the request. caller should have made
|
|
|
|
* sure there's at least one packet ready.
|
|
|
|
*
|
|
|
|
* returns true if the request completed because of short packet or the
|
|
|
|
* request buffer having filled (and maybe overran till end-of-packet).
|
|
|
|
*/
|
|
|
|
static int
|
2008-06-23 06:36:39 +08:00
|
|
|
read_fifo (struct pxa25x_ep *ep, struct pxa25x_request *req)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
u32 udccs;
|
|
|
|
u8 *buf;
|
|
|
|
unsigned bufferspace, count, is_short;
|
|
|
|
|
|
|
|
/* make sure there's a packet in the FIFO.
|
|
|
|
* UDCCS_{BO,IO}_RPC are all the same bit value.
|
|
|
|
* UDCCS_{BO,IO}_RNE are all the same bit value.
|
|
|
|
*/
|
|
|
|
udccs = *ep->reg_udccs;
|
|
|
|
if (unlikely ((udccs & UDCCS_BO_RPC) == 0))
|
|
|
|
break;
|
|
|
|
buf = req->req.buf + req->req.actual;
|
|
|
|
prefetchw(buf);
|
|
|
|
bufferspace = req->req.length - req->req.actual;
|
|
|
|
|
|
|
|
/* read all bytes from this packet */
|
|
|
|
if (likely (udccs & UDCCS_BO_RNE)) {
|
|
|
|
count = 1 + (0x0ff & *ep->reg_ubcr);
|
|
|
|
req->req.actual += min (count, bufferspace);
|
|
|
|
} else /* zlp */
|
|
|
|
count = 0;
|
|
|
|
is_short = (count < ep->ep.maxpacket);
|
|
|
|
DBG(DBG_VERY_NOISY, "read %s %02x, %d bytes%s req %p %d/%d\n",
|
|
|
|
ep->ep.name, udccs, count,
|
|
|
|
is_short ? "/S" : "",
|
|
|
|
req, req->req.actual, req->req.length);
|
|
|
|
while (likely (count-- != 0)) {
|
|
|
|
u8 byte = (u8) *ep->reg_uddr;
|
|
|
|
|
|
|
|
if (unlikely (bufferspace == 0)) {
|
|
|
|
/* this happens when the driver's buffer
|
|
|
|
* is smaller than what the host sent.
|
|
|
|
* discard the extra data.
|
|
|
|
*/
|
|
|
|
if (req->req.status != -EOVERFLOW)
|
|
|
|
DMSG("%s overflow %d\n",
|
|
|
|
ep->ep.name, count);
|
|
|
|
req->req.status = -EOVERFLOW;
|
|
|
|
} else {
|
|
|
|
*buf++ = byte;
|
|
|
|
bufferspace--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*ep->reg_udccs = UDCCS_BO_RPC;
|
|
|
|
/* RPC/RSP/RNE could now reflect the other packet buffer */
|
|
|
|
|
|
|
|
/* iso is one request per packet */
|
|
|
|
if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
|
|
|
|
if (udccs & UDCCS_IO_ROF)
|
|
|
|
req->req.status = -EHOSTUNREACH;
|
|
|
|
/* more like "is_done" */
|
|
|
|
is_short = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* completion */
|
|
|
|
if (is_short || req->req.actual == req->req.length) {
|
|
|
|
done (ep, req, 0);
|
|
|
|
if (list_empty(&ep->queue))
|
|
|
|
pio_irq_disable (ep->bEndpointAddress);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* finished that packet. the next one may be waiting... */
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* special ep0 version of the above. no UBCR0 or double buffering; status
|
|
|
|
* handshaking is magic. most device protocols don't need control-OUT.
|
|
|
|
* CDC vendor commands (and RNDIS), mass storage CB/CBI, and some other
|
|
|
|
* protocols do use them.
|
|
|
|
*/
|
|
|
|
static int
|
2008-06-23 06:36:39 +08:00
|
|
|
read_ep0_fifo (struct pxa25x_ep *ep, struct pxa25x_request *req)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
u8 *buf, byte;
|
|
|
|
unsigned bufferspace;
|
|
|
|
|
|
|
|
buf = req->req.buf + req->req.actual;
|
|
|
|
bufferspace = req->req.length - req->req.actual;
|
|
|
|
|
|
|
|
while (UDCCS0 & UDCCS0_RNE) {
|
|
|
|
byte = (u8) UDDR0;
|
|
|
|
|
|
|
|
if (unlikely (bufferspace == 0)) {
|
|
|
|
/* this happens when the driver's buffer
|
|
|
|
* is smaller than what the host sent.
|
|
|
|
* discard the extra data.
|
|
|
|
*/
|
|
|
|
if (req->req.status != -EOVERFLOW)
|
|
|
|
DMSG("%s overflow\n", ep->ep.name);
|
|
|
|
req->req.status = -EOVERFLOW;
|
|
|
|
} else {
|
|
|
|
*buf++ = byte;
|
|
|
|
req->req.actual++;
|
|
|
|
bufferspace--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UDCCS0 = UDCCS0_OPR | UDCCS0_IPR;
|
|
|
|
|
|
|
|
/* completion */
|
|
|
|
if (req->req.actual >= req->req.length)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* finished that packet. the next one may be waiting... */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static int
|
2008-06-23 06:36:39 +08:00
|
|
|
pxa25x_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_request *req;
|
|
|
|
struct pxa25x_ep *ep;
|
|
|
|
struct pxa25x_udc *dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
req = container_of(_req, struct pxa25x_request, req);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (unlikely (!_req || !_req->complete || !_req->buf
|
|
|
|
|| !list_empty(&req->queue))) {
|
2008-03-04 08:08:34 +08:00
|
|
|
DMSG("%s, bad params\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
ep = container_of(_ep, struct pxa25x_ep, ep);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (unlikely (!_ep || (!ep->desc && ep->ep.name != ep0name))) {
|
2008-03-04 08:08:34 +08:00
|
|
|
DMSG("%s, bad ep\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev = ep->dev;
|
|
|
|
if (unlikely (!dev->driver
|
|
|
|
|| dev->gadget.speed == USB_SPEED_UNKNOWN)) {
|
2008-03-04 08:08:34 +08:00
|
|
|
DMSG("%s, bogus device state\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ESHUTDOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* iso is always one packet per request, that's the only way
|
|
|
|
* we can report per-packet status. that also helps with dma.
|
|
|
|
*/
|
|
|
|
if (unlikely (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
|
|
|
|
&& req->req.length > le16_to_cpu
|
|
|
|
(ep->desc->wMaxPacketSize)))
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
DBG(DBG_NOISY, "%s queue req %p, len %d buf %p\n",
|
2007-06-30 21:30:04 +08:00
|
|
|
_ep->name, _req, _req->length, _req->buf);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
_req->status = -EINPROGRESS;
|
|
|
|
_req->actual = 0;
|
|
|
|
|
|
|
|
/* kickstart this i/o queue? */
|
|
|
|
if (list_empty(&ep->queue) && !ep->stopped) {
|
2007-12-31 03:56:27 +08:00
|
|
|
if (ep->desc == NULL/* ep0 */) {
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned length = _req->length;
|
|
|
|
|
|
|
|
switch (dev->ep0state) {
|
|
|
|
case EP0_IN_DATA_PHASE:
|
|
|
|
dev->stats.write.ops++;
|
|
|
|
if (write_ep0_fifo(ep, req))
|
|
|
|
req = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EP0_OUT_DATA_PHASE:
|
|
|
|
dev->stats.read.ops++;
|
|
|
|
/* messy ... */
|
|
|
|
if (dev->req_config) {
|
|
|
|
DBG(DBG_VERBOSE, "ep0 config ack%s\n",
|
|
|
|
dev->has_cfr ? "" : " raced");
|
|
|
|
if (dev->has_cfr)
|
|
|
|
UDCCFR = UDCCFR_AREN|UDCCFR_ACM
|
|
|
|
|UDCCFR_MB1;
|
|
|
|
done(ep, req, 0);
|
|
|
|
dev->ep0state = EP0_END_XFER;
|
|
|
|
local_irq_restore (flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (dev->req_pending)
|
|
|
|
ep0start(dev, UDCCS0_IPR, "OUT");
|
|
|
|
if (length == 0 || ((UDCCS0 & UDCCS0_RNE) != 0
|
|
|
|
&& read_ep0_fifo(ep, req))) {
|
|
|
|
ep0_idle(dev);
|
|
|
|
done(ep, req, 0);
|
|
|
|
req = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DMSG("ep0 i/o, odd state %d\n", dev->ep0state);
|
|
|
|
local_irq_restore (flags);
|
|
|
|
return -EL2HLT;
|
|
|
|
}
|
|
|
|
/* can the FIFO can satisfy the request immediately? */
|
2005-05-08 04:20:19 +08:00
|
|
|
} else if ((ep->bEndpointAddress & USB_DIR_IN) != 0) {
|
|
|
|
if ((*ep->reg_udccs & UDCCS_BI_TFS) != 0
|
|
|
|
&& write_fifo(ep, req))
|
|
|
|
req = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else if ((*ep->reg_udccs & UDCCS_BO_RFS) != 0
|
|
|
|
&& read_fifo(ep, req)) {
|
|
|
|
req = NULL;
|
|
|
|
}
|
|
|
|
|
2007-06-30 21:30:04 +08:00
|
|
|
if (likely (req && ep->desc))
|
2005-04-17 06:20:36 +08:00
|
|
|
pio_irq_enable(ep->bEndpointAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pio or dma irq handler advances the queue. */
|
2007-12-31 03:56:27 +08:00
|
|
|
if (likely(req != NULL))
|
2005-04-17 06:20:36 +08:00
|
|
|
list_add_tail(&req->queue, &ep->queue);
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2007-02-25 04:23:52 +08:00
|
|
|
* nuke - dequeue ALL requests
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2008-06-23 06:36:39 +08:00
|
|
|
static void nuke(struct pxa25x_ep *ep, int status)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_request *req;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* called with irqs blocked */
|
|
|
|
while (!list_empty(&ep->queue)) {
|
|
|
|
req = list_entry(ep->queue.next,
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_request,
|
2005-04-17 06:20:36 +08:00
|
|
|
queue);
|
|
|
|
done(ep, req, status);
|
|
|
|
}
|
|
|
|
if (ep->desc)
|
|
|
|
pio_irq_disable (ep->bEndpointAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* dequeue JUST ONE request */
|
2008-06-23 06:36:39 +08:00
|
|
|
static int pxa25x_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_ep *ep;
|
|
|
|
struct pxa25x_request *req;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
ep = container_of(_ep, struct pxa25x_ep, ep);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!_ep || ep->ep.name == ep0name)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
/* make sure it's actually queued on this endpoint */
|
|
|
|
list_for_each_entry (req, &ep->queue, queue) {
|
|
|
|
if (&req->req == _req)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (&req->req != _req) {
|
|
|
|
local_irq_restore(flags);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2007-06-30 21:30:04 +08:00
|
|
|
done(ep, req, -ECONNRESET);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static int pxa25x_ep_set_halt(struct usb_ep *_ep, int value)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_ep *ep;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
ep = container_of(_ep, struct pxa25x_ep, ep);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (unlikely (!_ep
|
|
|
|
|| (!ep->desc && ep->ep.name != ep0name))
|
|
|
|
|| ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
|
2008-03-04 08:08:34 +08:00
|
|
|
DMSG("%s, bad ep\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (value == 0) {
|
|
|
|
/* this path (reset toggle+halt) is needed to implement
|
|
|
|
* SET_INTERFACE on normal hardware. but it can't be
|
|
|
|
* done from software on the PXA UDC, and the hardware
|
|
|
|
* forgets to do it as part of SET_INTERFACE automagic.
|
|
|
|
*/
|
|
|
|
DMSG("only host can clear %s halt\n", _ep->name);
|
|
|
|
return -EROFS;
|
|
|
|
}
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
if ((ep->bEndpointAddress & USB_DIR_IN) != 0
|
|
|
|
&& ((*ep->reg_udccs & UDCCS_BI_TFS) == 0
|
|
|
|
|| !list_empty(&ep->queue))) {
|
|
|
|
local_irq_restore(flags);
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FST bit is the same for control, bulk in, bulk out, interrupt in */
|
|
|
|
*ep->reg_udccs = UDCCS_BI_FST|UDCCS_BI_FTF;
|
|
|
|
|
|
|
|
/* ep0 needs special care */
|
|
|
|
if (!ep->desc) {
|
|
|
|
start_watchdog(ep->dev);
|
|
|
|
ep->dev->req_pending = 0;
|
|
|
|
ep->dev->ep0state = EP0_STALL;
|
|
|
|
|
2007-02-25 04:23:52 +08:00
|
|
|
/* and bulk/intr endpoints like dropping stalls too */
|
|
|
|
} else {
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < 1000; i += 20) {
|
|
|
|
if (*ep->reg_udccs & UDCCS_BI_SST)
|
|
|
|
break;
|
|
|
|
udelay(20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
local_irq_restore(flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
DBG(DBG_VERBOSE, "%s halt\n", _ep->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static int pxa25x_ep_fifo_status(struct usb_ep *_ep)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_ep *ep;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
ep = container_of(_ep, struct pxa25x_ep, ep);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!_ep) {
|
2008-03-04 08:08:34 +08:00
|
|
|
DMSG("%s, bad ep\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
/* pxa can't report unclaimed bytes from IN fifos */
|
|
|
|
if ((ep->bEndpointAddress & USB_DIR_IN) != 0)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
if (ep->dev->gadget.speed == USB_SPEED_UNKNOWN
|
|
|
|
|| (*ep->reg_udccs & UDCCS_BO_RFS) == 0)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return (*ep->reg_ubcr & 0xfff) + 1;
|
|
|
|
}
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static void pxa25x_ep_fifo_flush(struct usb_ep *_ep)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_ep *ep;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
ep = container_of(_ep, struct pxa25x_ep, ep);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!_ep || ep->ep.name == ep0name || !list_empty(&ep->queue)) {
|
2008-03-04 08:08:34 +08:00
|
|
|
DMSG("%s, bad ep\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* toggle and halt bits stay unchanged */
|
|
|
|
|
|
|
|
/* for OUT, just read and discard the FIFO contents. */
|
|
|
|
if ((ep->bEndpointAddress & USB_DIR_IN) == 0) {
|
|
|
|
while (((*ep->reg_udccs) & UDCCS_BO_RNE) != 0)
|
|
|
|
(void) *ep->reg_uddr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* most IN status is the same, but ISO can't stall */
|
|
|
|
*ep->reg_udccs = UDCCS_BI_TPC|UDCCS_BI_FTF|UDCCS_BI_TUR
|
2009-02-19 18:57:46 +08:00
|
|
|
| (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
|
|
|
|
? 0 : UDCCS_BI_SST);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static struct usb_ep_ops pxa25x_ep_ops = {
|
|
|
|
.enable = pxa25x_ep_enable,
|
|
|
|
.disable = pxa25x_ep_disable,
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
.alloc_request = pxa25x_ep_alloc_request,
|
|
|
|
.free_request = pxa25x_ep_free_request,
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
.queue = pxa25x_ep_queue,
|
|
|
|
.dequeue = pxa25x_ep_dequeue,
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
.set_halt = pxa25x_ep_set_halt,
|
|
|
|
.fifo_status = pxa25x_ep_fifo_status,
|
|
|
|
.fifo_flush = pxa25x_ep_fifo_flush,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------
|
2007-02-25 04:23:52 +08:00
|
|
|
* device-scoped parts of the api to the usb controller hardware
|
2005-04-17 06:20:36 +08:00
|
|
|
* ---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static int pxa25x_udc_get_frame(struct usb_gadget *_gadget)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
return ((UFNRH & 0x07) << 8) | (UFNRL & 0xff);
|
|
|
|
}
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static int pxa25x_udc_wakeup(struct usb_gadget *_gadget)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* host may not have enabled remote wakeup */
|
|
|
|
if ((UDCCS0 & UDCCS0_DRWF) == 0)
|
|
|
|
return -EHOSTUNREACH;
|
|
|
|
udc_set_mask_UDCCR(UDCCR_RSM);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static void stop_activity(struct pxa25x_udc *, struct usb_gadget_driver *);
|
|
|
|
static void udc_enable (struct pxa25x_udc *);
|
|
|
|
static void udc_disable(struct pxa25x_udc *);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* We disable the UDC -- and its 48 MHz clock -- whenever it's not
|
2007-02-25 04:23:52 +08:00
|
|
|
* in active use.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2008-06-23 06:36:39 +08:00
|
|
|
static int pullup(struct pxa25x_udc *udc)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-23 09:17:19 +08:00
|
|
|
int is_active = udc->vbus && udc->pullup && !udc->suspended;
|
2005-04-17 06:20:36 +08:00
|
|
|
DMSG("%s\n", is_active ? "active" : "inactive");
|
2008-02-23 09:17:19 +08:00
|
|
|
if (is_active) {
|
|
|
|
if (!udc->active) {
|
|
|
|
udc->active = 1;
|
|
|
|
/* Enable clock for USB device */
|
|
|
|
clk_enable(udc->clk);
|
|
|
|
udc_enable(udc);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-02-23 09:17:19 +08:00
|
|
|
} else {
|
|
|
|
if (udc->active) {
|
|
|
|
if (udc->gadget.speed != USB_SPEED_UNKNOWN) {
|
|
|
|
DMSG("disconnect %s\n", udc->driver
|
|
|
|
? udc->driver->driver.name
|
|
|
|
: "(no driver)");
|
|
|
|
stop_activity(udc, udc->driver);
|
|
|
|
}
|
|
|
|
udc_disable(udc);
|
|
|
|
/* Disable clock for USB device */
|
|
|
|
clk_disable(udc->clk);
|
|
|
|
udc->active = 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* VBUS reporting logically comes from a transceiver */
|
2008-06-23 06:36:39 +08:00
|
|
|
static int pxa25x_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_udc *udc;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
udc = container_of(_gadget, struct pxa25x_udc, gadget);
|
2008-11-18 09:32:36 +08:00
|
|
|
udc->vbus = is_active;
|
2005-04-17 06:20:36 +08:00
|
|
|
DMSG("vbus %s\n", is_active ? "supplied" : "inactive");
|
2008-02-23 09:17:19 +08:00
|
|
|
pullup(udc);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* drivers may have software control over D+ pullup */
|
2008-06-23 06:36:39 +08:00
|
|
|
static int pxa25x_udc_pullup(struct usb_gadget *_gadget, int is_active)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_udc *udc;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
udc = container_of(_gadget, struct pxa25x_udc, gadget);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* not all boards support pullup control */
|
2009-07-01 18:42:45 +08:00
|
|
|
if (!gpio_is_valid(udc->mach->gpio_pullup) && !udc->mach->udc_command)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2008-02-23 09:17:19 +08:00
|
|
|
udc->pullup = (is_active != 0);
|
|
|
|
pullup(udc);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-01 18:46:25 +08:00
|
|
|
/* boards may consume current from VBUS, up to 100-500mA based on config.
|
|
|
|
* the 500uA suspend ceiling means that exclusively vbus-powered PXA designs
|
|
|
|
* violate USB specs.
|
|
|
|
*/
|
|
|
|
static int pxa25x_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
|
|
|
|
{
|
|
|
|
struct pxa25x_udc *udc;
|
|
|
|
|
|
|
|
udc = container_of(_gadget, struct pxa25x_udc, gadget);
|
|
|
|
|
|
|
|
if (udc->transceiver)
|
|
|
|
return otg_set_power(udc->transceiver, mA);
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static const struct usb_gadget_ops pxa25x_udc_ops = {
|
|
|
|
.get_frame = pxa25x_udc_get_frame,
|
|
|
|
.wakeup = pxa25x_udc_wakeup,
|
|
|
|
.vbus_session = pxa25x_udc_vbus_session,
|
|
|
|
.pullup = pxa25x_udc_pullup,
|
2009-07-01 18:46:25 +08:00
|
|
|
.vbus_draw = pxa25x_udc_vbus_draw,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2007-12-31 03:56:27 +08:00
|
|
|
#ifdef CONFIG_USB_GADGET_DEBUG_FS
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static int
|
2008-02-23 09:17:19 +08:00
|
|
|
udc_seq_show(struct seq_file *m, void *_d)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_udc *dev = m->private;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
2007-12-31 03:56:27 +08:00
|
|
|
int i;
|
2005-04-17 06:20:36 +08:00
|
|
|
u32 tmp;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
/* basic device status */
|
2007-12-31 03:56:27 +08:00
|
|
|
seq_printf(m, DRIVER_DESC "\n"
|
2005-04-17 06:20:36 +08:00
|
|
|
"%s version: %s\nGadget driver: %s\nHost %s\n\n",
|
2007-06-30 21:30:04 +08:00
|
|
|
driver_name, DRIVER_VERSION SIZE_STR "(pio)",
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->driver ? dev->driver->driver.name : "(none)",
|
2005-05-08 04:20:19 +08:00
|
|
|
is_vbus_present() ? "full speed" : "disconnected");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* registers for device and ep0 */
|
2007-12-31 03:56:27 +08:00
|
|
|
seq_printf(m,
|
2005-04-17 06:20:36 +08:00
|
|
|
"uicr %02X.%02X, usir %02X.%02x, ufnr %02X.%02X\n",
|
|
|
|
UICR1, UICR0, USIR1, USIR0, UFNRH, UFNRL);
|
|
|
|
|
|
|
|
tmp = UDCCR;
|
2007-12-31 03:56:27 +08:00
|
|
|
seq_printf(m,
|
2005-04-17 06:20:36 +08:00
|
|
|
"udccr %02X =%s%s%s%s%s%s%s%s\n", tmp,
|
|
|
|
(tmp & UDCCR_REM) ? " rem" : "",
|
|
|
|
(tmp & UDCCR_RSTIR) ? " rstir" : "",
|
|
|
|
(tmp & UDCCR_SRM) ? " srm" : "",
|
|
|
|
(tmp & UDCCR_SUSIR) ? " susir" : "",
|
|
|
|
(tmp & UDCCR_RESIR) ? " resir" : "",
|
|
|
|
(tmp & UDCCR_RSM) ? " rsm" : "",
|
|
|
|
(tmp & UDCCR_UDA) ? " uda" : "",
|
|
|
|
(tmp & UDCCR_UDE) ? " ude" : "");
|
|
|
|
|
|
|
|
tmp = UDCCS0;
|
2007-12-31 03:56:27 +08:00
|
|
|
seq_printf(m,
|
2005-04-17 06:20:36 +08:00
|
|
|
"udccs0 %02X =%s%s%s%s%s%s%s%s\n", tmp,
|
|
|
|
(tmp & UDCCS0_SA) ? " sa" : "",
|
|
|
|
(tmp & UDCCS0_RNE) ? " rne" : "",
|
|
|
|
(tmp & UDCCS0_FST) ? " fst" : "",
|
|
|
|
(tmp & UDCCS0_SST) ? " sst" : "",
|
|
|
|
(tmp & UDCCS0_DRWF) ? " dwrf" : "",
|
|
|
|
(tmp & UDCCS0_FTF) ? " ftf" : "",
|
|
|
|
(tmp & UDCCS0_IPR) ? " ipr" : "",
|
|
|
|
(tmp & UDCCS0_OPR) ? " opr" : "");
|
|
|
|
|
|
|
|
if (dev->has_cfr) {
|
|
|
|
tmp = UDCCFR;
|
2007-12-31 03:56:27 +08:00
|
|
|
seq_printf(m,
|
2005-04-17 06:20:36 +08:00
|
|
|
"udccfr %02X =%s%s\n", tmp,
|
|
|
|
(tmp & UDCCFR_AREN) ? " aren" : "",
|
|
|
|
(tmp & UDCCFR_ACM) ? " acm" : "");
|
|
|
|
}
|
|
|
|
|
2005-05-08 04:20:19 +08:00
|
|
|
if (!is_vbus_present() || !dev->driver)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto done;
|
|
|
|
|
2007-12-31 03:56:27 +08:00
|
|
|
seq_printf(m, "ep0 IN %lu/%lu, OUT %lu/%lu\nirqs %lu\n\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->stats.write.bytes, dev->stats.write.ops,
|
|
|
|
dev->stats.read.bytes, dev->stats.read.ops,
|
|
|
|
dev->stats.irqs);
|
|
|
|
|
|
|
|
/* dump endpoint queues */
|
|
|
|
for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_ep *ep = &dev->ep [i];
|
|
|
|
struct pxa25x_request *req;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (i != 0) {
|
2007-12-31 03:56:27 +08:00
|
|
|
const struct usb_endpoint_descriptor *desc;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-12-31 03:56:27 +08:00
|
|
|
desc = ep->desc;
|
|
|
|
if (!desc)
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
tmp = *dev->ep [i].reg_udccs;
|
2007-12-31 03:56:27 +08:00
|
|
|
seq_printf(m,
|
2007-06-30 21:30:04 +08:00
|
|
|
"%s max %d %s udccs %02x irqs %lu\n",
|
2007-12-31 03:56:27 +08:00
|
|
|
ep->ep.name, le16_to_cpu(desc->wMaxPacketSize),
|
2007-06-30 21:30:04 +08:00
|
|
|
"pio", tmp, ep->pio_irqs);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* TODO translate all five groups of udccs bits! */
|
|
|
|
|
|
|
|
} else /* ep0 should only have one transfer queued */
|
2007-12-31 03:56:27 +08:00
|
|
|
seq_printf(m, "ep0 max 16 pio irqs %lu\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
ep->pio_irqs);
|
|
|
|
|
|
|
|
if (list_empty(&ep->queue)) {
|
2007-12-31 03:56:27 +08:00
|
|
|
seq_printf(m, "\t(nothing queued)\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
list_for_each_entry(req, &ep->queue, queue) {
|
2007-12-31 03:56:27 +08:00
|
|
|
seq_printf(m,
|
2005-04-17 06:20:36 +08:00
|
|
|
"\treq %p len %d/%d buf %p\n",
|
|
|
|
&req->req, req->req.actual,
|
|
|
|
req->req.length, req->req.buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
local_irq_restore(flags);
|
2007-12-31 03:56:27 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-12-31 03:56:27 +08:00
|
|
|
static int
|
|
|
|
udc_debugfs_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, udc_seq_show, inode->i_private);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations debug_fops = {
|
|
|
|
.open = udc_debugfs_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define create_debug_files(dev) \
|
|
|
|
do { \
|
|
|
|
dev->debugfs_udc = debugfs_create_file(dev->gadget.name, \
|
|
|
|
S_IRUGO, NULL, dev, &debug_fops); \
|
|
|
|
} while (0)
|
|
|
|
#define remove_debug_files(dev) \
|
|
|
|
do { \
|
|
|
|
if (dev->debugfs_udc) \
|
|
|
|
debugfs_remove(dev->debugfs_udc); \
|
|
|
|
} while (0)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#else /* !CONFIG_USB_GADGET_DEBUG_FILES */
|
|
|
|
|
2007-12-31 03:56:27 +08:00
|
|
|
#define create_debug_files(dev) do {} while (0)
|
|
|
|
#define remove_debug_files(dev) do {} while (0)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
2007-02-25 04:23:52 +08:00
|
|
|
* udc_disable - disable USB device controller
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2008-06-23 06:36:39 +08:00
|
|
|
static void udc_disable(struct pxa25x_udc *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* block all irqs */
|
|
|
|
udc_set_mask_UDCCR(UDCCR_SRM|UDCCR_REM);
|
|
|
|
UICR0 = UICR1 = 0xff;
|
|
|
|
UFNRH = UFNRH_SIM;
|
|
|
|
|
|
|
|
/* if hardware supports it, disconnect from usb */
|
2005-05-08 04:20:19 +08:00
|
|
|
pullup_off();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
udc_clear_mask_UDCCR(UDCCR_UDE);
|
|
|
|
|
|
|
|
ep0_idle (dev);
|
|
|
|
dev->gadget.speed = USB_SPEED_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2007-02-25 04:23:52 +08:00
|
|
|
* udc_reinit - initialize software state
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2008-06-23 06:36:39 +08:00
|
|
|
static void udc_reinit(struct pxa25x_udc *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
/* device/ep0 records init */
|
|
|
|
INIT_LIST_HEAD (&dev->gadget.ep_list);
|
|
|
|
INIT_LIST_HEAD (&dev->gadget.ep0->ep_list);
|
|
|
|
dev->ep0state = EP0_IDLE;
|
|
|
|
|
|
|
|
/* basic endpoint records init */
|
|
|
|
for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_ep *ep = &dev->ep[i];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (i != 0)
|
|
|
|
list_add_tail (&ep->ep.ep_list, &dev->gadget.ep_list);
|
|
|
|
|
|
|
|
ep->desc = NULL;
|
|
|
|
ep->stopped = 0;
|
|
|
|
INIT_LIST_HEAD (&ep->queue);
|
2007-06-30 21:30:04 +08:00
|
|
|
ep->pio_irqs = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* the rest was statically initialized, and is read-only */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* until it's enabled, this UDC should be completely invisible
|
|
|
|
* to any USB host.
|
|
|
|
*/
|
2008-06-23 06:36:39 +08:00
|
|
|
static void udc_enable (struct pxa25x_udc *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
udc_clear_mask_UDCCR(UDCCR_UDE);
|
|
|
|
|
|
|
|
/* try to clear these bits before we enable the udc */
|
|
|
|
udc_ack_int_UDCCR(UDCCR_SUSIR|/*UDCCR_RSTIR|*/UDCCR_RESIR);
|
|
|
|
|
|
|
|
ep0_idle(dev);
|
|
|
|
dev->gadget.speed = USB_SPEED_UNKNOWN;
|
|
|
|
dev->stats.irqs = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sequence taken from chapter 12.5.10, PXA250 AppProcDevManual:
|
|
|
|
* - enable UDC
|
|
|
|
* - if RESET is already in progress, ack interrupt
|
|
|
|
* - unmask reset interrupt
|
|
|
|
*/
|
|
|
|
udc_set_mask_UDCCR(UDCCR_UDE);
|
|
|
|
if (!(UDCCR & UDCCR_UDA))
|
|
|
|
udc_ack_int_UDCCR(UDCCR_RSTIR);
|
|
|
|
|
|
|
|
if (dev->has_cfr /* UDC_RES2 is defined */) {
|
|
|
|
/* pxa255 (a0+) can avoid a set_config race that could
|
|
|
|
* prevent gadget drivers from configuring correctly
|
|
|
|
*/
|
|
|
|
UDCCFR = UDCCFR_ACM | UDCCFR_MB1;
|
|
|
|
} else {
|
|
|
|
/* "USB test mode" for pxa250 errata 40-42 (stepping a0, a1)
|
|
|
|
* which could result in missing packets and interrupts.
|
|
|
|
* supposedly one bit per endpoint, controlling whether it
|
|
|
|
* double buffers or not; ACM/AREN bits fit into the holes.
|
|
|
|
* zero bits (like USIR0_IRx) disable double buffering.
|
|
|
|
*/
|
|
|
|
UDC_RES1 = 0x00;
|
|
|
|
UDC_RES2 = 0x00;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* enable suspend/resume and reset irqs */
|
|
|
|
udc_clear_mask_UDCCR(UDCCR_SRM | UDCCR_REM);
|
|
|
|
|
|
|
|
/* enable ep0 irqs */
|
|
|
|
UICR0 &= ~UICR0_IM0;
|
|
|
|
|
|
|
|
/* if hardware supports it, pullup D+ and wait for reset */
|
2005-05-08 04:20:19 +08:00
|
|
|
pullup_on();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* when a driver is successfully registered, it will receive
|
|
|
|
* control requests including set_configuration(), which enables
|
|
|
|
* non-control requests. then usb traffic follows until a
|
|
|
|
* disconnect is reported. then a host may connect again, or
|
|
|
|
* the driver might get unbound.
|
|
|
|
*/
|
|
|
|
int usb_gadget_register_driver(struct usb_gadget_driver *driver)
|
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_udc *dev = the_controller;
|
2005-04-17 06:20:36 +08:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (!driver
|
2006-05-29 18:34:00 +08:00
|
|
|
|| driver->speed < USB_SPEED_FULL
|
2005-04-17 06:20:36 +08:00
|
|
|
|| !driver->bind
|
|
|
|
|| !driver->disconnect
|
|
|
|
|| !driver->setup)
|
|
|
|
return -EINVAL;
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
if (dev->driver)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
/* first hook up the driver ... */
|
|
|
|
dev->driver = driver;
|
|
|
|
dev->gadget.dev.driver = &driver->driver;
|
|
|
|
dev->pullup = 1;
|
|
|
|
|
2007-02-25 04:23:52 +08:00
|
|
|
retval = device_add (&dev->gadget.dev);
|
|
|
|
if (retval) {
|
|
|
|
fail:
|
|
|
|
dev->driver = NULL;
|
|
|
|
dev->gadget.dev.driver = NULL;
|
|
|
|
return retval;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
retval = driver->bind(&dev->gadget);
|
|
|
|
if (retval) {
|
|
|
|
DMSG("bind to driver %s --> error %d\n",
|
|
|
|
driver->driver.name, retval);
|
|
|
|
device_del (&dev->gadget.dev);
|
2007-02-25 04:23:52 +08:00
|
|
|
goto fail;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ... then enable host detection and ep0; and we're ready
|
|
|
|
* for set_configuration as well as eventual disconnect.
|
|
|
|
*/
|
|
|
|
DMSG("registered gadget driver '%s'\n", driver->driver.name);
|
2009-07-01 18:46:25 +08:00
|
|
|
|
|
|
|
/* connect to bus through transceiver */
|
|
|
|
if (dev->transceiver) {
|
|
|
|
retval = otg_set_peripheral(dev->transceiver, &dev->gadget);
|
|
|
|
if (retval) {
|
|
|
|
DMSG("can't bind to transceiver\n");
|
|
|
|
if (driver->unbind)
|
|
|
|
driver->unbind(&dev->gadget);
|
|
|
|
goto bind_fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-23 09:17:19 +08:00
|
|
|
pullup(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
dump_state(dev);
|
|
|
|
return 0;
|
2009-07-01 18:46:25 +08:00
|
|
|
bind_fail:
|
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(usb_gadget_register_driver);
|
|
|
|
|
|
|
|
static void
|
2008-06-23 06:36:39 +08:00
|
|
|
stop_activity(struct pxa25x_udc *dev, struct usb_gadget_driver *driver)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* don't disconnect drivers more than once */
|
|
|
|
if (dev->gadget.speed == USB_SPEED_UNKNOWN)
|
|
|
|
driver = NULL;
|
|
|
|
dev->gadget.speed = USB_SPEED_UNKNOWN;
|
|
|
|
|
|
|
|
/* prevent new request submissions, kill any outstanding requests */
|
|
|
|
for (i = 0; i < PXA_UDC_NUM_ENDPOINTS; i++) {
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_ep *ep = &dev->ep[i];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ep->stopped = 1;
|
|
|
|
nuke(ep, -ESHUTDOWN);
|
|
|
|
}
|
|
|
|
del_timer_sync(&dev->timer);
|
|
|
|
|
|
|
|
/* report disconnect; the driver is already quiesced */
|
|
|
|
if (driver)
|
|
|
|
driver->disconnect(&dev->gadget);
|
|
|
|
|
|
|
|
/* re-init driver-visible data structures */
|
|
|
|
udc_reinit(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
|
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_udc *dev = the_controller;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
2006-12-05 19:15:33 +08:00
|
|
|
if (!driver || driver != dev->driver || !driver->unbind)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
local_irq_disable();
|
2008-02-23 09:17:19 +08:00
|
|
|
dev->pullup = 0;
|
|
|
|
pullup(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
stop_activity(dev, driver);
|
|
|
|
local_irq_enable();
|
|
|
|
|
2009-07-01 18:46:25 +08:00
|
|
|
if (dev->transceiver)
|
|
|
|
(void) otg_set_peripheral(dev->transceiver, NULL);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
driver->unbind(&dev->gadget);
|
2007-11-21 01:32:00 +08:00
|
|
|
dev->gadget.dev.driver = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->driver = NULL;
|
|
|
|
|
|
|
|
device_del (&dev->gadget.dev);
|
|
|
|
|
|
|
|
DMSG("unregistered gadget driver '%s'\n", driver->driver.name);
|
|
|
|
dump_state(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(usb_gadget_unregister_driver);
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_LUBBOCK
|
|
|
|
|
|
|
|
/* Lubbock has separate connect and disconnect irqs. More typical designs
|
|
|
|
* use one GPIO as the VBUS IRQ, and another to control the D+ pullup.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static irqreturn_t
|
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 21:55:46 +08:00
|
|
|
lubbock_vbus_irq(int irq, void *_dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_udc *dev = _dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
int vbus;
|
|
|
|
|
|
|
|
dev->stats.irqs++;
|
|
|
|
switch (irq) {
|
|
|
|
case LUBBOCK_USB_IRQ:
|
|
|
|
vbus = 1;
|
|
|
|
disable_irq(LUBBOCK_USB_IRQ);
|
|
|
|
enable_irq(LUBBOCK_USB_DISC_IRQ);
|
|
|
|
break;
|
|
|
|
case LUBBOCK_USB_DISC_IRQ:
|
|
|
|
vbus = 0;
|
|
|
|
disable_irq(LUBBOCK_USB_DISC_IRQ);
|
|
|
|
enable_irq(LUBBOCK_USB_IRQ);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
pxa25x_udc_vbus_session(&dev->gadget, vbus);
|
2005-04-17 06:20:36 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
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 21:55:46 +08:00
|
|
|
static irqreturn_t udc_vbus_irq(int irq, void *_dev)
|
2006-06-30 03:25:39 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_udc *dev = _dev;
|
2006-06-30 03:25:39 +08:00
|
|
|
|
2008-11-18 09:32:36 +08:00
|
|
|
pxa25x_udc_vbus_session(&dev->gadget, is_vbus_present());
|
2006-06-30 03:25:39 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static inline void clear_ep_state (struct pxa25x_udc *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
/* hardware SET_{CONFIGURATION,INTERFACE} automagic resets endpoint
|
|
|
|
* fifos, and pending transactions mustn't be continued in any case.
|
|
|
|
*/
|
|
|
|
for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++)
|
|
|
|
nuke(&dev->ep[i], -ECONNABORTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void udc_watchdog(unsigned long _dev)
|
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_udc *dev = (void *)_dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
local_irq_disable();
|
|
|
|
if (dev->ep0state == EP0_STALL
|
|
|
|
&& (UDCCS0 & UDCCS0_FST) == 0
|
|
|
|
&& (UDCCS0 & UDCCS0_SST) == 0) {
|
|
|
|
UDCCS0 = UDCCS0_FST|UDCCS0_FTF;
|
|
|
|
DBG(DBG_VERBOSE, "ep0 re-stall\n");
|
|
|
|
start_watchdog(dev);
|
|
|
|
}
|
|
|
|
local_irq_enable();
|
|
|
|
}
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static void handle_ep0 (struct pxa25x_udc *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
u32 udccs0 = UDCCS0;
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_ep *ep = &dev->ep [0];
|
|
|
|
struct pxa25x_request *req;
|
2005-04-17 06:20:36 +08:00
|
|
|
union {
|
|
|
|
struct usb_ctrlrequest r;
|
|
|
|
u8 raw [8];
|
|
|
|
u32 word [2];
|
|
|
|
} u;
|
|
|
|
|
|
|
|
if (list_empty(&ep->queue))
|
|
|
|
req = NULL;
|
|
|
|
else
|
2008-06-23 06:36:39 +08:00
|
|
|
req = list_entry(ep->queue.next, struct pxa25x_request, queue);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* clear stall status */
|
|
|
|
if (udccs0 & UDCCS0_SST) {
|
|
|
|
nuke(ep, -EPIPE);
|
|
|
|
UDCCS0 = UDCCS0_SST;
|
|
|
|
del_timer(&dev->timer);
|
|
|
|
ep0_idle(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* previous request unfinished? non-error iff back-to-back ... */
|
|
|
|
if ((udccs0 & UDCCS0_SA) != 0 && dev->ep0state != EP0_IDLE) {
|
|
|
|
nuke(ep, 0);
|
|
|
|
del_timer(&dev->timer);
|
|
|
|
ep0_idle(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (dev->ep0state) {
|
|
|
|
case EP0_IDLE:
|
|
|
|
/* late-breaking status? */
|
|
|
|
udccs0 = UDCCS0;
|
|
|
|
|
|
|
|
/* start control request? */
|
|
|
|
if (likely((udccs0 & (UDCCS0_OPR|UDCCS0_SA|UDCCS0_RNE))
|
|
|
|
== (UDCCS0_OPR|UDCCS0_SA|UDCCS0_RNE))) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
nuke (ep, -EPROTO);
|
|
|
|
|
|
|
|
/* read SETUP packet */
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (unlikely(!(UDCCS0 & UDCCS0_RNE))) {
|
|
|
|
bad_setup:
|
|
|
|
DMSG("SETUP %d!\n", i);
|
|
|
|
goto stall;
|
|
|
|
}
|
|
|
|
u.raw [i] = (u8) UDDR0;
|
|
|
|
}
|
|
|
|
if (unlikely((UDCCS0 & UDCCS0_RNE) != 0))
|
|
|
|
goto bad_setup;
|
|
|
|
|
|
|
|
got_setup:
|
|
|
|
DBG(DBG_VERBOSE, "SETUP %02x.%02x v%04x i%04x l%04x\n",
|
|
|
|
u.r.bRequestType, u.r.bRequest,
|
|
|
|
le16_to_cpu(u.r.wValue),
|
|
|
|
le16_to_cpu(u.r.wIndex),
|
|
|
|
le16_to_cpu(u.r.wLength));
|
|
|
|
|
|
|
|
/* cope with automagic for some standard requests. */
|
|
|
|
dev->req_std = (u.r.bRequestType & USB_TYPE_MASK)
|
|
|
|
== USB_TYPE_STANDARD;
|
|
|
|
dev->req_config = 0;
|
|
|
|
dev->req_pending = 1;
|
|
|
|
switch (u.r.bRequest) {
|
|
|
|
/* hardware restricts gadget drivers here! */
|
|
|
|
case USB_REQ_SET_CONFIGURATION:
|
|
|
|
if (u.r.bRequestType == USB_RECIP_DEVICE) {
|
|
|
|
/* reflect hardware's automagic
|
|
|
|
* up to the gadget driver.
|
|
|
|
*/
|
|
|
|
config_change:
|
|
|
|
dev->req_config = 1;
|
|
|
|
clear_ep_state(dev);
|
|
|
|
/* if !has_cfr, there's no synch
|
|
|
|
* else use AREN (later) not SA|OPR
|
|
|
|
* USIR0_IR0 acts edge sensitive
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
/* ... and here, even more ... */
|
|
|
|
case USB_REQ_SET_INTERFACE:
|
|
|
|
if (u.r.bRequestType == USB_RECIP_INTERFACE) {
|
|
|
|
/* udc hardware is broken by design:
|
|
|
|
* - altsetting may only be zero;
|
|
|
|
* - hw resets all interfaces' eps;
|
|
|
|
* - ep reset doesn't include halt(?).
|
|
|
|
*/
|
|
|
|
DMSG("broken set_interface (%d/%d)\n",
|
|
|
|
le16_to_cpu(u.r.wIndex),
|
|
|
|
le16_to_cpu(u.r.wValue));
|
|
|
|
goto config_change;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
/* hardware was supposed to hide this */
|
|
|
|
case USB_REQ_SET_ADDRESS:
|
|
|
|
if (u.r.bRequestType == USB_RECIP_DEVICE) {
|
|
|
|
ep0start(dev, 0, "address");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (u.r.bRequestType & USB_DIR_IN)
|
|
|
|
dev->ep0state = EP0_IN_DATA_PHASE;
|
|
|
|
else
|
|
|
|
dev->ep0state = EP0_OUT_DATA_PHASE;
|
|
|
|
|
|
|
|
i = dev->driver->setup(&dev->gadget, &u.r);
|
|
|
|
if (i < 0) {
|
|
|
|
/* hardware automagic preventing STALL... */
|
|
|
|
if (dev->req_config) {
|
|
|
|
/* hardware sometimes neglects to tell
|
|
|
|
* tell us about config change events,
|
|
|
|
* so later ones may fail...
|
|
|
|
*/
|
2008-07-25 16:45:52 +08:00
|
|
|
WARNING("config change %02x fail %d?\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
u.r.bRequest, i);
|
|
|
|
return;
|
|
|
|
/* TODO experiment: if has_cfr,
|
|
|
|
* hardware didn't ACK; maybe we
|
|
|
|
* could actually STALL!
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
DBG(DBG_VERBOSE, "protocol STALL, "
|
|
|
|
"%02x err %d\n", UDCCS0, i);
|
|
|
|
stall:
|
|
|
|
/* the watchdog timer helps deal with cases
|
|
|
|
* where udc seems to clear FST wrongly, and
|
|
|
|
* then NAKs instead of STALLing.
|
|
|
|
*/
|
|
|
|
ep0start(dev, UDCCS0_FST|UDCCS0_FTF, "stall");
|
|
|
|
start_watchdog(dev);
|
|
|
|
dev->ep0state = EP0_STALL;
|
|
|
|
|
|
|
|
/* deferred i/o == no response yet */
|
|
|
|
} else if (dev->req_pending) {
|
|
|
|
if (likely(dev->ep0state == EP0_IN_DATA_PHASE
|
|
|
|
|| dev->req_std || u.r.wLength))
|
|
|
|
ep0start(dev, 0, "defer");
|
|
|
|
else
|
|
|
|
ep0start(dev, UDCCS0_IPR, "defer/IPR");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* expect at least one data or status stage irq */
|
|
|
|
return;
|
|
|
|
|
|
|
|
} else if (likely((udccs0 & (UDCCS0_OPR|UDCCS0_SA))
|
|
|
|
== (UDCCS0_OPR|UDCCS0_SA))) {
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
/* pxa210/250 erratum 131 for B0/B1 says RNE lies.
|
|
|
|
* still observed on a pxa255 a0.
|
|
|
|
*/
|
|
|
|
DBG(DBG_VERBOSE, "e131\n");
|
|
|
|
nuke(ep, -EPROTO);
|
|
|
|
|
|
|
|
/* read SETUP data, but don't trust it too much */
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
u.raw [i] = (u8) UDDR0;
|
|
|
|
if ((u.r.bRequestType & USB_RECIP_MASK)
|
|
|
|
> USB_RECIP_OTHER)
|
|
|
|
goto stall;
|
|
|
|
if (u.word [0] == 0 && u.word [1] == 0)
|
|
|
|
goto stall;
|
|
|
|
goto got_setup;
|
|
|
|
} else {
|
|
|
|
/* some random early IRQ:
|
|
|
|
* - we acked FST
|
|
|
|
* - IPR cleared
|
|
|
|
* - OPR got set, without SA (likely status stage)
|
|
|
|
*/
|
|
|
|
UDCCS0 = udccs0 & (UDCCS0_SA|UDCCS0_OPR);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EP0_IN_DATA_PHASE: /* GET_DESCRIPTOR etc */
|
|
|
|
if (udccs0 & UDCCS0_OPR) {
|
|
|
|
UDCCS0 = UDCCS0_OPR|UDCCS0_FTF;
|
|
|
|
DBG(DBG_VERBOSE, "ep0in premature status\n");
|
|
|
|
if (req)
|
|
|
|
done(ep, req, 0);
|
|
|
|
ep0_idle(dev);
|
|
|
|
} else /* irq was IPR clearing */ {
|
|
|
|
if (req) {
|
|
|
|
/* this IN packet might finish the request */
|
|
|
|
(void) write_ep0_fifo(ep, req);
|
|
|
|
} /* else IN token before response was written */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EP0_OUT_DATA_PHASE: /* SET_DESCRIPTOR etc */
|
|
|
|
if (udccs0 & UDCCS0_OPR) {
|
|
|
|
if (req) {
|
|
|
|
/* this OUT packet might finish the request */
|
|
|
|
if (read_ep0_fifo(ep, req))
|
|
|
|
done(ep, req, 0);
|
|
|
|
/* else more OUT packets expected */
|
|
|
|
} /* else OUT token before read was issued */
|
|
|
|
} else /* irq was IPR clearing */ {
|
|
|
|
DBG(DBG_VERBOSE, "ep0out premature status\n");
|
|
|
|
if (req)
|
|
|
|
done(ep, req, 0);
|
|
|
|
ep0_idle(dev);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EP0_END_XFER:
|
|
|
|
if (req)
|
|
|
|
done(ep, req, 0);
|
|
|
|
/* ack control-IN status (maybe in-zlp was skipped)
|
|
|
|
* also appears after some config change events.
|
|
|
|
*/
|
|
|
|
if (udccs0 & UDCCS0_OPR)
|
|
|
|
UDCCS0 = UDCCS0_OPR;
|
|
|
|
ep0_idle(dev);
|
|
|
|
break;
|
|
|
|
case EP0_STALL:
|
|
|
|
UDCCS0 = UDCCS0_FST;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
USIR0 = USIR0_IR0;
|
|
|
|
}
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static void handle_ep(struct pxa25x_ep *ep)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_request *req;
|
2005-04-17 06:20:36 +08:00
|
|
|
int is_in = ep->bEndpointAddress & USB_DIR_IN;
|
|
|
|
int completed;
|
|
|
|
u32 udccs, tmp;
|
|
|
|
|
|
|
|
do {
|
|
|
|
completed = 0;
|
|
|
|
if (likely (!list_empty(&ep->queue)))
|
|
|
|
req = list_entry(ep->queue.next,
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_request, queue);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
|
|
|
req = NULL;
|
|
|
|
|
|
|
|
// TODO check FST handling
|
|
|
|
|
|
|
|
udccs = *ep->reg_udccs;
|
|
|
|
if (unlikely(is_in)) { /* irq from TPC, SST, or (ISO) TUR */
|
|
|
|
tmp = UDCCS_BI_TUR;
|
|
|
|
if (likely(ep->bmAttributes == USB_ENDPOINT_XFER_BULK))
|
|
|
|
tmp |= UDCCS_BI_SST;
|
|
|
|
tmp &= udccs;
|
|
|
|
if (likely (tmp))
|
|
|
|
*ep->reg_udccs = tmp;
|
|
|
|
if (req && likely ((udccs & UDCCS_BI_TFS) != 0))
|
|
|
|
completed = write_fifo(ep, req);
|
|
|
|
|
|
|
|
} else { /* irq from RPC (or for ISO, ROF) */
|
|
|
|
if (likely(ep->bmAttributes == USB_ENDPOINT_XFER_BULK))
|
|
|
|
tmp = UDCCS_BO_SST | UDCCS_BO_DME;
|
|
|
|
else
|
|
|
|
tmp = UDCCS_IO_ROF | UDCCS_IO_DME;
|
|
|
|
tmp &= udccs;
|
|
|
|
if (likely(tmp))
|
|
|
|
*ep->reg_udccs = tmp;
|
|
|
|
|
|
|
|
/* fifos can hold packets, ready for reading... */
|
|
|
|
if (likely(req)) {
|
|
|
|
completed = read_fifo(ep, req);
|
|
|
|
} else
|
|
|
|
pio_irq_disable (ep->bEndpointAddress);
|
|
|
|
}
|
|
|
|
ep->pio_irqs++;
|
|
|
|
} while (completed);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-06-23 06:36:39 +08:00
|
|
|
* pxa25x_udc_irq - interrupt handler
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* avoid delays in ep0 processing. the control handshaking isn't always
|
|
|
|
* under software control (pxa250c0 and the pxa255 are better), and delays
|
|
|
|
* could cause usb protocol errors.
|
|
|
|
*/
|
|
|
|
static irqreturn_t
|
2008-06-23 06:36:39 +08:00
|
|
|
pxa25x_udc_irq(int irq, void *_dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_udc *dev = _dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
int handled;
|
|
|
|
|
|
|
|
dev->stats.irqs++;
|
|
|
|
do {
|
|
|
|
u32 udccr = UDCCR;
|
|
|
|
|
|
|
|
handled = 0;
|
|
|
|
|
|
|
|
/* SUSpend Interrupt Request */
|
|
|
|
if (unlikely(udccr & UDCCR_SUSIR)) {
|
|
|
|
udc_ack_int_UDCCR(UDCCR_SUSIR);
|
|
|
|
handled = 1;
|
2005-05-08 04:20:19 +08:00
|
|
|
DBG(DBG_VERBOSE, "USB suspend%s\n", is_vbus_present()
|
2005-04-17 06:20:36 +08:00
|
|
|
? "" : "+disconnect");
|
|
|
|
|
2005-05-08 04:20:19 +08:00
|
|
|
if (!is_vbus_present())
|
2005-04-17 06:20:36 +08:00
|
|
|
stop_activity(dev, dev->driver);
|
|
|
|
else if (dev->gadget.speed != USB_SPEED_UNKNOWN
|
|
|
|
&& dev->driver
|
|
|
|
&& dev->driver->suspend)
|
|
|
|
dev->driver->suspend(&dev->gadget);
|
|
|
|
ep0_idle (dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RESume Interrupt Request */
|
|
|
|
if (unlikely(udccr & UDCCR_RESIR)) {
|
|
|
|
udc_ack_int_UDCCR(UDCCR_RESIR);
|
|
|
|
handled = 1;
|
|
|
|
DBG(DBG_VERBOSE, "USB resume\n");
|
|
|
|
|
|
|
|
if (dev->gadget.speed != USB_SPEED_UNKNOWN
|
|
|
|
&& dev->driver
|
|
|
|
&& dev->driver->resume
|
2005-05-08 04:20:19 +08:00
|
|
|
&& is_vbus_present())
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->driver->resume(&dev->gadget);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ReSeT Interrupt Request - USB reset */
|
|
|
|
if (unlikely(udccr & UDCCR_RSTIR)) {
|
|
|
|
udc_ack_int_UDCCR(UDCCR_RSTIR);
|
|
|
|
handled = 1;
|
|
|
|
|
|
|
|
if ((UDCCR & UDCCR_UDA) == 0) {
|
|
|
|
DBG(DBG_VERBOSE, "USB reset start\n");
|
|
|
|
|
|
|
|
/* reset driver and endpoints,
|
|
|
|
* in case that's not yet done
|
|
|
|
*/
|
|
|
|
stop_activity (dev, dev->driver);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
DBG(DBG_VERBOSE, "USB reset end\n");
|
|
|
|
dev->gadget.speed = USB_SPEED_FULL;
|
|
|
|
memset(&dev->stats, 0, sizeof dev->stats);
|
|
|
|
/* driver and endpoints are still reset */
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
u32 usir0 = USIR0 & ~UICR0;
|
|
|
|
u32 usir1 = USIR1 & ~UICR1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (unlikely (!usir0 && !usir1))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
DBG(DBG_VERY_NOISY, "irq %02x.%02x\n", usir1, usir0);
|
|
|
|
|
|
|
|
/* control traffic */
|
|
|
|
if (usir0 & USIR0_IR0) {
|
|
|
|
dev->ep[0].pio_irqs++;
|
|
|
|
handle_ep0(dev);
|
|
|
|
handled = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* endpoint data transfers */
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
u32 tmp = 1 << i;
|
|
|
|
|
|
|
|
if (i && (usir0 & tmp)) {
|
|
|
|
handle_ep(&dev->ep[i]);
|
|
|
|
USIR0 |= tmp;
|
|
|
|
handled = 1;
|
|
|
|
}
|
2009-07-01 18:43:58 +08:00
|
|
|
#ifndef CONFIG_USB_PXA25X_SMALL
|
2005-04-17 06:20:36 +08:00
|
|
|
if (usir1 & tmp) {
|
|
|
|
handle_ep(&dev->ep[i+8]);
|
|
|
|
USIR1 |= tmp;
|
|
|
|
handled = 1;
|
|
|
|
}
|
2009-07-01 18:43:58 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we could also ask for 1 msec SOF (SIR) interrupts */
|
|
|
|
|
|
|
|
} while (handled);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static void nop_release (struct device *dev)
|
|
|
|
{
|
2008-05-02 12:02:41 +08:00
|
|
|
DMSG("%s %s\n", __func__, dev_name(dev));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this uses load-time allocation and initialization (instead of
|
|
|
|
* doing it at run-time) to save code, eliminate fault paths, and
|
|
|
|
* be more obviously correct.
|
|
|
|
*/
|
2008-06-23 06:36:39 +08:00
|
|
|
static struct pxa25x_udc memory = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.gadget = {
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_udc_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.ep0 = &memory.ep[0].ep,
|
|
|
|
.name = driver_name,
|
|
|
|
.dev = {
|
2009-01-07 02:44:42 +08:00
|
|
|
.init_name = "gadget",
|
2005-04-17 06:20:36 +08:00
|
|
|
.release = nop_release,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
/* control endpoint */
|
|
|
|
.ep[0] = {
|
|
|
|
.ep = {
|
|
|
|
.name = ep0name,
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_ep_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.maxpacket = EP0_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
.reg_udccs = &UDCCS0,
|
|
|
|
.reg_uddr = &UDDR0,
|
|
|
|
},
|
|
|
|
|
|
|
|
/* first group of endpoints */
|
|
|
|
.ep[1] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep1in-bulk",
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_ep_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.maxpacket = BULK_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
.fifo_size = BULK_FIFO_SIZE,
|
|
|
|
.bEndpointAddress = USB_DIR_IN | 1,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
.reg_udccs = &UDCCS1,
|
|
|
|
.reg_uddr = &UDDR1,
|
|
|
|
},
|
|
|
|
.ep[2] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep2out-bulk",
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_ep_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.maxpacket = BULK_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
.fifo_size = BULK_FIFO_SIZE,
|
|
|
|
.bEndpointAddress = 2,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
.reg_udccs = &UDCCS2,
|
|
|
|
.reg_ubcr = &UBCR2,
|
|
|
|
.reg_uddr = &UDDR2,
|
|
|
|
},
|
2008-06-23 06:36:39 +08:00
|
|
|
#ifndef CONFIG_USB_PXA25X_SMALL
|
2005-04-17 06:20:36 +08:00
|
|
|
.ep[3] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep3in-iso",
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_ep_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.maxpacket = ISO_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
.fifo_size = ISO_FIFO_SIZE,
|
|
|
|
.bEndpointAddress = USB_DIR_IN | 3,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_ISOC,
|
|
|
|
.reg_udccs = &UDCCS3,
|
|
|
|
.reg_uddr = &UDDR3,
|
|
|
|
},
|
|
|
|
.ep[4] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep4out-iso",
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_ep_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.maxpacket = ISO_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
.fifo_size = ISO_FIFO_SIZE,
|
|
|
|
.bEndpointAddress = 4,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_ISOC,
|
|
|
|
.reg_udccs = &UDCCS4,
|
|
|
|
.reg_ubcr = &UBCR4,
|
|
|
|
.reg_uddr = &UDDR4,
|
|
|
|
},
|
|
|
|
.ep[5] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep5in-int",
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_ep_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.maxpacket = INT_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
.fifo_size = INT_FIFO_SIZE,
|
|
|
|
.bEndpointAddress = USB_DIR_IN | 5,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_INT,
|
|
|
|
.reg_udccs = &UDCCS5,
|
|
|
|
.reg_uddr = &UDDR5,
|
|
|
|
},
|
|
|
|
|
|
|
|
/* second group of endpoints */
|
|
|
|
.ep[6] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep6in-bulk",
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_ep_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.maxpacket = BULK_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
.fifo_size = BULK_FIFO_SIZE,
|
|
|
|
.bEndpointAddress = USB_DIR_IN | 6,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
.reg_udccs = &UDCCS6,
|
|
|
|
.reg_uddr = &UDDR6,
|
|
|
|
},
|
|
|
|
.ep[7] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep7out-bulk",
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_ep_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.maxpacket = BULK_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
.fifo_size = BULK_FIFO_SIZE,
|
|
|
|
.bEndpointAddress = 7,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
.reg_udccs = &UDCCS7,
|
|
|
|
.reg_ubcr = &UBCR7,
|
|
|
|
.reg_uddr = &UDDR7,
|
|
|
|
},
|
|
|
|
.ep[8] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep8in-iso",
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_ep_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.maxpacket = ISO_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
.fifo_size = ISO_FIFO_SIZE,
|
|
|
|
.bEndpointAddress = USB_DIR_IN | 8,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_ISOC,
|
|
|
|
.reg_udccs = &UDCCS8,
|
|
|
|
.reg_uddr = &UDDR8,
|
|
|
|
},
|
|
|
|
.ep[9] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep9out-iso",
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_ep_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.maxpacket = ISO_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
.fifo_size = ISO_FIFO_SIZE,
|
|
|
|
.bEndpointAddress = 9,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_ISOC,
|
|
|
|
.reg_udccs = &UDCCS9,
|
|
|
|
.reg_ubcr = &UBCR9,
|
|
|
|
.reg_uddr = &UDDR9,
|
|
|
|
},
|
|
|
|
.ep[10] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep10in-int",
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_ep_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.maxpacket = INT_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
.fifo_size = INT_FIFO_SIZE,
|
|
|
|
.bEndpointAddress = USB_DIR_IN | 10,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_INT,
|
|
|
|
.reg_udccs = &UDCCS10,
|
|
|
|
.reg_uddr = &UDDR10,
|
|
|
|
},
|
|
|
|
|
|
|
|
/* third group of endpoints */
|
|
|
|
.ep[11] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep11in-bulk",
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_ep_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.maxpacket = BULK_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
.fifo_size = BULK_FIFO_SIZE,
|
|
|
|
.bEndpointAddress = USB_DIR_IN | 11,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
.reg_udccs = &UDCCS11,
|
|
|
|
.reg_uddr = &UDDR11,
|
|
|
|
},
|
|
|
|
.ep[12] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep12out-bulk",
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_ep_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.maxpacket = BULK_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
.fifo_size = BULK_FIFO_SIZE,
|
|
|
|
.bEndpointAddress = 12,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
.reg_udccs = &UDCCS12,
|
|
|
|
.reg_ubcr = &UBCR12,
|
|
|
|
.reg_uddr = &UDDR12,
|
|
|
|
},
|
|
|
|
.ep[13] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep13in-iso",
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_ep_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.maxpacket = ISO_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
.fifo_size = ISO_FIFO_SIZE,
|
|
|
|
.bEndpointAddress = USB_DIR_IN | 13,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_ISOC,
|
|
|
|
.reg_udccs = &UDCCS13,
|
|
|
|
.reg_uddr = &UDDR13,
|
|
|
|
},
|
|
|
|
.ep[14] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep14out-iso",
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_ep_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.maxpacket = ISO_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
.fifo_size = ISO_FIFO_SIZE,
|
|
|
|
.bEndpointAddress = 14,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_ISOC,
|
|
|
|
.reg_udccs = &UDCCS14,
|
|
|
|
.reg_ubcr = &UBCR14,
|
|
|
|
.reg_uddr = &UDDR14,
|
|
|
|
},
|
|
|
|
.ep[15] = {
|
|
|
|
.ep = {
|
|
|
|
.name = "ep15in-int",
|
2008-06-23 06:36:39 +08:00
|
|
|
.ops = &pxa25x_ep_ops,
|
2005-04-17 06:20:36 +08:00
|
|
|
.maxpacket = INT_FIFO_SIZE,
|
|
|
|
},
|
|
|
|
.dev = &memory,
|
|
|
|
.fifo_size = INT_FIFO_SIZE,
|
|
|
|
.bEndpointAddress = USB_DIR_IN | 15,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_INT,
|
|
|
|
.reg_udccs = &UDCCS15,
|
|
|
|
.reg_uddr = &UDDR15,
|
|
|
|
},
|
2008-06-23 06:36:39 +08:00
|
|
|
#endif /* !CONFIG_USB_PXA25X_SMALL */
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define CP15R0_VENDOR_MASK 0xffffe000
|
|
|
|
|
|
|
|
#if defined(CONFIG_ARCH_PXA)
|
|
|
|
#define CP15R0_XSCALE_VALUE 0x69052000 /* intel/arm/xscale */
|
|
|
|
|
|
|
|
#elif defined(CONFIG_ARCH_IXP4XX)
|
|
|
|
#define CP15R0_XSCALE_VALUE 0x69054000 /* intel/arm/ixp4xx */
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CP15R0_PROD_MASK 0x000003f0
|
|
|
|
#define PXA25x 0x00000100 /* and PXA26x */
|
|
|
|
#define PXA210 0x00000120
|
|
|
|
|
|
|
|
#define CP15R0_REV_MASK 0x0000000f
|
|
|
|
|
|
|
|
#define CP15R0_PRODREV_MASK (CP15R0_PROD_MASK | CP15R0_REV_MASK)
|
|
|
|
|
|
|
|
#define PXA255_A0 0x00000106 /* or PXA260_B1 */
|
|
|
|
#define PXA250_C0 0x00000105 /* or PXA26x_B0 */
|
|
|
|
#define PXA250_B2 0x00000104
|
|
|
|
#define PXA250_B1 0x00000103 /* or PXA260_A0 */
|
|
|
|
#define PXA250_B0 0x00000102
|
|
|
|
#define PXA250_A1 0x00000101
|
|
|
|
#define PXA250_A0 0x00000100
|
|
|
|
|
|
|
|
#define PXA210_C0 0x00000125
|
|
|
|
#define PXA210_B2 0x00000124
|
|
|
|
#define PXA210_B1 0x00000123
|
|
|
|
#define PXA210_B0 0x00000122
|
|
|
|
#define IXP425_A0 0x000001c1
|
2006-11-21 03:38:57 +08:00
|
|
|
#define IXP425_B0 0x000001f1
|
2006-05-29 18:34:00 +08:00
|
|
|
#define IXP465_AD 0x00000200
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2007-02-25 04:23:52 +08:00
|
|
|
* probe - binds to the platform device
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2008-06-23 06:36:39 +08:00
|
|
|
static int __init pxa25x_udc_probe(struct platform_device *pdev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_udc *dev = &memory;
|
2007-06-30 21:30:04 +08:00
|
|
|
int retval, vbus_irq, irq;
|
2005-04-17 06:20:36 +08:00
|
|
|
u32 chiprev;
|
|
|
|
|
|
|
|
/* insist on Intel/ARM/XScale */
|
|
|
|
asm("mrc%? p15, 0, %0, c0, c0" : "=r" (chiprev));
|
|
|
|
if ((chiprev & CP15R0_VENDOR_MASK) != CP15R0_XSCALE_VALUE) {
|
2007-11-20 04:58:36 +08:00
|
|
|
pr_err("%s: not XScale!\n", driver_name);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* trigger chiprev-specific logic */
|
|
|
|
switch (chiprev & CP15R0_PRODREV_MASK) {
|
|
|
|
#if defined(CONFIG_ARCH_PXA)
|
|
|
|
case PXA255_A0:
|
|
|
|
dev->has_cfr = 1;
|
|
|
|
break;
|
|
|
|
case PXA250_A0:
|
|
|
|
case PXA250_A1:
|
|
|
|
/* A0/A1 "not released"; ep 13, 15 unusable */
|
|
|
|
/* fall through */
|
|
|
|
case PXA250_B2: case PXA210_B2:
|
|
|
|
case PXA250_B1: case PXA210_B1:
|
|
|
|
case PXA250_B0: case PXA210_B0:
|
2007-06-30 21:30:04 +08:00
|
|
|
/* OUT-DMA is broken ... */
|
2005-04-17 06:20:36 +08:00
|
|
|
/* fall through */
|
|
|
|
case PXA250_C0: case PXA210_C0:
|
|
|
|
break;
|
|
|
|
#elif defined(CONFIG_ARCH_IXP4XX)
|
|
|
|
case IXP425_A0:
|
2006-11-21 03:38:57 +08:00
|
|
|
case IXP425_B0:
|
2006-05-29 18:34:00 +08:00
|
|
|
case IXP465_AD:
|
|
|
|
dev->has_cfr = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2007-11-20 04:58:36 +08:00
|
|
|
pr_err("%s: unrecognized processor: %08x\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
driver_name, chiprev);
|
|
|
|
/* iop3xx, ixp4xx, ... */
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2007-02-25 04:23:52 +08:00
|
|
|
irq = platform_get_irq(pdev, 0);
|
|
|
|
if (irq < 0)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2008-11-12 01:52:32 +08:00
|
|
|
dev->clk = clk_get(&pdev->dev, NULL);
|
2007-08-20 17:33:35 +08:00
|
|
|
if (IS_ERR(dev->clk)) {
|
|
|
|
retval = PTR_ERR(dev->clk);
|
|
|
|
goto err_clk;
|
|
|
|
}
|
|
|
|
|
2007-06-30 21:30:04 +08:00
|
|
|
pr_debug("%s: IRQ %d%s%s\n", driver_name, irq,
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->has_cfr ? "" : " (!cfr)",
|
2007-06-30 21:30:04 +08:00
|
|
|
SIZE_STR "(pio)"
|
2005-04-17 06:20:36 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
/* other non-static parts of init */
|
2005-11-10 06:32:44 +08:00
|
|
|
dev->dev = &pdev->dev;
|
|
|
|
dev->mach = pdev->dev.platform_data;
|
2007-06-30 21:25:35 +08:00
|
|
|
|
2009-07-01 18:46:25 +08:00
|
|
|
dev->transceiver = otg_get_transceiver();
|
|
|
|
|
2009-07-01 18:42:45 +08:00
|
|
|
if (gpio_is_valid(dev->mach->gpio_vbus)) {
|
2007-06-30 21:25:35 +08:00
|
|
|
if ((retval = gpio_request(dev->mach->gpio_vbus,
|
2008-06-23 06:36:39 +08:00
|
|
|
"pxa25x_udc GPIO VBUS"))) {
|
2007-06-30 21:25:35 +08:00
|
|
|
dev_dbg(&pdev->dev,
|
|
|
|
"can't get vbus gpio %d, err: %d\n",
|
|
|
|
dev->mach->gpio_vbus, retval);
|
2007-08-20 17:33:35 +08:00
|
|
|
goto err_gpio_vbus;
|
2007-06-30 21:25:35 +08:00
|
|
|
}
|
|
|
|
gpio_direction_input(dev->mach->gpio_vbus);
|
|
|
|
vbus_irq = gpio_to_irq(dev->mach->gpio_vbus);
|
2006-06-30 03:25:39 +08:00
|
|
|
} else
|
|
|
|
vbus_irq = 0;
|
2007-06-30 21:25:35 +08:00
|
|
|
|
2009-07-01 18:42:45 +08:00
|
|
|
if (gpio_is_valid(dev->mach->gpio_pullup)) {
|
2007-06-30 21:25:35 +08:00
|
|
|
if ((retval = gpio_request(dev->mach->gpio_pullup,
|
2008-06-23 06:36:39 +08:00
|
|
|
"pca25x_udc GPIO PULLUP"))) {
|
2007-06-30 21:25:35 +08:00
|
|
|
dev_dbg(&pdev->dev,
|
|
|
|
"can't get pullup gpio %d, err: %d\n",
|
|
|
|
dev->mach->gpio_pullup, retval);
|
2007-08-20 17:33:35 +08:00
|
|
|
goto err_gpio_pullup;
|
2007-06-30 21:25:35 +08:00
|
|
|
}
|
|
|
|
gpio_direction_output(dev->mach->gpio_pullup, 0);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
init_timer(&dev->timer);
|
|
|
|
dev->timer.function = udc_watchdog;
|
|
|
|
dev->timer.data = (unsigned long) dev;
|
|
|
|
|
|
|
|
device_initialize(&dev->gadget.dev);
|
2005-11-10 06:32:44 +08:00
|
|
|
dev->gadget.dev.parent = &pdev->dev;
|
|
|
|
dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
the_controller = dev;
|
2005-11-10 06:32:44 +08:00
|
|
|
platform_set_drvdata(pdev, dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
udc_disable(dev);
|
|
|
|
udc_reinit(dev);
|
|
|
|
|
2008-11-25 03:43:30 +08:00
|
|
|
dev->vbus = !!is_vbus_present();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* irq setup after old hardware state is cleaned up */
|
2008-06-23 06:36:39 +08:00
|
|
|
retval = request_irq(irq, pxa25x_udc_irq,
|
2006-07-02 10:29:44 +08:00
|
|
|
IRQF_DISABLED, driver_name, dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval != 0) {
|
2007-11-20 04:58:36 +08:00
|
|
|
pr_err("%s: can't get irq %d, err %d\n",
|
2007-02-25 04:23:52 +08:00
|
|
|
driver_name, irq, retval);
|
2007-08-20 17:33:35 +08:00
|
|
|
goto err_irq1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
dev->got_irq = 1;
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_LUBBOCK
|
|
|
|
if (machine_is_lubbock()) {
|
|
|
|
retval = request_irq(LUBBOCK_USB_DISC_IRQ,
|
|
|
|
lubbock_vbus_irq,
|
2006-07-02 10:29:44 +08:00
|
|
|
IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
|
2005-04-17 06:20:36 +08:00
|
|
|
driver_name, dev);
|
|
|
|
if (retval != 0) {
|
2007-11-20 04:58:36 +08:00
|
|
|
pr_err("%s: can't get irq %i, err %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
driver_name, LUBBOCK_USB_DISC_IRQ, retval);
|
|
|
|
lubbock_fail0:
|
2007-08-20 17:33:35 +08:00
|
|
|
goto err_irq_lub;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
retval = request_irq(LUBBOCK_USB_IRQ,
|
|
|
|
lubbock_vbus_irq,
|
2006-07-02 10:29:44 +08:00
|
|
|
IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
|
2005-04-17 06:20:36 +08:00
|
|
|
driver_name, dev);
|
|
|
|
if (retval != 0) {
|
2007-11-20 04:58:36 +08:00
|
|
|
pr_err("%s: can't get irq %i, err %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
driver_name, LUBBOCK_USB_IRQ, retval);
|
|
|
|
free_irq(LUBBOCK_USB_DISC_IRQ, dev);
|
|
|
|
goto lubbock_fail0;
|
|
|
|
}
|
2006-06-30 03:25:39 +08:00
|
|
|
} else
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2006-06-30 03:25:39 +08:00
|
|
|
if (vbus_irq) {
|
|
|
|
retval = request_irq(vbus_irq, udc_vbus_irq,
|
2007-08-20 17:33:35 +08:00
|
|
|
IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
|
|
|
|
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
|
2006-06-30 03:25:39 +08:00
|
|
|
driver_name, dev);
|
|
|
|
if (retval != 0) {
|
2007-11-20 04:58:36 +08:00
|
|
|
pr_err("%s: can't get irq %i, err %d\n",
|
2006-06-30 03:25:39 +08:00
|
|
|
driver_name, vbus_irq, retval);
|
2007-08-20 17:33:35 +08:00
|
|
|
goto err_vbus_irq;
|
2006-06-30 03:25:39 +08:00
|
|
|
}
|
|
|
|
}
|
2007-12-31 03:56:27 +08:00
|
|
|
create_debug_files(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
2007-08-20 17:33:35 +08:00
|
|
|
|
|
|
|
err_vbus_irq:
|
|
|
|
#ifdef CONFIG_ARCH_LUBBOCK
|
|
|
|
free_irq(LUBBOCK_USB_DISC_IRQ, dev);
|
|
|
|
err_irq_lub:
|
|
|
|
#endif
|
|
|
|
free_irq(irq, dev);
|
|
|
|
err_irq1:
|
2009-07-01 18:42:45 +08:00
|
|
|
if (gpio_is_valid(dev->mach->gpio_pullup))
|
2007-08-20 17:33:35 +08:00
|
|
|
gpio_free(dev->mach->gpio_pullup);
|
|
|
|
err_gpio_pullup:
|
2009-07-01 18:42:45 +08:00
|
|
|
if (gpio_is_valid(dev->mach->gpio_vbus))
|
2007-08-20 17:33:35 +08:00
|
|
|
gpio_free(dev->mach->gpio_vbus);
|
|
|
|
err_gpio_vbus:
|
2009-07-01 18:46:25 +08:00
|
|
|
if (dev->transceiver) {
|
|
|
|
otg_put_transceiver(dev->transceiver);
|
|
|
|
dev->transceiver = NULL;
|
|
|
|
}
|
2007-08-20 17:33:35 +08:00
|
|
|
clk_put(dev->clk);
|
|
|
|
err_clk:
|
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-05-08 04:20:19 +08:00
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static void pxa25x_udc_shutdown(struct platform_device *_dev)
|
2005-05-08 04:20:19 +08:00
|
|
|
{
|
|
|
|
pullup_off();
|
|
|
|
}
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static int __exit pxa25x_udc_remove(struct platform_device *pdev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_udc *dev = platform_get_drvdata(pdev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-12-05 19:15:33 +08:00
|
|
|
if (dev->driver)
|
|
|
|
return -EBUSY;
|
|
|
|
|
2008-02-23 09:17:19 +08:00
|
|
|
dev->pullup = 0;
|
|
|
|
pullup(dev);
|
|
|
|
|
2007-12-31 03:56:27 +08:00
|
|
|
remove_debug_files(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (dev->got_irq) {
|
2007-02-25 04:23:52 +08:00
|
|
|
free_irq(platform_get_irq(pdev, 0), dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->got_irq = 0;
|
|
|
|
}
|
2006-05-29 18:34:00 +08:00
|
|
|
#ifdef CONFIG_ARCH_LUBBOCK
|
2005-04-17 06:20:36 +08:00
|
|
|
if (machine_is_lubbock()) {
|
|
|
|
free_irq(LUBBOCK_USB_DISC_IRQ, dev);
|
|
|
|
free_irq(LUBBOCK_USB_IRQ, dev);
|
|
|
|
}
|
2006-05-29 18:34:00 +08:00
|
|
|
#endif
|
2009-07-01 18:42:45 +08:00
|
|
|
if (gpio_is_valid(dev->mach->gpio_vbus)) {
|
2007-06-30 21:25:35 +08:00
|
|
|
free_irq(gpio_to_irq(dev->mach->gpio_vbus), dev);
|
|
|
|
gpio_free(dev->mach->gpio_vbus);
|
|
|
|
}
|
2009-07-01 18:42:45 +08:00
|
|
|
if (gpio_is_valid(dev->mach->gpio_pullup))
|
2007-06-30 21:25:35 +08:00
|
|
|
gpio_free(dev->mach->gpio_pullup);
|
|
|
|
|
2007-08-20 17:33:35 +08:00
|
|
|
clk_put(dev->clk);
|
|
|
|
|
2009-07-01 18:46:25 +08:00
|
|
|
if (dev->transceiver) {
|
|
|
|
otg_put_transceiver(dev->transceiver);
|
|
|
|
dev->transceiver = NULL;
|
|
|
|
}
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
platform_set_drvdata(pdev, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
the_controller = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
|
|
|
|
/* USB suspend (controlled by the host) and system suspend (controlled
|
|
|
|
* by the PXA) don't necessarily work well together. If USB is active,
|
|
|
|
* the 48 MHz clock is required; so the system can't enter 33 MHz idle
|
|
|
|
* mode, or any deeper PM saving state.
|
|
|
|
*
|
|
|
|
* For now, we punt and forcibly disconnect from the USB host when PXA
|
|
|
|
* enters any suspend state. While we're disconnected, we always disable
|
2007-02-25 04:23:52 +08:00
|
|
|
* the 48MHz USB clock ... allowing PXA sleep and/or 33 MHz idle states.
|
2005-04-17 06:20:36 +08:00
|
|
|
* Boards without software pullup control shouldn't use those states.
|
|
|
|
* VBUS IRQs should probably be ignored so that the PXA device just acts
|
|
|
|
* "dead" to USB hosts until system resume.
|
|
|
|
*/
|
2008-06-23 06:36:39 +08:00
|
|
|
static int pxa25x_udc_suspend(struct platform_device *dev, pm_message_t state)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_udc *udc = platform_get_drvdata(dev);
|
2008-02-23 09:17:19 +08:00
|
|
|
unsigned long flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-07-01 18:42:45 +08:00
|
|
|
if (!gpio_is_valid(udc->mach->gpio_pullup) && !udc->mach->udc_command)
|
2008-07-25 16:45:52 +08:00
|
|
|
WARNING("USB host won't detect disconnect!\n");
|
2008-02-23 09:17:19 +08:00
|
|
|
udc->suspended = 1;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
pullup(udc);
|
|
|
|
local_irq_restore(flags);
|
2005-10-29 00:52:56 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-23 06:36:39 +08:00
|
|
|
static int pxa25x_udc_resume(struct platform_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-06-23 06:36:39 +08:00
|
|
|
struct pxa25x_udc *udc = platform_get_drvdata(dev);
|
2008-02-23 09:17:19 +08:00
|
|
|
unsigned long flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-02-23 09:17:19 +08:00
|
|
|
udc->suspended = 0;
|
|
|
|
local_irq_save(flags);
|
|
|
|
pullup(udc);
|
|
|
|
local_irq_restore(flags);
|
2005-10-29 00:52:56 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2008-06-23 06:36:39 +08:00
|
|
|
#define pxa25x_udc_suspend NULL
|
|
|
|
#define pxa25x_udc_resume NULL
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2005-11-10 06:32:44 +08:00
|
|
|
static struct platform_driver udc_driver = {
|
2008-06-23 06:36:39 +08:00
|
|
|
.shutdown = pxa25x_udc_shutdown,
|
|
|
|
.remove = __exit_p(pxa25x_udc_remove),
|
|
|
|
.suspend = pxa25x_udc_suspend,
|
|
|
|
.resume = pxa25x_udc_resume,
|
2005-11-10 06:32:44 +08:00
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
2008-06-23 06:36:39 +08:00
|
|
|
.name = "pxa25x-udc",
|
2005-11-10 06:32:44 +08:00
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init udc_init(void)
|
|
|
|
{
|
2007-11-20 04:58:36 +08:00
|
|
|
pr_info("%s: version %s\n", driver_name, DRIVER_VERSION);
|
2008-06-23 06:36:39 +08:00
|
|
|
return platform_driver_probe(&udc_driver, pxa25x_udc_probe);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
module_init(udc_init);
|
|
|
|
|
|
|
|
static void __exit udc_exit(void)
|
|
|
|
{
|
2005-11-10 06:32:44 +08:00
|
|
|
platform_driver_unregister(&udc_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
module_exit(udc_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_AUTHOR("Frank Becker, Robert Schwebel, David Brownell");
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-06-23 06:36:39 +08:00
|
|
|
MODULE_ALIAS("platform:pxa25x-udc");
|