2017-11-03 18:28:30 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2008-07-24 17:27:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2005-2006 by Texas Instruments
|
|
|
|
*
|
|
|
|
* This file is part of the Inventra Controller Driver for Linux.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/clk.h>
|
2012-06-26 20:10:32 +08:00
|
|
|
#include <linux/err.h>
|
2008-07-24 17:27:36 +08:00
|
|
|
#include <linux/io.h>
|
2008-09-11 16:53:23 +08:00
|
|
|
#include <linux/gpio.h>
|
2010-12-02 15:16:55 +08:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
2014-04-17 04:28:32 +08:00
|
|
|
#include <linux/usb/usb_phy_generic.h>
|
2008-07-24 17:27:36 +08:00
|
|
|
|
2009-07-01 18:32:43 +08:00
|
|
|
#include <mach/cputype.h>
|
2012-05-25 09:50:18 +08:00
|
|
|
#include <mach/hardware.h>
|
2009-01-25 09:56:17 +08:00
|
|
|
|
2008-07-24 17:27:36 +08:00
|
|
|
#include <asm/mach-types.h>
|
|
|
|
|
|
|
|
#include "musb_core.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_MACH_DAVINCI_EVM
|
2009-12-15 19:29:57 +08:00
|
|
|
#define GPIO_nVBUS_DRV 160
|
2008-07-24 17:27:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "davinci.h"
|
|
|
|
#include "cppi_dma.h"
|
|
|
|
|
|
|
|
|
2009-02-25 07:31:54 +08:00
|
|
|
#define USB_PHY_CTRL IO_ADDRESS(USBPHY_CTL_PADDR)
|
|
|
|
#define DM355_DEEPSLEEP IO_ADDRESS(DM355_DEEPSLEEP_PADDR)
|
|
|
|
|
2010-12-02 15:38:12 +08:00
|
|
|
struct davinci_glue {
|
|
|
|
struct device *dev;
|
|
|
|
struct platform_device *musb;
|
2010-12-02 15:57:08 +08:00
|
|
|
struct clk *clk;
|
2010-12-02 15:38:12 +08:00
|
|
|
};
|
|
|
|
|
2008-07-24 17:27:36 +08:00
|
|
|
/* REVISIT (PM) we should be able to keep the PHY in low power mode most
|
|
|
|
* of the time (24 MHZ oscillator and PLL off, etc) by setting POWER.D0
|
|
|
|
* and, when in host mode, autosuspending idle root ports... PHYPLLON
|
|
|
|
* (overriding SUSPENDM?) then likely needs to stay off.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline void phy_on(void)
|
|
|
|
{
|
2009-02-25 07:31:54 +08:00
|
|
|
u32 phy_ctrl = __raw_readl(USB_PHY_CTRL);
|
|
|
|
|
|
|
|
/* power everything up; start the on-chip PHY and its PLL */
|
|
|
|
phy_ctrl &= ~(USBPHY_OSCPDWN | USBPHY_OTGPDWN | USBPHY_PHYPDWN);
|
|
|
|
phy_ctrl |= USBPHY_SESNDEN | USBPHY_VBDTCTEN | USBPHY_PHYPLLON;
|
|
|
|
__raw_writel(phy_ctrl, USB_PHY_CTRL);
|
|
|
|
|
|
|
|
/* wait for PLL to lock before proceeding */
|
|
|
|
while ((__raw_readl(USB_PHY_CTRL) & USBPHY_PHYCLKGD) == 0)
|
2008-07-24 17:27:36 +08:00
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void phy_off(void)
|
|
|
|
{
|
2009-02-25 07:31:54 +08:00
|
|
|
u32 phy_ctrl = __raw_readl(USB_PHY_CTRL);
|
|
|
|
|
|
|
|
/* powerdown the on-chip PHY, its PLL, and the OTG block */
|
|
|
|
phy_ctrl &= ~(USBPHY_SESNDEN | USBPHY_VBDTCTEN | USBPHY_PHYPLLON);
|
|
|
|
phy_ctrl |= USBPHY_OSCPDWN | USBPHY_OTGPDWN | USBPHY_PHYPDWN;
|
|
|
|
__raw_writel(phy_ctrl, USB_PHY_CTRL);
|
2008-07-24 17:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dma_off = 1;
|
|
|
|
|
2010-12-01 19:22:05 +08:00
|
|
|
static void davinci_musb_enable(struct musb *musb)
|
2008-07-24 17:27:36 +08:00
|
|
|
{
|
|
|
|
u32 tmp, old, val;
|
|
|
|
|
|
|
|
/* workaround: setup irqs through both register sets */
|
|
|
|
tmp = (musb->epmask & DAVINCI_USB_TX_ENDPTS_MASK)
|
|
|
|
<< DAVINCI_USB_TXINT_SHIFT;
|
|
|
|
musb_writel(musb->ctrl_base, DAVINCI_USB_INT_MASK_SET_REG, tmp);
|
|
|
|
old = tmp;
|
|
|
|
tmp = (musb->epmask & (0xfffe & DAVINCI_USB_RX_ENDPTS_MASK))
|
|
|
|
<< DAVINCI_USB_RXINT_SHIFT;
|
|
|
|
musb_writel(musb->ctrl_base, DAVINCI_USB_INT_MASK_SET_REG, tmp);
|
|
|
|
tmp |= old;
|
|
|
|
|
|
|
|
val = ~MUSB_INTR_SOF;
|
|
|
|
tmp |= ((val & 0x01ff) << DAVINCI_USB_USBINT_SHIFT);
|
|
|
|
musb_writel(musb->ctrl_base, DAVINCI_USB_INT_MASK_SET_REG, tmp);
|
|
|
|
|
|
|
|
if (is_dma_capable() && !dma_off)
|
|
|
|
printk(KERN_WARNING "%s %s: dma not reactivated\n",
|
|
|
|
__FILE__, __func__);
|
|
|
|
else
|
|
|
|
dma_off = 0;
|
|
|
|
|
|
|
|
/* force a DRVVBUS irq so we can start polling for ID change */
|
2011-11-24 21:46:26 +08:00
|
|
|
musb_writel(musb->ctrl_base, DAVINCI_USB_INT_SET_REG,
|
2008-07-24 17:27:36 +08:00
|
|
|
DAVINCI_INTR_DRVVBUS << DAVINCI_USB_USBINT_SHIFT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable the HDRC and flush interrupts
|
|
|
|
*/
|
2010-12-01 19:22:05 +08:00
|
|
|
static void davinci_musb_disable(struct musb *musb)
|
2008-07-24 17:27:36 +08:00
|
|
|
{
|
|
|
|
/* because we don't set CTRLR.UINT, "important" to:
|
|
|
|
* - not read/write INTRUSB/INTRUSBE
|
|
|
|
* - (except during initial setup, as workaround)
|
|
|
|
* - use INTSETR/INTCLRR instead
|
|
|
|
*/
|
|
|
|
musb_writel(musb->ctrl_base, DAVINCI_USB_INT_MASK_CLR_REG,
|
|
|
|
DAVINCI_USB_USBINT_MASK
|
|
|
|
| DAVINCI_USB_TXINT_MASK
|
|
|
|
| DAVINCI_USB_RXINT_MASK);
|
|
|
|
musb_writel(musb->ctrl_base, DAVINCI_USB_EOI_REG, 0);
|
|
|
|
|
|
|
|
if (is_dma_capable() && !dma_off)
|
|
|
|
WARNING("dma still active\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define portstate(stmt) stmt
|
|
|
|
|
2009-02-25 07:31:54 +08:00
|
|
|
/*
|
|
|
|
* VBUS SWITCHING IS BOARD-SPECIFIC ... at least for the DM6446 EVM,
|
|
|
|
* which doesn't wire DRVVBUS to the FET that switches it. Unclear
|
|
|
|
* if that's a problem with the DM6446 chip or just with that board.
|
|
|
|
*
|
|
|
|
* In either case, the DM355 EVM automates DRVVBUS the normal way,
|
|
|
|
* when J10 is out, and TI documents it as handling OTG.
|
|
|
|
*/
|
2008-07-24 17:27:36 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_MACH_DAVINCI_EVM
|
|
|
|
|
2009-02-25 07:31:54 +08:00
|
|
|
static int vbus_state = -1;
|
|
|
|
|
2008-07-24 17:27:36 +08:00
|
|
|
/* I2C operations are always synchronous, and require a task context.
|
|
|
|
* With unloaded systems, using the shared workqueue seems to suffice
|
|
|
|
* to satisfy the 100msec A_WAIT_VRISE timeout...
|
|
|
|
*/
|
|
|
|
static void evm_deferred_drvvbus(struct work_struct *ignored)
|
|
|
|
{
|
2008-09-11 16:53:23 +08:00
|
|
|
gpio_set_value_cansleep(GPIO_nVBUS_DRV, vbus_state);
|
2008-07-24 17:27:36 +08:00
|
|
|
vbus_state = !vbus_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* EVM */
|
|
|
|
|
2010-12-01 19:22:05 +08:00
|
|
|
static void davinci_musb_source_power(struct musb *musb, int is_on, int immediate)
|
2008-07-24 17:27:36 +08:00
|
|
|
{
|
2009-02-25 07:31:54 +08:00
|
|
|
#ifdef CONFIG_MACH_DAVINCI_EVM
|
2008-07-24 17:27:36 +08:00
|
|
|
if (is_on)
|
|
|
|
is_on = 1;
|
|
|
|
|
|
|
|
if (vbus_state == is_on)
|
|
|
|
return;
|
|
|
|
vbus_state = !is_on; /* 0/1 vs "-1 == unknown/init" */
|
|
|
|
|
|
|
|
if (machine_is_davinci_evm()) {
|
2009-02-25 07:31:54 +08:00
|
|
|
static DECLARE_WORK(evm_vbus_work, evm_deferred_drvvbus);
|
|
|
|
|
2008-07-24 17:27:36 +08:00
|
|
|
if (immediate)
|
2008-09-11 16:53:23 +08:00
|
|
|
gpio_set_value_cansleep(GPIO_nVBUS_DRV, vbus_state);
|
2008-07-24 17:27:36 +08:00
|
|
|
else
|
|
|
|
schedule_work(&evm_vbus_work);
|
|
|
|
}
|
|
|
|
if (immediate)
|
|
|
|
vbus_state = is_on;
|
2009-02-25 07:31:54 +08:00
|
|
|
#endif
|
2008-07-24 17:27:36 +08:00
|
|
|
}
|
|
|
|
|
2010-12-01 19:22:05 +08:00
|
|
|
static void davinci_musb_set_vbus(struct musb *musb, int is_on)
|
2008-07-24 17:27:36 +08:00
|
|
|
{
|
|
|
|
WARN_ON(is_on && is_peripheral_active(musb));
|
2010-12-01 19:22:05 +08:00
|
|
|
davinci_musb_source_power(musb, is_on, 0);
|
2008-07-24 17:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define POLL_SECONDS 2
|
|
|
|
|
2017-10-24 18:08:35 +08:00
|
|
|
static void otg_timer(struct timer_list *t)
|
2008-07-24 17:27:36 +08:00
|
|
|
{
|
2017-10-24 18:08:35 +08:00
|
|
|
struct musb *musb = from_timer(musb, t, dev_timer);
|
2008-07-24 17:27:36 +08:00
|
|
|
void __iomem *mregs = musb->mregs;
|
|
|
|
u8 devctl;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/* We poll because DaVinci's won't expose several OTG-critical
|
|
|
|
* status change events (from the transceiver) otherwise.
|
|
|
|
*/
|
|
|
|
devctl = musb_readb(mregs, MUSB_DEVCTL);
|
2011-05-11 17:44:08 +08:00
|
|
|
dev_dbg(musb->controller, "poll devctl %02x (%s)\n", devctl,
|
2014-10-31 01:41:13 +08:00
|
|
|
usb_otg_state_string(musb->xceiv->otg->state));
|
2008-07-24 17:27:36 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&musb->lock, flags);
|
2014-10-31 01:41:13 +08:00
|
|
|
switch (musb->xceiv->otg->state) {
|
2008-07-24 17:27:36 +08:00
|
|
|
case OTG_STATE_A_WAIT_VFALL:
|
|
|
|
/* Wait till VBUS falls below SessionEnd (~0.2V); the 1.3 RTL
|
|
|
|
* seems to mis-handle session "start" otherwise (or in our
|
|
|
|
* case "recover"), in routine "VBUS was valid by the time
|
|
|
|
* VBUSERR got reported during enumeration" cases.
|
|
|
|
*/
|
|
|
|
if (devctl & MUSB_DEVCTL_VBUS) {
|
2017-10-24 18:08:35 +08:00
|
|
|
mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ);
|
2008-07-24 17:27:36 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-10-31 01:41:13 +08:00
|
|
|
musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
|
2008-07-24 17:27:36 +08:00
|
|
|
musb_writel(musb->ctrl_base, DAVINCI_USB_INT_SET_REG,
|
|
|
|
MUSB_INTR_VBUSERROR << DAVINCI_USB_USBINT_SHIFT);
|
|
|
|
break;
|
|
|
|
case OTG_STATE_B_IDLE:
|
2011-11-24 21:46:26 +08:00
|
|
|
/*
|
|
|
|
* There's no ID-changed IRQ, so we have no good way to tell
|
2008-07-24 17:27:36 +08:00
|
|
|
* when to switch to the A-Default state machine (by setting
|
|
|
|
* the DEVCTL.SESSION flag).
|
|
|
|
*
|
|
|
|
* Workaround: whenever we're in B_IDLE, try setting the
|
|
|
|
* session flag every few seconds. If it works, ID was
|
|
|
|
* grounded and we're now in the A-Default state machine.
|
|
|
|
*
|
|
|
|
* NOTE setting the session flag is _supposed_ to trigger
|
|
|
|
* SRP, but clearly it doesn't.
|
|
|
|
*/
|
|
|
|
musb_writeb(mregs, MUSB_DEVCTL,
|
|
|
|
devctl | MUSB_DEVCTL_SESSION);
|
|
|
|
devctl = musb_readb(mregs, MUSB_DEVCTL);
|
|
|
|
if (devctl & MUSB_DEVCTL_BDEVICE)
|
2017-10-24 18:08:35 +08:00
|
|
|
mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ);
|
2008-07-24 17:27:36 +08:00
|
|
|
else
|
2014-10-31 01:41:13 +08:00
|
|
|
musb->xceiv->otg->state = OTG_STATE_A_IDLE;
|
2008-07-24 17:27:36 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&musb->lock, flags);
|
|
|
|
}
|
|
|
|
|
2010-12-01 19:22:05 +08:00
|
|
|
static irqreturn_t davinci_musb_interrupt(int irq, void *__hci)
|
2008-07-24 17:27:36 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
irqreturn_t retval = IRQ_NONE;
|
|
|
|
struct musb *musb = __hci;
|
2012-02-13 19:24:15 +08:00
|
|
|
struct usb_otg *otg = musb->xceiv->otg;
|
2008-07-24 17:27:36 +08:00
|
|
|
void __iomem *tibase = musb->ctrl_base;
|
2009-03-28 03:59:46 +08:00
|
|
|
struct cppi *cppi;
|
2008-07-24 17:27:36 +08:00
|
|
|
u32 tmp;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&musb->lock, flags);
|
|
|
|
|
|
|
|
/* NOTE: DaVinci shadows the Mentor IRQs. Don't manage them through
|
|
|
|
* the Mentor registers (except for setup), use the TI ones and EOI.
|
|
|
|
*
|
2010-02-13 04:58:11 +08:00
|
|
|
* Docs describe irq "vector" registers associated with the CPPI and
|
2008-07-24 17:27:36 +08:00
|
|
|
* USB EOI registers. These hold a bitmask corresponding to the
|
|
|
|
* current IRQ, not an irq handler address. Would using those bits
|
|
|
|
* resolve some of the races observed in this dispatch code??
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* CPPI interrupts share the same IRQ line, but have their own
|
|
|
|
* mask, state, "vector", and EOI registers.
|
|
|
|
*/
|
2009-03-28 03:59:46 +08:00
|
|
|
cppi = container_of(musb->dma_controller, struct cppi, controller);
|
2015-05-02 03:29:27 +08:00
|
|
|
if (is_cppi_enabled(musb) && musb->dma_controller && !cppi->irq)
|
2009-03-28 03:59:46 +08:00
|
|
|
retval = cppi_interrupt(irq, __hci);
|
2008-07-24 17:27:36 +08:00
|
|
|
|
|
|
|
/* ack and handle non-CPPI interrupts */
|
|
|
|
tmp = musb_readl(tibase, DAVINCI_USB_INT_SRC_MASKED_REG);
|
|
|
|
musb_writel(tibase, DAVINCI_USB_INT_SRC_CLR_REG, tmp);
|
2011-05-11 17:44:08 +08:00
|
|
|
dev_dbg(musb->controller, "IRQ %08x\n", tmp);
|
2008-07-24 17:27:36 +08:00
|
|
|
|
|
|
|
musb->int_rx = (tmp & DAVINCI_USB_RXINT_MASK)
|
|
|
|
>> DAVINCI_USB_RXINT_SHIFT;
|
|
|
|
musb->int_tx = (tmp & DAVINCI_USB_TXINT_MASK)
|
|
|
|
>> DAVINCI_USB_TXINT_SHIFT;
|
|
|
|
musb->int_usb = (tmp & DAVINCI_USB_USBINT_MASK)
|
|
|
|
>> DAVINCI_USB_USBINT_SHIFT;
|
|
|
|
|
|
|
|
/* DRVVBUS irqs are the only proxy we have (a very poor one!) for
|
|
|
|
* DaVinci's missing ID change IRQ. We need an ID change IRQ to
|
|
|
|
* switch appropriately between halves of the OTG state machine.
|
|
|
|
* Managing DEVCTL.SESSION per Mentor docs requires we know its
|
|
|
|
* value, but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set.
|
|
|
|
* Also, DRVVBUS pulses for SRP (but not at 5V) ...
|
|
|
|
*/
|
|
|
|
if (tmp & (DAVINCI_INTR_DRVVBUS << DAVINCI_USB_USBINT_SHIFT)) {
|
|
|
|
int drvvbus = musb_readl(tibase, DAVINCI_USB_STAT_REG);
|
|
|
|
void __iomem *mregs = musb->mregs;
|
|
|
|
u8 devctl = musb_readb(mregs, MUSB_DEVCTL);
|
|
|
|
int err = musb->int_usb & MUSB_INTR_VBUSERROR;
|
|
|
|
|
2011-11-24 21:46:26 +08:00
|
|
|
err = musb->int_usb & MUSB_INTR_VBUSERROR;
|
2008-07-24 17:27:36 +08:00
|
|
|
if (err) {
|
|
|
|
/* The Mentor core doesn't debounce VBUS as needed
|
|
|
|
* to cope with device connect current spikes. This
|
|
|
|
* means it's not uncommon for bus-powered devices
|
|
|
|
* to get VBUS errors during enumeration.
|
|
|
|
*
|
|
|
|
* This is a workaround, but newer RTL from Mentor
|
|
|
|
* seems to allow a better one: "re"starting sessions
|
|
|
|
* without waiting (on EVM, a **long** time) for VBUS
|
|
|
|
* to stop registering in devctl.
|
|
|
|
*/
|
|
|
|
musb->int_usb &= ~MUSB_INTR_VBUSERROR;
|
2014-10-31 01:41:13 +08:00
|
|
|
musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL;
|
2017-10-24 18:08:35 +08:00
|
|
|
mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ);
|
2008-07-24 17:27:36 +08:00
|
|
|
WARNING("VBUS error workaround (delay coming)\n");
|
2011-11-24 21:46:26 +08:00
|
|
|
} else if (drvvbus) {
|
2008-07-24 17:27:36 +08:00
|
|
|
MUSB_HST_MODE(musb);
|
2014-10-31 01:41:13 +08:00
|
|
|
musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
|
2008-07-24 17:27:36 +08:00
|
|
|
portstate(musb->port1_status |= USB_PORT_STAT_POWER);
|
2017-10-24 18:08:35 +08:00
|
|
|
del_timer(&musb->dev_timer);
|
2008-07-24 17:27:36 +08:00
|
|
|
} else {
|
|
|
|
musb->is_active = 0;
|
|
|
|
MUSB_DEV_MODE(musb);
|
2014-10-31 01:41:13 +08:00
|
|
|
musb->xceiv->otg->state = OTG_STATE_B_IDLE;
|
2008-07-24 17:27:36 +08:00
|
|
|
portstate(musb->port1_status &= ~USB_PORT_STAT_POWER);
|
|
|
|
}
|
|
|
|
|
2009-07-01 18:36:16 +08:00
|
|
|
/* NOTE: this must complete poweron within 100 msec
|
|
|
|
* (OTG_TIME_A_WAIT_VRISE) but we don't check for that.
|
|
|
|
*/
|
2010-12-01 19:22:05 +08:00
|
|
|
davinci_musb_source_power(musb, drvvbus, 0);
|
2011-05-11 17:44:08 +08:00
|
|
|
dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
|
2008-07-24 17:27:36 +08:00
|
|
|
drvvbus ? "on" : "off",
|
2014-10-31 01:41:13 +08:00
|
|
|
usb_otg_state_string(musb->xceiv->otg->state),
|
2008-07-24 17:27:36 +08:00
|
|
|
err ? " ERROR" : "",
|
|
|
|
devctl);
|
|
|
|
retval = IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (musb->int_tx || musb->int_rx || musb->int_usb)
|
|
|
|
retval |= musb_interrupt(musb);
|
|
|
|
|
|
|
|
/* irq stays asserted until EOI is written */
|
|
|
|
musb_writel(tibase, DAVINCI_USB_EOI_REG, 0);
|
|
|
|
|
|
|
|
/* poll for ID change */
|
2014-10-31 01:41:13 +08:00
|
|
|
if (musb->xceiv->otg->state == OTG_STATE_B_IDLE)
|
2017-10-24 18:08:35 +08:00
|
|
|
mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ);
|
2008-07-24 17:27:36 +08:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&musb->lock, flags);
|
|
|
|
|
2009-03-28 03:52:43 +08:00
|
|
|
return retval;
|
2008-07-24 17:27:36 +08:00
|
|
|
}
|
|
|
|
|
2010-12-01 19:22:05 +08:00
|
|
|
static int davinci_musb_set_mode(struct musb *musb, u8 mode)
|
2008-11-24 19:06:47 +08:00
|
|
|
{
|
|
|
|
/* EVM can't do this (right?) */
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2010-12-01 19:22:05 +08:00
|
|
|
static int davinci_musb_init(struct musb *musb)
|
2008-07-24 17:27:36 +08:00
|
|
|
{
|
|
|
|
void __iomem *tibase = musb->ctrl_base;
|
|
|
|
u32 revision;
|
2013-01-04 23:13:58 +08:00
|
|
|
int ret = -ENODEV;
|
2008-07-24 17:27:36 +08:00
|
|
|
|
2012-06-22 19:32:46 +08:00
|
|
|
musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
|
2013-01-04 23:13:58 +08:00
|
|
|
if (IS_ERR_OR_NULL(musb->xceiv)) {
|
|
|
|
ret = -EPROBE_DEFER;
|
2012-04-16 23:03:10 +08:00
|
|
|
goto unregister;
|
2013-01-04 23:13:58 +08:00
|
|
|
}
|
2009-04-01 03:30:04 +08:00
|
|
|
|
2008-07-24 17:27:36 +08:00
|
|
|
musb->mregs += DAVINCI_BASE_OFFSET;
|
|
|
|
|
|
|
|
/* returns zero if e.g. not clocked */
|
|
|
|
revision = musb_readl(tibase, DAVINCI_USB_VERSION_REG);
|
|
|
|
if (revision == 0)
|
2009-04-01 03:30:04 +08:00
|
|
|
goto fail;
|
2008-07-24 17:27:36 +08:00
|
|
|
|
2017-10-24 18:08:35 +08:00
|
|
|
timer_setup(&musb->dev_timer, otg_timer, 0);
|
2008-07-24 17:27:36 +08:00
|
|
|
|
2010-12-01 19:22:05 +08:00
|
|
|
davinci_musb_source_power(musb, 0, 1);
|
2008-07-24 17:27:36 +08:00
|
|
|
|
2009-02-25 07:31:54 +08:00
|
|
|
/* dm355 EVM swaps D+/D- for signal integrity, and
|
|
|
|
* is clocked from the main 24 MHz crystal.
|
|
|
|
*/
|
|
|
|
if (machine_is_davinci_dm355_evm()) {
|
|
|
|
u32 phy_ctrl = __raw_readl(USB_PHY_CTRL);
|
|
|
|
|
|
|
|
phy_ctrl &= ~(3 << 9);
|
|
|
|
phy_ctrl |= USBPHY_DATAPOL;
|
|
|
|
__raw_writel(phy_ctrl, USB_PHY_CTRL);
|
|
|
|
}
|
|
|
|
|
2009-07-01 18:32:43 +08:00
|
|
|
/* On dm355, the default-A state machine needs DRVVBUS control.
|
|
|
|
* If we won't be a host, there's no need to turn it on.
|
|
|
|
*/
|
|
|
|
if (cpu_is_davinci_dm355()) {
|
|
|
|
u32 deepsleep = __raw_readl(DM355_DEEPSLEEP);
|
|
|
|
|
2011-11-24 21:46:26 +08:00
|
|
|
deepsleep &= ~DRVVBUS_FORCE;
|
2009-07-01 18:32:43 +08:00
|
|
|
__raw_writel(deepsleep, DM355_DEEPSLEEP);
|
|
|
|
}
|
|
|
|
|
2008-07-24 17:27:36 +08:00
|
|
|
/* reset the controller */
|
|
|
|
musb_writel(tibase, DAVINCI_USB_CTRL_REG, 0x1);
|
|
|
|
|
|
|
|
/* start the on-chip PHY and its PLL */
|
|
|
|
phy_on();
|
|
|
|
|
|
|
|
msleep(5);
|
|
|
|
|
|
|
|
/* NOTE: irqs are in mixed mode, not bypass to pure-musb */
|
|
|
|
pr_debug("DaVinci OTG revision %08x phy %03x control %02x\n",
|
2009-02-25 07:31:54 +08:00
|
|
|
revision, __raw_readl(USB_PHY_CTRL),
|
2008-07-24 17:27:36 +08:00
|
|
|
musb_readb(tibase, DAVINCI_USB_CTRL_REG));
|
|
|
|
|
2010-12-01 19:22:05 +08:00
|
|
|
musb->isr = davinci_musb_interrupt;
|
2008-07-24 17:27:36 +08:00
|
|
|
return 0;
|
2009-04-01 03:30:04 +08:00
|
|
|
|
|
|
|
fail:
|
2012-06-22 19:32:45 +08:00
|
|
|
usb_put_phy(musb->xceiv);
|
2012-04-16 23:03:10 +08:00
|
|
|
unregister:
|
2014-04-17 04:20:44 +08:00
|
|
|
usb_phy_generic_unregister();
|
2013-01-04 23:13:58 +08:00
|
|
|
return ret;
|
2008-07-24 17:27:36 +08:00
|
|
|
}
|
|
|
|
|
2010-12-01 19:22:05 +08:00
|
|
|
static int davinci_musb_exit(struct musb *musb)
|
2008-07-24 17:27:36 +08:00
|
|
|
{
|
2018-05-21 21:42:18 +08:00
|
|
|
int maxdelay = 30;
|
|
|
|
u8 devctl, warn = 0;
|
|
|
|
|
2017-10-24 18:08:35 +08:00
|
|
|
del_timer_sync(&musb->dev_timer);
|
2008-07-24 17:27:36 +08:00
|
|
|
|
2009-07-01 18:32:43 +08:00
|
|
|
/* force VBUS off */
|
|
|
|
if (cpu_is_davinci_dm355()) {
|
|
|
|
u32 deepsleep = __raw_readl(DM355_DEEPSLEEP);
|
|
|
|
|
|
|
|
deepsleep &= ~DRVVBUS_FORCE;
|
|
|
|
deepsleep |= DRVVBUS_OVERRIDE;
|
|
|
|
__raw_writel(deepsleep, DM355_DEEPSLEEP);
|
|
|
|
}
|
|
|
|
|
2010-12-01 19:22:05 +08:00
|
|
|
davinci_musb_source_power(musb, 0 /*off*/, 1);
|
2008-07-24 17:27:36 +08:00
|
|
|
|
2018-05-21 21:42:18 +08:00
|
|
|
/*
|
|
|
|
* delay, to avoid problems with module reload.
|
|
|
|
* if there's no peripheral connected, this can take a
|
|
|
|
* long time to fall, especially on EVM with huge C133.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
|
|
|
|
if (!(devctl & MUSB_DEVCTL_VBUS))
|
|
|
|
break;
|
|
|
|
if ((devctl & MUSB_DEVCTL_VBUS) != warn) {
|
|
|
|
warn = devctl & MUSB_DEVCTL_VBUS;
|
|
|
|
dev_dbg(musb->controller, "VBUS %d\n",
|
|
|
|
warn >> MUSB_DEVCTL_VBUS_SHIFT);
|
|
|
|
}
|
|
|
|
msleep(1000);
|
|
|
|
maxdelay--;
|
|
|
|
} while (maxdelay > 0);
|
2008-07-24 17:27:36 +08:00
|
|
|
|
2018-05-21 21:42:18 +08:00
|
|
|
/* in OTG mode, another host might be connected */
|
|
|
|
if (devctl & MUSB_DEVCTL_VBUS)
|
|
|
|
dev_dbg(musb->controller, "VBUS off timeout (devctl %02x)\n", devctl);
|
2008-07-24 17:27:36 +08:00
|
|
|
|
|
|
|
phy_off();
|
2009-02-21 05:45:17 +08:00
|
|
|
|
2012-06-22 19:32:45 +08:00
|
|
|
usb_put_phy(musb->xceiv);
|
2009-04-01 03:30:04 +08:00
|
|
|
|
2008-07-24 17:27:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2010-12-01 19:22:05 +08:00
|
|
|
|
2010-12-02 15:48:58 +08:00
|
|
|
static const struct musb_platform_ops davinci_ops = {
|
2015-05-02 03:29:27 +08:00
|
|
|
.quirks = MUSB_DMA_CPPI,
|
2010-12-01 19:22:05 +08:00
|
|
|
.init = davinci_musb_init,
|
|
|
|
.exit = davinci_musb_exit,
|
|
|
|
|
2015-05-02 03:29:28 +08:00
|
|
|
#ifdef CONFIG_USB_TI_CPPI_DMA
|
|
|
|
.dma_init = cppi_dma_controller_create,
|
|
|
|
.dma_exit = cppi_dma_controller_destroy,
|
|
|
|
#endif
|
2010-12-01 19:22:05 +08:00
|
|
|
.enable = davinci_musb_enable,
|
|
|
|
.disable = davinci_musb_disable,
|
|
|
|
|
|
|
|
.set_mode = davinci_musb_set_mode,
|
|
|
|
|
|
|
|
.set_vbus = davinci_musb_set_vbus,
|
|
|
|
};
|
2010-12-02 15:16:55 +08:00
|
|
|
|
2013-09-20 07:14:38 +08:00
|
|
|
static const struct platform_device_info davinci_dev_info = {
|
|
|
|
.name = "musb-hdrc",
|
|
|
|
.id = PLATFORM_DEVID_AUTO,
|
|
|
|
.dma_mask = DMA_BIT_MASK(32),
|
|
|
|
};
|
2010-12-02 15:16:55 +08:00
|
|
|
|
2012-11-20 02:21:48 +08:00
|
|
|
static int davinci_probe(struct platform_device *pdev)
|
2010-12-02 15:16:55 +08:00
|
|
|
{
|
2013-09-22 05:43:58 +08:00
|
|
|
struct resource musb_resources[3];
|
2013-07-30 16:03:12 +08:00
|
|
|
struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2010-12-02 15:16:55 +08:00
|
|
|
struct platform_device *musb;
|
2010-12-02 15:38:12 +08:00
|
|
|
struct davinci_glue *glue;
|
2013-09-20 07:14:38 +08:00
|
|
|
struct platform_device_info pinfo;
|
2010-12-02 15:57:08 +08:00
|
|
|
struct clk *clk;
|
2010-12-02 15:16:55 +08:00
|
|
|
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
|
usb: musb: davinci: use devm_ functions.
This patch moves data allocated using kzalloc to managed data allocated
using devm_kzalloc and cleans now unnecessary kfrees in probe and remove
functions. Also, a label is done away with and clk_get is replaced by it
corresponding devm version and the clk_puts are done away with. The
labels are renamed to make them ordered.
The following Coccinelle semantic patch was used for making the change:
@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};
@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
<+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
?-kfree(e);
...+>
}
@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
<...
- kfree(e);
...>
}
Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2014-06-03 00:26:01 +08:00
|
|
|
glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
|
2014-10-14 15:56:06 +08:00
|
|
|
if (!glue)
|
2010-12-02 15:38:12 +08:00
|
|
|
goto err0;
|
|
|
|
|
usb: musb: davinci: use devm_ functions.
This patch moves data allocated using kzalloc to managed data allocated
using devm_kzalloc and cleans now unnecessary kfrees in probe and remove
functions. Also, a label is done away with and clk_get is replaced by it
corresponding devm version and the clk_puts are done away with. The
labels are renamed to make them ordered.
The following Coccinelle semantic patch was used for making the change:
@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};
@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
<+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
?-kfree(e);
...+>
}
@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
<...
- kfree(e);
...>
}
Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2014-06-03 00:26:01 +08:00
|
|
|
clk = devm_clk_get(&pdev->dev, "usb");
|
2010-12-02 15:57:08 +08:00
|
|
|
if (IS_ERR(clk)) {
|
|
|
|
dev_err(&pdev->dev, "failed to get clock\n");
|
|
|
|
ret = PTR_ERR(clk);
|
usb: musb: davinci: use devm_ functions.
This patch moves data allocated using kzalloc to managed data allocated
using devm_kzalloc and cleans now unnecessary kfrees in probe and remove
functions. Also, a label is done away with and clk_get is replaced by it
corresponding devm version and the clk_puts are done away with. The
labels are renamed to make them ordered.
The following Coccinelle semantic patch was used for making the change:
@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};
@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
<+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
?-kfree(e);
...+>
}
@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
<...
- kfree(e);
...>
}
Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2014-06-03 00:26:01 +08:00
|
|
|
goto err0;
|
2010-12-02 15:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = clk_enable(clk);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "failed to enable clock\n");
|
usb: musb: davinci: use devm_ functions.
This patch moves data allocated using kzalloc to managed data allocated
using devm_kzalloc and cleans now unnecessary kfrees in probe and remove
functions. Also, a label is done away with and clk_get is replaced by it
corresponding devm version and the clk_puts are done away with. The
labels are renamed to make them ordered.
The following Coccinelle semantic patch was used for making the change:
@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};
@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
<+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
?-kfree(e);
...+>
}
@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
<...
- kfree(e);
...>
}
Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2014-06-03 00:26:01 +08:00
|
|
|
goto err0;
|
2010-12-02 15:57:08 +08:00
|
|
|
}
|
|
|
|
|
2010-12-02 15:38:12 +08:00
|
|
|
glue->dev = &pdev->dev;
|
2010-12-02 15:57:08 +08:00
|
|
|
glue->clk = clk;
|
2010-12-02 15:38:12 +08:00
|
|
|
|
2010-12-02 15:48:58 +08:00
|
|
|
pdata->platform_ops = &davinci_ops;
|
|
|
|
|
2014-04-17 05:05:17 +08:00
|
|
|
usb_phy_generic_register();
|
2010-12-02 15:38:12 +08:00
|
|
|
platform_set_drvdata(pdev, glue);
|
2010-12-02 15:16:55 +08:00
|
|
|
|
2013-04-24 22:21:42 +08:00
|
|
|
memset(musb_resources, 0x00, sizeof(*musb_resources) *
|
|
|
|
ARRAY_SIZE(musb_resources));
|
|
|
|
|
|
|
|
musb_resources[0].name = pdev->resource[0].name;
|
|
|
|
musb_resources[0].start = pdev->resource[0].start;
|
|
|
|
musb_resources[0].end = pdev->resource[0].end;
|
|
|
|
musb_resources[0].flags = pdev->resource[0].flags;
|
|
|
|
|
|
|
|
musb_resources[1].name = pdev->resource[1].name;
|
|
|
|
musb_resources[1].start = pdev->resource[1].start;
|
|
|
|
musb_resources[1].end = pdev->resource[1].end;
|
|
|
|
musb_resources[1].flags = pdev->resource[1].flags;
|
2013-09-22 05:43:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For DM6467 3 resources are passed. A placeholder for the 3rd
|
|
|
|
* resource is always there, so it's safe to always copy it...
|
|
|
|
*/
|
|
|
|
musb_resources[2].name = pdev->resource[2].name;
|
|
|
|
musb_resources[2].start = pdev->resource[2].start;
|
|
|
|
musb_resources[2].end = pdev->resource[2].end;
|
|
|
|
musb_resources[2].flags = pdev->resource[2].flags;
|
2013-04-24 22:21:42 +08:00
|
|
|
|
2013-09-20 07:14:38 +08:00
|
|
|
pinfo = davinci_dev_info;
|
|
|
|
pinfo.parent = &pdev->dev;
|
|
|
|
pinfo.res = musb_resources;
|
|
|
|
pinfo.num_res = ARRAY_SIZE(musb_resources);
|
|
|
|
pinfo.data = pdata;
|
|
|
|
pinfo.size_data = sizeof(*pdata);
|
|
|
|
|
|
|
|
glue->musb = musb = platform_device_register_full(&pinfo);
|
|
|
|
if (IS_ERR(musb)) {
|
|
|
|
ret = PTR_ERR(musb);
|
|
|
|
dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
|
usb: musb: davinci: use devm_ functions.
This patch moves data allocated using kzalloc to managed data allocated
using devm_kzalloc and cleans now unnecessary kfrees in probe and remove
functions. Also, a label is done away with and clk_get is replaced by it
corresponding devm version and the clk_puts are done away with. The
labels are renamed to make them ordered.
The following Coccinelle semantic patch was used for making the change:
@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};
@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
<+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
?-kfree(e);
...+>
}
@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
<...
- kfree(e);
...>
}
Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2014-06-03 00:26:01 +08:00
|
|
|
goto err1;
|
2010-12-02 15:16:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
usb: musb: davinci: use devm_ functions.
This patch moves data allocated using kzalloc to managed data allocated
using devm_kzalloc and cleans now unnecessary kfrees in probe and remove
functions. Also, a label is done away with and clk_get is replaced by it
corresponding devm version and the clk_puts are done away with. The
labels are renamed to make them ordered.
The following Coccinelle semantic patch was used for making the change:
@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};
@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
<+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
?-kfree(e);
...+>
}
@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
<...
- kfree(e);
...>
}
Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2014-06-03 00:26:01 +08:00
|
|
|
err1:
|
2010-12-02 15:57:08 +08:00
|
|
|
clk_disable(clk);
|
|
|
|
|
2010-12-02 15:16:55 +08:00
|
|
|
err0:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-20 02:26:20 +08:00
|
|
|
static int davinci_remove(struct platform_device *pdev)
|
2010-12-02 15:16:55 +08:00
|
|
|
{
|
2010-12-02 15:38:12 +08:00
|
|
|
struct davinci_glue *glue = platform_get_drvdata(pdev);
|
2010-12-02 15:16:55 +08:00
|
|
|
|
2012-10-23 13:35:46 +08:00
|
|
|
platform_device_unregister(glue->musb);
|
2014-04-17 05:05:17 +08:00
|
|
|
usb_phy_generic_unregister();
|
2010-12-02 15:57:08 +08:00
|
|
|
clk_disable(glue->clk);
|
2010-12-02 15:16:55 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver davinci_driver = {
|
2012-01-26 18:40:23 +08:00
|
|
|
.probe = davinci_probe,
|
2012-11-20 02:21:08 +08:00
|
|
|
.remove = davinci_remove,
|
2010-12-02 15:16:55 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "musb-davinci",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("DaVinci MUSB Glue Layer");
|
|
|
|
MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
2012-10-11 02:37:07 +08:00
|
|
|
module_platform_driver(davinci_driver);
|