2008-07-24 09:27:36 +00:00
|
|
|
/*
|
|
|
|
* MUSB OTG driver core code
|
|
|
|
*
|
|
|
|
* Copyright 2005 Mentor Graphics Corporation
|
|
|
|
* Copyright (C) 2005-2006 by Texas Instruments
|
|
|
|
* Copyright (C) 2006-2007 Nokia Corporation
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
|
|
|
* NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
|
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Inventra (Multipoint) Dual-Role Controller Driver for Linux.
|
|
|
|
*
|
|
|
|
* This consists of a Host Controller Driver (HCD) and a peripheral
|
|
|
|
* controller driver implementing the "Gadget" API; OTG support is
|
|
|
|
* in the works. These are normal Linux-USB controller drivers which
|
|
|
|
* use IRQs and have no dedicated thread.
|
|
|
|
*
|
|
|
|
* This version of the driver has only been used with products from
|
|
|
|
* Texas Instruments. Those products integrate the Inventra logic
|
|
|
|
* with other DMA, IRQ, and bus modules, as well as other logic that
|
|
|
|
* needs to be reflected in this driver.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* NOTE: the original Mentor code here was pretty much a collection
|
|
|
|
* of mechanisms that don't seem to have been fully integrated/working
|
|
|
|
* for *any* Linux kernel version. This version aims at Linux 2.6.now,
|
|
|
|
* Key open issues include:
|
|
|
|
*
|
|
|
|
* - Lack of host-side transaction scheduling, for all transfer types.
|
|
|
|
* The hardware doesn't do it; instead, software must.
|
|
|
|
*
|
|
|
|
* This is not an issue for OTG devices that don't support external
|
|
|
|
* hubs, but for more "normal" USB hosts it's a user issue that the
|
|
|
|
* "multipoint" support doesn't scale in the expected ways. That
|
|
|
|
* includes DaVinci EVM in a common non-OTG mode.
|
|
|
|
*
|
|
|
|
* * Control and bulk use dedicated endpoints, and there's as
|
|
|
|
* yet no mechanism to either (a) reclaim the hardware when
|
|
|
|
* peripherals are NAKing, which gets complicated with bulk
|
|
|
|
* endpoints, or (b) use more than a single bulk endpoint in
|
|
|
|
* each direction.
|
|
|
|
*
|
|
|
|
* RESULT: one device may be perceived as blocking another one.
|
|
|
|
*
|
|
|
|
* * Interrupt and isochronous will dynamically allocate endpoint
|
|
|
|
* hardware, but (a) there's no record keeping for bandwidth;
|
|
|
|
* (b) in the common case that few endpoints are available, there
|
|
|
|
* is no mechanism to reuse endpoints to talk to multiple devices.
|
|
|
|
*
|
|
|
|
* RESULT: At one extreme, bandwidth can be overcommitted in
|
|
|
|
* some hardware configurations, no faults will be reported.
|
|
|
|
* At the other extreme, the bandwidth capabilities which do
|
|
|
|
* exist tend to be severely undercommitted. You can't yet hook
|
|
|
|
* up both a keyboard and a mouse to an external USB hub.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This gets many kinds of configuration information:
|
|
|
|
* - Kconfig for everything user-configurable
|
|
|
|
* - platform_device for addressing, irq, and platform_data
|
2014-01-02 13:57:47 +00:00
|
|
|
* - platform_data is mostly for board-specific information
|
2008-09-11 08:53:23 +00:00
|
|
|
* (plus recentrly, SOC or family details)
|
2008-07-24 09:27:36 +00:00
|
|
|
*
|
|
|
|
* Most of the conditional compilation will (someday) vanish.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/kobject.h>
|
2011-05-25 12:13:24 +00:00
|
|
|
#include <linux/prefetch.h>
|
2008-07-24 09:27:36 +00:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/io.h>
|
2012-08-31 11:09:50 +00:00
|
|
|
#include <linux/dma-mapping.h>
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
#include "musb_core.h"
|
|
|
|
|
2009-03-31 19:32:12 +00:00
|
|
|
#define TA_WAIT_BCON(m) max_t(int, (m)->a_wait_bcon, OTG_TIME_A_WAIT_BCON)
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define DRIVER_AUTHOR "Mentor Graphics, Texas Instruments, Nokia"
|
|
|
|
#define DRIVER_DESC "Inventra Dual-Role USB Controller Driver"
|
|
|
|
|
2008-08-10 18:22:35 +00:00
|
|
|
#define MUSB_VERSION "6.0"
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
#define DRIVER_INFO DRIVER_DESC ", v" MUSB_VERSION
|
|
|
|
|
2010-12-02 06:49:26 +00:00
|
|
|
#define MUSB_DRIVER_NAME "musb-hdrc"
|
2008-07-24 09:27:36 +00:00
|
|
|
const char musb_driver_name[] = MUSB_DRIVER_NAME;
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION(DRIVER_INFO);
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("platform:" MUSB_DRIVER_NAME);
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static inline struct musb *dev_to_musb(struct device *dev)
|
|
|
|
{
|
|
|
|
return dev_get_drvdata(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2010-03-25 11:25:28 +00:00
|
|
|
#ifndef CONFIG_BLACKFIN
|
2012-02-13 11:24:18 +00:00
|
|
|
static int musb_ulpi_read(struct usb_phy *phy, u32 offset)
|
2010-03-25 11:25:28 +00:00
|
|
|
{
|
2012-02-13 11:24:18 +00:00
|
|
|
void __iomem *addr = phy->io_priv;
|
2010-03-25 11:25:28 +00:00
|
|
|
int i = 0;
|
|
|
|
u8 r;
|
|
|
|
u8 power;
|
2012-03-21 14:35:52 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
pm_runtime_get_sync(phy->io_dev);
|
2010-03-25 11:25:28 +00:00
|
|
|
|
|
|
|
/* Make sure the transceiver is not in low power mode */
|
|
|
|
power = musb_readb(addr, MUSB_POWER);
|
|
|
|
power &= ~MUSB_POWER_SUSPENDM;
|
|
|
|
musb_writeb(addr, MUSB_POWER, power);
|
|
|
|
|
|
|
|
/* REVISIT: musbhdrc_ulpi_an.pdf recommends setting the
|
|
|
|
* ULPICarKitControlDisableUTMI after clearing POWER_SUSPENDM.
|
|
|
|
*/
|
|
|
|
|
|
|
|
musb_writeb(addr, MUSB_ULPI_REG_ADDR, (u8)offset);
|
|
|
|
musb_writeb(addr, MUSB_ULPI_REG_CONTROL,
|
|
|
|
MUSB_ULPI_REG_REQ | MUSB_ULPI_RDN_WR);
|
|
|
|
|
|
|
|
while (!(musb_readb(addr, MUSB_ULPI_REG_CONTROL)
|
|
|
|
& MUSB_ULPI_REG_CMPLT)) {
|
|
|
|
i++;
|
2012-03-21 14:35:52 +00:00
|
|
|
if (i == 10000) {
|
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-03-25 11:25:28 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
r = musb_readb(addr, MUSB_ULPI_REG_CONTROL);
|
|
|
|
r &= ~MUSB_ULPI_REG_CMPLT;
|
|
|
|
musb_writeb(addr, MUSB_ULPI_REG_CONTROL, r);
|
|
|
|
|
2012-03-21 14:35:52 +00:00
|
|
|
ret = musb_readb(addr, MUSB_ULPI_REG_DATA);
|
|
|
|
|
|
|
|
out:
|
|
|
|
pm_runtime_put(phy->io_dev);
|
|
|
|
|
|
|
|
return ret;
|
2010-03-25 11:25:28 +00:00
|
|
|
}
|
|
|
|
|
2012-02-13 11:24:18 +00:00
|
|
|
static int musb_ulpi_write(struct usb_phy *phy, u32 offset, u32 data)
|
2010-03-25 11:25:28 +00:00
|
|
|
{
|
2012-02-13 11:24:18 +00:00
|
|
|
void __iomem *addr = phy->io_priv;
|
2010-03-25 11:25:28 +00:00
|
|
|
int i = 0;
|
|
|
|
u8 r = 0;
|
|
|
|
u8 power;
|
2012-03-21 14:35:52 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
pm_runtime_get_sync(phy->io_dev);
|
2010-03-25 11:25:28 +00:00
|
|
|
|
|
|
|
/* Make sure the transceiver is not in low power mode */
|
|
|
|
power = musb_readb(addr, MUSB_POWER);
|
|
|
|
power &= ~MUSB_POWER_SUSPENDM;
|
|
|
|
musb_writeb(addr, MUSB_POWER, power);
|
|
|
|
|
|
|
|
musb_writeb(addr, MUSB_ULPI_REG_ADDR, (u8)offset);
|
|
|
|
musb_writeb(addr, MUSB_ULPI_REG_DATA, (u8)data);
|
|
|
|
musb_writeb(addr, MUSB_ULPI_REG_CONTROL, MUSB_ULPI_REG_REQ);
|
|
|
|
|
|
|
|
while (!(musb_readb(addr, MUSB_ULPI_REG_CONTROL)
|
|
|
|
& MUSB_ULPI_REG_CMPLT)) {
|
|
|
|
i++;
|
2012-03-21 14:35:52 +00:00
|
|
|
if (i == 10000) {
|
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-03-25 11:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
r = musb_readb(addr, MUSB_ULPI_REG_CONTROL);
|
|
|
|
r &= ~MUSB_ULPI_REG_CMPLT;
|
|
|
|
musb_writeb(addr, MUSB_ULPI_REG_CONTROL, r);
|
|
|
|
|
2012-03-21 14:35:52 +00:00
|
|
|
out:
|
|
|
|
pm_runtime_put(phy->io_dev);
|
|
|
|
|
|
|
|
return ret;
|
2010-03-25 11:25:28 +00:00
|
|
|
}
|
|
|
|
#else
|
2010-06-24 17:37:08 +00:00
|
|
|
#define musb_ulpi_read NULL
|
|
|
|
#define musb_ulpi_write NULL
|
2010-03-25 11:25:28 +00:00
|
|
|
#endif
|
|
|
|
|
2012-02-13 11:24:18 +00:00
|
|
|
static struct usb_phy_io_ops musb_ulpi_access = {
|
2010-03-25 11:25:28 +00:00
|
|
|
.read = musb_ulpi_read,
|
|
|
|
.write = musb_ulpi_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2010-12-01 12:23:48 +00:00
|
|
|
#if !defined(CONFIG_USB_MUSB_TUSB6010) && !defined(CONFIG_USB_MUSB_BLACKFIN)
|
2008-12-02 19:33:48 +00:00
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
/*
|
|
|
|
* Load an endpoint's FIFO
|
|
|
|
*/
|
|
|
|
void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
|
|
|
|
{
|
2011-05-11 09:44:08 +00:00
|
|
|
struct musb *musb = hw_ep->musb;
|
2008-07-24 09:27:36 +00:00
|
|
|
void __iomem *fifo = hw_ep->fifo;
|
|
|
|
|
2012-07-20 05:37:24 +00:00
|
|
|
if (unlikely(len == 0))
|
|
|
|
return;
|
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
prefetch((u8 *)src);
|
|
|
|
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n",
|
2008-07-24 09:27:36 +00:00
|
|
|
'T', hw_ep->epnum, fifo, len, src);
|
|
|
|
|
|
|
|
/* we can't assume unaligned reads work */
|
|
|
|
if (likely((0x01 & (unsigned long) src) == 0)) {
|
|
|
|
u16 index = 0;
|
|
|
|
|
|
|
|
/* best case is 32bit-aligned source address */
|
|
|
|
if ((0x02 & (unsigned long) src) == 0) {
|
|
|
|
if (len >= 4) {
|
2012-12-17 23:59:48 +00:00
|
|
|
iowrite32_rep(fifo, src + index, len >> 2);
|
2008-07-24 09:27:36 +00:00
|
|
|
index += len & ~0x03;
|
|
|
|
}
|
|
|
|
if (len & 0x02) {
|
|
|
|
musb_writew(fifo, 0, *(u16 *)&src[index]);
|
|
|
|
index += 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (len >= 2) {
|
2012-12-17 23:59:48 +00:00
|
|
|
iowrite16_rep(fifo, src + index, len >> 1);
|
2008-07-24 09:27:36 +00:00
|
|
|
index += len & ~0x01;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (len & 0x01)
|
|
|
|
musb_writeb(fifo, 0, src[index]);
|
|
|
|
} else {
|
|
|
|
/* byte aligned */
|
2012-12-17 23:59:48 +00:00
|
|
|
iowrite8_rep(fifo, src, len);
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-19 07:08:13 +00:00
|
|
|
#if !defined(CONFIG_USB_MUSB_AM35X)
|
2008-07-24 09:27:36 +00:00
|
|
|
/*
|
|
|
|
* Unload an endpoint's FIFO
|
|
|
|
*/
|
|
|
|
void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
|
|
|
|
{
|
2011-05-11 09:44:08 +00:00
|
|
|
struct musb *musb = hw_ep->musb;
|
2008-07-24 09:27:36 +00:00
|
|
|
void __iomem *fifo = hw_ep->fifo;
|
|
|
|
|
2012-07-20 05:37:24 +00:00
|
|
|
if (unlikely(len == 0))
|
|
|
|
return;
|
|
|
|
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n",
|
2008-07-24 09:27:36 +00:00
|
|
|
'R', hw_ep->epnum, fifo, len, dst);
|
|
|
|
|
|
|
|
/* we can't assume unaligned writes work */
|
|
|
|
if (likely((0x01 & (unsigned long) dst) == 0)) {
|
|
|
|
u16 index = 0;
|
|
|
|
|
|
|
|
/* best case is 32bit-aligned destination address */
|
|
|
|
if ((0x02 & (unsigned long) dst) == 0) {
|
|
|
|
if (len >= 4) {
|
2012-12-17 23:59:48 +00:00
|
|
|
ioread32_rep(fifo, dst, len >> 2);
|
2008-07-24 09:27:36 +00:00
|
|
|
index = len & ~0x03;
|
|
|
|
}
|
|
|
|
if (len & 0x02) {
|
|
|
|
*(u16 *)&dst[index] = musb_readw(fifo, 0);
|
|
|
|
index += 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (len >= 2) {
|
2012-12-17 23:59:48 +00:00
|
|
|
ioread16_rep(fifo, dst, len >> 1);
|
2008-07-24 09:27:36 +00:00
|
|
|
index = len & ~0x01;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (len & 0x01)
|
|
|
|
dst[index] = musb_readb(fifo, 0);
|
|
|
|
} else {
|
|
|
|
/* byte aligned */
|
2012-12-17 23:59:48 +00:00
|
|
|
ioread8_rep(fifo, dst, len);
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-19 07:08:13 +00:00
|
|
|
#endif
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
#endif /* normal PIO */
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* for high speed test mode; see USB 2.0 spec 7.1.20 */
|
|
|
|
static const u8 musb_test_packet[53] = {
|
|
|
|
/* implicit SYNC then DATA0 to start */
|
|
|
|
|
|
|
|
/* JKJKJKJK x9 */
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
/* JJKKJJKK x8 */
|
|
|
|
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
|
|
|
|
/* JJJJKKKK x8 */
|
|
|
|
0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee, 0xee,
|
|
|
|
/* JJJJJJJKKKKKKK x8 */
|
|
|
|
0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
/* JJJJJJJK x8 */
|
|
|
|
0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd,
|
|
|
|
/* JKKKKKKK x10, JK */
|
|
|
|
0xfc, 0x7e, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0x7e
|
|
|
|
|
|
|
|
/* implicit CRC16 then EOP to end */
|
|
|
|
};
|
|
|
|
|
|
|
|
void musb_load_testpacket(struct musb *musb)
|
|
|
|
{
|
|
|
|
void __iomem *regs = musb->endpoints[0].regs;
|
|
|
|
|
|
|
|
musb_ep_select(musb->mregs, 0);
|
|
|
|
musb_write_fifo(musb->control_ep,
|
|
|
|
sizeof(musb_test_packet), musb_test_packet);
|
|
|
|
musb_writew(regs, MUSB_CSR0, MUSB_CSR0_TXPKTRDY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handles OTG hnp timeouts, such as b_ase0_brst
|
|
|
|
*/
|
2012-08-07 11:00:50 +00:00
|
|
|
static void musb_otg_timer_func(unsigned long data)
|
2008-07-24 09:27:36 +00:00
|
|
|
{
|
|
|
|
struct musb *musb = (struct musb *)data;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&musb->lock, flags);
|
2009-03-31 19:30:04 +00:00
|
|
|
switch (musb->xceiv->state) {
|
2008-07-24 09:27:36 +00:00
|
|
|
case OTG_STATE_B_WAIT_ACON:
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "HNP: b_wait_acon timeout; back to b_peripheral\n");
|
2008-07-24 09:27:36 +00:00
|
|
|
musb_g_disconnect(musb);
|
2009-03-31 19:30:04 +00:00
|
|
|
musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
|
2008-07-24 09:27:36 +00:00
|
|
|
musb->is_active = 0;
|
|
|
|
break;
|
2009-03-31 19:35:09 +00:00
|
|
|
case OTG_STATE_A_SUSPEND:
|
2008-07-24 09:27:36 +00:00
|
|
|
case OTG_STATE_A_WAIT_BCON:
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "HNP: %s timeout\n",
|
2013-03-07 08:39:57 +00:00
|
|
|
usb_otg_state_string(musb->xceiv->state));
|
2010-12-01 11:22:05 +00:00
|
|
|
musb_platform_set_vbus(musb, 0);
|
2009-03-31 19:35:09 +00:00
|
|
|
musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
|
2008-07-24 09:27:36 +00:00
|
|
|
break;
|
|
|
|
default:
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "HNP: Unhandled mode %s\n",
|
2013-03-07 08:39:57 +00:00
|
|
|
usb_otg_state_string(musb->xceiv->state));
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&musb->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-03-31 19:32:12 +00:00
|
|
|
* Stops the HNP transition. Caller must take care of locking.
|
2008-07-24 09:27:36 +00:00
|
|
|
*/
|
|
|
|
void musb_hnp_stop(struct musb *musb)
|
|
|
|
{
|
2013-04-10 19:55:50 +00:00
|
|
|
struct usb_hcd *hcd = musb->hcd;
|
2008-07-24 09:27:36 +00:00
|
|
|
void __iomem *mbase = musb->mregs;
|
|
|
|
u8 reg;
|
|
|
|
|
2013-03-07 08:39:57 +00:00
|
|
|
dev_dbg(musb->controller, "HNP: stop from %s\n",
|
|
|
|
usb_otg_state_string(musb->xceiv->state));
|
2009-03-31 19:35:09 +00:00
|
|
|
|
2009-03-31 19:30:04 +00:00
|
|
|
switch (musb->xceiv->state) {
|
2008-07-24 09:27:36 +00:00
|
|
|
case OTG_STATE_A_PERIPHERAL:
|
|
|
|
musb_g_disconnect(musb);
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "HNP: back to %s\n",
|
2013-03-07 08:39:57 +00:00
|
|
|
usb_otg_state_string(musb->xceiv->state));
|
2008-07-24 09:27:36 +00:00
|
|
|
break;
|
|
|
|
case OTG_STATE_B_HOST:
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "HNP: Disabling HR\n");
|
2013-04-10 19:55:45 +00:00
|
|
|
if (hcd)
|
|
|
|
hcd->self.is_b_host = 0;
|
2009-03-31 19:30:04 +00:00
|
|
|
musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
|
2008-07-24 09:27:36 +00:00
|
|
|
MUSB_DEV_MODE(musb);
|
|
|
|
reg = musb_readb(mbase, MUSB_POWER);
|
|
|
|
reg |= MUSB_POWER_SUSPENDM;
|
|
|
|
musb_writeb(mbase, MUSB_POWER, reg);
|
|
|
|
/* REVISIT: Start SESSION_REQUEST here? */
|
|
|
|
break;
|
|
|
|
default:
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "HNP: Stopping in unknown state %s\n",
|
2013-03-07 08:39:57 +00:00
|
|
|
usb_otg_state_string(musb->xceiv->state));
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When returning to A state after HNP, avoid hub_port_rebounce(),
|
|
|
|
* which cause occasional OPT A "Did not receive reset after connect"
|
|
|
|
* errors.
|
|
|
|
*/
|
2010-03-04 22:05:08 +00:00
|
|
|
musb->port1_status &= ~(USB_PORT_STAT_C_CONNECTION << 16);
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupt Service Routine to record USB "global" interrupts.
|
|
|
|
* Since these do not happen often and signify things of
|
|
|
|
* paramount importance, it seems OK to check them individually;
|
|
|
|
* the order of the tests is specified in the manual
|
|
|
|
*
|
|
|
|
* @param musb instance pointer
|
|
|
|
* @param int_usb register contents
|
|
|
|
* @param devctl
|
|
|
|
* @param power
|
|
|
|
*/
|
|
|
|
|
|
|
|
static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
|
2012-10-30 18:52:23 +00:00
|
|
|
u8 devctl)
|
2008-07-24 09:27:36 +00:00
|
|
|
{
|
|
|
|
irqreturn_t handled = IRQ_NONE;
|
|
|
|
|
2012-10-30 18:52:23 +00:00
|
|
|
dev_dbg(musb->controller, "<== DevCtl=%02x, int_usb=0x%x\n", devctl,
|
2008-07-24 09:27:36 +00:00
|
|
|
int_usb);
|
|
|
|
|
|
|
|
/* in host mode, the peripheral may issue remote wakeup.
|
|
|
|
* in peripheral mode, the host may resume the link.
|
|
|
|
* spurious RESUME irqs happen too, paired with SUSPEND.
|
|
|
|
*/
|
|
|
|
if (int_usb & MUSB_INTR_RESUME) {
|
|
|
|
handled = IRQ_HANDLED;
|
2013-03-07 08:39:57 +00:00
|
|
|
dev_dbg(musb->controller, "RESUME (%s)\n", usb_otg_state_string(musb->xceiv->state));
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
if (devctl & MUSB_DEVCTL_HM) {
|
2010-03-12 08:27:24 +00:00
|
|
|
void __iomem *mbase = musb->mregs;
|
2012-10-30 18:52:23 +00:00
|
|
|
u8 power;
|
2010-03-12 08:27:24 +00:00
|
|
|
|
2009-03-31 19:30:04 +00:00
|
|
|
switch (musb->xceiv->state) {
|
2008-07-24 09:27:36 +00:00
|
|
|
case OTG_STATE_A_SUSPEND:
|
|
|
|
/* remote wakeup? later, GetPortStatus
|
|
|
|
* will stop RESUME signaling
|
|
|
|
*/
|
|
|
|
|
2012-10-30 18:52:23 +00:00
|
|
|
power = musb_readb(musb->mregs, MUSB_POWER);
|
2008-07-24 09:27:36 +00:00
|
|
|
if (power & MUSB_POWER_SUSPENDM) {
|
|
|
|
/* spurious */
|
|
|
|
musb->int_usb &= ~MUSB_INTR_SUSPEND;
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "Spurious SUSPENDM\n");
|
2008-07-24 09:27:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
power &= ~MUSB_POWER_SUSPENDM;
|
|
|
|
musb_writeb(mbase, MUSB_POWER,
|
|
|
|
power | MUSB_POWER_RESUME);
|
|
|
|
|
|
|
|
musb->port1_status |=
|
|
|
|
(USB_PORT_STAT_C_SUSPEND << 16)
|
|
|
|
| MUSB_PORT_STAT_RESUME;
|
2014-01-15 13:09:49 +00:00
|
|
|
musb->rh_timer = jiffies
|
|
|
|
+ msecs_to_jiffies(20);
|
2013-12-18 19:23:46 +00:00
|
|
|
schedule_delayed_work(
|
2014-02-05 14:34:18 +00:00
|
|
|
&musb->finish_resume_work,
|
|
|
|
msecs_to_jiffies(20));
|
2008-07-24 09:27:36 +00:00
|
|
|
|
2009-03-31 19:30:04 +00:00
|
|
|
musb->xceiv->state = OTG_STATE_A_HOST;
|
2008-07-24 09:27:36 +00:00
|
|
|
musb->is_active = 1;
|
2013-04-10 19:55:42 +00:00
|
|
|
musb_host_resume_root_hub(musb);
|
2008-07-24 09:27:36 +00:00
|
|
|
break;
|
|
|
|
case OTG_STATE_B_WAIT_ACON:
|
2009-03-31 19:30:04 +00:00
|
|
|
musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
|
2008-07-24 09:27:36 +00:00
|
|
|
musb->is_active = 1;
|
|
|
|
MUSB_DEV_MODE(musb);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARNING("bogus %s RESUME (%s)\n",
|
|
|
|
"host",
|
2013-03-07 08:39:57 +00:00
|
|
|
usb_otg_state_string(musb->xceiv->state));
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-03-31 19:30:04 +00:00
|
|
|
switch (musb->xceiv->state) {
|
2008-07-24 09:27:36 +00:00
|
|
|
case OTG_STATE_A_SUSPEND:
|
|
|
|
/* possibly DISCONNECT is upcoming */
|
2009-03-31 19:30:04 +00:00
|
|
|
musb->xceiv->state = OTG_STATE_A_HOST;
|
2013-04-10 19:55:42 +00:00
|
|
|
musb_host_resume_root_hub(musb);
|
2008-07-24 09:27:36 +00:00
|
|
|
break;
|
|
|
|
case OTG_STATE_B_WAIT_ACON:
|
|
|
|
case OTG_STATE_B_PERIPHERAL:
|
|
|
|
/* disconnect while suspended? we may
|
|
|
|
* not get a disconnect irq...
|
|
|
|
*/
|
|
|
|
if ((devctl & MUSB_DEVCTL_VBUS)
|
|
|
|
!= (3 << MUSB_DEVCTL_VBUS_SHIFT)
|
|
|
|
) {
|
|
|
|
musb->int_usb |= MUSB_INTR_DISCONNECT;
|
|
|
|
musb->int_usb &= ~MUSB_INTR_SUSPEND;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
musb_g_resume(musb);
|
|
|
|
break;
|
|
|
|
case OTG_STATE_B_IDLE:
|
|
|
|
musb->int_usb &= ~MUSB_INTR_SUSPEND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARNING("bogus %s RESUME (%s)\n",
|
|
|
|
"peripheral",
|
2013-03-07 08:39:57 +00:00
|
|
|
usb_otg_state_string(musb->xceiv->state));
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* see manual for the order of the tests */
|
|
|
|
if (int_usb & MUSB_INTR_SESSREQ) {
|
2010-03-12 08:27:24 +00:00
|
|
|
void __iomem *mbase = musb->mregs;
|
|
|
|
|
2010-10-29 09:23:27 +00:00
|
|
|
if ((devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS
|
|
|
|
&& (devctl & MUSB_DEVCTL_BDEVICE)) {
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "SessReq while on B state\n");
|
2010-09-24 10:44:13 +00:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "SESSION_REQUEST (%s)\n",
|
2013-03-07 08:39:57 +00:00
|
|
|
usb_otg_state_string(musb->xceiv->state));
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
/* IRQ arrives from ID pin sense or (later, if VBUS power
|
|
|
|
* is removed) SRP. responses are time critical:
|
|
|
|
* - turn on VBUS (with silicon-specific mechanism)
|
|
|
|
* - go through A_WAIT_VRISE
|
|
|
|
* - ... to A_WAIT_BCON.
|
|
|
|
* a_wait_vrise_tmout triggers VBUS_ERROR transitions
|
|
|
|
*/
|
|
|
|
musb_writeb(mbase, MUSB_DEVCTL, MUSB_DEVCTL_SESSION);
|
|
|
|
musb->ep0_stage = MUSB_EP0_START;
|
2009-03-31 19:30:04 +00:00
|
|
|
musb->xceiv->state = OTG_STATE_A_IDLE;
|
2008-07-24 09:27:36 +00:00
|
|
|
MUSB_HST_MODE(musb);
|
2010-12-01 11:22:05 +00:00
|
|
|
musb_platform_set_vbus(musb, 1);
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
handled = IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (int_usb & MUSB_INTR_VBUSERROR) {
|
|
|
|
int ignore = 0;
|
|
|
|
|
|
|
|
/* During connection as an A-Device, we may see a short
|
|
|
|
* current spikes causing voltage drop, because of cable
|
|
|
|
* and peripheral capacitance combined with vbus draw.
|
|
|
|
* (So: less common with truly self-powered devices, where
|
|
|
|
* vbus doesn't act like a power supply.)
|
|
|
|
*
|
|
|
|
* Such spikes are short; usually less than ~500 usec, max
|
|
|
|
* of ~2 msec. That is, they're not sustained overcurrent
|
|
|
|
* errors, though they're reported using VBUSERROR irqs.
|
|
|
|
*
|
|
|
|
* Workarounds: (a) hardware: use self powered devices.
|
|
|
|
* (b) software: ignore non-repeated VBUS errors.
|
|
|
|
*
|
|
|
|
* REVISIT: do delays from lots of DEBUG_KERNEL checks
|
|
|
|
* make trouble here, keeping VBUS < 4.4V ?
|
|
|
|
*/
|
2009-03-31 19:30:04 +00:00
|
|
|
switch (musb->xceiv->state) {
|
2008-07-24 09:27:36 +00:00
|
|
|
case OTG_STATE_A_HOST:
|
|
|
|
/* recovery is dicey once we've gotten past the
|
|
|
|
* initial stages of enumeration, but if VBUS
|
|
|
|
* stayed ok at the other end of the link, and
|
|
|
|
* another reset is due (at least for high speed,
|
|
|
|
* to redo the chirp etc), it might work OK...
|
|
|
|
*/
|
|
|
|
case OTG_STATE_A_WAIT_BCON:
|
|
|
|
case OTG_STATE_A_WAIT_VRISE:
|
|
|
|
if (musb->vbuserr_retry) {
|
2010-03-12 08:27:24 +00:00
|
|
|
void __iomem *mbase = musb->mregs;
|
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
musb->vbuserr_retry--;
|
|
|
|
ignore = 1;
|
|
|
|
devctl |= MUSB_DEVCTL_SESSION;
|
|
|
|
musb_writeb(mbase, MUSB_DEVCTL, devctl);
|
|
|
|
} else {
|
|
|
|
musb->port1_status |=
|
2010-03-04 22:05:08 +00:00
|
|
|
USB_PORT_STAT_OVERCURRENT
|
|
|
|
| (USB_PORT_STAT_C_OVERCURRENT << 16);
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-03-10 00:49:28 +00:00
|
|
|
dev_printk(ignore ? KERN_DEBUG : KERN_ERR, musb->controller,
|
|
|
|
"VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n",
|
2013-03-07 08:39:57 +00:00
|
|
|
usb_otg_state_string(musb->xceiv->state),
|
2008-07-24 09:27:36 +00:00
|
|
|
devctl,
|
|
|
|
({ char *s;
|
|
|
|
switch (devctl & MUSB_DEVCTL_VBUS) {
|
|
|
|
case 0 << MUSB_DEVCTL_VBUS_SHIFT:
|
|
|
|
s = "<SessEnd"; break;
|
|
|
|
case 1 << MUSB_DEVCTL_VBUS_SHIFT:
|
|
|
|
s = "<AValid"; break;
|
|
|
|
case 2 << MUSB_DEVCTL_VBUS_SHIFT:
|
|
|
|
s = "<VBusValid"; break;
|
|
|
|
/* case 3 << MUSB_DEVCTL_VBUS_SHIFT: */
|
|
|
|
default:
|
|
|
|
s = "VALID"; break;
|
2013-10-08 23:01:37 +00:00
|
|
|
} s; }),
|
2008-07-24 09:27:36 +00:00
|
|
|
VBUSERR_RETRY_COUNT - musb->vbuserr_retry,
|
|
|
|
musb->port1_status);
|
|
|
|
|
|
|
|
/* go through A_WAIT_VFALL then start a new session */
|
|
|
|
if (!ignore)
|
2010-12-01 11:22:05 +00:00
|
|
|
musb_platform_set_vbus(musb, 0);
|
2008-07-24 09:27:36 +00:00
|
|
|
handled = IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2009-12-28 11:40:40 +00:00
|
|
|
if (int_usb & MUSB_INTR_SUSPEND) {
|
2012-10-30 18:52:23 +00:00
|
|
|
dev_dbg(musb->controller, "SUSPEND (%s) devctl %02x\n",
|
2013-03-07 08:39:57 +00:00
|
|
|
usb_otg_state_string(musb->xceiv->state), devctl);
|
2009-12-28 11:40:40 +00:00
|
|
|
handled = IRQ_HANDLED;
|
|
|
|
|
|
|
|
switch (musb->xceiv->state) {
|
|
|
|
case OTG_STATE_A_PERIPHERAL:
|
|
|
|
/* We also come here if the cable is removed, since
|
|
|
|
* this silicon doesn't report ID-no-longer-grounded.
|
|
|
|
*
|
|
|
|
* We depend on T(a_wait_bcon) to shut us down, and
|
|
|
|
* hope users don't do anything dicey during this
|
|
|
|
* undesired detour through A_WAIT_BCON.
|
|
|
|
*/
|
|
|
|
musb_hnp_stop(musb);
|
2013-04-10 19:55:42 +00:00
|
|
|
musb_host_resume_root_hub(musb);
|
2009-12-28 11:40:40 +00:00
|
|
|
musb_root_disconnect(musb);
|
|
|
|
musb_platform_try_idle(musb, jiffies
|
|
|
|
+ msecs_to_jiffies(musb->a_wait_bcon
|
|
|
|
? : OTG_TIME_A_WAIT_BCON));
|
|
|
|
|
|
|
|
break;
|
|
|
|
case OTG_STATE_B_IDLE:
|
|
|
|
if (!musb->is_active)
|
|
|
|
break;
|
|
|
|
case OTG_STATE_B_PERIPHERAL:
|
|
|
|
musb_g_suspend(musb);
|
2014-02-25 16:58:43 +00:00
|
|
|
musb->is_active = musb->g.b_hnp_enable;
|
2009-12-28 11:40:40 +00:00
|
|
|
if (musb->is_active) {
|
|
|
|
musb->xceiv->state = OTG_STATE_B_WAIT_ACON;
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "HNP: Setting timer for b_ase0_brst\n");
|
2009-12-28 11:40:40 +00:00
|
|
|
mod_timer(&musb->otg_timer, jiffies
|
|
|
|
+ msecs_to_jiffies(
|
|
|
|
OTG_TIME_B_ASE0_BRST));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OTG_STATE_A_WAIT_BCON:
|
|
|
|
if (musb->a_wait_bcon != 0)
|
|
|
|
musb_platform_try_idle(musb, jiffies
|
|
|
|
+ msecs_to_jiffies(musb->a_wait_bcon));
|
|
|
|
break;
|
|
|
|
case OTG_STATE_A_HOST:
|
|
|
|
musb->xceiv->state = OTG_STATE_A_SUSPEND;
|
2014-02-25 16:58:43 +00:00
|
|
|
musb->is_active = musb->hcd->self.b_hnp_enable;
|
2009-12-28 11:40:40 +00:00
|
|
|
break;
|
|
|
|
case OTG_STATE_B_HOST:
|
|
|
|
/* Transition to B_PERIPHERAL, see 6.8.2.6 p 44 */
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "REVISIT: SUSPEND as B_HOST\n");
|
2009-12-28 11:40:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* "should not happen" */
|
|
|
|
musb->is_active = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
if (int_usb & MUSB_INTR_CONNECT) {
|
2013-04-10 19:55:50 +00:00
|
|
|
struct usb_hcd *hcd = musb->hcd;
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
handled = IRQ_HANDLED;
|
|
|
|
musb->is_active = 1;
|
|
|
|
|
|
|
|
musb->ep0_stage = MUSB_EP0_START;
|
|
|
|
|
|
|
|
/* flush endpoints when transitioning from Device Mode */
|
|
|
|
if (is_peripheral_active(musb)) {
|
|
|
|
/* REVISIT HNP; just force disconnect */
|
|
|
|
}
|
2012-10-30 18:52:26 +00:00
|
|
|
musb->intrtxe = musb->epmask;
|
|
|
|
musb_writew(musb->mregs, MUSB_INTRTXE, musb->intrtxe);
|
2012-10-30 18:52:25 +00:00
|
|
|
musb->intrrxe = musb->epmask & 0xfffe;
|
|
|
|
musb_writew(musb->mregs, MUSB_INTRRXE, musb->intrrxe);
|
2010-07-08 08:33:00 +00:00
|
|
|
musb_writeb(musb->mregs, MUSB_INTRUSBE, 0xf7);
|
2008-07-24 09:27:36 +00:00
|
|
|
musb->port1_status &= ~(USB_PORT_STAT_LOW_SPEED
|
|
|
|
|USB_PORT_STAT_HIGH_SPEED
|
|
|
|
|USB_PORT_STAT_ENABLE
|
|
|
|
);
|
|
|
|
musb->port1_status |= USB_PORT_STAT_CONNECTION
|
|
|
|
|(USB_PORT_STAT_C_CONNECTION << 16);
|
|
|
|
|
|
|
|
/* high vs full speed is just a guess until after reset */
|
|
|
|
if (devctl & MUSB_DEVCTL_LSDEV)
|
|
|
|
musb->port1_status |= USB_PORT_STAT_LOW_SPEED;
|
|
|
|
|
|
|
|
/* indicate new connection to OTG machine */
|
2009-03-31 19:30:04 +00:00
|
|
|
switch (musb->xceiv->state) {
|
2008-07-24 09:27:36 +00:00
|
|
|
case OTG_STATE_B_PERIPHERAL:
|
|
|
|
if (int_usb & MUSB_INTR_SUSPEND) {
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "HNP: SUSPEND+CONNECT, now b_host\n");
|
2008-07-24 09:27:36 +00:00
|
|
|
int_usb &= ~MUSB_INTR_SUSPEND;
|
2009-04-02 17:16:11 +00:00
|
|
|
goto b_host;
|
2008-07-24 09:27:36 +00:00
|
|
|
} else
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "CONNECT as b_peripheral???\n");
|
2008-07-24 09:27:36 +00:00
|
|
|
break;
|
|
|
|
case OTG_STATE_B_WAIT_ACON:
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "HNP: CONNECT, now b_host\n");
|
2009-04-02 17:16:11 +00:00
|
|
|
b_host:
|
2009-03-31 19:30:04 +00:00
|
|
|
musb->xceiv->state = OTG_STATE_B_HOST;
|
2013-04-10 19:55:45 +00:00
|
|
|
if (musb->hcd)
|
|
|
|
musb->hcd->self.is_b_host = 1;
|
2009-04-02 17:16:11 +00:00
|
|
|
del_timer(&musb->otg_timer);
|
2008-07-24 09:27:36 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if ((devctl & MUSB_DEVCTL_VBUS)
|
|
|
|
== (3 << MUSB_DEVCTL_VBUS_SHIFT)) {
|
2009-03-31 19:30:04 +00:00
|
|
|
musb->xceiv->state = OTG_STATE_A_HOST;
|
2013-04-10 19:55:42 +00:00
|
|
|
if (hcd)
|
|
|
|
hcd->self.is_b_host = 0;
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-04-02 17:16:11 +00:00
|
|
|
|
2013-04-10 19:55:42 +00:00
|
|
|
musb_host_poke_root_hub(musb);
|
2009-04-02 17:16:11 +00:00
|
|
|
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n",
|
2013-03-07 08:39:57 +00:00
|
|
|
usb_otg_state_string(musb->xceiv->state), devctl);
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
|
2013-04-29 09:02:24 +00:00
|
|
|
if (int_usb & MUSB_INTR_DISCONNECT) {
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n",
|
2013-03-07 08:39:57 +00:00
|
|
|
usb_otg_state_string(musb->xceiv->state),
|
2009-12-28 11:40:40 +00:00
|
|
|
MUSB_MODE(musb), devctl);
|
|
|
|
handled = IRQ_HANDLED;
|
|
|
|
|
|
|
|
switch (musb->xceiv->state) {
|
|
|
|
case OTG_STATE_A_HOST:
|
|
|
|
case OTG_STATE_A_SUSPEND:
|
2013-04-10 19:55:42 +00:00
|
|
|
musb_host_resume_root_hub(musb);
|
2009-12-28 11:40:40 +00:00
|
|
|
musb_root_disconnect(musb);
|
2011-11-24 13:46:26 +00:00
|
|
|
if (musb->a_wait_bcon != 0)
|
2009-12-28 11:40:40 +00:00
|
|
|
musb_platform_try_idle(musb, jiffies
|
|
|
|
+ msecs_to_jiffies(musb->a_wait_bcon));
|
|
|
|
break;
|
|
|
|
case OTG_STATE_B_HOST:
|
|
|
|
/* REVISIT this behaves for "real disconnect"
|
|
|
|
* cases; make sure the other transitions from
|
|
|
|
* from B_HOST act right too. The B_HOST code
|
|
|
|
* in hnp_stop() is currently not used...
|
|
|
|
*/
|
|
|
|
musb_root_disconnect(musb);
|
2013-04-10 19:55:45 +00:00
|
|
|
if (musb->hcd)
|
|
|
|
musb->hcd->self.is_b_host = 0;
|
2009-12-28 11:40:40 +00:00
|
|
|
musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
|
|
|
|
MUSB_DEV_MODE(musb);
|
|
|
|
musb_g_disconnect(musb);
|
|
|
|
break;
|
|
|
|
case OTG_STATE_A_PERIPHERAL:
|
|
|
|
musb_hnp_stop(musb);
|
|
|
|
musb_root_disconnect(musb);
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case OTG_STATE_B_WAIT_ACON:
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case OTG_STATE_B_PERIPHERAL:
|
|
|
|
case OTG_STATE_B_IDLE:
|
|
|
|
musb_g_disconnect(musb);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARNING("unhandled DISCONNECT transition (%s)\n",
|
2013-03-07 08:39:57 +00:00
|
|
|
usb_otg_state_string(musb->xceiv->state));
|
2009-12-28 11:40:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
/* mentor saves a bit: bus reset and babble share the same irq.
|
|
|
|
* only host sees babble; only peripheral sees bus reset.
|
|
|
|
*/
|
|
|
|
if (int_usb & MUSB_INTR_RESET) {
|
2009-12-28 11:40:40 +00:00
|
|
|
handled = IRQ_HANDLED;
|
2011-11-24 13:46:27 +00:00
|
|
|
if ((devctl & MUSB_DEVCTL_HM) != 0) {
|
2008-07-24 09:27:36 +00:00
|
|
|
/*
|
|
|
|
* Looks like non-HS BABBLE can be ignored, but
|
|
|
|
* HS BABBLE is an error condition. For HS the solution
|
|
|
|
* is to avoid babble in the first place and fix what
|
|
|
|
* caused BABBLE. When HS BABBLE happens we can only
|
|
|
|
* stop the session.
|
|
|
|
*/
|
|
|
|
if (devctl & (MUSB_DEVCTL_FSDEV | MUSB_DEVCTL_LSDEV))
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "BABBLE devctl: %02x\n", devctl);
|
2008-07-24 09:27:36 +00:00
|
|
|
else {
|
|
|
|
ERR("Stopping host session -- babble\n");
|
2009-12-28 11:40:40 +00:00
|
|
|
musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
2011-11-24 13:46:27 +00:00
|
|
|
} else {
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "BUS RESET as %s\n",
|
2013-03-07 08:39:57 +00:00
|
|
|
usb_otg_state_string(musb->xceiv->state));
|
2009-03-31 19:30:04 +00:00
|
|
|
switch (musb->xceiv->state) {
|
2008-07-24 09:27:36 +00:00
|
|
|
case OTG_STATE_A_SUSPEND:
|
|
|
|
musb_g_reset(musb);
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */
|
2009-03-31 19:32:12 +00:00
|
|
|
/* never use invalid T(a_wait_bcon) */
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "HNP: in %s, %d msec timeout\n",
|
2013-03-07 08:39:57 +00:00
|
|
|
usb_otg_state_string(musb->xceiv->state),
|
2011-05-05 10:11:21 +00:00
|
|
|
TA_WAIT_BCON(musb));
|
2009-03-31 19:32:12 +00:00
|
|
|
mod_timer(&musb->otg_timer, jiffies
|
|
|
|
+ msecs_to_jiffies(TA_WAIT_BCON(musb)));
|
2008-07-24 09:27:36 +00:00
|
|
|
break;
|
|
|
|
case OTG_STATE_A_PERIPHERAL:
|
2009-04-02 17:16:11 +00:00
|
|
|
del_timer(&musb->otg_timer);
|
|
|
|
musb_g_reset(musb);
|
2008-07-24 09:27:36 +00:00
|
|
|
break;
|
|
|
|
case OTG_STATE_B_WAIT_ACON:
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "HNP: RESET (%s), to b_peripheral\n",
|
2013-03-07 08:39:57 +00:00
|
|
|
usb_otg_state_string(musb->xceiv->state));
|
2009-03-31 19:30:04 +00:00
|
|
|
musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
|
2008-07-24 09:27:36 +00:00
|
|
|
musb_g_reset(musb);
|
|
|
|
break;
|
|
|
|
case OTG_STATE_B_IDLE:
|
2009-03-31 19:30:04 +00:00
|
|
|
musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
|
2008-07-24 09:27:36 +00:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
case OTG_STATE_B_PERIPHERAL:
|
|
|
|
musb_g_reset(musb);
|
|
|
|
break;
|
|
|
|
default:
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "Unhandled BUS RESET as %s\n",
|
2013-03-07 08:39:57 +00:00
|
|
|
usb_otg_state_string(musb->xceiv->state));
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* REVISIT ... this would be for multiplexing periodic endpoints, or
|
|
|
|
* supporting transfer phasing to prevent exceeding ISO bandwidth
|
|
|
|
* limits of a given frame or microframe.
|
|
|
|
*
|
|
|
|
* It's not needed for peripheral side, which dedicates endpoints;
|
|
|
|
* though it _might_ use SOF irqs for other purposes.
|
|
|
|
*
|
|
|
|
* And it's not currently needed for host side, which also dedicates
|
|
|
|
* endpoints, relies on TX/RX interval registers, and isn't claimed
|
|
|
|
* to support ISO transfers yet.
|
|
|
|
*/
|
|
|
|
if (int_usb & MUSB_INTR_SOF) {
|
|
|
|
void __iomem *mbase = musb->mregs;
|
|
|
|
struct musb_hw_ep *ep;
|
|
|
|
u8 epnum;
|
|
|
|
u16 frame;
|
|
|
|
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "START_OF_FRAME\n");
|
2008-07-24 09:27:36 +00:00
|
|
|
handled = IRQ_HANDLED;
|
|
|
|
|
|
|
|
/* start any periodic Tx transfers waiting for current frame */
|
|
|
|
frame = musb_readw(mbase, MUSB_FRAME);
|
|
|
|
ep = musb->endpoints;
|
|
|
|
for (epnum = 1; (epnum < musb->nr_endpoints)
|
|
|
|
&& (musb->epmask >= (1 << epnum));
|
|
|
|
epnum++, ep++) {
|
|
|
|
/*
|
|
|
|
* FIXME handle framecounter wraps (12 bits)
|
|
|
|
* eliminate duplicated StartUrb logic
|
|
|
|
*/
|
|
|
|
if (ep->dwWaitFrame >= frame) {
|
|
|
|
ep->dwWaitFrame = 0;
|
|
|
|
pr_debug("SOF --> periodic TX%s on %d\n",
|
|
|
|
ep->tx_channel ? " DMA" : "",
|
|
|
|
epnum);
|
|
|
|
if (!ep->tx_channel)
|
|
|
|
musb_h_tx_start(musb, epnum);
|
|
|
|
else
|
|
|
|
cppi_hostdma_start(musb, epnum);
|
|
|
|
}
|
|
|
|
} /* end of for loop */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-12-28 11:40:40 +00:00
|
|
|
schedule_work(&musb->irq_work);
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
return handled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static void musb_generic_disable(struct musb *musb)
|
|
|
|
{
|
|
|
|
void __iomem *mbase = musb->mregs;
|
|
|
|
u16 temp;
|
|
|
|
|
|
|
|
/* disable interrupts */
|
|
|
|
musb_writeb(mbase, MUSB_INTRUSBE, 0);
|
2012-10-30 18:52:26 +00:00
|
|
|
musb->intrtxe = 0;
|
2008-07-24 09:27:36 +00:00
|
|
|
musb_writew(mbase, MUSB_INTRTXE, 0);
|
2012-10-30 18:52:25 +00:00
|
|
|
musb->intrrxe = 0;
|
2008-07-24 09:27:36 +00:00
|
|
|
musb_writew(mbase, MUSB_INTRRXE, 0);
|
|
|
|
|
|
|
|
/* off */
|
|
|
|
musb_writeb(mbase, MUSB_DEVCTL, 0);
|
|
|
|
|
|
|
|
/* flush pending interrupts */
|
|
|
|
temp = musb_readb(mbase, MUSB_INTRUSB);
|
|
|
|
temp = musb_readw(mbase, MUSB_INTRTX);
|
|
|
|
temp = musb_readw(mbase, MUSB_INTRRX);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-10-11 08:38:13 +00:00
|
|
|
/*
|
|
|
|
* Program the HDRC to start (enable interrupts, dma, etc.).
|
|
|
|
*/
|
|
|
|
void musb_start(struct musb *musb)
|
|
|
|
{
|
|
|
|
void __iomem *regs = musb->mregs;
|
|
|
|
u8 devctl = musb_readb(regs, MUSB_DEVCTL);
|
|
|
|
|
|
|
|
dev_dbg(musb->controller, "<== devctl %02x\n", devctl);
|
|
|
|
|
|
|
|
/* Set INT enable registers, enable interrupts */
|
|
|
|
musb->intrtxe = musb->epmask;
|
|
|
|
musb_writew(regs, MUSB_INTRTXE, musb->intrtxe);
|
|
|
|
musb->intrrxe = musb->epmask & 0xfffe;
|
|
|
|
musb_writew(regs, MUSB_INTRRXE, musb->intrrxe);
|
|
|
|
musb_writeb(regs, MUSB_INTRUSBE, 0xf7);
|
|
|
|
|
|
|
|
musb_writeb(regs, MUSB_TESTMODE, 0);
|
|
|
|
|
|
|
|
/* put into basic highspeed mode and start session */
|
|
|
|
musb_writeb(regs, MUSB_POWER, MUSB_POWER_ISOUPDATE
|
|
|
|
| MUSB_POWER_HSENAB
|
|
|
|
/* ENSUSPEND wedges tusb */
|
|
|
|
/* | MUSB_POWER_ENSUSPEND */
|
|
|
|
);
|
|
|
|
|
|
|
|
musb->is_active = 0;
|
|
|
|
devctl = musb_readb(regs, MUSB_DEVCTL);
|
|
|
|
devctl &= ~MUSB_DEVCTL_SESSION;
|
|
|
|
|
|
|
|
/* session started after:
|
|
|
|
* (a) ID-grounded irq, host mode;
|
|
|
|
* (b) vbus present/connect IRQ, peripheral mode;
|
|
|
|
* (c) peripheral initiates, using SRP
|
|
|
|
*/
|
|
|
|
if (musb->port_mode != MUSB_PORT_MODE_HOST &&
|
|
|
|
(devctl & MUSB_DEVCTL_VBUS) == MUSB_DEVCTL_VBUS) {
|
|
|
|
musb->is_active = 1;
|
|
|
|
} else {
|
|
|
|
devctl |= MUSB_DEVCTL_SESSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
musb_platform_enable(musb);
|
|
|
|
musb_writeb(regs, MUSB_DEVCTL, devctl);
|
|
|
|
}
|
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
/*
|
|
|
|
* Make the HDRC stop (disable interrupts, etc.);
|
|
|
|
* reversible by musb_start
|
|
|
|
* called on gadget driver unregister
|
|
|
|
* with controller locked, irqs blocked
|
|
|
|
* acts as a NOP unless some role activated the hardware
|
|
|
|
*/
|
|
|
|
void musb_stop(struct musb *musb)
|
|
|
|
{
|
|
|
|
/* stop IRQs, timers, ... */
|
|
|
|
musb_platform_disable(musb);
|
|
|
|
musb_generic_disable(musb);
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "HDRC disabled\n");
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
/* FIXME
|
|
|
|
* - mark host and/or peripheral drivers unusable/inactive
|
|
|
|
* - disable DMA (and enable it in HdrcStart)
|
|
|
|
* - make sure we can musb_start() after musb_stop(); with
|
|
|
|
* OTG mode, gadget driver module rmmod/modprobe cycles that
|
|
|
|
* - ...
|
|
|
|
*/
|
|
|
|
musb_platform_try_idle(musb, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void musb_shutdown(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct musb *musb = dev_to_musb(&pdev->dev);
|
|
|
|
unsigned long flags;
|
|
|
|
|
2011-03-22 10:32:12 +00:00
|
|
|
pm_runtime_get_sync(musb->controller);
|
2012-01-12 13:22:45 +00:00
|
|
|
|
2013-04-10 19:55:47 +00:00
|
|
|
musb_host_cleanup(musb);
|
2012-01-12 13:22:45 +00:00
|
|
|
musb_gadget_cleanup(musb);
|
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
spin_lock_irqsave(&musb->lock, flags);
|
|
|
|
musb_platform_disable(musb);
|
|
|
|
musb_generic_disable(musb);
|
|
|
|
spin_unlock_irqrestore(&musb->lock, flags);
|
|
|
|
|
2010-10-10 18:52:22 +00:00
|
|
|
musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
|
|
|
|
musb_platform_exit(musb);
|
|
|
|
|
2011-03-22 10:32:12 +00:00
|
|
|
pm_runtime_put(musb->controller);
|
2008-07-24 09:27:36 +00:00
|
|
|
/* FIXME power down */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The silicon either has hard-wired endpoint configurations, or else
|
|
|
|
* "dynamic fifo" sizing. The driver has support for both, though at this
|
2008-09-11 08:53:23 +00:00
|
|
|
* writing only the dynamic sizing is very well tested. Since we switched
|
|
|
|
* away from compile-time hardware parameters, we can no longer rely on
|
|
|
|
* dead code elimination to leave only the relevant one in the object file.
|
2008-07-24 09:27:36 +00:00
|
|
|
*
|
|
|
|
* We don't currently use dynamic fifo setup capability to do anything
|
|
|
|
* more than selecting one of a bunch of predefined configurations.
|
|
|
|
*/
|
2011-06-29 09:45:03 +00:00
|
|
|
#if defined(CONFIG_USB_MUSB_TUSB6010) \
|
|
|
|
|| defined(CONFIG_USB_MUSB_TUSB6010_MODULE) \
|
|
|
|
|| defined(CONFIG_USB_MUSB_OMAP2PLUS) \
|
|
|
|
|| defined(CONFIG_USB_MUSB_OMAP2PLUS_MODULE) \
|
|
|
|
|| defined(CONFIG_USB_MUSB_AM35X) \
|
2012-03-12 14:00:22 +00:00
|
|
|
|| defined(CONFIG_USB_MUSB_AM35X_MODULE) \
|
|
|
|
|| defined(CONFIG_USB_MUSB_DSPS) \
|
|
|
|
|| defined(CONFIG_USB_MUSB_DSPS_MODULE)
|
2012-11-19 18:24:34 +00:00
|
|
|
static ushort fifo_mode = 4;
|
2011-06-29 09:45:03 +00:00
|
|
|
#elif defined(CONFIG_USB_MUSB_UX500) \
|
|
|
|
|| defined(CONFIG_USB_MUSB_UX500_MODULE)
|
2012-11-19 18:24:34 +00:00
|
|
|
static ushort fifo_mode = 5;
|
2008-07-24 09:27:36 +00:00
|
|
|
#else
|
2012-11-19 18:24:34 +00:00
|
|
|
static ushort fifo_mode = 2;
|
2008-07-24 09:27:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* "modprobe ... fifo_mode=1" etc */
|
|
|
|
module_param(fifo_mode, ushort, 0);
|
|
|
|
MODULE_PARM_DESC(fifo_mode, "initial endpoint configuration");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tables defining fifo_mode values. define more if you like.
|
|
|
|
* for host side, make sure both halves of ep1 are set up.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* mode 0 - fits in 2KB */
|
2012-11-19 18:24:34 +00:00
|
|
|
static struct musb_fifo_cfg mode_0_cfg[] = {
|
2008-07-24 09:27:36 +00:00
|
|
|
{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
|
|
|
|
{ .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* mode 1 - fits in 4KB */
|
2012-11-19 18:24:34 +00:00
|
|
|
static struct musb_fifo_cfg mode_1_cfg[] = {
|
2008-07-24 09:27:36 +00:00
|
|
|
{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, },
|
|
|
|
{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, },
|
|
|
|
{ .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, .mode = BUF_DOUBLE, },
|
|
|
|
{ .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
|
|
|
|
{ .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* mode 2 - fits in 4KB */
|
2012-11-19 18:24:34 +00:00
|
|
|
static struct musb_fifo_cfg mode_2_cfg[] = {
|
2008-07-24 09:27:36 +00:00
|
|
|
{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
|
|
|
|
{ .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* mode 3 - fits in 4KB */
|
2012-11-19 18:24:34 +00:00
|
|
|
static struct musb_fifo_cfg mode_3_cfg[] = {
|
2008-07-24 09:27:36 +00:00
|
|
|
{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, },
|
|
|
|
{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, },
|
|
|
|
{ .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 3, .style = FIFO_RXTX, .maxpacket = 256, },
|
|
|
|
{ .hw_ep_num = 4, .style = FIFO_RXTX, .maxpacket = 256, },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* mode 4 - fits in 16KB */
|
2012-11-19 18:24:34 +00:00
|
|
|
static struct musb_fifo_cfg mode_4_cfg[] = {
|
2008-07-24 09:27:36 +00:00
|
|
|
{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 3, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 3, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 4, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 4, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 5, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 5, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 6, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 6, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 7, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 7, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 8, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 8, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 9, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 9, .style = FIFO_RX, .maxpacket = 512, },
|
2009-04-03 23:16:17 +00:00
|
|
|
{ .hw_ep_num = 10, .style = FIFO_TX, .maxpacket = 256, },
|
|
|
|
{ .hw_ep_num = 10, .style = FIFO_RX, .maxpacket = 64, },
|
|
|
|
{ .hw_ep_num = 11, .style = FIFO_TX, .maxpacket = 256, },
|
|
|
|
{ .hw_ep_num = 11, .style = FIFO_RX, .maxpacket = 64, },
|
|
|
|
{ .hw_ep_num = 12, .style = FIFO_TX, .maxpacket = 256, },
|
|
|
|
{ .hw_ep_num = 12, .style = FIFO_RX, .maxpacket = 64, },
|
|
|
|
{ .hw_ep_num = 13, .style = FIFO_RXTX, .maxpacket = 4096, },
|
2008-07-24 09:27:36 +00:00
|
|
|
{ .hw_ep_num = 14, .style = FIFO_RXTX, .maxpacket = 1024, },
|
|
|
|
{ .hw_ep_num = 15, .style = FIFO_RXTX, .maxpacket = 1024, },
|
|
|
|
};
|
|
|
|
|
2009-12-28 11:40:34 +00:00
|
|
|
/* mode 5 - fits in 8KB */
|
2012-11-19 18:24:34 +00:00
|
|
|
static struct musb_fifo_cfg mode_5_cfg[] = {
|
2009-12-28 11:40:34 +00:00
|
|
|
{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 3, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 3, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 4, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 4, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 5, .style = FIFO_TX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 5, .style = FIFO_RX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 6, .style = FIFO_TX, .maxpacket = 32, },
|
|
|
|
{ .hw_ep_num = 6, .style = FIFO_RX, .maxpacket = 32, },
|
|
|
|
{ .hw_ep_num = 7, .style = FIFO_TX, .maxpacket = 32, },
|
|
|
|
{ .hw_ep_num = 7, .style = FIFO_RX, .maxpacket = 32, },
|
|
|
|
{ .hw_ep_num = 8, .style = FIFO_TX, .maxpacket = 32, },
|
|
|
|
{ .hw_ep_num = 8, .style = FIFO_RX, .maxpacket = 32, },
|
|
|
|
{ .hw_ep_num = 9, .style = FIFO_TX, .maxpacket = 32, },
|
|
|
|
{ .hw_ep_num = 9, .style = FIFO_RX, .maxpacket = 32, },
|
|
|
|
{ .hw_ep_num = 10, .style = FIFO_TX, .maxpacket = 32, },
|
|
|
|
{ .hw_ep_num = 10, .style = FIFO_RX, .maxpacket = 32, },
|
|
|
|
{ .hw_ep_num = 11, .style = FIFO_TX, .maxpacket = 32, },
|
|
|
|
{ .hw_ep_num = 11, .style = FIFO_RX, .maxpacket = 32, },
|
|
|
|
{ .hw_ep_num = 12, .style = FIFO_TX, .maxpacket = 32, },
|
|
|
|
{ .hw_ep_num = 12, .style = FIFO_RX, .maxpacket = 32, },
|
|
|
|
{ .hw_ep_num = 13, .style = FIFO_RXTX, .maxpacket = 512, },
|
|
|
|
{ .hw_ep_num = 14, .style = FIFO_RXTX, .maxpacket = 1024, },
|
|
|
|
{ .hw_ep_num = 15, .style = FIFO_RXTX, .maxpacket = 1024, },
|
|
|
|
};
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* configure a fifo; for non-shared endpoints, this may be called
|
|
|
|
* once for a tx fifo and once for an rx fifo.
|
|
|
|
*
|
|
|
|
* returns negative errno or offset for next fifo.
|
|
|
|
*/
|
2012-11-19 18:21:48 +00:00
|
|
|
static int
|
2008-07-24 09:27:36 +00:00
|
|
|
fifo_setup(struct musb *musb, struct musb_hw_ep *hw_ep,
|
2010-03-12 08:29:06 +00:00
|
|
|
const struct musb_fifo_cfg *cfg, u16 offset)
|
2008-07-24 09:27:36 +00:00
|
|
|
{
|
|
|
|
void __iomem *mbase = musb->mregs;
|
|
|
|
int size = 0;
|
|
|
|
u16 maxpacket = cfg->maxpacket;
|
|
|
|
u16 c_off = offset >> 3;
|
|
|
|
u8 c_size;
|
|
|
|
|
|
|
|
/* expect hw_ep has already been zero-initialized */
|
|
|
|
|
|
|
|
size = ffs(max(maxpacket, (u16) 8)) - 1;
|
|
|
|
maxpacket = 1 << size;
|
|
|
|
|
|
|
|
c_size = size - 3;
|
|
|
|
if (cfg->mode == BUF_DOUBLE) {
|
2008-08-08 09:40:54 +00:00
|
|
|
if ((offset + (maxpacket << 1)) >
|
|
|
|
(1 << (musb->config->ram_bits + 2)))
|
2008-07-24 09:27:36 +00:00
|
|
|
return -EMSGSIZE;
|
|
|
|
c_size |= MUSB_FIFOSZ_DPB;
|
|
|
|
} else {
|
2008-08-08 09:40:54 +00:00
|
|
|
if ((offset + maxpacket) > (1 << (musb->config->ram_bits + 2)))
|
2008-07-24 09:27:36 +00:00
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* configure the FIFO */
|
|
|
|
musb_writeb(mbase, MUSB_INDEX, hw_ep->epnum);
|
|
|
|
|
|
|
|
/* EP0 reserved endpoint for control, bidirectional;
|
2014-01-02 13:57:47 +00:00
|
|
|
* EP1 reserved for bulk, two unidirectional halves.
|
2008-07-24 09:27:36 +00:00
|
|
|
*/
|
|
|
|
if (hw_ep->epnum == 1)
|
|
|
|
musb->bulk_ep = hw_ep;
|
|
|
|
/* REVISIT error check: be sure ep0 can both rx and tx ... */
|
|
|
|
switch (cfg->style) {
|
|
|
|
case FIFO_TX:
|
2008-12-02 19:33:48 +00:00
|
|
|
musb_write_txfifosz(mbase, c_size);
|
|
|
|
musb_write_txfifoadd(mbase, c_off);
|
2008-07-24 09:27:36 +00:00
|
|
|
hw_ep->tx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
|
|
|
|
hw_ep->max_packet_sz_tx = maxpacket;
|
|
|
|
break;
|
|
|
|
case FIFO_RX:
|
2008-12-02 19:33:48 +00:00
|
|
|
musb_write_rxfifosz(mbase, c_size);
|
|
|
|
musb_write_rxfifoadd(mbase, c_off);
|
2008-07-24 09:27:36 +00:00
|
|
|
hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
|
|
|
|
hw_ep->max_packet_sz_rx = maxpacket;
|
|
|
|
break;
|
|
|
|
case FIFO_RXTX:
|
2008-12-02 19:33:48 +00:00
|
|
|
musb_write_txfifosz(mbase, c_size);
|
|
|
|
musb_write_txfifoadd(mbase, c_off);
|
2008-07-24 09:27:36 +00:00
|
|
|
hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB);
|
|
|
|
hw_ep->max_packet_sz_rx = maxpacket;
|
|
|
|
|
2008-12-02 19:33:48 +00:00
|
|
|
musb_write_rxfifosz(mbase, c_size);
|
|
|
|
musb_write_rxfifoadd(mbase, c_off);
|
2008-07-24 09:27:36 +00:00
|
|
|
hw_ep->tx_double_buffered = hw_ep->rx_double_buffered;
|
|
|
|
hw_ep->max_packet_sz_tx = maxpacket;
|
|
|
|
|
|
|
|
hw_ep->is_shared_fifo = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE rx and tx endpoint irqs aren't managed separately,
|
|
|
|
* which happens to be ok
|
|
|
|
*/
|
|
|
|
musb->epmask |= (1 << hw_ep->epnum);
|
|
|
|
|
|
|
|
return offset + (maxpacket << ((c_size & MUSB_FIFOSZ_DPB) ? 1 : 0));
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:24:34 +00:00
|
|
|
static struct musb_fifo_cfg ep0_cfg = {
|
2008-07-24 09:27:36 +00:00
|
|
|
.style = FIFO_RXTX, .maxpacket = 64,
|
|
|
|
};
|
|
|
|
|
2012-11-19 18:21:48 +00:00
|
|
|
static int ep_config_from_table(struct musb *musb)
|
2008-07-24 09:27:36 +00:00
|
|
|
{
|
2010-03-12 08:29:06 +00:00
|
|
|
const struct musb_fifo_cfg *cfg;
|
2008-07-24 09:27:36 +00:00
|
|
|
unsigned i, n;
|
|
|
|
int offset;
|
|
|
|
struct musb_hw_ep *hw_ep = musb->endpoints;
|
|
|
|
|
2010-03-12 08:29:06 +00:00
|
|
|
if (musb->config->fifo_cfg) {
|
|
|
|
cfg = musb->config->fifo_cfg;
|
|
|
|
n = musb->config->fifo_cfg_size;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
switch (fifo_mode) {
|
|
|
|
default:
|
|
|
|
fifo_mode = 0;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 0:
|
|
|
|
cfg = mode_0_cfg;
|
|
|
|
n = ARRAY_SIZE(mode_0_cfg);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
cfg = mode_1_cfg;
|
|
|
|
n = ARRAY_SIZE(mode_1_cfg);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
cfg = mode_2_cfg;
|
|
|
|
n = ARRAY_SIZE(mode_2_cfg);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
cfg = mode_3_cfg;
|
|
|
|
n = ARRAY_SIZE(mode_3_cfg);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
cfg = mode_4_cfg;
|
|
|
|
n = ARRAY_SIZE(mode_4_cfg);
|
|
|
|
break;
|
2009-12-28 11:40:34 +00:00
|
|
|
case 5:
|
|
|
|
cfg = mode_5_cfg;
|
|
|
|
n = ARRAY_SIZE(mode_5_cfg);
|
|
|
|
break;
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printk(KERN_DEBUG "%s: setup fifo_mode %d\n",
|
|
|
|
musb_driver_name, fifo_mode);
|
|
|
|
|
|
|
|
|
2010-03-12 08:29:06 +00:00
|
|
|
done:
|
2008-07-24 09:27:36 +00:00
|
|
|
offset = fifo_setup(musb, hw_ep, &ep0_cfg, 0);
|
|
|
|
/* assert(offset > 0) */
|
|
|
|
|
|
|
|
/* NOTE: for RTL versions >= 1.400 EPINFO and RAMINFO would
|
2008-08-08 09:40:54 +00:00
|
|
|
* be better than static musb->config->num_eps and DYN_FIFO_SIZE...
|
2008-07-24 09:27:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
u8 epn = cfg->hw_ep_num;
|
|
|
|
|
2008-08-08 09:40:54 +00:00
|
|
|
if (epn >= musb->config->num_eps) {
|
2008-07-24 09:27:36 +00:00
|
|
|
pr_debug("%s: invalid ep %d\n",
|
|
|
|
musb_driver_name, epn);
|
2008-11-24 11:06:50 +00:00
|
|
|
return -EINVAL;
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
offset = fifo_setup(musb, hw_ep + epn, cfg++, offset);
|
|
|
|
if (offset < 0) {
|
|
|
|
pr_debug("%s: mem overrun, ep %d\n",
|
|
|
|
musb_driver_name, epn);
|
2012-08-07 14:26:31 +00:00
|
|
|
return offset;
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
epn++;
|
|
|
|
musb->nr_endpoints = max(epn, musb->nr_endpoints);
|
|
|
|
}
|
|
|
|
|
|
|
|
printk(KERN_DEBUG "%s: %d/%d max ep, %d/%d memory\n",
|
|
|
|
musb_driver_name,
|
2008-08-08 09:40:54 +00:00
|
|
|
n + 1, musb->config->num_eps * 2 - 1,
|
|
|
|
offset, (1 << (musb->config->ram_bits + 2)));
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
if (!musb->bulk_ep) {
|
|
|
|
pr_debug("%s: missing bulk\n", musb_driver_name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ep_config_from_hw - when MUSB_C_DYNFIFO_DEF is false
|
|
|
|
* @param musb the controller
|
|
|
|
*/
|
2012-11-19 18:21:48 +00:00
|
|
|
static int ep_config_from_hw(struct musb *musb)
|
2008-07-24 09:27:36 +00:00
|
|
|
{
|
2008-12-02 19:33:48 +00:00
|
|
|
u8 epnum = 0;
|
2008-07-24 09:27:36 +00:00
|
|
|
struct musb_hw_ep *hw_ep;
|
2012-08-07 11:00:50 +00:00
|
|
|
void __iomem *mbase = musb->mregs;
|
2008-12-02 19:33:48 +00:00
|
|
|
int ret = 0;
|
2008-07-24 09:27:36 +00:00
|
|
|
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "<== static silicon ep config\n");
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
/* FIXME pick up ep0 maxpacket size */
|
|
|
|
|
2008-08-08 09:40:54 +00:00
|
|
|
for (epnum = 1; epnum < musb->config->num_eps; epnum++) {
|
2008-07-24 09:27:36 +00:00
|
|
|
musb_ep_select(mbase, epnum);
|
|
|
|
hw_ep = musb->endpoints + epnum;
|
|
|
|
|
2008-12-02 19:33:48 +00:00
|
|
|
ret = musb_read_fifosize(musb, hw_ep, epnum);
|
|
|
|
if (ret < 0)
|
2008-07-24 09:27:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* FIXME set up hw_ep->{rx,tx}_double_buffered */
|
|
|
|
|
|
|
|
/* pick an RX/TX endpoint for bulk */
|
|
|
|
if (hw_ep->max_packet_sz_tx < 512
|
|
|
|
|| hw_ep->max_packet_sz_rx < 512)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* REVISIT: this algorithm is lazy, we should at least
|
|
|
|
* try to pick a double buffered endpoint.
|
|
|
|
*/
|
|
|
|
if (musb->bulk_ep)
|
|
|
|
continue;
|
|
|
|
musb->bulk_ep = hw_ep;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!musb->bulk_ep) {
|
|
|
|
pr_debug("%s: missing bulk\n", musb_driver_name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum { MUSB_CONTROLLER_MHDRC, MUSB_CONTROLLER_HDRC, };
|
|
|
|
|
|
|
|
/* Initialize MUSB (M)HDRC part of the USB hardware subsystem;
|
|
|
|
* configure endpoints, or take their config from silicon
|
|
|
|
*/
|
2012-11-19 18:21:48 +00:00
|
|
|
static int musb_core_init(u16 musb_type, struct musb *musb)
|
2008-07-24 09:27:36 +00:00
|
|
|
{
|
|
|
|
u8 reg;
|
|
|
|
char *type;
|
2009-12-22 10:49:53 +00:00
|
|
|
char aInfo[90], aRevision[32], aDate[12];
|
2008-07-24 09:27:36 +00:00
|
|
|
void __iomem *mbase = musb->mregs;
|
|
|
|
int status = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* log core options (read using indexed model) */
|
2008-12-02 19:33:48 +00:00
|
|
|
reg = musb_read_configdata(mbase);
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
strcpy(aInfo, (reg & MUSB_CONFIGDATA_UTMIDW) ? "UTMI-16" : "UTMI-8");
|
2009-12-28 11:40:41 +00:00
|
|
|
if (reg & MUSB_CONFIGDATA_DYNFIFO) {
|
2008-07-24 09:27:36 +00:00
|
|
|
strcat(aInfo, ", dyn FIFOs");
|
2009-12-28 11:40:41 +00:00
|
|
|
musb->dyn_fifo = true;
|
|
|
|
}
|
2008-07-24 09:27:36 +00:00
|
|
|
if (reg & MUSB_CONFIGDATA_MPRXE) {
|
|
|
|
strcat(aInfo, ", bulk combine");
|
|
|
|
musb->bulk_combine = true;
|
|
|
|
}
|
|
|
|
if (reg & MUSB_CONFIGDATA_MPTXE) {
|
|
|
|
strcat(aInfo, ", bulk split");
|
|
|
|
musb->bulk_split = true;
|
|
|
|
}
|
|
|
|
if (reg & MUSB_CONFIGDATA_HBRXE) {
|
|
|
|
strcat(aInfo, ", HB-ISO Rx");
|
2009-04-03 23:16:17 +00:00
|
|
|
musb->hb_iso_rx = true;
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
if (reg & MUSB_CONFIGDATA_HBTXE) {
|
|
|
|
strcat(aInfo, ", HB-ISO Tx");
|
2009-04-03 23:16:17 +00:00
|
|
|
musb->hb_iso_tx = true;
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
if (reg & MUSB_CONFIGDATA_SOFTCONE)
|
|
|
|
strcat(aInfo, ", SoftConn");
|
|
|
|
|
|
|
|
printk(KERN_DEBUG "%s: ConfigData=0x%02x (%s)\n",
|
|
|
|
musb_driver_name, reg, aInfo);
|
|
|
|
|
|
|
|
aDate[0] = 0;
|
|
|
|
if (MUSB_CONTROLLER_MHDRC == musb_type) {
|
|
|
|
musb->is_multipoint = 1;
|
|
|
|
type = "M";
|
|
|
|
} else {
|
|
|
|
musb->is_multipoint = 0;
|
|
|
|
type = "";
|
|
|
|
#ifndef CONFIG_USB_OTG_BLACKLIST_HUB
|
|
|
|
printk(KERN_ERR
|
|
|
|
"%s: kernel must blacklist external hubs\n",
|
|
|
|
musb_driver_name);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* log release info */
|
2009-11-16 15:39:21 +00:00
|
|
|
musb->hwvers = musb_read_hwvers(mbase);
|
|
|
|
snprintf(aRevision, 32, "%d.%d%s", MUSB_HWVERS_MAJOR(musb->hwvers),
|
|
|
|
MUSB_HWVERS_MINOR(musb->hwvers),
|
|
|
|
(musb->hwvers & MUSB_HWVERS_RC) ? "RC" : "");
|
2008-07-24 09:27:36 +00:00
|
|
|
printk(KERN_DEBUG "%s: %sHDRC RTL version %s %s\n",
|
|
|
|
musb_driver_name, type, aRevision, aDate);
|
|
|
|
|
|
|
|
/* configure ep0 */
|
2008-12-02 19:33:48 +00:00
|
|
|
musb_configure_ep0(musb);
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
/* discover endpoint configuration */
|
|
|
|
musb->nr_endpoints = 1;
|
|
|
|
musb->epmask = 1;
|
|
|
|
|
2010-01-21 13:33:54 +00:00
|
|
|
if (musb->dyn_fifo)
|
|
|
|
status = ep_config_from_table(musb);
|
|
|
|
else
|
|
|
|
status = ep_config_from_hw(musb);
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
/* finish init, and print endpoint config */
|
|
|
|
for (i = 0; i < musb->nr_endpoints; i++) {
|
|
|
|
struct musb_hw_ep *hw_ep = musb->endpoints + i;
|
|
|
|
|
|
|
|
hw_ep->fifo = MUSB_FIFO_OFFSET(i) + mbase;
|
2011-10-02 14:45:47 +00:00
|
|
|
#if defined(CONFIG_USB_MUSB_TUSB6010) || defined (CONFIG_USB_MUSB_TUSB6010_MODULE)
|
2008-07-24 09:27:36 +00:00
|
|
|
hw_ep->fifo_async = musb->async + 0x400 + MUSB_FIFO_OFFSET(i);
|
|
|
|
hw_ep->fifo_sync = musb->sync + 0x400 + MUSB_FIFO_OFFSET(i);
|
|
|
|
hw_ep->fifo_sync_va =
|
|
|
|
musb->sync_va + 0x400 + MUSB_FIFO_OFFSET(i);
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
hw_ep->conf = mbase - 0x400 + TUSB_EP0_CONF;
|
|
|
|
else
|
|
|
|
hw_ep->conf = mbase + 0x400 + (((i - 1) & 0xf) << 2);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
hw_ep->regs = MUSB_EP_OFFSET(i, 0) + mbase;
|
2008-12-02 19:33:48 +00:00
|
|
|
hw_ep->target_regs = musb_read_target_reg_base(i, mbase);
|
2008-07-24 09:27:36 +00:00
|
|
|
hw_ep->rx_reinit = 1;
|
|
|
|
hw_ep->tx_reinit = 1;
|
|
|
|
|
|
|
|
if (hw_ep->max_packet_sz_tx) {
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller,
|
2008-07-24 09:27:36 +00:00
|
|
|
"%s: hw_ep %d%s, %smax %d\n",
|
|
|
|
musb_driver_name, i,
|
|
|
|
hw_ep->is_shared_fifo ? "shared" : "tx",
|
|
|
|
hw_ep->tx_double_buffered
|
|
|
|
? "doublebuffer, " : "",
|
|
|
|
hw_ep->max_packet_sz_tx);
|
|
|
|
}
|
|
|
|
if (hw_ep->max_packet_sz_rx && !hw_ep->is_shared_fifo) {
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller,
|
2008-07-24 09:27:36 +00:00
|
|
|
"%s: hw_ep %d%s, %smax %d\n",
|
|
|
|
musb_driver_name, i,
|
|
|
|
"rx",
|
|
|
|
hw_ep->rx_double_buffered
|
|
|
|
? "doublebuffer, " : "",
|
|
|
|
hw_ep->max_packet_sz_rx);
|
|
|
|
}
|
|
|
|
if (!(hw_ep->max_packet_sz_tx || hw_ep->max_packet_sz_rx))
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "hw_ep %d not configured\n", i);
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handle all the irqs defined by the HDRC core. for now we expect: other
|
|
|
|
* irq sources (phy, dma, etc) will be handled first, musb->int_* values
|
|
|
|
* will be assigned, and the irq will already have been acked.
|
|
|
|
*
|
|
|
|
* called in irq context with spinlock held, irqs blocked
|
|
|
|
*/
|
|
|
|
irqreturn_t musb_interrupt(struct musb *musb)
|
|
|
|
{
|
|
|
|
irqreturn_t retval = IRQ_NONE;
|
2012-10-30 18:52:23 +00:00
|
|
|
u8 devctl;
|
2008-07-24 09:27:36 +00:00
|
|
|
int ep_num;
|
|
|
|
u32 reg;
|
|
|
|
|
|
|
|
devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
|
|
|
|
|
2011-05-11 09:44:08 +00:00
|
|
|
dev_dbg(musb->controller, "** IRQ %s usb%04x tx%04x rx%04x\n",
|
2008-07-24 09:27:36 +00:00
|
|
|
(devctl & MUSB_DEVCTL_HM) ? "host" : "peripheral",
|
|
|
|
musb->int_usb, musb->int_tx, musb->int_rx);
|
|
|
|
|
|
|
|
/* the core can interrupt us for multiple reasons; docs have
|
|
|
|
* a generic interrupt flowchart to follow
|
|
|
|
*/
|
2010-06-24 17:37:06 +00:00
|
|
|
if (musb->int_usb)
|
2008-07-24 09:27:36 +00:00
|
|
|
retval |= musb_stage0_irq(musb, musb->int_usb,
|
2012-10-30 18:52:23 +00:00
|
|
|
devctl);
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
/* "stage 1" is handling endpoint irqs */
|
|
|
|
|
|
|
|
/* handle endpoint 0 first */
|
|
|
|
if (musb->int_tx & 1) {
|
|
|
|
if (devctl & MUSB_DEVCTL_HM)
|
|
|
|
retval |= musb_h_ep0_irq(musb);
|
|
|
|
else
|
|
|
|
retval |= musb_g_ep0_irq(musb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RX on endpoints 1-15 */
|
|
|
|
reg = musb->int_rx >> 1;
|
|
|
|
ep_num = 1;
|
|
|
|
while (reg) {
|
|
|
|
if (reg & 1) {
|
|
|
|
/* musb_ep_select(musb->mregs, ep_num); */
|
|
|
|
/* REVISIT just retval = ep->rx_irq(...) */
|
|
|
|
retval = IRQ_HANDLED;
|
2011-11-24 13:46:27 +00:00
|
|
|
if (devctl & MUSB_DEVCTL_HM)
|
|
|
|
musb_host_rx(musb, ep_num);
|
|
|
|
else
|
|
|
|
musb_g_rx(musb, ep_num);
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reg >>= 1;
|
|
|
|
ep_num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TX on endpoints 1-15 */
|
|
|
|
reg = musb->int_tx >> 1;
|
|
|
|
ep_num = 1;
|
|
|
|
while (reg) {
|
|
|
|
if (reg & 1) {
|
|
|
|
/* musb_ep_select(musb->mregs, ep_num); */
|
|
|
|
/* REVISIT just retval |= ep->tx_irq(...) */
|
|
|
|
retval = IRQ_HANDLED;
|
2011-11-24 13:46:27 +00:00
|
|
|
if (devctl & MUSB_DEVCTL_HM)
|
|
|
|
musb_host_tx(musb, ep_num);
|
|
|
|
else
|
|
|
|
musb_g_tx(musb, ep_num);
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
reg >>= 1;
|
|
|
|
ep_num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2011-05-11 10:02:23 +00:00
|
|
|
EXPORT_SYMBOL_GPL(musb_interrupt);
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
#ifndef CONFIG_MUSB_PIO_ONLY
|
2012-11-19 18:24:34 +00:00
|
|
|
static bool use_dma = 1;
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
/* "modprobe ... use_dma=0" etc */
|
|
|
|
module_param(use_dma, bool, 0);
|
|
|
|
MODULE_PARM_DESC(use_dma, "enable/disable use of DMA");
|
|
|
|
|
|
|
|
void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit)
|
|
|
|
{
|
|
|
|
u8 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
|
|
|
|
|
|
|
|
/* called with controller lock already held */
|
|
|
|
|
|
|
|
if (!epnum) {
|
|
|
|
#ifndef CONFIG_USB_TUSB_OMAP_DMA
|
|
|
|
if (!is_cppi_enabled()) {
|
|
|
|
/* endpoint 0 */
|
|
|
|
if (devctl & MUSB_DEVCTL_HM)
|
|
|
|
musb_h_ep0_irq(musb);
|
|
|
|
else
|
|
|
|
musb_g_ep0_irq(musb);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
/* endpoints 1..15 */
|
|
|
|
if (transmit) {
|
2011-11-24 13:46:27 +00:00
|
|
|
if (devctl & MUSB_DEVCTL_HM)
|
|
|
|
musb_host_tx(musb, epnum);
|
|
|
|
else
|
|
|
|
musb_g_tx(musb, epnum);
|
2008-07-24 09:27:36 +00:00
|
|
|
} else {
|
|
|
|
/* receive */
|
2011-11-24 13:46:27 +00:00
|
|
|
if (devctl & MUSB_DEVCTL_HM)
|
|
|
|
musb_host_rx(musb, epnum);
|
|
|
|
else
|
|
|
|
musb_g_rx(musb, epnum);
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-02 14:45:47 +00:00
|
|
|
EXPORT_SYMBOL_GPL(musb_dma_completion);
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
#define use_dma 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
musb_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct musb *musb = dev_to_musb(dev);
|
|
|
|
unsigned long flags;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&musb->lock, flags);
|
2013-03-07 08:39:57 +00:00
|
|
|
ret = sprintf(buf, "%s\n", usb_otg_state_string(musb->xceiv->state));
|
2008-07-24 09:27:36 +00:00
|
|
|
spin_unlock_irqrestore(&musb->lock, flags);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
musb_mode_store(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t n)
|
|
|
|
{
|
|
|
|
struct musb *musb = dev_to_musb(dev);
|
|
|
|
unsigned long flags;
|
2008-11-24 11:06:47 +00:00
|
|
|
int status;
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&musb->lock, flags);
|
2008-11-24 11:06:47 +00:00
|
|
|
if (sysfs_streq(buf, "host"))
|
|
|
|
status = musb_platform_set_mode(musb, MUSB_HOST);
|
|
|
|
else if (sysfs_streq(buf, "peripheral"))
|
|
|
|
status = musb_platform_set_mode(musb, MUSB_PERIPHERAL);
|
|
|
|
else if (sysfs_streq(buf, "otg"))
|
|
|
|
status = musb_platform_set_mode(musb, MUSB_OTG);
|
|
|
|
else
|
|
|
|
status = -EINVAL;
|
2008-07-24 09:27:36 +00:00
|
|
|
spin_unlock_irqrestore(&musb->lock, flags);
|
|
|
|
|
2008-11-24 11:06:47 +00:00
|
|
|
return (status == 0) ? n : status;
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
static DEVICE_ATTR(mode, 0644, musb_mode_show, musb_mode_store);
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
musb_vbus_store(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t n)
|
|
|
|
{
|
|
|
|
struct musb *musb = dev_to_musb(dev);
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long val;
|
|
|
|
|
|
|
|
if (sscanf(buf, "%lu", &val) < 1) {
|
2009-12-15 09:08:43 +00:00
|
|
|
dev_err(dev, "Invalid VBUS timeout ms value\n");
|
2008-07-24 09:27:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&musb->lock, flags);
|
2009-03-31 19:32:12 +00:00
|
|
|
/* force T(a_wait_bcon) to be zero/unlimited *OR* valid */
|
|
|
|
musb->a_wait_bcon = val ? max_t(int, val, OTG_TIME_A_WAIT_BCON) : 0 ;
|
2009-03-31 19:30:04 +00:00
|
|
|
if (musb->xceiv->state == OTG_STATE_A_WAIT_BCON)
|
2008-07-24 09:27:36 +00:00
|
|
|
musb->is_active = 0;
|
|
|
|
musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val));
|
|
|
|
spin_unlock_irqrestore(&musb->lock, flags);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
musb_vbus_show(struct device *dev, struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct musb *musb = dev_to_musb(dev);
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long val;
|
|
|
|
int vbus;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&musb->lock, flags);
|
|
|
|
val = musb->a_wait_bcon;
|
2009-03-31 19:32:12 +00:00
|
|
|
/* FIXME get_vbus_status() is normally #defined as false...
|
|
|
|
* and is effectively TUSB-specific.
|
|
|
|
*/
|
2008-07-24 09:27:36 +00:00
|
|
|
vbus = musb_platform_get_vbus_status(musb);
|
|
|
|
spin_unlock_irqrestore(&musb->lock, flags);
|
|
|
|
|
2009-03-31 19:32:12 +00:00
|
|
|
return sprintf(buf, "Vbus %s, timeout %lu msec\n",
|
2008-07-24 09:27:36 +00:00
|
|
|
vbus ? "on" : "off", val);
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR(vbus, 0644, musb_vbus_show, musb_vbus_store);
|
|
|
|
|
|
|
|
/* Gadget drivers can't know that a host is connected so they might want
|
|
|
|
* to start SRP, but users can. This allows userspace to trigger SRP.
|
|
|
|
*/
|
|
|
|
static ssize_t
|
|
|
|
musb_srp_store(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t n)
|
|
|
|
{
|
|
|
|
struct musb *musb = dev_to_musb(dev);
|
|
|
|
unsigned short srp;
|
|
|
|
|
|
|
|
if (sscanf(buf, "%hu", &srp) != 1
|
|
|
|
|| (srp != 1)) {
|
2009-12-15 09:08:43 +00:00
|
|
|
dev_err(dev, "SRP: Value must be 1\n");
|
2008-07-24 09:27:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (srp == 1)
|
|
|
|
musb_g_wakeup(musb);
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR(srp, 0644, NULL, musb_srp_store);
|
|
|
|
|
2009-12-15 09:08:38 +00:00
|
|
|
static struct attribute *musb_attributes[] = {
|
|
|
|
&dev_attr_mode.attr,
|
|
|
|
&dev_attr_vbus.attr,
|
|
|
|
&dev_attr_srp.attr,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct attribute_group musb_attr_group = {
|
|
|
|
.attrs = musb_attributes,
|
|
|
|
};
|
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
/* Only used to provide driver mode change events */
|
|
|
|
static void musb_irq_work(struct work_struct *data)
|
|
|
|
{
|
|
|
|
struct musb *musb = container_of(data, struct musb, irq_work);
|
|
|
|
|
2012-08-31 11:09:50 +00:00
|
|
|
if (musb->xceiv->state != musb->xceiv_old_state) {
|
|
|
|
musb->xceiv_old_state = musb->xceiv->state;
|
2008-07-24 09:27:36 +00:00
|
|
|
sysfs_notify(&musb->controller->kobj, NULL, "mode");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------
|
|
|
|
* Init support
|
|
|
|
*/
|
|
|
|
|
2012-11-19 18:21:48 +00:00
|
|
|
static struct musb *allocate_instance(struct device *dev,
|
2008-08-08 09:40:54 +00:00
|
|
|
struct musb_hdrc_config *config, void __iomem *mbase)
|
2008-07-24 09:27:36 +00:00
|
|
|
{
|
|
|
|
struct musb *musb;
|
|
|
|
struct musb_hw_ep *ep;
|
|
|
|
int epnum;
|
2013-04-10 19:55:45 +00:00
|
|
|
int ret;
|
2008-07-24 09:27:36 +00:00
|
|
|
|
2013-04-10 19:55:45 +00:00
|
|
|
musb = devm_kzalloc(dev, sizeof(*musb), GFP_KERNEL);
|
|
|
|
if (!musb)
|
2008-07-24 09:27:36 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&musb->control);
|
|
|
|
INIT_LIST_HEAD(&musb->in_bulk);
|
|
|
|
INIT_LIST_HEAD(&musb->out_bulk);
|
|
|
|
|
|
|
|
musb->vbuserr_retry = VBUSERR_RETRY_COUNT;
|
2009-03-31 19:32:12 +00:00
|
|
|
musb->a_wait_bcon = OTG_TIME_A_WAIT_BCON;
|
2008-07-24 09:27:36 +00:00
|
|
|
musb->mregs = mbase;
|
|
|
|
musb->ctrl_base = mbase;
|
|
|
|
musb->nIrq = -ENODEV;
|
2008-08-08 09:40:54 +00:00
|
|
|
musb->config = config;
|
2008-09-15 10:09:31 +00:00
|
|
|
BUG_ON(musb->config->num_eps > MUSB_C_NUM_EPS);
|
2008-07-24 09:27:36 +00:00
|
|
|
for (epnum = 0, ep = musb->endpoints;
|
2008-08-08 09:40:54 +00:00
|
|
|
epnum < musb->config->num_eps;
|
2008-07-24 09:27:36 +00:00
|
|
|
epnum++, ep++) {
|
|
|
|
ep->musb = musb;
|
|
|
|
ep->epnum = epnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
musb->controller = dev;
|
2010-12-01 11:22:05 +00:00
|
|
|
|
2013-04-10 19:55:45 +00:00
|
|
|
ret = musb_host_alloc(musb);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err_free;
|
|
|
|
|
|
|
|
dev_set_drvdata(dev, musb);
|
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
return musb;
|
2013-04-10 19:55:45 +00:00
|
|
|
|
|
|
|
err_free:
|
|
|
|
return NULL;
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void musb_free(struct musb *musb)
|
|
|
|
{
|
|
|
|
/* this has multiple entry modes. it handles fault cleanup after
|
|
|
|
* probe(), where things may be partially set up, as well as rmmod
|
|
|
|
* cleanup after everything's been de-activated.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SYSFS
|
2009-12-15 09:08:38 +00:00
|
|
|
sysfs_remove_group(&musb->controller->kobj, &musb_attr_group);
|
2008-07-24 09:27:36 +00:00
|
|
|
#endif
|
|
|
|
|
2009-01-25 01:56:39 +00:00
|
|
|
if (musb->nIrq >= 0) {
|
|
|
|
if (musb->irq_wake)
|
|
|
|
disable_irq_wake(musb->nIrq);
|
2008-07-24 09:27:36 +00:00
|
|
|
free_irq(musb->nIrq, musb);
|
|
|
|
}
|
|
|
|
|
2013-04-10 19:55:45 +00:00
|
|
|
musb_host_free(musb);
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
|
2013-12-18 19:23:46 +00:00
|
|
|
static void musb_deassert_reset(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct musb *musb;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
musb = container_of(work, struct musb, deassert_reset_work.work);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&musb->lock, flags);
|
|
|
|
|
|
|
|
if (musb->port1_status & USB_PORT_STAT_RESET)
|
|
|
|
musb_port_reset(musb, false);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&musb->lock, flags);
|
|
|
|
}
|
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
/*
|
|
|
|
* Perform generic per-controller initialization.
|
|
|
|
*
|
2012-08-21 17:22:45 +00:00
|
|
|
* @dev: the controller (already clocked, etc)
|
|
|
|
* @nIrq: IRQ number
|
|
|
|
* @ctrl: virtual address of controller registers,
|
2008-07-24 09:27:36 +00:00
|
|
|
* not yet corrected for platform-specific offsets
|
|
|
|
*/
|
2012-11-19 18:21:48 +00:00
|
|
|
static int
|
2008-07-24 09:27:36 +00:00
|
|
|
musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
struct musb *musb;
|
2013-07-30 08:03:12 +00:00
|
|
|
struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
/* The driver might handle more features than the board; OK.
|
|
|
|
* Fail when the board needs a feature that's not enabled.
|
|
|
|
*/
|
|
|
|
if (!plat) {
|
|
|
|
dev_dbg(dev, "no platform_data?\n");
|
2010-03-25 11:14:33 +00:00
|
|
|
status = -ENODEV;
|
|
|
|
goto fail0;
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
2010-03-25 11:14:33 +00:00
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
/* allocate */
|
2008-08-08 09:40:54 +00:00
|
|
|
musb = allocate_instance(dev, plat->config, ctrl);
|
2010-03-25 11:14:33 +00:00
|
|
|
if (!musb) {
|
|
|
|
status = -ENOMEM;
|
|
|
|
goto fail0;
|
|
|
|
}
|
2008-07-24 09:27:36 +00:00
|
|
|
|
usb: musb: Idle path retention and offmode support for OMAP3
This patch supports the retention and offmode support in the idle path for
musb driver using runtime pm APIs.
This is restricted to support offmode and retention only when device not
connected.When device/cable connected with gadget driver loaded,configured
to no idle/standby which will not allow the core transition to retention
or off.
There is no context save/restore done by hardware for musb in OMAP3
and OMAP4,driver has to take care of saving and restoring the context
during offmode.
Musb has a requirement of configuring sysconfig register to force
idle/standby mode and set the ENFORCE bit in module STANDBY register
for retention and offmode support.
Runtime pm and hwmod frameworks will take care of configuring to force
idle/standby when pm_runtime_put_sync is called and back to no
idle/standby when pm_runeime_get_sync is called.
Compile, boot tested and also tested the retention in the idle path on
OMAP3630Zoom3. And tested the global suspend/resume with offmode enabled.
Usb basic functionality tested on OMAP4430SDP.
There is some problem with idle path offmode in mainline, I could not test
with offmode. But I have tested this patch with resetting the controller
in the idle path when wakeup from retention just to make sure that the
context is lost, and restore path is working fine.
Removed .suspend/.resume fnction pointers and functions because there
is no need of having these functions as all required work is done
at runtime in the driver.
There is no need to call the runtime pm api with glue driver device
as glue layer device is the parent of musb core device, when runtime apis
are called for the child, parent device runtime functionality
will be invoked.
Design overview:
pm_runtime_get_sync: When called with musb core device takes care of
enabling the clock, calling runtime callback function of omap2430 glue
layer, runtime call back of musb driver and configure the musb sysconfig
to no idle/standby
pm_runtime_put: Takes care of calling runtime callback function of omap2430
glue layer, runtime call back of musb driver, Configure the musb sysconfig
to force idle/standby and disable the clock.
During musb driver load: Call pm_runtime_get_sync.
End of musb driver load: Call pm_runtime_put
During gadget driver load: Call pm_runtime_get_sync,
End of gadget driver load: Call pm_runtime_put if there is no device
or cable is connected.
During unload of the gadget driver:Call pm_runtime_get_sync if cable/device
is not connected.
End of the gadget driver unload : pm_runtime_put
During unload of musb driver : Call pm_runtime_get_sync
End of unload: Call pm_runtime_put
On connect of usb cable/device -> transceiver notification(VBUS and ID-GND):
pm_runtime_get_sync only if the gadget driver loaded.
On disconnect of the cable/device -> Disconnect Notification:
pm_runtime_put if the gadget driver is loaded.
Signed-off-by: Hema HK <hemahk@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-02-28 08:49:34 +00:00
|
|
|
pm_runtime_use_autosuspend(musb->controller);
|
|
|
|
pm_runtime_set_autosuspend_delay(musb->controller, 200);
|
|
|
|
pm_runtime_enable(musb->controller);
|
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
spin_lock_init(&musb->lock);
|
|
|
|
musb->board_set_power = plat->set_power;
|
|
|
|
musb->min_power = plat->min_power;
|
2010-12-02 07:48:58 +00:00
|
|
|
musb->ops = plat->platform_ops;
|
2013-04-10 19:55:48 +00:00
|
|
|
musb->port_mode = plat->mode;
|
2008-07-24 09:27:36 +00:00
|
|
|
|
2009-03-31 19:30:04 +00:00
|
|
|
/* The musb_platform_init() call:
|
2012-11-06 13:32:13 +00:00
|
|
|
* - adjusts musb->mregs
|
|
|
|
* - sets the musb->isr
|
2014-01-02 13:57:47 +00:00
|
|
|
* - may initialize an integrated transceiver
|
2012-06-22 11:32:45 +00:00
|
|
|
* - initializes musb->xceiv, usually by otg_get_phy()
|
2009-03-31 19:30:04 +00:00
|
|
|
* - stops powering VBUS
|
|
|
|
*
|
2011-06-23 18:39:20 +00:00
|
|
|
* There are various transceiver configurations. Blackfin,
|
2009-03-31 19:30:04 +00:00
|
|
|
* DaVinci, TUSB60x0, and others integrate them. OMAP3 uses
|
|
|
|
* external/discrete ones in various flavors (twl4030 family,
|
|
|
|
* isp1504, non-OTG, etc) mostly hooking up through ULPI.
|
2008-07-24 09:27:36 +00:00
|
|
|
*/
|
2010-09-23 00:27:40 +00:00
|
|
|
status = musb_platform_init(musb);
|
2008-07-24 09:27:36 +00:00
|
|
|
if (status < 0)
|
2010-12-02 07:57:08 +00:00
|
|
|
goto fail1;
|
2010-03-25 11:14:33 +00:00
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
if (!musb->isr) {
|
|
|
|
status = -ENODEV;
|
2012-02-04 17:43:51 +00:00
|
|
|
goto fail2;
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
|
2010-03-25 11:25:28 +00:00
|
|
|
if (!musb->xceiv->io_ops) {
|
2012-03-21 14:35:52 +00:00
|
|
|
musb->xceiv->io_dev = musb->controller;
|
2010-03-25 11:25:28 +00:00
|
|
|
musb->xceiv->io_priv = musb->mregs;
|
|
|
|
musb->xceiv->io_ops = &musb_ulpi_access;
|
|
|
|
}
|
|
|
|
|
2012-02-04 17:43:51 +00:00
|
|
|
pm_runtime_get_sync(musb->controller);
|
|
|
|
|
2013-10-16 10:50:08 +00:00
|
|
|
if (use_dma && dev->dma_mask) {
|
2013-06-19 15:38:11 +00:00
|
|
|
musb->dma_controller = dma_controller_create(musb, musb->mregs);
|
2013-10-16 10:50:08 +00:00
|
|
|
if (IS_ERR(musb->dma_controller)) {
|
|
|
|
status = PTR_ERR(musb->dma_controller);
|
|
|
|
goto fail2_5;
|
|
|
|
}
|
|
|
|
}
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
/* be sure interrupts are disabled before connecting ISR */
|
|
|
|
musb_platform_disable(musb);
|
|
|
|
musb_generic_disable(musb);
|
|
|
|
|
2013-11-06 08:25:27 +00:00
|
|
|
/* Init IRQ workqueue before request_irq */
|
|
|
|
INIT_WORK(&musb->irq_work, musb_irq_work);
|
2013-12-18 19:23:46 +00:00
|
|
|
INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset);
|
|
|
|
INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume);
|
2013-11-06 08:25:27 +00:00
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
/* setup musb parts of the core (especially endpoints) */
|
2008-08-08 09:40:54 +00:00
|
|
|
status = musb_core_init(plat->config->multipoint
|
2008-07-24 09:27:36 +00:00
|
|
|
? MUSB_CONTROLLER_MHDRC
|
|
|
|
: MUSB_CONTROLLER_HDRC, musb);
|
|
|
|
if (status < 0)
|
2010-03-25 11:14:33 +00:00
|
|
|
goto fail3;
|
2008-07-24 09:27:36 +00:00
|
|
|
|
2009-03-31 19:32:12 +00:00
|
|
|
setup_timer(&musb->otg_timer, musb_otg_timer_func, (unsigned long) musb);
|
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
/* attach to the IRQ */
|
2008-11-07 00:52:53 +00:00
|
|
|
if (request_irq(nIrq, musb->isr, 0, dev_name(dev), musb)) {
|
2008-07-24 09:27:36 +00:00
|
|
|
dev_err(dev, "request_irq %d failed!\n", nIrq);
|
|
|
|
status = -ENODEV;
|
2010-03-25 11:14:33 +00:00
|
|
|
goto fail3;
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
musb->nIrq = nIrq;
|
2011-11-24 13:46:26 +00:00
|
|
|
/* FIXME this handles wakeup irqs wrong */
|
2008-11-24 11:06:53 +00:00
|
|
|
if (enable_irq_wake(nIrq) == 0) {
|
|
|
|
musb->irq_wake = 1;
|
2008-07-24 09:27:36 +00:00
|
|
|
device_init_wakeup(dev, 1);
|
2008-11-24 11:06:53 +00:00
|
|
|
} else {
|
|
|
|
musb->irq_wake = 0;
|
|
|
|
}
|
2008-07-24 09:27:36 +00:00
|
|
|
|
2011-11-24 13:46:26 +00:00
|
|
|
/* program PHY to use external vBus if required */
|
|
|
|
if (plat->extvbus) {
|
|
|
|
u8 busctl = musb_read_ulpi_buscontrol(musb->mregs);
|
|
|
|
busctl |= MUSB_ULPI_USE_EXTVBUS;
|
|
|
|
musb_write_ulpi_buscontrol(musb->mregs, busctl);
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
|
2013-03-10 00:48:55 +00:00
|
|
|
if (musb->xceiv->otg->default_a) {
|
|
|
|
MUSB_HST_MODE(musb);
|
|
|
|
musb->xceiv->state = OTG_STATE_A_IDLE;
|
|
|
|
} else {
|
|
|
|
MUSB_DEV_MODE(musb);
|
|
|
|
musb->xceiv->state = OTG_STATE_B_IDLE;
|
|
|
|
}
|
2008-07-24 09:27:36 +00:00
|
|
|
|
2013-04-10 19:55:49 +00:00
|
|
|
switch (musb->port_mode) {
|
|
|
|
case MUSB_PORT_MODE_HOST:
|
|
|
|
status = musb_host_setup(musb, plat->power);
|
2013-10-29 17:17:17 +00:00
|
|
|
if (status < 0)
|
|
|
|
goto fail3;
|
|
|
|
status = musb_platform_set_mode(musb, MUSB_HOST);
|
2013-04-10 19:55:49 +00:00
|
|
|
break;
|
|
|
|
case MUSB_PORT_MODE_GADGET:
|
|
|
|
status = musb_gadget_setup(musb);
|
2013-10-29 17:17:17 +00:00
|
|
|
if (status < 0)
|
|
|
|
goto fail3;
|
|
|
|
status = musb_platform_set_mode(musb, MUSB_PERIPHERAL);
|
2013-04-10 19:55:49 +00:00
|
|
|
break;
|
|
|
|
case MUSB_PORT_MODE_DUAL_ROLE:
|
|
|
|
status = musb_host_setup(musb, plat->power);
|
|
|
|
if (status < 0)
|
|
|
|
goto fail3;
|
|
|
|
status = musb_gadget_setup(musb);
|
2013-10-29 17:17:17 +00:00
|
|
|
if (status) {
|
2013-10-16 10:50:06 +00:00
|
|
|
musb_host_cleanup(musb);
|
2013-10-29 17:17:17 +00:00
|
|
|
goto fail3;
|
|
|
|
}
|
|
|
|
status = musb_platform_set_mode(musb, MUSB_OTG);
|
2013-04-10 19:55:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(dev, "unsupported port mode %d\n", musb->port_mode);
|
|
|
|
break;
|
|
|
|
}
|
2008-07-24 09:27:36 +00:00
|
|
|
|
2010-03-25 11:14:32 +00:00
|
|
|
if (status < 0)
|
2010-03-25 11:14:33 +00:00
|
|
|
goto fail3;
|
2008-07-24 09:27:36 +00:00
|
|
|
|
2010-03-12 08:29:11 +00:00
|
|
|
status = musb_init_debugfs(musb);
|
|
|
|
if (status < 0)
|
2010-03-25 11:25:18 +00:00
|
|
|
goto fail4;
|
2010-03-12 08:29:11 +00:00
|
|
|
|
2009-12-15 09:08:38 +00:00
|
|
|
status = sysfs_create_group(&musb->controller->kobj, &musb_attr_group);
|
2008-09-11 08:53:25 +00:00
|
|
|
if (status)
|
2010-03-25 11:25:18 +00:00
|
|
|
goto fail5;
|
2008-07-24 09:27:36 +00:00
|
|
|
|
2012-02-04 17:43:51 +00:00
|
|
|
pm_runtime_put(musb->controller);
|
|
|
|
|
2008-09-11 08:53:25 +00:00
|
|
|
return 0;
|
2008-07-24 09:27:36 +00:00
|
|
|
|
2010-03-25 11:25:18 +00:00
|
|
|
fail5:
|
|
|
|
musb_exit_debugfs(musb);
|
|
|
|
|
2010-03-25 11:14:33 +00:00
|
|
|
fail4:
|
2011-11-24 13:46:26 +00:00
|
|
|
musb_gadget_cleanup(musb);
|
2013-10-16 10:50:06 +00:00
|
|
|
musb_host_cleanup(musb);
|
2010-03-25 11:14:33 +00:00
|
|
|
|
|
|
|
fail3:
|
2013-11-06 08:25:27 +00:00
|
|
|
cancel_work_sync(&musb->irq_work);
|
2013-12-18 19:23:46 +00:00
|
|
|
cancel_delayed_work_sync(&musb->finish_resume_work);
|
|
|
|
cancel_delayed_work_sync(&musb->deassert_reset_work);
|
2013-06-19 15:38:14 +00:00
|
|
|
if (musb->dma_controller)
|
|
|
|
dma_controller_destroy(musb->dma_controller);
|
2013-10-16 10:50:08 +00:00
|
|
|
fail2_5:
|
2012-02-04 17:43:51 +00:00
|
|
|
pm_runtime_put_sync(musb->controller);
|
|
|
|
|
|
|
|
fail2:
|
2010-03-25 11:14:33 +00:00
|
|
|
if (musb->irq_wake)
|
|
|
|
device_init_wakeup(dev, 0);
|
2008-07-24 09:27:36 +00:00
|
|
|
musb_platform_exit(musb);
|
2008-09-11 08:53:25 +00:00
|
|
|
|
2010-03-25 11:14:33 +00:00
|
|
|
fail1:
|
2013-01-04 15:13:06 +00:00
|
|
|
pm_runtime_disable(musb->controller);
|
2010-03-25 11:14:33 +00:00
|
|
|
dev_err(musb->controller,
|
|
|
|
"musb_init_controller failed with status %d\n", status);
|
|
|
|
|
2008-09-11 08:53:25 +00:00
|
|
|
musb_free(musb);
|
|
|
|
|
2010-03-25 11:14:33 +00:00
|
|
|
fail0:
|
|
|
|
|
2008-09-11 08:53:25 +00:00
|
|
|
return status;
|
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* all implementations (PCI bridge to FPGA, VLYNQ, etc) should just
|
|
|
|
* bridge to a platform device; this driver then suffices.
|
|
|
|
*/
|
2012-11-19 18:21:48 +00:00
|
|
|
static int musb_probe(struct platform_device *pdev)
|
2008-07-24 09:27:36 +00:00
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
2010-09-29 16:26:39 +00:00
|
|
|
int irq = platform_get_irq_byname(pdev, "mc");
|
2008-07-24 09:27:36 +00:00
|
|
|
struct resource *iomem;
|
|
|
|
void __iomem *base;
|
|
|
|
|
|
|
|
iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2010-12-10 18:03:29 +00:00
|
|
|
if (!iomem || irq <= 0)
|
2008-07-24 09:27:36 +00:00
|
|
|
return -ENODEV;
|
|
|
|
|
2013-02-04 17:04:45 +00:00
|
|
|
base = devm_ioremap_resource(dev, iomem);
|
|
|
|
if (IS_ERR(base))
|
|
|
|
return PTR_ERR(base);
|
2008-07-24 09:27:36 +00:00
|
|
|
|
2013-02-04 17:04:45 +00:00
|
|
|
return musb_init_controller(dev, irq, base);
|
2008-07-24 09:27:36 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 18:26:20 +00:00
|
|
|
static int musb_remove(struct platform_device *pdev)
|
2008-07-24 09:27:36 +00:00
|
|
|
{
|
2012-08-31 11:09:50 +00:00
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct musb *musb = dev_to_musb(dev);
|
2008-07-24 09:27:36 +00:00
|
|
|
|
|
|
|
/* this gets called on rmmod.
|
|
|
|
* - Host mode: host may still be active
|
|
|
|
* - Peripheral mode: peripheral is deactivated (or never-activated)
|
|
|
|
* - OTG mode: both roles are deactivated (or never-activated)
|
|
|
|
*/
|
2010-03-12 08:29:11 +00:00
|
|
|
musb_exit_debugfs(musb);
|
2008-07-24 09:27:36 +00:00
|
|
|
musb_shutdown(pdev);
|
2010-03-25 11:14:32 +00:00
|
|
|
|
2013-10-16 10:50:07 +00:00
|
|
|
if (musb->dma_controller)
|
|
|
|
dma_controller_destroy(musb->dma_controller);
|
|
|
|
|
2013-11-06 08:25:27 +00:00
|
|
|
cancel_work_sync(&musb->irq_work);
|
2013-12-18 19:23:46 +00:00
|
|
|
cancel_delayed_work_sync(&musb->finish_resume_work);
|
|
|
|
cancel_delayed_work_sync(&musb->deassert_reset_work);
|
2008-07-24 09:27:36 +00:00
|
|
|
musb_free(musb);
|
2012-08-31 11:09:50 +00:00
|
|
|
device_init_wakeup(dev, 0);
|
2008-07-24 09:27:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
|
2010-12-02 10:28:39 +00:00
|
|
|
static void musb_save_context(struct musb *musb)
|
2010-01-21 13:33:52 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
void __iomem *musb_base = musb->mregs;
|
2010-09-24 10:44:07 +00:00
|
|
|
void __iomem *epio;
|
2010-01-21 13:33:52 +00:00
|
|
|
|
2011-11-24 13:46:26 +00:00
|
|
|
musb->context.frame = musb_readw(musb_base, MUSB_FRAME);
|
|
|
|
musb->context.testmode = musb_readb(musb_base, MUSB_TESTMODE);
|
|
|
|
musb->context.busctl = musb_read_ulpi_buscontrol(musb->mregs);
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.power = musb_readb(musb_base, MUSB_POWER);
|
|
|
|
musb->context.intrusbe = musb_readb(musb_base, MUSB_INTRUSBE);
|
|
|
|
musb->context.index = musb_readb(musb_base, MUSB_INDEX);
|
|
|
|
musb->context.devctl = musb_readb(musb_base, MUSB_DEVCTL);
|
2010-01-21 13:33:52 +00:00
|
|
|
|
2010-09-24 10:44:07 +00:00
|
|
|
for (i = 0; i < musb->config->num_eps; ++i) {
|
2011-06-27 12:57:46 +00:00
|
|
|
struct musb_hw_ep *hw_ep;
|
|
|
|
|
|
|
|
hw_ep = &musb->endpoints[i];
|
|
|
|
if (!hw_ep)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
epio = hw_ep->regs;
|
|
|
|
if (!epio)
|
|
|
|
continue;
|
|
|
|
|
2011-09-07 16:19:23 +00:00
|
|
|
musb_writeb(musb_base, MUSB_INDEX, i);
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].txmaxp =
|
2010-09-24 10:44:07 +00:00
|
|
|
musb_readw(epio, MUSB_TXMAXP);
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].txcsr =
|
2010-09-24 10:44:07 +00:00
|
|
|
musb_readw(epio, MUSB_TXCSR);
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].rxmaxp =
|
2010-09-24 10:44:07 +00:00
|
|
|
musb_readw(epio, MUSB_RXMAXP);
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].rxcsr =
|
2010-09-24 10:44:07 +00:00
|
|
|
musb_readw(epio, MUSB_RXCSR);
|
2010-01-21 13:33:52 +00:00
|
|
|
|
|
|
|
if (musb->dyn_fifo) {
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].txfifoadd =
|
2010-01-21 13:33:52 +00:00
|
|
|
musb_read_txfifoadd(musb_base);
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].rxfifoadd =
|
2010-01-21 13:33:52 +00:00
|
|
|
musb_read_rxfifoadd(musb_base);
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].txfifosz =
|
2010-01-21 13:33:52 +00:00
|
|
|
musb_read_txfifosz(musb_base);
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].rxfifosz =
|
2010-01-21 13:33:52 +00:00
|
|
|
musb_read_rxfifosz(musb_base);
|
|
|
|
}
|
2011-11-24 13:46:26 +00:00
|
|
|
|
|
|
|
musb->context.index_regs[i].txtype =
|
|
|
|
musb_readb(epio, MUSB_TXTYPE);
|
|
|
|
musb->context.index_regs[i].txinterval =
|
|
|
|
musb_readb(epio, MUSB_TXINTERVAL);
|
|
|
|
musb->context.index_regs[i].rxtype =
|
|
|
|
musb_readb(epio, MUSB_RXTYPE);
|
|
|
|
musb->context.index_regs[i].rxinterval =
|
|
|
|
musb_readb(epio, MUSB_RXINTERVAL);
|
|
|
|
|
|
|
|
musb->context.index_regs[i].txfunaddr =
|
|
|
|
musb_read_txfunaddr(musb_base, i);
|
|
|
|
musb->context.index_regs[i].txhubaddr =
|
|
|
|
musb_read_txhubaddr(musb_base, i);
|
|
|
|
musb->context.index_regs[i].txhubport =
|
|
|
|
musb_read_txhubport(musb_base, i);
|
|
|
|
|
|
|
|
musb->context.index_regs[i].rxfunaddr =
|
|
|
|
musb_read_rxfunaddr(musb_base, i);
|
|
|
|
musb->context.index_regs[i].rxhubaddr =
|
|
|
|
musb_read_rxhubaddr(musb_base, i);
|
|
|
|
musb->context.index_regs[i].rxhubport =
|
|
|
|
musb_read_rxhubport(musb_base, i);
|
2010-01-21 13:33:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-02 10:28:39 +00:00
|
|
|
static void musb_restore_context(struct musb *musb)
|
2010-01-21 13:33:52 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
void __iomem *musb_base = musb->mregs;
|
|
|
|
void __iomem *ep_target_regs;
|
2010-09-24 10:44:07 +00:00
|
|
|
void __iomem *epio;
|
2014-02-04 13:29:33 +00:00
|
|
|
u8 power;
|
2010-01-21 13:33:52 +00:00
|
|
|
|
2011-11-24 13:46:26 +00:00
|
|
|
musb_writew(musb_base, MUSB_FRAME, musb->context.frame);
|
|
|
|
musb_writeb(musb_base, MUSB_TESTMODE, musb->context.testmode);
|
|
|
|
musb_write_ulpi_buscontrol(musb->mregs, musb->context.busctl);
|
2014-02-04 13:29:33 +00:00
|
|
|
|
|
|
|
/* Don't affect SUSPENDM/RESUME bits in POWER reg */
|
|
|
|
power = musb_readb(musb_base, MUSB_POWER);
|
|
|
|
power &= MUSB_POWER_SUSPENDM | MUSB_POWER_RESUME;
|
|
|
|
musb->context.power &= ~(MUSB_POWER_SUSPENDM | MUSB_POWER_RESUME);
|
|
|
|
power |= musb->context.power;
|
|
|
|
musb_writeb(musb_base, MUSB_POWER, power);
|
|
|
|
|
2012-10-30 18:52:26 +00:00
|
|
|
musb_writew(musb_base, MUSB_INTRTXE, musb->intrtxe);
|
2012-10-30 18:52:25 +00:00
|
|
|
musb_writew(musb_base, MUSB_INTRRXE, musb->intrrxe);
|
2010-12-01 11:53:27 +00:00
|
|
|
musb_writeb(musb_base, MUSB_INTRUSBE, musb->context.intrusbe);
|
|
|
|
musb_writeb(musb_base, MUSB_DEVCTL, musb->context.devctl);
|
2010-01-21 13:33:52 +00:00
|
|
|
|
2010-09-24 10:44:07 +00:00
|
|
|
for (i = 0; i < musb->config->num_eps; ++i) {
|
2011-06-27 12:57:46 +00:00
|
|
|
struct musb_hw_ep *hw_ep;
|
|
|
|
|
|
|
|
hw_ep = &musb->endpoints[i];
|
|
|
|
if (!hw_ep)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
epio = hw_ep->regs;
|
|
|
|
if (!epio)
|
|
|
|
continue;
|
|
|
|
|
2011-09-07 16:19:23 +00:00
|
|
|
musb_writeb(musb_base, MUSB_INDEX, i);
|
2010-09-24 10:44:07 +00:00
|
|
|
musb_writew(epio, MUSB_TXMAXP,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].txmaxp);
|
2010-09-24 10:44:07 +00:00
|
|
|
musb_writew(epio, MUSB_TXCSR,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].txcsr);
|
2010-09-24 10:44:07 +00:00
|
|
|
musb_writew(epio, MUSB_RXMAXP,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].rxmaxp);
|
2010-09-24 10:44:07 +00:00
|
|
|
musb_writew(epio, MUSB_RXCSR,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].rxcsr);
|
2010-01-21 13:33:52 +00:00
|
|
|
|
|
|
|
if (musb->dyn_fifo) {
|
|
|
|
musb_write_txfifosz(musb_base,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].txfifosz);
|
2010-01-21 13:33:52 +00:00
|
|
|
musb_write_rxfifosz(musb_base,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].rxfifosz);
|
2010-01-21 13:33:52 +00:00
|
|
|
musb_write_txfifoadd(musb_base,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].txfifoadd);
|
2010-01-21 13:33:52 +00:00
|
|
|
musb_write_rxfifoadd(musb_base,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].rxfifoadd);
|
2010-01-21 13:33:52 +00:00
|
|
|
}
|
|
|
|
|
2011-11-24 13:46:26 +00:00
|
|
|
musb_writeb(epio, MUSB_TXTYPE,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].txtype);
|
2011-11-24 13:46:26 +00:00
|
|
|
musb_writeb(epio, MUSB_TXINTERVAL,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].txinterval);
|
2011-11-24 13:46:26 +00:00
|
|
|
musb_writeb(epio, MUSB_RXTYPE,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].rxtype);
|
2011-11-24 13:46:26 +00:00
|
|
|
musb_writeb(epio, MUSB_RXINTERVAL,
|
2010-01-21 13:33:52 +00:00
|
|
|
|
2011-11-24 13:46:26 +00:00
|
|
|
musb->context.index_regs[i].rxinterval);
|
|
|
|
musb_write_txfunaddr(musb_base, i,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].txfunaddr);
|
2011-11-24 13:46:26 +00:00
|
|
|
musb_write_txhubaddr(musb_base, i,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].txhubaddr);
|
2011-11-24 13:46:26 +00:00
|
|
|
musb_write_txhubport(musb_base, i,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].txhubport);
|
2010-01-21 13:33:52 +00:00
|
|
|
|
2011-11-24 13:46:26 +00:00
|
|
|
ep_target_regs =
|
|
|
|
musb_read_target_reg_base(i, musb_base);
|
2010-01-21 13:33:52 +00:00
|
|
|
|
2011-11-24 13:46:26 +00:00
|
|
|
musb_write_rxfunaddr(ep_target_regs,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].rxfunaddr);
|
2011-11-24 13:46:26 +00:00
|
|
|
musb_write_rxhubaddr(ep_target_regs,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].rxhubaddr);
|
2011-11-24 13:46:26 +00:00
|
|
|
musb_write_rxhubport(ep_target_regs,
|
2010-12-01 11:53:27 +00:00
|
|
|
musb->context.index_regs[i].rxhubport);
|
2010-01-21 13:33:52 +00:00
|
|
|
}
|
2011-07-08 09:36:13 +00:00
|
|
|
musb_writeb(musb_base, MUSB_INDEX, musb->context.index);
|
2010-01-21 13:33:52 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 11:22:56 +00:00
|
|
|
static int musb_suspend(struct device *dev)
|
2008-07-24 09:27:36 +00:00
|
|
|
{
|
2011-06-27 12:57:12 +00:00
|
|
|
struct musb *musb = dev_to_musb(dev);
|
2008-07-24 09:27:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&musb->lock, flags);
|
|
|
|
|
|
|
|
if (is_peripheral_active(musb)) {
|
|
|
|
/* FIXME force disconnect unless we know USB will wake
|
|
|
|
* the system up quickly enough to respond ...
|
|
|
|
*/
|
|
|
|
} else if (is_host_active(musb)) {
|
|
|
|
/* we know all the children are suspended; sometimes
|
|
|
|
* they will even be wakeup-enabled.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2013-11-25 21:26:40 +00:00
|
|
|
musb_save_context(musb);
|
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
spin_unlock_irqrestore(&musb->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-08 11:22:56 +00:00
|
|
|
static int musb_resume_noirq(struct device *dev)
|
2008-07-24 09:27:36 +00:00
|
|
|
{
|
2013-11-25 21:26:40 +00:00
|
|
|
struct musb *musb = dev_to_musb(dev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For static cmos like DaVinci, register values were preserved
|
2009-03-27 01:56:51 +00:00
|
|
|
* unless for some reason the whole soc powered down or the USB
|
|
|
|
* module got reset through the PSC (vs just being disabled).
|
2013-11-25 21:26:40 +00:00
|
|
|
*
|
|
|
|
* For the DSPS glue layer though, a full register restore has to
|
|
|
|
* be done. As it shouldn't harm other platforms, we do it
|
|
|
|
* unconditionally.
|
2008-07-24 09:27:36 +00:00
|
|
|
*/
|
2013-11-25 21:26:40 +00:00
|
|
|
|
|
|
|
musb_restore_context(musb);
|
|
|
|
|
2008-07-24 09:27:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
usb: musb: Idle path retention and offmode support for OMAP3
This patch supports the retention and offmode support in the idle path for
musb driver using runtime pm APIs.
This is restricted to support offmode and retention only when device not
connected.When device/cable connected with gadget driver loaded,configured
to no idle/standby which will not allow the core transition to retention
or off.
There is no context save/restore done by hardware for musb in OMAP3
and OMAP4,driver has to take care of saving and restoring the context
during offmode.
Musb has a requirement of configuring sysconfig register to force
idle/standby mode and set the ENFORCE bit in module STANDBY register
for retention and offmode support.
Runtime pm and hwmod frameworks will take care of configuring to force
idle/standby when pm_runtime_put_sync is called and back to no
idle/standby when pm_runeime_get_sync is called.
Compile, boot tested and also tested the retention in the idle path on
OMAP3630Zoom3. And tested the global suspend/resume with offmode enabled.
Usb basic functionality tested on OMAP4430SDP.
There is some problem with idle path offmode in mainline, I could not test
with offmode. But I have tested this patch with resetting the controller
in the idle path when wakeup from retention just to make sure that the
context is lost, and restore path is working fine.
Removed .suspend/.resume fnction pointers and functions because there
is no need of having these functions as all required work is done
at runtime in the driver.
There is no need to call the runtime pm api with glue driver device
as glue layer device is the parent of musb core device, when runtime apis
are called for the child, parent device runtime functionality
will be invoked.
Design overview:
pm_runtime_get_sync: When called with musb core device takes care of
enabling the clock, calling runtime callback function of omap2430 glue
layer, runtime call back of musb driver and configure the musb sysconfig
to no idle/standby
pm_runtime_put: Takes care of calling runtime callback function of omap2430
glue layer, runtime call back of musb driver, Configure the musb sysconfig
to force idle/standby and disable the clock.
During musb driver load: Call pm_runtime_get_sync.
End of musb driver load: Call pm_runtime_put
During gadget driver load: Call pm_runtime_get_sync,
End of gadget driver load: Call pm_runtime_put if there is no device
or cable is connected.
During unload of the gadget driver:Call pm_runtime_get_sync if cable/device
is not connected.
End of the gadget driver unload : pm_runtime_put
During unload of musb driver : Call pm_runtime_get_sync
End of unload: Call pm_runtime_put
On connect of usb cable/device -> transceiver notification(VBUS and ID-GND):
pm_runtime_get_sync only if the gadget driver loaded.
On disconnect of the cable/device -> Disconnect Notification:
pm_runtime_put if the gadget driver is loaded.
Signed-off-by: Hema HK <hemahk@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-02-28 08:49:34 +00:00
|
|
|
static int musb_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct musb *musb = dev_to_musb(dev);
|
|
|
|
|
|
|
|
musb_save_context(musb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int musb_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct musb *musb = dev_to_musb(dev);
|
|
|
|
static int first = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When pm_runtime_get_sync called for the first time in driver
|
|
|
|
* init, some of the structure is still not initialized which is
|
|
|
|
* used in restore function. But clock needs to be
|
|
|
|
* enabled before any register access, so
|
|
|
|
* pm_runtime_get_sync has to be called.
|
|
|
|
* Also context restore without save does not make
|
|
|
|
* any sense
|
|
|
|
*/
|
|
|
|
if (!first)
|
|
|
|
musb_restore_context(musb);
|
|
|
|
first = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-15 02:00:08 +00:00
|
|
|
static const struct dev_pm_ops musb_dev_pm_ops = {
|
2009-07-08 11:22:56 +00:00
|
|
|
.suspend = musb_suspend,
|
|
|
|
.resume_noirq = musb_resume_noirq,
|
usb: musb: Idle path retention and offmode support for OMAP3
This patch supports the retention and offmode support in the idle path for
musb driver using runtime pm APIs.
This is restricted to support offmode and retention only when device not
connected.When device/cable connected with gadget driver loaded,configured
to no idle/standby which will not allow the core transition to retention
or off.
There is no context save/restore done by hardware for musb in OMAP3
and OMAP4,driver has to take care of saving and restoring the context
during offmode.
Musb has a requirement of configuring sysconfig register to force
idle/standby mode and set the ENFORCE bit in module STANDBY register
for retention and offmode support.
Runtime pm and hwmod frameworks will take care of configuring to force
idle/standby when pm_runtime_put_sync is called and back to no
idle/standby when pm_runeime_get_sync is called.
Compile, boot tested and also tested the retention in the idle path on
OMAP3630Zoom3. And tested the global suspend/resume with offmode enabled.
Usb basic functionality tested on OMAP4430SDP.
There is some problem with idle path offmode in mainline, I could not test
with offmode. But I have tested this patch with resetting the controller
in the idle path when wakeup from retention just to make sure that the
context is lost, and restore path is working fine.
Removed .suspend/.resume fnction pointers and functions because there
is no need of having these functions as all required work is done
at runtime in the driver.
There is no need to call the runtime pm api with glue driver device
as glue layer device is the parent of musb core device, when runtime apis
are called for the child, parent device runtime functionality
will be invoked.
Design overview:
pm_runtime_get_sync: When called with musb core device takes care of
enabling the clock, calling runtime callback function of omap2430 glue
layer, runtime call back of musb driver and configure the musb sysconfig
to no idle/standby
pm_runtime_put: Takes care of calling runtime callback function of omap2430
glue layer, runtime call back of musb driver, Configure the musb sysconfig
to force idle/standby and disable the clock.
During musb driver load: Call pm_runtime_get_sync.
End of musb driver load: Call pm_runtime_put
During gadget driver load: Call pm_runtime_get_sync,
End of gadget driver load: Call pm_runtime_put if there is no device
or cable is connected.
During unload of the gadget driver:Call pm_runtime_get_sync if cable/device
is not connected.
End of the gadget driver unload : pm_runtime_put
During unload of musb driver : Call pm_runtime_get_sync
End of unload: Call pm_runtime_put
On connect of usb cable/device -> transceiver notification(VBUS and ID-GND):
pm_runtime_get_sync only if the gadget driver loaded.
On disconnect of the cable/device -> Disconnect Notification:
pm_runtime_put if the gadget driver is loaded.
Signed-off-by: Hema HK <hemahk@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2011-02-28 08:49:34 +00:00
|
|
|
.runtime_suspend = musb_runtime_suspend,
|
|
|
|
.runtime_resume = musb_runtime_resume,
|
2009-07-08 11:22:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define MUSB_DEV_PM_OPS (&musb_dev_pm_ops)
|
2008-07-24 09:27:36 +00:00
|
|
|
#else
|
2009-07-08 11:22:56 +00:00
|
|
|
#define MUSB_DEV_PM_OPS NULL
|
2008-07-24 09:27:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct platform_driver musb_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = (char *)musb_driver_name,
|
|
|
|
.bus = &platform_bus_type,
|
|
|
|
.owner = THIS_MODULE,
|
2009-07-08 11:22:56 +00:00
|
|
|
.pm = MUSB_DEV_PM_OPS,
|
2008-07-24 09:27:36 +00:00
|
|
|
},
|
2012-01-26 10:40:23 +00:00
|
|
|
.probe = musb_probe,
|
2012-11-19 18:21:08 +00:00
|
|
|
.remove = musb_remove,
|
2008-07-24 09:27:36 +00:00
|
|
|
.shutdown = musb_shutdown,
|
|
|
|
};
|
|
|
|
|
2013-12-26 12:24:52 +00:00
|
|
|
module_platform_driver(musb_driver);
|