2008-11-18 06:14:51 +08:00
|
|
|
/*
|
2012-05-11 22:25:54 +08:00
|
|
|
* udc.c - ChipIdea UDC driver
|
2008-11-18 06:14:51 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: David Lopo
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
2009-04-16 04:28:36 +08:00
|
|
|
#include <linux/delay.h>
|
2008-11-18 06:14:51 +08:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/dmapool.h>
|
2012-06-26 20:10:32 +08:00
|
|
|
#include <linux/err.h>
|
2013-03-30 08:46:18 +08:00
|
|
|
#include <linux/irqreturn.h>
|
2008-11-18 06:14:51 +08:00
|
|
|
#include <linux/kernel.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2010-12-07 20:24:04 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
2008-11-18 06:14:51 +08:00
|
|
|
#include <linux/usb/ch9.h>
|
|
|
|
#include <linux/usb/gadget.h>
|
2010-12-07 20:24:02 +08:00
|
|
|
#include <linux/usb/otg.h>
|
2012-05-11 22:25:46 +08:00
|
|
|
#include <linux/usb/chipidea.h>
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-05-11 22:25:46 +08:00
|
|
|
#include "ci.h"
|
|
|
|
#include "udc.h"
|
|
|
|
#include "bits.h"
|
|
|
|
#include "debug.h"
|
2011-10-11 00:38:06 +08:00
|
|
|
|
2008-11-18 06:14:51 +08:00
|
|
|
/* control endpoint description */
|
|
|
|
static const struct usb_endpoint_descriptor
|
2011-01-11 11:49:22 +08:00
|
|
|
ctrl_endpt_out_desc = {
|
2008-11-18 06:14:51 +08:00
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
2011-01-11 11:49:22 +08:00
|
|
|
.bEndpointAddress = USB_DIR_OUT,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_CONTROL,
|
|
|
|
.wMaxPacketSize = cpu_to_le16(CTRL_PAYLOAD_MAX),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct usb_endpoint_descriptor
|
|
|
|
ctrl_endpt_in_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_IN,
|
2008-11-18 06:14:51 +08:00
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_CONTROL,
|
|
|
|
.wMaxPacketSize = cpu_to_le16(CTRL_PAYLOAD_MAX),
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_ep_bit: calculates the bit number
|
|
|
|
* @num: endpoint number
|
|
|
|
* @dir: endpoint direction
|
|
|
|
*
|
|
|
|
* This function returns bit number
|
|
|
|
*/
|
|
|
|
static inline int hw_ep_bit(int num, int dir)
|
|
|
|
{
|
|
|
|
return num + (dir ? 16 : 0);
|
|
|
|
}
|
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
static inline int ep_to_bit(struct ci_hdrc *ci, int n)
|
2011-10-11 00:38:10 +08:00
|
|
|
{
|
2012-07-07 22:56:40 +08:00
|
|
|
int fill = 16 - ci->hw_ep_max / 2;
|
2011-10-11 00:38:10 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
if (n >= ci->hw_ep_max / 2)
|
2011-10-11 00:38:10 +08:00
|
|
|
n += fill;
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2008-11-18 06:14:51 +08:00
|
|
|
/**
|
2012-09-12 19:58:01 +08:00
|
|
|
* hw_device_state: enables/disables interrupts (execute without interruption)
|
2008-11-18 06:14:51 +08:00
|
|
|
* @dma: 0 => disable, !0 => enable and set dma engine
|
|
|
|
*
|
|
|
|
* This function returns an error code
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int hw_device_state(struct ci_hdrc *ci, u32 dma)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
|
|
|
if (dma) {
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_write(ci, OP_ENDPTLISTADDR, ~0, dma);
|
2008-11-18 06:14:51 +08:00
|
|
|
/* interrupt, error, port change, reset, sleep/suspend */
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_write(ci, OP_USBINTR, ~0,
|
2008-11-18 06:14:51 +08:00
|
|
|
USBi_UI|USBi_UEI|USBi_PCI|USBi_URI|USBi_SLI);
|
|
|
|
} else {
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_write(ci, OP_USBINTR, ~0, 0);
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_ep_flush: flush endpoint fifo (execute without interruption)
|
|
|
|
* @num: endpoint number
|
|
|
|
* @dir: endpoint direction
|
|
|
|
*
|
|
|
|
* This function returns an error code
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int hw_ep_flush(struct ci_hdrc *ci, int num, int dir)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
|
|
|
int n = hw_ep_bit(num, dir);
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* flush any pending transfer */
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_write(ci, OP_ENDPTFLUSH, BIT(n), BIT(n));
|
|
|
|
while (hw_read(ci, OP_ENDPTFLUSH, BIT(n)))
|
2008-11-18 06:14:51 +08:00
|
|
|
cpu_relax();
|
2012-07-07 22:56:40 +08:00
|
|
|
} while (hw_read(ci, OP_ENDPTSTAT, BIT(n)));
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_ep_disable: disables endpoint (execute without interruption)
|
|
|
|
* @num: endpoint number
|
|
|
|
* @dir: endpoint direction
|
|
|
|
*
|
|
|
|
* This function returns an error code
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int hw_ep_disable(struct ci_hdrc *ci, int num, int dir)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_ep_flush(ci, num, dir);
|
|
|
|
hw_write(ci, OP_ENDPTCTRL + num,
|
2012-05-09 04:28:58 +08:00
|
|
|
dir ? ENDPTCTRL_TXE : ENDPTCTRL_RXE, 0);
|
2008-11-18 06:14:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_ep_enable: enables endpoint (execute without interruption)
|
|
|
|
* @num: endpoint number
|
|
|
|
* @dir: endpoint direction
|
|
|
|
* @type: endpoint type
|
|
|
|
*
|
|
|
|
* This function returns an error code
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int hw_ep_enable(struct ci_hdrc *ci, int num, int dir, int type)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
|
|
|
u32 mask, data;
|
|
|
|
|
|
|
|
if (dir) {
|
|
|
|
mask = ENDPTCTRL_TXT; /* type */
|
2013-03-30 18:53:55 +08:00
|
|
|
data = type << __ffs(mask);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
mask |= ENDPTCTRL_TXS; /* unstall */
|
|
|
|
mask |= ENDPTCTRL_TXR; /* reset data toggle */
|
|
|
|
data |= ENDPTCTRL_TXR;
|
|
|
|
mask |= ENDPTCTRL_TXE; /* enable */
|
|
|
|
data |= ENDPTCTRL_TXE;
|
|
|
|
} else {
|
|
|
|
mask = ENDPTCTRL_RXT; /* type */
|
2013-03-30 18:53:55 +08:00
|
|
|
data = type << __ffs(mask);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
mask |= ENDPTCTRL_RXS; /* unstall */
|
|
|
|
mask |= ENDPTCTRL_RXR; /* reset data toggle */
|
|
|
|
data |= ENDPTCTRL_RXR;
|
|
|
|
mask |= ENDPTCTRL_RXE; /* enable */
|
|
|
|
data |= ENDPTCTRL_RXE;
|
|
|
|
}
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_write(ci, OP_ENDPTCTRL + num, mask, data);
|
2008-11-18 06:14:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_ep_get_halt: return endpoint halt status
|
|
|
|
* @num: endpoint number
|
|
|
|
* @dir: endpoint direction
|
|
|
|
*
|
|
|
|
* This function returns 1 if endpoint halted
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int hw_ep_get_halt(struct ci_hdrc *ci, int num, int dir)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
|
|
|
u32 mask = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS;
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
return hw_read(ci, OP_ENDPTCTRL + num, mask) ? 1 : 0;
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_test_and_clear_setup_status: test & clear setup status (execute without
|
|
|
|
* interruption)
|
2011-10-11 00:38:10 +08:00
|
|
|
* @n: endpoint number
|
2008-11-18 06:14:51 +08:00
|
|
|
*
|
|
|
|
* This function returns setup status
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int hw_test_and_clear_setup_status(struct ci_hdrc *ci, int n)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2012-07-07 22:56:40 +08:00
|
|
|
n = ep_to_bit(ci, n);
|
|
|
|
return hw_test_and_clear(ci, OP_ENDPTSETUPSTAT, BIT(n));
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_ep_prime: primes endpoint (execute without interruption)
|
|
|
|
* @num: endpoint number
|
|
|
|
* @dir: endpoint direction
|
|
|
|
* @is_ctrl: true if control endpoint
|
|
|
|
*
|
|
|
|
* This function returns an error code
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int hw_ep_prime(struct ci_hdrc *ci, int num, int dir, int is_ctrl)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
|
|
|
int n = hw_ep_bit(num, dir);
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
if (is_ctrl && dir == RX && hw_read(ci, OP_ENDPTSETUPSTAT, BIT(num)))
|
2008-11-18 06:14:51 +08:00
|
|
|
return -EAGAIN;
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_write(ci, OP_ENDPTPRIME, BIT(n), BIT(n));
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
while (hw_read(ci, OP_ENDPTPRIME, BIT(n)))
|
2008-11-18 06:14:51 +08:00
|
|
|
cpu_relax();
|
2012-07-07 22:56:40 +08:00
|
|
|
if (is_ctrl && dir == RX && hw_read(ci, OP_ENDPTSETUPSTAT, BIT(num)))
|
2008-11-18 06:14:51 +08:00
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
/* status shoult be tested according with manual but it doesn't work */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_ep_set_halt: configures ep halt & resets data toggle after clear (execute
|
|
|
|
* without interruption)
|
|
|
|
* @num: endpoint number
|
|
|
|
* @dir: endpoint direction
|
|
|
|
* @value: true => stall, false => unstall
|
|
|
|
*
|
|
|
|
* This function returns an error code
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int hw_ep_set_halt(struct ci_hdrc *ci, int num, int dir, int value)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
|
|
|
if (value != 0 && value != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
do {
|
2013-06-24 19:46:36 +08:00
|
|
|
enum ci_hw_regs reg = OP_ENDPTCTRL + num;
|
2008-11-18 06:14:51 +08:00
|
|
|
u32 mask_xs = dir ? ENDPTCTRL_TXS : ENDPTCTRL_RXS;
|
|
|
|
u32 mask_xr = dir ? ENDPTCTRL_TXR : ENDPTCTRL_RXR;
|
|
|
|
|
|
|
|
/* data toggle - reserved for EP0 but it's in ESS */
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_write(ci, reg, mask_xs|mask_xr,
|
2012-05-09 04:28:59 +08:00
|
|
|
value ? mask_xs : mask_xr);
|
2012-07-07 22:56:40 +08:00
|
|
|
} while (value != hw_ep_get_halt(ci, num, dir));
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_is_port_high_speed: test if port is high speed
|
|
|
|
*
|
|
|
|
* This function returns true if high speed port
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int hw_port_is_high_speed(struct ci_hdrc *ci)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2012-07-07 22:56:40 +08:00
|
|
|
return ci->hw_bank.lpm ? hw_read(ci, OP_DEVLC, DEVLC_PSPD) :
|
|
|
|
hw_read(ci, OP_PORTSC, PORTSC_HSP);
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_read_intr_enable: returns interrupt enable register
|
|
|
|
*
|
|
|
|
* This function returns register data
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static u32 hw_read_intr_enable(struct ci_hdrc *ci)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2012-07-07 22:56:40 +08:00
|
|
|
return hw_read(ci, OP_USBINTR, ~0);
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_read_intr_status: returns interrupt status register
|
|
|
|
*
|
|
|
|
* This function returns register data
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static u32 hw_read_intr_status(struct ci_hdrc *ci)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2012-07-07 22:56:40 +08:00
|
|
|
return hw_read(ci, OP_USBSTS, ~0);
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_test_and_clear_complete: test & clear complete status (execute without
|
|
|
|
* interruption)
|
2011-10-11 00:38:10 +08:00
|
|
|
* @n: endpoint number
|
2008-11-18 06:14:51 +08:00
|
|
|
*
|
|
|
|
* This function returns complete status
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int hw_test_and_clear_complete(struct ci_hdrc *ci, int n)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2012-07-07 22:56:40 +08:00
|
|
|
n = ep_to_bit(ci, n);
|
|
|
|
return hw_test_and_clear(ci, OP_ENDPTCOMPLETE, BIT(n));
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_test_and_clear_intr_active: test & clear active interrupts (execute
|
|
|
|
* without interruption)
|
|
|
|
*
|
|
|
|
* This function returns active interrutps
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static u32 hw_test_and_clear_intr_active(struct ci_hdrc *ci)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2012-07-07 22:56:40 +08:00
|
|
|
u32 reg = hw_read_intr_status(ci) & hw_read_intr_enable(ci);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_write(ci, OP_USBSTS, ~0, reg);
|
2008-11-18 06:14:51 +08:00
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_test_and_clear_setup_guard: test & clear setup guard (execute without
|
|
|
|
* interruption)
|
|
|
|
*
|
|
|
|
* This function returns guard value
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int hw_test_and_clear_setup_guard(struct ci_hdrc *ci)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2012-07-07 22:56:40 +08:00
|
|
|
return hw_test_and_write(ci, OP_USBCMD, USBCMD_SUTW, 0);
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_test_and_set_setup_guard: test & set setup guard (execute without
|
|
|
|
* interruption)
|
|
|
|
*
|
|
|
|
* This function returns guard value
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int hw_test_and_set_setup_guard(struct ci_hdrc *ci)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2012-07-07 22:56:40 +08:00
|
|
|
return hw_test_and_write(ci, OP_USBCMD, USBCMD_SUTW, USBCMD_SUTW);
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_usb_set_address: configures USB address (execute without interruption)
|
|
|
|
* @value: new USB address
|
|
|
|
*
|
usb: gadget: ci13xxx: don't use "advance" feature when setting address
Newer versions of the chipidea controller support the "advance" setting
of usb address, which means instead of setting it immediately, deferring
it till the status completion. Unfortunately, older versions of the
controller don't have this feature, so in order to support those too, we
simply don't use it. It's about 4 lines of extra code, and isn't in any
way critical to performance. While at it, change the return value of the
hw_usb_set_address() to void, since it can't fail in any measurable way.
With this patch, ci13xxx_udc driver works with the chipidea controller in
kirkwood (feroceon SoC), as found in, for example, sheevaplug.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-05-11 22:25:43 +08:00
|
|
|
* This function explicitly sets the address, without the "USBADRA" (advance)
|
|
|
|
* feature, which is not supported by older versions of the controller.
|
2008-11-18 06:14:51 +08:00
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static void hw_usb_set_address(struct ci_hdrc *ci, u8 value)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_write(ci, OP_DEVICEADDR, DEVICEADDR_USBADR,
|
2013-03-30 18:53:55 +08:00
|
|
|
value << __ffs(DEVICEADDR_USBADR));
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hw_usb_reset: restart device after a bus reset (execute without
|
|
|
|
* interruption)
|
|
|
|
*
|
|
|
|
* This function returns an error code
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int hw_usb_reset(struct ci_hdrc *ci)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_usb_set_address(ci, 0);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
/* ESS flushes only at end?!? */
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_write(ci, OP_ENDPTFLUSH, ~0, ~0);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
/* clear setup token semaphores */
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_write(ci, OP_ENDPTSETUPSTAT, 0, 0);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
/* clear complete status */
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_write(ci, OP_ENDPTCOMPLETE, 0, 0);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
/* wait until all bits cleared */
|
2012-07-07 22:56:40 +08:00
|
|
|
while (hw_read(ci, OP_ENDPTPRIME, ~0))
|
2008-11-18 06:14:51 +08:00
|
|
|
udelay(10); /* not RTOS friendly */
|
|
|
|
|
|
|
|
/* reset all endpoints ? */
|
|
|
|
|
|
|
|
/* reset internal status and wait for further instructions
|
|
|
|
no need to verify the port reset status (ESS does it) */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* UTIL block
|
|
|
|
*****************************************************************************/
|
2013-06-13 22:59:53 +08:00
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
static int add_td_to_list(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq,
|
2013-06-13 22:59:53 +08:00
|
|
|
unsigned length)
|
|
|
|
{
|
2013-06-13 22:59:54 +08:00
|
|
|
int i;
|
|
|
|
u32 temp;
|
2013-06-13 22:59:53 +08:00
|
|
|
struct td_node *lastnode, *node = kzalloc(sizeof(struct td_node),
|
|
|
|
GFP_ATOMIC);
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
node->ptr = dma_pool_alloc(hwep->td_pool, GFP_ATOMIC,
|
2013-06-13 22:59:53 +08:00
|
|
|
&node->dma);
|
|
|
|
if (node->ptr == NULL) {
|
|
|
|
kfree(node);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
memset(node->ptr, 0, sizeof(struct ci_hw_td));
|
2013-06-13 22:59:54 +08:00
|
|
|
node->ptr->token = cpu_to_le32(length << __ffs(TD_TOTAL_BYTES));
|
|
|
|
node->ptr->token &= cpu_to_le32(TD_TOTAL_BYTES);
|
|
|
|
node->ptr->token |= cpu_to_le32(TD_STATUS_ACTIVE);
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
temp = (u32) (hwreq->req.dma + hwreq->req.actual);
|
2013-06-13 22:59:54 +08:00
|
|
|
if (length) {
|
|
|
|
node->ptr->page[0] = cpu_to_le32(temp);
|
|
|
|
for (i = 1; i < TD_PAGE_COUNT; i++) {
|
2013-06-24 19:46:36 +08:00
|
|
|
u32 page = temp + i * CI_HDRC_PAGE_SIZE;
|
2013-06-13 22:59:54 +08:00
|
|
|
page &= ~TD_RESERVED_MASK;
|
|
|
|
node->ptr->page[i] = cpu_to_le32(page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwreq->req.actual += length;
|
2013-06-13 22:59:53 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (!list_empty(&hwreq->tds)) {
|
2013-06-13 22:59:53 +08:00
|
|
|
/* get the last entry */
|
2013-06-13 23:00:03 +08:00
|
|
|
lastnode = list_entry(hwreq->tds.prev,
|
2013-06-13 22:59:53 +08:00
|
|
|
struct td_node, td);
|
|
|
|
lastnode->ptr->next = cpu_to_le32(node->dma);
|
|
|
|
}
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&node->td);
|
2013-06-13 23:00:03 +08:00
|
|
|
list_add_tail(&node->td, &hwreq->tds);
|
2013-06-13 22:59:53 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-18 06:14:51 +08:00
|
|
|
/**
|
|
|
|
* _usb_addr: calculates endpoint address from direction & number
|
|
|
|
* @ep: endpoint
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static inline u8 _usb_addr(struct ci_hw_ep *ep)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
|
|
|
return ((ep->dir == TX) ? USB_ENDPOINT_DIR_MASK : 0) | ep->num;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _hardware_queue: configures a request at hardware level
|
|
|
|
* @gadget: gadget
|
2013-06-13 23:00:03 +08:00
|
|
|
* @hwep: endpoint
|
2008-11-18 06:14:51 +08:00
|
|
|
*
|
|
|
|
* This function returns an error code
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int _hardware_enqueue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hdrc *ci = hwep->ci;
|
2011-02-18 20:13:16 +08:00
|
|
|
int ret = 0;
|
2013-06-13 23:00:03 +08:00
|
|
|
unsigned rest = hwreq->req.length;
|
2013-06-13 22:59:54 +08:00
|
|
|
int pages = TD_PAGE_COUNT;
|
2013-06-13 22:59:53 +08:00
|
|
|
struct td_node *firstnode, *lastnode;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
/* don't queue twice */
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwreq->req.status == -EALREADY)
|
2008-11-18 06:14:51 +08:00
|
|
|
return -EALREADY;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwreq->req.status = -EALREADY;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
ret = usb_gadget_map_request(&ci->gadget, &hwreq->req, hwep->dir);
|
2012-05-11 22:25:56 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2013-06-13 22:59:54 +08:00
|
|
|
/*
|
|
|
|
* The first buffer could be not page aligned.
|
|
|
|
* In that case we have to span into one extra td.
|
|
|
|
*/
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwreq->req.dma % PAGE_SIZE)
|
2013-06-13 22:59:54 +08:00
|
|
|
pages--;
|
2013-06-13 22:59:53 +08:00
|
|
|
|
2013-06-13 22:59:54 +08:00
|
|
|
if (rest == 0)
|
2013-06-13 23:00:03 +08:00
|
|
|
add_td_to_list(hwep, hwreq, 0);
|
2013-06-13 22:59:53 +08:00
|
|
|
|
2013-06-13 22:59:54 +08:00
|
|
|
while (rest > 0) {
|
2013-06-13 23:00:03 +08:00
|
|
|
unsigned count = min(hwreq->req.length - hwreq->req.actual,
|
2013-06-24 19:46:36 +08:00
|
|
|
(unsigned)(pages * CI_HDRC_PAGE_SIZE));
|
2013-06-13 23:00:03 +08:00
|
|
|
add_td_to_list(hwep, hwreq, count);
|
2013-06-13 22:59:54 +08:00
|
|
|
rest -= count;
|
2011-02-18 20:13:16 +08:00
|
|
|
}
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwreq->req.zero && hwreq->req.length
|
|
|
|
&& (hwreq->req.length % hwep->ep.maxpacket == 0))
|
|
|
|
add_td_to_list(hwep, hwreq, 0);
|
2013-06-13 22:59:53 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
firstnode = list_first_entry(&hwreq->tds, struct td_node, td);
|
2013-06-13 22:59:54 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
lastnode = list_entry(hwreq->tds.prev,
|
2013-06-13 22:59:53 +08:00
|
|
|
struct td_node, td);
|
|
|
|
|
|
|
|
lastnode->ptr->next = cpu_to_le32(TD_TERMINATE);
|
2013-06-13 23:00:03 +08:00
|
|
|
if (!hwreq->req.no_interrupt)
|
2013-06-13 22:59:53 +08:00
|
|
|
lastnode->ptr->token |= cpu_to_le32(TD_IOC);
|
2013-04-04 18:13:46 +08:00
|
|
|
wmb();
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwreq->req.actual = 0;
|
|
|
|
if (!list_empty(&hwep->qh.queue)) {
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_req *hwreqprev;
|
2013-06-13 23:00:03 +08:00
|
|
|
int n = hw_ep_bit(hwep->num, hwep->dir);
|
2011-02-18 20:13:16 +08:00
|
|
|
int tmp_stat;
|
2013-06-13 22:59:53 +08:00
|
|
|
struct td_node *prevlastnode;
|
|
|
|
u32 next = firstnode->dma & TD_ADDR_MASK;
|
2011-02-18 20:13:16 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwreqprev = list_entry(hwep->qh.queue.prev,
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_req, queue);
|
2013-06-13 23:00:03 +08:00
|
|
|
prevlastnode = list_entry(hwreqprev->tds.prev,
|
2013-06-13 22:59:53 +08:00
|
|
|
struct td_node, td);
|
|
|
|
|
|
|
|
prevlastnode->ptr->next = cpu_to_le32(next);
|
2011-02-18 20:13:16 +08:00
|
|
|
wmb();
|
2012-07-07 22:56:40 +08:00
|
|
|
if (hw_read(ci, OP_ENDPTPRIME, BIT(n)))
|
2011-02-18 20:13:16 +08:00
|
|
|
goto done;
|
|
|
|
do {
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_write(ci, OP_USBCMD, USBCMD_ATDTW, USBCMD_ATDTW);
|
|
|
|
tmp_stat = hw_read(ci, OP_ENDPTSTAT, BIT(n));
|
|
|
|
} while (!hw_read(ci, OP_USBCMD, USBCMD_ATDTW));
|
|
|
|
hw_write(ci, OP_USBCMD, USBCMD_ATDTW, 0);
|
2011-02-18 20:13:16 +08:00
|
|
|
if (tmp_stat)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* QH configuration */
|
2013-06-13 23:00:03 +08:00
|
|
|
hwep->qh.ptr->td.next = cpu_to_le32(firstnode->dma);
|
|
|
|
hwep->qh.ptr->td.token &=
|
2013-03-30 18:54:04 +08:00
|
|
|
cpu_to_le32(~(TD_STATUS_HALTED|TD_STATUS_ACTIVE));
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwep->type == USB_ENDPOINT_XFER_ISOC) {
|
|
|
|
u32 mul = hwreq->req.length / hwep->ep.maxpacket;
|
2013-06-13 22:59:47 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwreq->req.length % hwep->ep.maxpacket)
|
2013-06-13 22:59:47 +08:00
|
|
|
mul++;
|
2013-06-13 23:00:03 +08:00
|
|
|
hwep->qh.ptr->cap |= mul << __ffs(QH_MULT);
|
2013-06-13 22:59:47 +08:00
|
|
|
}
|
|
|
|
|
2008-11-18 06:14:51 +08:00
|
|
|
wmb(); /* synchronize before ep prime */
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
ret = hw_ep_prime(ci, hwep->num, hwep->dir,
|
|
|
|
hwep->type == USB_ENDPOINT_XFER_CONTROL);
|
2011-02-18 20:13:16 +08:00
|
|
|
done:
|
|
|
|
return ret;
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-13 22:59:54 +08:00
|
|
|
/*
|
|
|
|
* free_pending_td: remove a pending request for the endpoint
|
2013-06-13 23:00:03 +08:00
|
|
|
* @hwep: endpoint
|
2013-06-13 22:59:54 +08:00
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static void free_pending_td(struct ci_hw_ep *hwep)
|
2013-06-13 22:59:54 +08:00
|
|
|
{
|
2013-06-13 23:00:03 +08:00
|
|
|
struct td_node *pending = hwep->pending_td;
|
2013-06-13 22:59:54 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
dma_pool_free(hwep->td_pool, pending->ptr, pending->dma);
|
|
|
|
hwep->pending_td = NULL;
|
2013-06-13 22:59:54 +08:00
|
|
|
kfree(pending);
|
|
|
|
}
|
|
|
|
|
2008-11-18 06:14:51 +08:00
|
|
|
/**
|
|
|
|
* _hardware_dequeue: handles a request at hardware level
|
|
|
|
* @gadget: gadget
|
2013-06-13 23:00:03 +08:00
|
|
|
* @hwep: endpoint
|
2008-11-18 06:14:51 +08:00
|
|
|
*
|
|
|
|
* This function returns an error code
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2013-06-13 22:59:53 +08:00
|
|
|
u32 tmptoken;
|
2013-06-13 22:59:54 +08:00
|
|
|
struct td_node *node, *tmpnode;
|
|
|
|
unsigned remaining_length;
|
2013-06-13 23:00:03 +08:00
|
|
|
unsigned actual = hwreq->req.length;
|
2013-03-30 18:54:07 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwreq->req.status != -EALREADY)
|
2008-11-18 06:14:51 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwreq->req.status = 0;
|
2011-02-18 20:13:16 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
list_for_each_entry_safe(node, tmpnode, &hwreq->tds, td) {
|
2013-06-13 22:59:53 +08:00
|
|
|
tmptoken = le32_to_cpu(node->ptr->token);
|
2013-06-13 22:59:54 +08:00
|
|
|
if ((TD_STATUS_ACTIVE & tmptoken) != 0) {
|
2013-06-13 23:00:03 +08:00
|
|
|
hwreq->req.status = -EALREADY;
|
2011-02-18 20:13:16 +08:00
|
|
|
return -EBUSY;
|
2013-06-13 22:59:53 +08:00
|
|
|
}
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 22:59:54 +08:00
|
|
|
remaining_length = (tmptoken & TD_TOTAL_BYTES);
|
|
|
|
remaining_length >>= __ffs(TD_TOTAL_BYTES);
|
|
|
|
actual -= remaining_length;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwreq->req.status = tmptoken & TD_STATUS;
|
|
|
|
if ((TD_STATUS_HALTED & hwreq->req.status)) {
|
|
|
|
hwreq->req.status = -EPIPE;
|
2013-06-13 22:59:54 +08:00
|
|
|
break;
|
2013-06-13 23:00:03 +08:00
|
|
|
} else if ((TD_STATUS_DT_ERR & hwreq->req.status)) {
|
|
|
|
hwreq->req.status = -EPROTO;
|
2013-06-13 22:59:54 +08:00
|
|
|
break;
|
2013-06-13 23:00:03 +08:00
|
|
|
} else if ((TD_STATUS_TR_ERR & hwreq->req.status)) {
|
|
|
|
hwreq->req.status = -EILSEQ;
|
2013-06-13 22:59:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (remaining_length) {
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwep->dir) {
|
|
|
|
hwreq->req.status = -EPROTO;
|
2013-06-13 22:59:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* As the hardware could still address the freed td
|
|
|
|
* which will run the udc unusable, the cleanup of the
|
|
|
|
* td has to be delayed by one.
|
|
|
|
*/
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwep->pending_td)
|
|
|
|
free_pending_td(hwep);
|
2013-06-13 22:59:54 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwep->pending_td = node;
|
2013-06-13 22:59:54 +08:00
|
|
|
list_del_init(&node->td);
|
|
|
|
}
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
usb_gadget_unmap_request(&hwep->ci->gadget, &hwreq->req, hwep->dir);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwreq->req.actual += actual;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwreq->req.status)
|
|
|
|
return hwreq->req.status;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
return hwreq->req.actual;
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _ep_nuke: dequeues all endpoint requests
|
2013-06-13 23:00:03 +08:00
|
|
|
* @hwep: endpoint
|
2008-11-18 06:14:51 +08:00
|
|
|
*
|
|
|
|
* This function returns an error code
|
|
|
|
* Caller must hold lock
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int _ep_nuke(struct ci_hw_ep *hwep)
|
2013-06-13 23:00:03 +08:00
|
|
|
__releases(hwep->lock)
|
|
|
|
__acquires(hwep->lock)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2013-06-13 22:59:54 +08:00
|
|
|
struct td_node *node, *tmpnode;
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwep == NULL)
|
2008-11-18 06:14:51 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hw_ep_flush(hwep->ci, hwep->num, hwep->dir);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
while (!list_empty(&hwep->qh.queue)) {
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
/* pop oldest request */
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_req *hwreq = list_entry(hwep->qh.queue.next,
|
|
|
|
struct ci_hw_req, queue);
|
2013-04-04 18:13:47 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
list_for_each_entry_safe(node, tmpnode, &hwreq->tds, td) {
|
|
|
|
dma_pool_free(hwep->td_pool, node->ptr, node->dma);
|
2013-06-13 22:59:54 +08:00
|
|
|
list_del_init(&node->td);
|
|
|
|
node->ptr = NULL;
|
|
|
|
kfree(node);
|
2013-04-04 18:13:47 +08:00
|
|
|
}
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
list_del_init(&hwreq->queue);
|
|
|
|
hwreq->req.status = -ESHUTDOWN;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwreq->req.complete != NULL) {
|
|
|
|
spin_unlock(hwep->lock);
|
|
|
|
hwreq->req.complete(&hwep->ep, &hwreq->req);
|
|
|
|
spin_lock(hwep->lock);
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
}
|
2013-06-13 22:59:54 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwep->pending_td)
|
|
|
|
free_pending_td(hwep);
|
2013-06-13 22:59:54 +08:00
|
|
|
|
2008-11-18 06:14:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* _gadget_stop_activity: stops all USB activity, flushes & disables all endpts
|
|
|
|
* @gadget: gadget
|
|
|
|
*
|
|
|
|
* This function returns an error code
|
|
|
|
*/
|
|
|
|
static int _gadget_stop_activity(struct usb_gadget *gadget)
|
|
|
|
{
|
|
|
|
struct usb_ep *ep;
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hdrc *ci = container_of(gadget, struct ci_hdrc, gadget);
|
2011-02-18 20:13:17 +08:00
|
|
|
unsigned long flags;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_lock_irqsave(&ci->lock, flags);
|
|
|
|
ci->gadget.speed = USB_SPEED_UNKNOWN;
|
|
|
|
ci->remote_wakeup = 0;
|
|
|
|
ci->suspended = 0;
|
|
|
|
spin_unlock_irqrestore(&ci->lock, flags);
|
2011-02-18 20:13:17 +08:00
|
|
|
|
2008-11-18 06:14:51 +08:00
|
|
|
/* flush all endpoints */
|
|
|
|
gadget_for_each_ep(ep, gadget) {
|
|
|
|
usb_ep_fifo_flush(ep);
|
|
|
|
}
|
2012-07-07 22:56:40 +08:00
|
|
|
usb_ep_fifo_flush(&ci->ep0out->ep);
|
|
|
|
usb_ep_fifo_flush(&ci->ep0in->ep);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
if (ci->driver)
|
|
|
|
ci->driver->disconnect(gadget);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
/* make sure to disable all endpoints */
|
|
|
|
gadget_for_each_ep(ep, gadget) {
|
|
|
|
usb_ep_disable(ep);
|
|
|
|
}
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
if (ci->status != NULL) {
|
|
|
|
usb_ep_free_request(&ci->ep0in->ep, ci->status);
|
|
|
|
ci->status = NULL;
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ISR block
|
|
|
|
*****************************************************************************/
|
|
|
|
/**
|
|
|
|
* isr_reset_handler: USB reset interrupt handler
|
2012-07-07 22:56:40 +08:00
|
|
|
* @ci: UDC device
|
2008-11-18 06:14:51 +08:00
|
|
|
*
|
|
|
|
* This function resets USB engine after a bus reset occurred
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static void isr_reset_handler(struct ci_hdrc *ci)
|
2012-07-07 22:56:40 +08:00
|
|
|
__releases(ci->lock)
|
|
|
|
__acquires(ci->lock)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_unlock(&ci->lock);
|
|
|
|
retval = _gadget_stop_activity(&ci->gadget);
|
2008-11-18 06:14:51 +08:00
|
|
|
if (retval)
|
|
|
|
goto done;
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
retval = hw_usb_reset(ci);
|
2008-11-18 06:14:51 +08:00
|
|
|
if (retval)
|
|
|
|
goto done;
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
ci->status = usb_ep_alloc_request(&ci->ep0in->ep, GFP_ATOMIC);
|
|
|
|
if (ci->status == NULL)
|
2011-05-02 14:26:32 +08:00
|
|
|
retval = -ENOMEM;
|
2011-01-11 11:49:22 +08:00
|
|
|
|
2012-05-11 22:25:50 +08:00
|
|
|
done:
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_lock(&ci->lock);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
if (retval)
|
2012-07-07 22:56:40 +08:00
|
|
|
dev_err(ci->dev, "error: %i\n", retval);
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* isr_get_status_complete: get_status request complete function
|
|
|
|
* @ep: endpoint
|
|
|
|
* @req: request handled
|
|
|
|
*
|
|
|
|
* Caller must release lock
|
|
|
|
*/
|
|
|
|
static void isr_get_status_complete(struct usb_ep *ep, struct usb_request *req)
|
|
|
|
{
|
2012-05-09 04:29:02 +08:00
|
|
|
if (ep == NULL || req == NULL)
|
2008-11-18 06:14:51 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
kfree(req->buf);
|
|
|
|
usb_ep_free_request(ep, req);
|
|
|
|
}
|
|
|
|
|
2013-03-30 18:54:09 +08:00
|
|
|
/**
|
|
|
|
* _ep_queue: queues (submits) an I/O request to an endpoint
|
|
|
|
*
|
|
|
|
* Caller must hold lock
|
|
|
|
*/
|
|
|
|
static int _ep_queue(struct usb_ep *ep, struct usb_request *req,
|
|
|
|
gfp_t __maybe_unused gfp_flags)
|
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep);
|
|
|
|
struct ci_hw_req *hwreq = container_of(req, struct ci_hw_req, req);
|
|
|
|
struct ci_hdrc *ci = hwep->ci;
|
2013-03-30 18:54:09 +08:00
|
|
|
int retval = 0;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (ep == NULL || req == NULL || hwep->ep.desc == NULL)
|
2013-03-30 18:54:09 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwep->type == USB_ENDPOINT_XFER_CONTROL) {
|
2013-03-30 18:54:09 +08:00
|
|
|
if (req->length)
|
2013-06-13 23:00:03 +08:00
|
|
|
hwep = (ci->ep0_dir == RX) ?
|
2013-03-30 18:54:09 +08:00
|
|
|
ci->ep0out : ci->ep0in;
|
2013-06-13 23:00:03 +08:00
|
|
|
if (!list_empty(&hwep->qh.queue)) {
|
|
|
|
_ep_nuke(hwep);
|
2013-03-30 18:54:09 +08:00
|
|
|
retval = -EOVERFLOW;
|
2013-06-13 23:00:03 +08:00
|
|
|
dev_warn(hwep->ci->dev, "endpoint ctrl %X nuked\n",
|
|
|
|
_usb_addr(hwep));
|
2013-03-30 18:54:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (usb_endpoint_xfer_isoc(hwep->ep.desc) &&
|
|
|
|
hwreq->req.length > (1 + hwep->ep.mult) * hwep->ep.maxpacket) {
|
|
|
|
dev_err(hwep->ci->dev, "request length too big for isochronous\n");
|
2013-06-13 22:59:47 +08:00
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
2013-03-30 18:54:09 +08:00
|
|
|
/* first nuke then test link, e.g. previous status has not sent */
|
2013-06-13 23:00:03 +08:00
|
|
|
if (!list_empty(&hwreq->queue)) {
|
|
|
|
dev_err(hwep->ci->dev, "request already in queue\n");
|
2013-03-30 18:54:09 +08:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* push request */
|
2013-06-13 23:00:03 +08:00
|
|
|
hwreq->req.status = -EINPROGRESS;
|
|
|
|
hwreq->req.actual = 0;
|
2013-03-30 18:54:09 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
retval = _hardware_enqueue(hwep, hwreq);
|
2013-03-30 18:54:09 +08:00
|
|
|
|
|
|
|
if (retval == -EALREADY)
|
|
|
|
retval = 0;
|
|
|
|
if (!retval)
|
2013-06-13 23:00:03 +08:00
|
|
|
list_add_tail(&hwreq->queue, &hwep->qh.queue);
|
2013-03-30 18:54:09 +08:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2008-11-18 06:14:51 +08:00
|
|
|
/**
|
|
|
|
* isr_get_status_response: get_status request response
|
2012-07-07 22:56:40 +08:00
|
|
|
* @ci: ci struct
|
2008-11-18 06:14:51 +08:00
|
|
|
* @setup: setup request packet
|
|
|
|
*
|
|
|
|
* This function returns an error code
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int isr_get_status_response(struct ci_hdrc *ci,
|
2008-11-18 06:14:51 +08:00
|
|
|
struct usb_ctrlrequest *setup)
|
2013-06-13 23:00:03 +08:00
|
|
|
__releases(hwep->lock)
|
|
|
|
__acquires(hwep->lock)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_ep *hwep = ci->ep0in;
|
2008-11-18 06:14:51 +08:00
|
|
|
struct usb_request *req = NULL;
|
|
|
|
gfp_t gfp_flags = GFP_ATOMIC;
|
|
|
|
int dir, num, retval;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwep == NULL || setup == NULL)
|
2008-11-18 06:14:51 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_unlock(hwep->lock);
|
|
|
|
req = usb_ep_alloc_request(&hwep->ep, gfp_flags);
|
|
|
|
spin_lock(hwep->lock);
|
2008-11-18 06:14:51 +08:00
|
|
|
if (req == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
req->complete = isr_get_status_complete;
|
|
|
|
req->length = 2;
|
|
|
|
req->buf = kzalloc(req->length, gfp_flags);
|
|
|
|
if (req->buf == NULL) {
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto err_free_req;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((setup->bRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) {
|
2011-02-18 20:13:17 +08:00
|
|
|
/* Assume that device is bus powered for now. */
|
2012-07-07 22:56:40 +08:00
|
|
|
*(u16 *)req->buf = ci->remote_wakeup << 1;
|
2008-11-18 06:14:51 +08:00
|
|
|
retval = 0;
|
|
|
|
} else if ((setup->bRequestType & USB_RECIP_MASK) \
|
|
|
|
== USB_RECIP_ENDPOINT) {
|
|
|
|
dir = (le16_to_cpu(setup->wIndex) & USB_ENDPOINT_DIR_MASK) ?
|
|
|
|
TX : RX;
|
|
|
|
num = le16_to_cpu(setup->wIndex) & USB_ENDPOINT_NUMBER_MASK;
|
2012-07-07 22:56:40 +08:00
|
|
|
*(u16 *)req->buf = hw_ep_get_halt(ci, num, dir);
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
/* else do nothing; reserved for future use */
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
retval = _ep_queue(&hwep->ep, req, gfp_flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
if (retval)
|
|
|
|
goto err_free_buf;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_free_buf:
|
|
|
|
kfree(req->buf);
|
|
|
|
err_free_req:
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_unlock(hwep->lock);
|
|
|
|
usb_ep_free_request(&hwep->ep, req);
|
|
|
|
spin_lock(hwep->lock);
|
2008-11-18 06:14:51 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-02-18 20:13:18 +08:00
|
|
|
/**
|
|
|
|
* isr_setup_status_complete: setup_status request complete function
|
|
|
|
* @ep: endpoint
|
|
|
|
* @req: request handled
|
|
|
|
*
|
|
|
|
* Caller must release lock. Put the port in test mode if test mode
|
|
|
|
* feature is selected.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
isr_setup_status_complete(struct usb_ep *ep, struct usb_request *req)
|
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hdrc *ci = req->context;
|
2011-02-18 20:13:18 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
if (ci->setaddr) {
|
|
|
|
hw_usb_set_address(ci, ci->address);
|
|
|
|
ci->setaddr = false;
|
usb: gadget: ci13xxx: don't use "advance" feature when setting address
Newer versions of the chipidea controller support the "advance" setting
of usb address, which means instead of setting it immediately, deferring
it till the status completion. Unfortunately, older versions of the
controller don't have this feature, so in order to support those too, we
simply don't use it. It's about 4 lines of extra code, and isn't in any
way critical to performance. While at it, change the return value of the
hw_usb_set_address() to void, since it can't fail in any measurable way.
With this patch, ci13xxx_udc driver works with the chipidea controller in
kirkwood (feroceon SoC), as found in, for example, sheevaplug.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-05-11 22:25:43 +08:00
|
|
|
}
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_lock_irqsave(&ci->lock, flags);
|
|
|
|
if (ci->test_mode)
|
|
|
|
hw_port_test_set(ci, ci->test_mode);
|
|
|
|
spin_unlock_irqrestore(&ci->lock, flags);
|
2011-02-18 20:13:18 +08:00
|
|
|
}
|
|
|
|
|
2008-11-18 06:14:51 +08:00
|
|
|
/**
|
|
|
|
* isr_setup_status_phase: queues the status phase of a setup transation
|
2012-07-07 22:56:40 +08:00
|
|
|
* @ci: ci struct
|
2008-11-18 06:14:51 +08:00
|
|
|
*
|
|
|
|
* This function returns an error code
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int isr_setup_status_phase(struct ci_hdrc *ci)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
|
|
|
int retval;
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_ep *hwep;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwep = (ci->ep0_dir == TX) ? ci->ep0out : ci->ep0in;
|
2012-07-07 22:56:40 +08:00
|
|
|
ci->status->context = ci;
|
|
|
|
ci->status->complete = isr_setup_status_complete;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
retval = _ep_queue(&hwep->ep, ci->status, GFP_ATOMIC);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* isr_tr_complete_low: transaction complete low level handler
|
2013-06-13 23:00:03 +08:00
|
|
|
* @hwep: endpoint
|
2008-11-18 06:14:51 +08:00
|
|
|
*
|
|
|
|
* This function returns an error code
|
|
|
|
* Caller must hold lock
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int isr_tr_complete_low(struct ci_hw_ep *hwep)
|
2013-06-13 23:00:03 +08:00
|
|
|
__releases(hwep->lock)
|
|
|
|
__acquires(hwep->lock)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_req *hwreq, *hwreqtemp;
|
|
|
|
struct ci_hw_ep *hweptemp = hwep;
|
2012-09-12 19:58:04 +08:00
|
|
|
int retval = 0;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
list_for_each_entry_safe(hwreq, hwreqtemp, &hwep->qh.queue,
|
2011-02-18 20:13:16 +08:00
|
|
|
queue) {
|
2013-06-13 23:00:03 +08:00
|
|
|
retval = _hardware_dequeue(hwep, hwreq);
|
2011-02-18 20:13:16 +08:00
|
|
|
if (retval < 0)
|
|
|
|
break;
|
2013-06-13 23:00:03 +08:00
|
|
|
list_del_init(&hwreq->queue);
|
|
|
|
if (hwreq->req.complete != NULL) {
|
|
|
|
spin_unlock(hwep->lock);
|
|
|
|
if ((hwep->type == USB_ENDPOINT_XFER_CONTROL) &&
|
|
|
|
hwreq->req.length)
|
|
|
|
hweptemp = hwep->ci->ep0in;
|
|
|
|
hwreq->req.complete(&hweptemp->ep, &hwreq->req);
|
|
|
|
spin_lock(hwep->lock);
|
2011-02-18 20:13:16 +08:00
|
|
|
}
|
2010-12-15 15:45:50 +08:00
|
|
|
}
|
|
|
|
|
2011-05-02 14:26:27 +08:00
|
|
|
if (retval == -EBUSY)
|
2011-02-18 20:13:16 +08:00
|
|
|
retval = 0;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* isr_tr_complete_handler: transaction complete interrupt handler
|
2012-07-07 22:56:40 +08:00
|
|
|
* @ci: UDC descriptor
|
2008-11-18 06:14:51 +08:00
|
|
|
*
|
|
|
|
* This function handles traffic events
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static void isr_tr_complete_handler(struct ci_hdrc *ci)
|
2012-07-07 22:56:40 +08:00
|
|
|
__releases(ci->lock)
|
|
|
|
__acquires(ci->lock)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
|
|
|
unsigned i;
|
2011-02-18 20:13:18 +08:00
|
|
|
u8 tmode = 0;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
for (i = 0; i < ci->hw_ep_max; i++) {
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_ep *hwep = &ci->ci_hw_ep[i];
|
2011-05-02 14:26:30 +08:00
|
|
|
int type, num, dir, err = -EINVAL;
|
2008-11-18 06:14:51 +08:00
|
|
|
struct usb_ctrlrequest req;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwep->ep.desc == NULL)
|
2008-11-18 06:14:51 +08:00
|
|
|
continue; /* not configured */
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
if (hw_test_and_clear_complete(ci, i)) {
|
2013-06-13 23:00:03 +08:00
|
|
|
err = isr_tr_complete_low(hwep);
|
|
|
|
if (hwep->type == USB_ENDPOINT_XFER_CONTROL) {
|
2008-11-18 06:14:51 +08:00
|
|
|
if (err > 0) /* needs status phase */
|
2012-07-07 22:56:40 +08:00
|
|
|
err = isr_setup_status_phase(ci);
|
2008-11-18 06:14:51 +08:00
|
|
|
if (err < 0) {
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_unlock(&ci->lock);
|
2013-06-13 23:00:03 +08:00
|
|
|
if (usb_ep_set_halt(&hwep->ep))
|
2012-07-07 22:56:40 +08:00
|
|
|
dev_err(ci->dev,
|
2012-04-28 02:24:39 +08:00
|
|
|
"error: ep_set_halt\n");
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_lock(&ci->lock);
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwep->type != USB_ENDPOINT_XFER_CONTROL ||
|
2012-07-07 22:56:40 +08:00
|
|
|
!hw_test_and_clear_setup_status(ci, i))
|
2008-11-18 06:14:51 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (i != 0) {
|
2012-07-07 22:56:40 +08:00
|
|
|
dev_warn(ci->dev, "ctrl traffic at endpoint %d\n", i);
|
2008-11-18 06:14:51 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-01-11 11:49:22 +08:00
|
|
|
/*
|
|
|
|
* Flush data and handshake transactions of previous
|
|
|
|
* setup packet.
|
|
|
|
*/
|
2012-07-07 22:56:40 +08:00
|
|
|
_ep_nuke(ci->ep0out);
|
|
|
|
_ep_nuke(ci->ep0in);
|
2011-01-11 11:49:22 +08:00
|
|
|
|
2008-11-18 06:14:51 +08:00
|
|
|
/* read_setup_packet */
|
|
|
|
do {
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_test_and_set_setup_guard(ci);
|
2013-06-13 23:00:03 +08:00
|
|
|
memcpy(&req, &hwep->qh.ptr->setup, sizeof(req));
|
2012-07-07 22:56:40 +08:00
|
|
|
} while (!hw_test_and_clear_setup_guard(ci));
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
type = req.bRequestType;
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
ci->ep0_dir = (type & USB_DIR_IN) ? TX : RX;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
switch (req.bRequest) {
|
|
|
|
case USB_REQ_CLEAR_FEATURE:
|
2011-02-18 20:13:17 +08:00
|
|
|
if (type == (USB_DIR_OUT|USB_RECIP_ENDPOINT) &&
|
|
|
|
le16_to_cpu(req.wValue) ==
|
|
|
|
USB_ENDPOINT_HALT) {
|
|
|
|
if (req.wLength != 0)
|
|
|
|
break;
|
|
|
|
num = le16_to_cpu(req.wIndex);
|
2011-05-02 14:26:30 +08:00
|
|
|
dir = num & USB_ENDPOINT_DIR_MASK;
|
2011-02-18 20:13:17 +08:00
|
|
|
num &= USB_ENDPOINT_NUMBER_MASK;
|
2011-05-02 14:26:30 +08:00
|
|
|
if (dir) /* TX */
|
2012-07-07 22:56:40 +08:00
|
|
|
num += ci->hw_ep_max/2;
|
2013-06-24 19:46:36 +08:00
|
|
|
if (!ci->ci_hw_ep[num].wedge) {
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_unlock(&ci->lock);
|
2011-02-18 20:13:17 +08:00
|
|
|
err = usb_ep_clear_halt(
|
2013-06-24 19:46:36 +08:00
|
|
|
&ci->ci_hw_ep[num].ep);
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_lock(&ci->lock);
|
2011-02-18 20:13:17 +08:00
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
}
|
2012-07-07 22:56:40 +08:00
|
|
|
err = isr_setup_status_phase(ci);
|
2011-02-18 20:13:17 +08:00
|
|
|
} else if (type == (USB_DIR_OUT|USB_RECIP_DEVICE) &&
|
|
|
|
le16_to_cpu(req.wValue) ==
|
|
|
|
USB_DEVICE_REMOTE_WAKEUP) {
|
|
|
|
if (req.wLength != 0)
|
2008-11-18 06:14:51 +08:00
|
|
|
break;
|
2012-07-07 22:56:40 +08:00
|
|
|
ci->remote_wakeup = 0;
|
|
|
|
err = isr_setup_status_phase(ci);
|
2011-02-18 20:13:17 +08:00
|
|
|
} else {
|
|
|
|
goto delegate;
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case USB_REQ_GET_STATUS:
|
|
|
|
if (type != (USB_DIR_IN|USB_RECIP_DEVICE) &&
|
|
|
|
type != (USB_DIR_IN|USB_RECIP_ENDPOINT) &&
|
|
|
|
type != (USB_DIR_IN|USB_RECIP_INTERFACE))
|
|
|
|
goto delegate;
|
|
|
|
if (le16_to_cpu(req.wLength) != 2 ||
|
|
|
|
le16_to_cpu(req.wValue) != 0)
|
|
|
|
break;
|
2012-07-07 22:56:40 +08:00
|
|
|
err = isr_get_status_response(ci, &req);
|
2008-11-18 06:14:51 +08:00
|
|
|
break;
|
|
|
|
case USB_REQ_SET_ADDRESS:
|
|
|
|
if (type != (USB_DIR_OUT|USB_RECIP_DEVICE))
|
|
|
|
goto delegate;
|
|
|
|
if (le16_to_cpu(req.wLength) != 0 ||
|
|
|
|
le16_to_cpu(req.wIndex) != 0)
|
|
|
|
break;
|
2012-07-07 22:56:40 +08:00
|
|
|
ci->address = (u8)le16_to_cpu(req.wValue);
|
|
|
|
ci->setaddr = true;
|
|
|
|
err = isr_setup_status_phase(ci);
|
2008-11-18 06:14:51 +08:00
|
|
|
break;
|
|
|
|
case USB_REQ_SET_FEATURE:
|
2011-02-18 20:13:17 +08:00
|
|
|
if (type == (USB_DIR_OUT|USB_RECIP_ENDPOINT) &&
|
|
|
|
le16_to_cpu(req.wValue) ==
|
|
|
|
USB_ENDPOINT_HALT) {
|
|
|
|
if (req.wLength != 0)
|
|
|
|
break;
|
|
|
|
num = le16_to_cpu(req.wIndex);
|
2011-05-02 14:26:30 +08:00
|
|
|
dir = num & USB_ENDPOINT_DIR_MASK;
|
2011-02-18 20:13:17 +08:00
|
|
|
num &= USB_ENDPOINT_NUMBER_MASK;
|
2011-05-02 14:26:30 +08:00
|
|
|
if (dir) /* TX */
|
2012-07-07 22:56:40 +08:00
|
|
|
num += ci->hw_ep_max/2;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_unlock(&ci->lock);
|
2013-06-24 19:46:36 +08:00
|
|
|
err = usb_ep_set_halt(&ci->ci_hw_ep[num].ep);
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_lock(&ci->lock);
|
2011-02-18 20:13:17 +08:00
|
|
|
if (!err)
|
2012-07-07 22:56:40 +08:00
|
|
|
isr_setup_status_phase(ci);
|
2011-02-18 20:13:18 +08:00
|
|
|
} else if (type == (USB_DIR_OUT|USB_RECIP_DEVICE)) {
|
2011-02-18 20:13:17 +08:00
|
|
|
if (req.wLength != 0)
|
|
|
|
break;
|
2011-02-18 20:13:18 +08:00
|
|
|
switch (le16_to_cpu(req.wValue)) {
|
|
|
|
case USB_DEVICE_REMOTE_WAKEUP:
|
2012-07-07 22:56:40 +08:00
|
|
|
ci->remote_wakeup = 1;
|
|
|
|
err = isr_setup_status_phase(ci);
|
2011-02-18 20:13:18 +08:00
|
|
|
break;
|
|
|
|
case USB_DEVICE_TEST_MODE:
|
|
|
|
tmode = le16_to_cpu(req.wIndex) >> 8;
|
|
|
|
switch (tmode) {
|
|
|
|
case TEST_J:
|
|
|
|
case TEST_K:
|
|
|
|
case TEST_SE0_NAK:
|
|
|
|
case TEST_PACKET:
|
|
|
|
case TEST_FORCE_EN:
|
2012-07-07 22:56:40 +08:00
|
|
|
ci->test_mode = tmode;
|
2011-02-18 20:13:18 +08:00
|
|
|
err = isr_setup_status_phase(
|
2012-07-07 22:56:40 +08:00
|
|
|
ci);
|
2011-02-18 20:13:18 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
goto delegate;
|
|
|
|
}
|
2011-02-18 20:13:17 +08:00
|
|
|
} else {
|
|
|
|
goto delegate;
|
|
|
|
}
|
2008-11-18 06:14:51 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
delegate:
|
|
|
|
if (req.wLength == 0) /* no data phase */
|
2012-07-07 22:56:40 +08:00
|
|
|
ci->ep0_dir = TX;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_unlock(&ci->lock);
|
|
|
|
err = ci->driver->setup(&ci->gadget, &req);
|
|
|
|
spin_lock(&ci->lock);
|
2008-11-18 06:14:51 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err < 0) {
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_unlock(&ci->lock);
|
2013-06-13 23:00:03 +08:00
|
|
|
if (usb_ep_set_halt(&hwep->ep))
|
2012-07-07 22:56:40 +08:00
|
|
|
dev_err(ci->dev, "error: ep_set_halt\n");
|
|
|
|
spin_lock(&ci->lock);
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* ENDPT block
|
|
|
|
*****************************************************************************/
|
|
|
|
/**
|
|
|
|
* ep_enable: configure endpoint, making it usable
|
|
|
|
*
|
|
|
|
* Check usb_ep_enable() at "usb_gadget.h" for details
|
|
|
|
*/
|
|
|
|
static int ep_enable(struct usb_ep *ep,
|
|
|
|
const struct usb_endpoint_descriptor *desc)
|
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep);
|
2011-01-11 11:49:22 +08:00
|
|
|
int retval = 0;
|
2008-11-18 06:14:51 +08:00
|
|
|
unsigned long flags;
|
2013-03-30 18:54:05 +08:00
|
|
|
u32 cap = 0;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
if (ep == NULL || desc == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_lock_irqsave(hwep->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
/* only internal SW should enable ctrl endpts */
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwep->ep.desc = desc;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (!list_empty(&hwep->qh.queue))
|
|
|
|
dev_warn(hwep->ci->dev, "enabling a non-empty endpoint!\n");
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwep->dir = usb_endpoint_dir_in(desc) ? TX : RX;
|
|
|
|
hwep->num = usb_endpoint_num(desc);
|
|
|
|
hwep->type = usb_endpoint_type(desc);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwep->ep.maxpacket = usb_endpoint_maxp(desc) & 0x07ff;
|
|
|
|
hwep->ep.mult = QH_ISO_MULT(usb_endpoint_maxp(desc));
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwep->type == USB_ENDPOINT_XFER_CONTROL)
|
2013-03-30 18:54:05 +08:00
|
|
|
cap |= QH_IOS;
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwep->num)
|
2013-03-30 18:54:06 +08:00
|
|
|
cap |= QH_ZLT;
|
2013-06-13 23:00:03 +08:00
|
|
|
cap |= (hwep->ep.maxpacket << __ffs(QH_MAX_PKT)) & QH_MAX_PKT;
|
2013-03-30 18:54:05 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwep->qh.ptr->cap = cpu_to_le32(cap);
|
2013-03-30 18:54:05 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwep->qh.ptr->td.next |= cpu_to_le32(TD_TERMINATE); /* needed? */
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2011-05-02 14:26:32 +08:00
|
|
|
/*
|
|
|
|
* Enable endpoints in the HW other than ep0 as ep0
|
|
|
|
* is always enabled
|
|
|
|
*/
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwep->num)
|
|
|
|
retval |= hw_ep_enable(hwep->ci, hwep->num, hwep->dir,
|
|
|
|
hwep->type);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_unlock_irqrestore(hwep->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ep_disable: endpoint is no longer usable
|
|
|
|
*
|
|
|
|
* Check usb_ep_disable() at "usb_gadget.h" for details
|
|
|
|
*/
|
|
|
|
static int ep_disable(struct usb_ep *ep)
|
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep);
|
2008-11-18 06:14:51 +08:00
|
|
|
int direction, retval = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (ep == NULL)
|
|
|
|
return -EINVAL;
|
2013-06-13 23:00:03 +08:00
|
|
|
else if (hwep->ep.desc == NULL)
|
2008-11-18 06:14:51 +08:00
|
|
|
return -EBUSY;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_lock_irqsave(hwep->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
/* only internal SW should disable ctrl endpts */
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
direction = hwep->dir;
|
2008-11-18 06:14:51 +08:00
|
|
|
do {
|
2013-06-13 23:00:03 +08:00
|
|
|
retval |= _ep_nuke(hwep);
|
|
|
|
retval |= hw_ep_disable(hwep->ci, hwep->num, hwep->dir);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwep->type == USB_ENDPOINT_XFER_CONTROL)
|
|
|
|
hwep->dir = (hwep->dir == TX) ? RX : TX;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
} while (hwep->dir != direction);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwep->ep.desc = NULL;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_unlock_irqrestore(hwep->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ep_alloc_request: allocate a request object to use with this endpoint
|
|
|
|
*
|
|
|
|
* Check usb_ep_alloc_request() at "usb_gadget.h" for details
|
|
|
|
*/
|
|
|
|
static struct usb_request *ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
|
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_req *hwreq = NULL;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-05-09 04:29:02 +08:00
|
|
|
if (ep == NULL)
|
2008-11-18 06:14:51 +08:00
|
|
|
return NULL;
|
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
hwreq = kzalloc(sizeof(struct ci_hw_req), gfp_flags);
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwreq != NULL) {
|
|
|
|
INIT_LIST_HEAD(&hwreq->queue);
|
|
|
|
INIT_LIST_HEAD(&hwreq->tds);
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
return (hwreq == NULL) ? NULL : &hwreq->req;
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ep_free_request: frees a request object
|
|
|
|
*
|
|
|
|
* Check usb_ep_free_request() at "usb_gadget.h" for details
|
|
|
|
*/
|
|
|
|
static void ep_free_request(struct usb_ep *ep, struct usb_request *req)
|
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep);
|
|
|
|
struct ci_hw_req *hwreq = container_of(req, struct ci_hw_req, req);
|
2013-06-13 22:59:54 +08:00
|
|
|
struct td_node *node, *tmpnode;
|
2008-11-18 06:14:51 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (ep == NULL || req == NULL) {
|
|
|
|
return;
|
2013-06-13 23:00:03 +08:00
|
|
|
} else if (!list_empty(&hwreq->queue)) {
|
|
|
|
dev_err(hwep->ci->dev, "freeing queued request\n");
|
2008-11-18 06:14:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_lock_irqsave(hwep->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
list_for_each_entry_safe(node, tmpnode, &hwreq->tds, td) {
|
|
|
|
dma_pool_free(hwep->td_pool, node->ptr, node->dma);
|
2013-06-13 22:59:54 +08:00
|
|
|
list_del_init(&node->td);
|
|
|
|
node->ptr = NULL;
|
|
|
|
kfree(node);
|
|
|
|
}
|
2013-06-13 22:59:53 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
kfree(hwreq);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_unlock_irqrestore(hwep->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ep_queue: queues (submits) an I/O request to an endpoint
|
|
|
|
*
|
|
|
|
* Check usb_ep_queue()* at usb_gadget.h" for details
|
|
|
|
*/
|
|
|
|
static int ep_queue(struct usb_ep *ep, struct usb_request *req,
|
|
|
|
gfp_t __maybe_unused gfp_flags)
|
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep);
|
2008-11-18 06:14:51 +08:00
|
|
|
int retval = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (ep == NULL || req == NULL || hwep->ep.desc == NULL)
|
2008-11-18 06:14:51 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_lock_irqsave(hwep->lock, flags);
|
2013-03-30 18:54:09 +08:00
|
|
|
retval = _ep_queue(ep, req, gfp_flags);
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_unlock_irqrestore(hwep->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ep_dequeue: dequeues (cancels, unlinks) an I/O request from an endpoint
|
|
|
|
*
|
|
|
|
* Check usb_ep_dequeue() at "usb_gadget.h" for details
|
|
|
|
*/
|
|
|
|
static int ep_dequeue(struct usb_ep *ep, struct usb_request *req)
|
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep);
|
|
|
|
struct ci_hw_req *hwreq = container_of(req, struct ci_hw_req, req);
|
2008-11-18 06:14:51 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (ep == NULL || req == NULL || hwreq->req.status != -EALREADY ||
|
|
|
|
hwep->ep.desc == NULL || list_empty(&hwreq->queue) ||
|
|
|
|
list_empty(&hwep->qh.queue))
|
2008-11-18 06:14:51 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_lock_irqsave(hwep->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hw_ep_flush(hwep->ci, hwep->num, hwep->dir);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
/* pop request */
|
2013-06-13 23:00:03 +08:00
|
|
|
list_del_init(&hwreq->queue);
|
2012-05-11 22:25:56 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
usb_gadget_unmap_request(&hwep->ci->gadget, req, hwep->dir);
|
2012-05-11 22:25:56 +08:00
|
|
|
|
2008-11-18 06:14:51 +08:00
|
|
|
req->status = -ECONNRESET;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwreq->req.complete != NULL) {
|
|
|
|
spin_unlock(hwep->lock);
|
|
|
|
hwreq->req.complete(&hwep->ep, &hwreq->req);
|
|
|
|
spin_lock(hwep->lock);
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_unlock_irqrestore(hwep->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ep_set_halt: sets the endpoint halt feature
|
|
|
|
*
|
|
|
|
* Check usb_ep_set_halt() at "usb_gadget.h" for details
|
|
|
|
*/
|
|
|
|
static int ep_set_halt(struct usb_ep *ep, int value)
|
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep);
|
2008-11-18 06:14:51 +08:00
|
|
|
int direction, retval = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (ep == NULL || hwep->ep.desc == NULL)
|
2008-11-18 06:14:51 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (usb_endpoint_xfer_isoc(hwep->ep.desc))
|
2013-06-13 22:59:47 +08:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_lock_irqsave(hwep->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
#ifndef STALL_IN
|
|
|
|
/* g_file_storage MS compliant but g_zero fails chapter 9 compliance */
|
2013-06-13 23:00:03 +08:00
|
|
|
if (value && hwep->type == USB_ENDPOINT_XFER_BULK && hwep->dir == TX &&
|
|
|
|
!list_empty(&hwep->qh.queue)) {
|
|
|
|
spin_unlock_irqrestore(hwep->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
direction = hwep->dir;
|
2008-11-18 06:14:51 +08:00
|
|
|
do {
|
2013-06-13 23:00:03 +08:00
|
|
|
retval |= hw_ep_set_halt(hwep->ci, hwep->num, hwep->dir, value);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
if (!value)
|
2013-06-13 23:00:03 +08:00
|
|
|
hwep->wedge = 0;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (hwep->type == USB_ENDPOINT_XFER_CONTROL)
|
|
|
|
hwep->dir = (hwep->dir == TX) ? RX : TX;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
} while (hwep->dir != direction);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_unlock_irqrestore(hwep->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ep_set_wedge: sets the halt feature and ignores clear requests
|
|
|
|
*
|
|
|
|
* Check usb_ep_set_wedge() at "usb_gadget.h" for details
|
|
|
|
*/
|
|
|
|
static int ep_set_wedge(struct usb_ep *ep)
|
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep);
|
2008-11-18 06:14:51 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
if (ep == NULL || hwep->ep.desc == NULL)
|
2008-11-18 06:14:51 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_lock_irqsave(hwep->lock, flags);
|
|
|
|
hwep->wedge = 1;
|
|
|
|
spin_unlock_irqrestore(hwep->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
return usb_ep_set_halt(ep);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ep_fifo_flush: flushes contents of a fifo
|
|
|
|
*
|
|
|
|
* Check usb_ep_fifo_flush() at "usb_gadget.h" for details
|
|
|
|
*/
|
|
|
|
static void ep_fifo_flush(struct usb_ep *ep)
|
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_ep *hwep = container_of(ep, struct ci_hw_ep, ep);
|
2008-11-18 06:14:51 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (ep == NULL) {
|
2013-06-13 23:00:03 +08:00
|
|
|
dev_err(hwep->ci->dev, "%02X: -EINVAL\n", _usb_addr(hwep));
|
2008-11-18 06:14:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_lock_irqsave(hwep->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hw_ep_flush(hwep->ci, hwep->num, hwep->dir);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
spin_unlock_irqrestore(hwep->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Endpoint-specific part of the API to the USB controller hardware
|
|
|
|
* Check "usb_gadget.h" for details
|
|
|
|
*/
|
|
|
|
static const struct usb_ep_ops usb_ep_ops = {
|
|
|
|
.enable = ep_enable,
|
|
|
|
.disable = ep_disable,
|
|
|
|
.alloc_request = ep_alloc_request,
|
|
|
|
.free_request = ep_free_request,
|
|
|
|
.queue = ep_queue,
|
|
|
|
.dequeue = ep_dequeue,
|
|
|
|
.set_halt = ep_set_halt,
|
|
|
|
.set_wedge = ep_set_wedge,
|
|
|
|
.fifo_flush = ep_fifo_flush,
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* GADGET block
|
|
|
|
*****************************************************************************/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int ci_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
|
2010-12-07 20:24:02 +08:00
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget);
|
2010-12-07 20:24:02 +08:00
|
|
|
unsigned long flags;
|
|
|
|
int gadget_ready = 0;
|
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
if (!(ci->platdata->flags & CI_HDRC_PULLUP_ON_VBUS))
|
2010-12-07 20:24:02 +08:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_lock_irqsave(&ci->lock, flags);
|
|
|
|
ci->vbus_active = is_active;
|
|
|
|
if (ci->driver)
|
2010-12-07 20:24:02 +08:00
|
|
|
gadget_ready = 1;
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_unlock_irqrestore(&ci->lock, flags);
|
2010-12-07 20:24:02 +08:00
|
|
|
|
|
|
|
if (gadget_ready) {
|
|
|
|
if (is_active) {
|
2010-12-07 20:24:04 +08:00
|
|
|
pm_runtime_get_sync(&_gadget->dev);
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_device_reset(ci, USBMODE_CM_DC);
|
|
|
|
hw_device_state(ci, ci->ep0out->qh.dma);
|
2010-12-07 20:24:02 +08:00
|
|
|
} else {
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_device_state(ci, 0);
|
|
|
|
if (ci->platdata->notify_event)
|
|
|
|
ci->platdata->notify_event(ci,
|
2013-06-24 19:46:36 +08:00
|
|
|
CI_HDRC_CONTROLLER_STOPPED_EVENT);
|
2012-07-07 22:56:40 +08:00
|
|
|
_gadget_stop_activity(&ci->gadget);
|
2010-12-07 20:24:04 +08:00
|
|
|
pm_runtime_put_sync(&_gadget->dev);
|
2010-12-07 20:24:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
static int ci_udc_wakeup(struct usb_gadget *_gadget)
|
2011-02-18 20:13:17 +08:00
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget);
|
2011-02-18 20:13:17 +08:00
|
|
|
unsigned long flags;
|
|
|
|
int ret = 0;
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_lock_irqsave(&ci->lock, flags);
|
|
|
|
if (!ci->remote_wakeup) {
|
2011-02-18 20:13:17 +08:00
|
|
|
ret = -EOPNOTSUPP;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-07-07 22:56:40 +08:00
|
|
|
if (!hw_read(ci, OP_PORTSC, PORTSC_SUSP)) {
|
2011-02-18 20:13:17 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_write(ci, OP_PORTSC, PORTSC_FPR, PORTSC_FPR);
|
2011-02-18 20:13:17 +08:00
|
|
|
out:
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_unlock_irqrestore(&ci->lock, flags);
|
2011-02-18 20:13:17 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
static int ci_udc_vbus_draw(struct usb_gadget *_gadget, unsigned ma)
|
2011-05-04 12:49:47 +08:00
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget);
|
2011-05-04 12:49:47 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
if (ci->transceiver)
|
2013-06-13 23:00:03 +08:00
|
|
|
return usb_phy_set_power(ci->transceiver, ma);
|
2011-05-04 12:49:47 +08:00
|
|
|
return -ENOTSUPP;
|
|
|
|
}
|
|
|
|
|
2012-09-12 19:58:01 +08:00
|
|
|
/* Change Data+ pullup status
|
|
|
|
* this func is used by usb_gadget_connect/disconnet
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int ci_udc_pullup(struct usb_gadget *_gadget, int is_on)
|
2012-09-12 19:58:01 +08:00
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget);
|
2012-09-12 19:58:01 +08:00
|
|
|
|
|
|
|
if (is_on)
|
|
|
|
hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS);
|
|
|
|
else
|
|
|
|
hw_write(ci, OP_USBCMD, USBCMD_RS, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
static int ci_udc_start(struct usb_gadget *gadget,
|
2012-05-09 04:29:04 +08:00
|
|
|
struct usb_gadget_driver *driver);
|
2013-06-24 19:46:36 +08:00
|
|
|
static int ci_udc_stop(struct usb_gadget *gadget,
|
2012-05-09 04:29:04 +08:00
|
|
|
struct usb_gadget_driver *driver);
|
2008-11-18 06:14:51 +08:00
|
|
|
/**
|
|
|
|
* Device operations part of the API to the USB controller hardware,
|
|
|
|
* which don't involve endpoints (or i/o)
|
|
|
|
* Check "usb_gadget.h" for details
|
|
|
|
*/
|
2010-12-07 20:24:02 +08:00
|
|
|
static const struct usb_gadget_ops usb_gadget_ops = {
|
2013-06-24 19:46:36 +08:00
|
|
|
.vbus_session = ci_udc_vbus_session,
|
|
|
|
.wakeup = ci_udc_wakeup,
|
|
|
|
.pullup = ci_udc_pullup,
|
|
|
|
.vbus_draw = ci_udc_vbus_draw,
|
|
|
|
.udc_start = ci_udc_start,
|
|
|
|
.udc_stop = ci_udc_stop,
|
2010-12-07 20:24:02 +08:00
|
|
|
};
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
static int init_eps(struct ci_hdrc *ci)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2012-05-09 04:29:03 +08:00
|
|
|
int retval = 0, i, j;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
for (i = 0; i < ci->hw_ep_max/2; i++)
|
2011-01-11 11:49:22 +08:00
|
|
|
for (j = RX; j <= TX; j++) {
|
2012-07-07 22:56:40 +08:00
|
|
|
int k = i + j * ci->hw_ep_max/2;
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_ep *hwep = &ci->ci_hw_ep[k];
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
scnprintf(hwep->name, sizeof(hwep->name), "ep%i%s", i,
|
2011-01-11 11:49:22 +08:00
|
|
|
(j == TX) ? "in" : "out");
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwep->ci = ci;
|
|
|
|
hwep->lock = &ci->lock;
|
|
|
|
hwep->td_pool = ci->td_pool;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwep->ep.name = hwep->name;
|
|
|
|
hwep->ep.ops = &usb_ep_ops;
|
2012-09-12 19:58:00 +08:00
|
|
|
/*
|
|
|
|
* for ep0: maxP defined in desc, for other
|
|
|
|
* eps, maxP is set by epautoconfig() called
|
|
|
|
* by gadget layer
|
|
|
|
*/
|
2013-06-13 23:00:03 +08:00
|
|
|
hwep->ep.maxpacket = (unsigned short)~0;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
INIT_LIST_HEAD(&hwep->qh.queue);
|
|
|
|
hwep->qh.ptr = dma_pool_alloc(ci->qh_pool, GFP_KERNEL,
|
|
|
|
&hwep->qh.dma);
|
|
|
|
if (hwep->qh.ptr == NULL)
|
2008-11-18 06:14:51 +08:00
|
|
|
retval = -ENOMEM;
|
|
|
|
else
|
2013-06-13 23:00:03 +08:00
|
|
|
memset(hwep->qh.ptr, 0, sizeof(*hwep->qh.ptr));
|
2011-01-11 11:49:22 +08:00
|
|
|
|
2012-05-04 21:47:15 +08:00
|
|
|
/*
|
|
|
|
* set up shorthands for ep0 out and in endpoints,
|
|
|
|
* don't add to gadget's ep_list
|
|
|
|
*/
|
|
|
|
if (i == 0) {
|
|
|
|
if (j == RX)
|
2013-06-13 23:00:03 +08:00
|
|
|
ci->ep0out = hwep;
|
2012-05-04 21:47:15 +08:00
|
|
|
else
|
2013-06-13 23:00:03 +08:00
|
|
|
ci->ep0in = hwep;
|
2012-05-04 21:47:15 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
hwep->ep.maxpacket = CTRL_PAYLOAD_MAX;
|
2011-01-11 11:49:22 +08:00
|
|
|
continue;
|
2012-05-04 21:47:15 +08:00
|
|
|
}
|
2011-01-11 11:49:22 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
list_add_tail(&hwep->ep.ep_list, &ci->gadget.ep_list);
|
2011-01-11 11:49:22 +08:00
|
|
|
}
|
2012-05-09 04:29:03 +08:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
static void destroy_eps(struct ci_hdrc *ci)
|
2012-09-12 19:58:03 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ci->hw_ep_max; i++) {
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hw_ep *hwep = &ci->ci_hw_ep[i];
|
2012-09-12 19:58:03 +08:00
|
|
|
|
2013-06-13 23:00:03 +08:00
|
|
|
dma_pool_free(ci->qh_pool, hwep->qh.ptr, hwep->qh.dma);
|
2012-09-12 19:58:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-09 04:29:03 +08:00
|
|
|
/**
|
2013-06-24 19:46:36 +08:00
|
|
|
* ci_udc_start: register a gadget driver
|
2012-05-09 04:29:04 +08:00
|
|
|
* @gadget: our gadget
|
2012-05-09 04:29:03 +08:00
|
|
|
* @driver: the driver being registered
|
|
|
|
*
|
|
|
|
* Interrupts are enabled here.
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int ci_udc_start(struct usb_gadget *gadget,
|
2012-05-09 04:29:04 +08:00
|
|
|
struct usb_gadget_driver *driver)
|
2012-05-09 04:29:03 +08:00
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hdrc *ci = container_of(gadget, struct ci_hdrc, gadget);
|
2012-05-09 04:29:03 +08:00
|
|
|
unsigned long flags;
|
|
|
|
int retval = -ENOMEM;
|
|
|
|
|
2012-05-09 04:29:04 +08:00
|
|
|
if (driver->disconnect == NULL)
|
2012-05-09 04:29:03 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
ci->ep0out->ep.desc = &ctrl_endpt_out_desc;
|
|
|
|
retval = usb_ep_enable(&ci->ep0out->ep);
|
2011-05-02 14:26:32 +08:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
2011-06-29 21:41:57 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
ci->ep0in->ep.desc = &ctrl_endpt_in_desc;
|
|
|
|
retval = usb_ep_enable(&ci->ep0in->ep);
|
2011-05-02 14:26:32 +08:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_lock_irqsave(&ci->lock, flags);
|
|
|
|
|
|
|
|
ci->driver = driver;
|
|
|
|
pm_runtime_get_sync(&ci->gadget.dev);
|
2013-06-24 19:46:36 +08:00
|
|
|
if (ci->platdata->flags & CI_HDRC_PULLUP_ON_VBUS) {
|
2012-07-07 22:56:40 +08:00
|
|
|
if (ci->vbus_active) {
|
2013-06-24 19:46:36 +08:00
|
|
|
if (ci->platdata->flags & CI_HDRC_REGS_SHARED)
|
2012-07-07 22:56:40 +08:00
|
|
|
hw_device_reset(ci, USBMODE_CM_DC);
|
2010-12-07 20:24:02 +08:00
|
|
|
} else {
|
2012-07-07 22:56:40 +08:00
|
|
|
pm_runtime_put_sync(&ci->gadget.dev);
|
2010-12-07 20:24:02 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
retval = hw_device_state(ci, ci->ep0out->qh.dma);
|
2010-12-07 20:24:04 +08:00
|
|
|
if (retval)
|
2012-07-07 22:56:40 +08:00
|
|
|
pm_runtime_put_sync(&ci->gadget.dev);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
done:
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_unlock_irqrestore(&ci->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-06-24 19:46:36 +08:00
|
|
|
* ci_udc_stop: unregister a gadget driver
|
2008-11-18 06:14:51 +08:00
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int ci_udc_stop(struct usb_gadget *gadget,
|
2012-05-09 04:29:04 +08:00
|
|
|
struct usb_gadget_driver *driver)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2013-06-24 19:46:36 +08:00
|
|
|
struct ci_hdrc *ci = container_of(gadget, struct ci_hdrc, gadget);
|
2012-05-09 04:29:04 +08:00
|
|
|
unsigned long flags;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_lock_irqsave(&ci->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
if (!(ci->platdata->flags & CI_HDRC_PULLUP_ON_VBUS) ||
|
2012-07-07 22:56:40 +08:00
|
|
|
ci->vbus_active) {
|
|
|
|
hw_device_state(ci, 0);
|
|
|
|
if (ci->platdata->notify_event)
|
|
|
|
ci->platdata->notify_event(ci,
|
2013-06-24 19:46:36 +08:00
|
|
|
CI_HDRC_CONTROLLER_STOPPED_EVENT);
|
2012-07-07 22:56:40 +08:00
|
|
|
ci->driver = NULL;
|
|
|
|
spin_unlock_irqrestore(&ci->lock, flags);
|
|
|
|
_gadget_stop_activity(&ci->gadget);
|
|
|
|
spin_lock_irqsave(&ci->lock, flags);
|
|
|
|
pm_runtime_put(&ci->gadget.dev);
|
2010-12-07 20:24:02 +08:00
|
|
|
}
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_unlock_irqrestore(&ci->lock, flags);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* BUS block
|
|
|
|
*****************************************************************************/
|
|
|
|
/**
|
2012-07-07 22:56:40 +08:00
|
|
|
* udc_irq: ci interrupt handler
|
2008-11-18 06:14:51 +08:00
|
|
|
*
|
|
|
|
* This function returns IRQ_HANDLED if the IRQ has been handled
|
|
|
|
* It locks access to registers
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static irqreturn_t udc_irq(struct ci_hdrc *ci)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
|
|
|
irqreturn_t retval;
|
|
|
|
u32 intr;
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
if (ci == NULL)
|
2008-11-18 06:14:51 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_lock(&ci->lock);
|
2010-12-07 20:24:02 +08:00
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
if (ci->platdata->flags & CI_HDRC_REGS_SHARED) {
|
2012-07-07 22:56:40 +08:00
|
|
|
if (hw_read(ci, OP_USBMODE, USBMODE_CM) !=
|
2012-05-11 22:25:53 +08:00
|
|
|
USBMODE_CM_DC) {
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_unlock(&ci->lock);
|
2010-12-07 20:24:02 +08:00
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
}
|
2012-07-07 22:56:40 +08:00
|
|
|
intr = hw_test_and_clear_intr_active(ci);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-05-11 22:25:46 +08:00
|
|
|
if (intr) {
|
2008-11-18 06:14:51 +08:00
|
|
|
/* order defines priority - do NOT change it */
|
2012-05-11 22:25:46 +08:00
|
|
|
if (USBi_URI & intr)
|
2012-07-07 22:56:40 +08:00
|
|
|
isr_reset_handler(ci);
|
2012-05-11 22:25:46 +08:00
|
|
|
|
2008-11-18 06:14:51 +08:00
|
|
|
if (USBi_PCI & intr) {
|
2012-07-07 22:56:40 +08:00
|
|
|
ci->gadget.speed = hw_port_is_high_speed(ci) ?
|
2008-11-18 06:14:51 +08:00
|
|
|
USB_SPEED_HIGH : USB_SPEED_FULL;
|
2012-07-07 22:56:40 +08:00
|
|
|
if (ci->suspended && ci->driver->resume) {
|
|
|
|
spin_unlock(&ci->lock);
|
|
|
|
ci->driver->resume(&ci->gadget);
|
|
|
|
spin_lock(&ci->lock);
|
|
|
|
ci->suspended = 0;
|
2011-02-18 20:13:17 +08:00
|
|
|
}
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
2012-05-11 22:25:46 +08:00
|
|
|
|
|
|
|
if (USBi_UI & intr)
|
2012-07-07 22:56:40 +08:00
|
|
|
isr_tr_complete_handler(ci);
|
2012-05-11 22:25:46 +08:00
|
|
|
|
2011-02-18 20:13:17 +08:00
|
|
|
if (USBi_SLI & intr) {
|
2012-07-07 22:56:40 +08:00
|
|
|
if (ci->gadget.speed != USB_SPEED_UNKNOWN &&
|
|
|
|
ci->driver->suspend) {
|
|
|
|
ci->suspended = 1;
|
|
|
|
spin_unlock(&ci->lock);
|
|
|
|
ci->driver->suspend(&ci->gadget);
|
|
|
|
spin_lock(&ci->lock);
|
2011-02-18 20:13:17 +08:00
|
|
|
}
|
|
|
|
}
|
2008-11-18 06:14:51 +08:00
|
|
|
retval = IRQ_HANDLED;
|
|
|
|
} else {
|
|
|
|
retval = IRQ_NONE;
|
|
|
|
}
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_unlock(&ci->lock);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-05-11 22:25:47 +08:00
|
|
|
* udc_start: initialize gadget role
|
2012-07-07 22:56:40 +08:00
|
|
|
* @ci: chipidea controller
|
2008-11-18 06:14:51 +08:00
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static int udc_start(struct ci_hdrc *ci)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2012-07-07 22:56:40 +08:00
|
|
|
struct device *dev = ci->dev;
|
2008-11-18 06:14:51 +08:00
|
|
|
int retval = 0;
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
spin_lock_init(&ci->lock);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
ci->gadget.ops = &usb_gadget_ops;
|
|
|
|
ci->gadget.speed = USB_SPEED_UNKNOWN;
|
|
|
|
ci->gadget.max_speed = USB_SPEED_HIGH;
|
|
|
|
ci->gadget.is_otg = 0;
|
|
|
|
ci->gadget.name = ci->platdata->name;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
INIT_LIST_HEAD(&ci->gadget.ep_list);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-05-09 04:29:03 +08:00
|
|
|
/* alloc resources */
|
2013-06-24 19:46:36 +08:00
|
|
|
ci->qh_pool = dma_pool_create("ci_hw_qh", dev,
|
|
|
|
sizeof(struct ci_hw_qh),
|
|
|
|
64, CI_HDRC_PAGE_SIZE);
|
2012-07-07 22:56:40 +08:00
|
|
|
if (ci->qh_pool == NULL)
|
2012-05-11 22:25:47 +08:00
|
|
|
return -ENOMEM;
|
2012-05-09 04:29:03 +08:00
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
ci->td_pool = dma_pool_create("ci_hw_td", dev,
|
|
|
|
sizeof(struct ci_hw_td),
|
|
|
|
64, CI_HDRC_PAGE_SIZE);
|
2012-07-07 22:56:40 +08:00
|
|
|
if (ci->td_pool == NULL) {
|
2012-05-09 04:29:03 +08:00
|
|
|
retval = -ENOMEM;
|
|
|
|
goto free_qh_pool;
|
|
|
|
}
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
retval = init_eps(ci);
|
2012-05-09 04:29:03 +08:00
|
|
|
if (retval)
|
|
|
|
goto free_pools;
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
ci->gadget.ep0 = &ci->ep0in->ep;
|
2010-12-07 20:24:02 +08:00
|
|
|
|
2013-06-11 18:41:47 +08:00
|
|
|
if (ci->global_phy) {
|
2012-07-07 22:56:46 +08:00
|
|
|
ci->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
|
2013-06-11 18:41:47 +08:00
|
|
|
if (IS_ERR(ci->transceiver))
|
|
|
|
ci->transceiver = NULL;
|
|
|
|
}
|
2010-12-07 20:24:02 +08:00
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
if (ci->platdata->flags & CI_HDRC_REQUIRE_TRANSCEIVER) {
|
2012-07-07 22:56:40 +08:00
|
|
|
if (ci->transceiver == NULL) {
|
2010-12-07 20:24:02 +08:00
|
|
|
retval = -ENODEV;
|
2012-09-12 19:58:03 +08:00
|
|
|
goto destroy_eps;
|
2010-12-07 20:24:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-24 19:46:36 +08:00
|
|
|
if (!(ci->platdata->flags & CI_HDRC_REGS_SHARED)) {
|
2012-07-07 22:56:40 +08:00
|
|
|
retval = hw_device_reset(ci, USBMODE_CM_DC);
|
2010-12-07 20:24:02 +08:00
|
|
|
if (retval)
|
|
|
|
goto put_transceiver;
|
|
|
|
}
|
|
|
|
|
2013-06-11 18:41:47 +08:00
|
|
|
if (ci->transceiver) {
|
2012-07-07 22:56:40 +08:00
|
|
|
retval = otg_set_peripheral(ci->transceiver->otg,
|
|
|
|
&ci->gadget);
|
2013-08-14 17:44:05 +08:00
|
|
|
/*
|
|
|
|
* If we implement all USB functions using chipidea drivers,
|
|
|
|
* it doesn't need to call above API, meanwhile, if we only
|
|
|
|
* use gadget function, calling above API is useless.
|
|
|
|
*/
|
|
|
|
if (retval && retval != -ENOTSUPP)
|
usb: patches for v3.10 merge window
Here is the big Gadget & PHY pull request. Many of us have
been really busy lately getting multiple drivers to a better
position.
Since this pull request is so large, I will divide it in sections
so it's easier to grasp what's included.
- cleanups:
. UDC drivers no longer touch gadget->dev, that's now udc-core
responsibility
. Many more UDC drivers converted to usb_gadget_map/unmap_request()
. UDC drivers no longer initialize DMA-related fields from gadget's
device structure
. UDC drivers don't touch gadget.dev.driver directly
. UDC drivers don't assign gadget.dev.release directly
. Removal of some unused DMA_ADDR_INVALID
. Introduction of CONFIG_USB_PHY
. All phy drivers have been moved to drivers/usb/phy and renamed to
a common naming scheme
. Fix PHY layer so it never returns a NULL pointer, also fix all
callers to avoid using IS_ERR_OR_NULL()
. Sparse fixes all over the place
. drivers/usb/otg/ has been deleted
. Marvel drivers (mv_udc, ehci-mv, mv_otg and mv_u3d) improved clock
usage
- new features:
. UDC core now provides a generic way for tracking and reporting
UDC's state (not attached, resuming, suspended, addressed,
default, etc)
. twl4030-usb learned that it shouldn't be enabled during init
. Full DT support for DWC3 has been implemented
. ab8500-usb learned about pinctrl framework
. nop PHY learned about DeviceTree and regulators
. DWC3 learned about suspend/resume
. DWC3 can now be compiled in host-only and gadget-only (as well as
DRD) configurations
. UVC now enables streaming endpoint based on negotiated speed
. isp1301 now implements the PHY API properly
. configfs-based interface for gadget drivers which will lead to
the removal of all code which just combines functions together
to build functional gadget drivers.
. f_serial and f_obex were converted to new configfs interface while
maintaining old interface around.
- non-critical fixes:
. UVC gadget driver got fixes for Endpoint usage and stream calculation
. ab8500-usb fixed unbalanced clock and regulator API usage
. twl4030-usb got a fix for when OMAP3 is booted with cable connected
. fusb300_udc got a fix for DMA usage
. UVC got fixes for two assertions of the USB Video Class Compliance
specification revision 1.1
. build warning issues caused by recent addition of __must_check to
regulator API
These are all changes which deserve a mention, all other changes are related
to these one or minor spelling fixes and other similar tasks.
Signed-of-by: Felipe Balbi <balbi@ti.com>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iQIcBAABAgAGBQJRXG8GAAoJEIaOsuA1yqREJzYQAKMLW3J/TKTWS1DDuf7qMtMz
Ug6qChKZXgT1/QrNjsq2tx4jYIkNdSMtRKiUx0BnIptlUx6gM22gcsN8mXX/UJjC
FYAiWl+tYe85e9uayqqt+qVCZjTZCc7St4wQalugDHefvA7yCbiZpSaJRGlJMK+x
mePJ7MfrulDsYBXr0u+m2LOJ0qxMDi40k3/UN3aUu5yzrmBiRpVq1mySruvLwGFp
Pr6vBnprEc6bW5sRdUR4SICKLvLk5sHwHpvpkzDLYBIb/jXQwbfQri/HKeh4VMk8
trbsvHZyB7H8uuFsCHiBc6VtjcbZ4mxPUK+1PCq8hG077avdkm3ox0BERk9aRTeC
jg4mdpyWjgovwi882woPEQXNZoaAXpVDyI8tBRx92a+rGJjXSHhLQI+4Ffi4ZvzV
d+q1ZzrHxuzwa/BwcPETY76umXQqXWXg+ap1bHDY0RZFoPLdXMpl583NXGSn3gOD
dUlD0UlgYwb75333tRIPNQn3qOx0HVd6MlYPMNzl9t9c9qqfX78AYRny6ZucupRg
t9VZ6FO3D2yre9W7u3U3q2c9H7uSAKr/8xaNfvdsIWPncgvvYVIyE8MnR7AiHoPv
ZYESs/Gs6w9vUsHa9K4J16Ape7D3AMcGpXUoPUxTBHrwBexzt4j27VWtcL4ns/9r
0kcltUJ4Zq+PIjc7xgxe
=aF4r
-----END PGP SIGNATURE-----
Merge tag 'usb-for-v3.10' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb into usb-next
Felipe writes:
usb: patches for v3.10 merge window
Here is the big Gadget & PHY pull request. Many of us have
been really busy lately getting multiple drivers to a better
position.
Since this pull request is so large, I will divide it in sections
so it's easier to grasp what's included.
- cleanups:
. UDC drivers no longer touch gadget->dev, that's now udc-core
responsibility
. Many more UDC drivers converted to usb_gadget_map/unmap_request()
. UDC drivers no longer initialize DMA-related fields from gadget's
device structure
. UDC drivers don't touch gadget.dev.driver directly
. UDC drivers don't assign gadget.dev.release directly
. Removal of some unused DMA_ADDR_INVALID
. Introduction of CONFIG_USB_PHY
. All phy drivers have been moved to drivers/usb/phy and renamed to
a common naming scheme
. Fix PHY layer so it never returns a NULL pointer, also fix all
callers to avoid using IS_ERR_OR_NULL()
. Sparse fixes all over the place
. drivers/usb/otg/ has been deleted
. Marvel drivers (mv_udc, ehci-mv, mv_otg and mv_u3d) improved clock
usage
- new features:
. UDC core now provides a generic way for tracking and reporting
UDC's state (not attached, resuming, suspended, addressed,
default, etc)
. twl4030-usb learned that it shouldn't be enabled during init
. Full DT support for DWC3 has been implemented
. ab8500-usb learned about pinctrl framework
. nop PHY learned about DeviceTree and regulators
. DWC3 learned about suspend/resume
. DWC3 can now be compiled in host-only and gadget-only (as well as
DRD) configurations
. UVC now enables streaming endpoint based on negotiated speed
. isp1301 now implements the PHY API properly
. configfs-based interface for gadget drivers which will lead to
the removal of all code which just combines functions together
to build functional gadget drivers.
. f_serial and f_obex were converted to new configfs interface while
maintaining old interface around.
- non-critical fixes:
. UVC gadget driver got fixes for Endpoint usage and stream calculation
. ab8500-usb fixed unbalanced clock and regulator API usage
. twl4030-usb got a fix for when OMAP3 is booted with cable connected
. fusb300_udc got a fix for DMA usage
. UVC got fixes for two assertions of the USB Video Class Compliance
specification revision 1.1
. build warning issues caused by recent addition of __must_check to
regulator API
These are all changes which deserve a mention, all other changes are related
to these one or minor spelling fixes and other similar tasks.
Signed-of-by: Felipe Balbi <balbi@ti.com>
2013-04-06 06:18:00 +08:00
|
|
|
goto put_transceiver;
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|
2011-06-28 21:33:47 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
retval = usb_add_gadget_udc(dev, &ci->gadget);
|
2011-06-28 21:33:47 +08:00
|
|
|
if (retval)
|
|
|
|
goto remove_trans;
|
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
pm_runtime_no_callbacks(&ci->gadget.dev);
|
|
|
|
pm_runtime_enable(&ci->gadget.dev);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
2011-06-28 21:33:47 +08:00
|
|
|
remove_trans:
|
2013-06-11 18:41:47 +08:00
|
|
|
if (ci->transceiver) {
|
2012-09-12 19:58:02 +08:00
|
|
|
otg_set_peripheral(ci->transceiver->otg, NULL);
|
2012-07-07 22:56:46 +08:00
|
|
|
if (ci->global_phy)
|
|
|
|
usb_put_phy(ci->transceiver);
|
2011-06-28 21:33:47 +08:00
|
|
|
}
|
|
|
|
|
2012-04-28 02:24:39 +08:00
|
|
|
dev_err(dev, "error = %i\n", retval);
|
2010-12-07 20:24:02 +08:00
|
|
|
put_transceiver:
|
2013-06-11 18:41:47 +08:00
|
|
|
if (ci->transceiver && ci->global_phy)
|
2012-07-07 22:56:40 +08:00
|
|
|
usb_put_phy(ci->transceiver);
|
2012-09-12 19:58:03 +08:00
|
|
|
destroy_eps:
|
|
|
|
destroy_eps(ci);
|
2012-05-09 04:29:03 +08:00
|
|
|
free_pools:
|
2012-07-07 22:56:40 +08:00
|
|
|
dma_pool_destroy(ci->td_pool);
|
2012-05-09 04:29:03 +08:00
|
|
|
free_qh_pool:
|
2012-07-07 22:56:40 +08:00
|
|
|
dma_pool_destroy(ci->qh_pool);
|
2008-11-18 06:14:51 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* udc_remove: parent remove must call this to remove UDC
|
|
|
|
*
|
|
|
|
* No interrupts active, the IRQ has been released
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
static void udc_stop(struct ci_hdrc *ci)
|
2008-11-18 06:14:51 +08:00
|
|
|
{
|
2012-07-07 22:56:40 +08:00
|
|
|
if (ci == NULL)
|
2008-11-18 06:14:51 +08:00
|
|
|
return;
|
2012-05-09 04:29:02 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
usb_del_gadget_udc(&ci->gadget);
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-09-12 19:58:03 +08:00
|
|
|
destroy_eps(ci);
|
2012-05-09 04:29:03 +08:00
|
|
|
|
2012-07-07 22:56:40 +08:00
|
|
|
dma_pool_destroy(ci->td_pool);
|
|
|
|
dma_pool_destroy(ci->qh_pool);
|
2012-05-09 04:29:03 +08:00
|
|
|
|
2013-06-11 18:41:47 +08:00
|
|
|
if (ci->transceiver) {
|
2012-07-07 22:56:40 +08:00
|
|
|
otg_set_peripheral(ci->transceiver->otg, NULL);
|
2012-07-07 22:56:46 +08:00
|
|
|
if (ci->global_phy)
|
|
|
|
usb_put_phy(ci->transceiver);
|
2010-12-07 20:24:02 +08:00
|
|
|
}
|
2012-05-11 22:25:47 +08:00
|
|
|
/* my kobject is dynamic, I swear! */
|
2012-07-07 22:56:40 +08:00
|
|
|
memset(&ci->gadget, 0, sizeof(ci->gadget));
|
2012-05-11 22:25:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ci_hdrc_gadget_init - initialize device related bits
|
|
|
|
* ci: the controller
|
|
|
|
*
|
|
|
|
* This function enables the gadget role, if the device is "device capable".
|
|
|
|
*/
|
2013-06-24 19:46:36 +08:00
|
|
|
int ci_hdrc_gadget_init(struct ci_hdrc *ci)
|
2012-05-11 22:25:47 +08:00
|
|
|
{
|
|
|
|
struct ci_role_driver *rdrv;
|
|
|
|
|
|
|
|
if (!hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DC))
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
rdrv = devm_kzalloc(ci->dev, sizeof(struct ci_role_driver), GFP_KERNEL);
|
|
|
|
if (!rdrv)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
rdrv->start = udc_start;
|
|
|
|
rdrv->stop = udc_stop;
|
|
|
|
rdrv->irq = udc_irq;
|
|
|
|
rdrv->name = "gadget";
|
|
|
|
ci->roles[CI_ROLE_GADGET] = rdrv;
|
2008-11-18 06:14:51 +08:00
|
|
|
|
2012-05-11 22:25:47 +08:00
|
|
|
return 0;
|
2008-11-18 06:14:51 +08:00
|
|
|
}
|