2017-11-03 13:28:30 +03:00
// SPDX-License-Identifier: GPL-2.0
2010-09-24 14:44:03 +04:00
/*
* Texas Instruments DA8xx / OMAP - L1x " glue layer "
*
* Copyright ( c ) 2008 - 2009 MontaVista Software , Inc . < source @ mvista . com >
*
* Based on the DaVinci " glue layer " code .
* Copyright ( C ) 2005 - 2006 by Texas Instruments
*
2016-11-21 17:59:29 +03:00
* DT support
* Copyright ( c ) 2016 Petr Kulhavy < petr @ barix . com >
*
2010-09-24 14:44:03 +04:00
* This file is part of the Inventra Controller Driver for Linux .
*/
2011-11-10 11:58:04 +04:00
# include <linux/module.h>
2010-09-24 14:44:03 +04:00
# include <linux/clk.h>
2012-06-26 16:10:32 +04:00
# include <linux/err.h>
2010-09-24 14:44:03 +04:00
# include <linux/io.h>
2017-04-17 07:21:17 +03:00
# include <linux/of_platform.h>
2016-09-13 05:48:34 +03:00
# include <linux/phy/phy.h>
2010-12-02 10:19:35 +03:00
# include <linux/platform_device.h>
# include <linux/dma-mapping.h>
2014-04-17 00:28:32 +04:00
# include <linux/usb/usb_phy_generic.h>
2010-09-24 14:44:03 +04:00
# include "musb_core.h"
/*
* DA8XX specific definitions
*/
/* USB 2.0 OTG module registers */
# define DA8XX_USB_REVISION_REG 0x00
# define DA8XX_USB_CTRL_REG 0x04
# define DA8XX_USB_STAT_REG 0x08
# define DA8XX_USB_EMULATION_REG 0x0c
# define DA8XX_USB_SRP_FIX_TIME_REG 0x18
# define DA8XX_USB_INTR_SRC_REG 0x20
# define DA8XX_USB_INTR_SRC_SET_REG 0x24
# define DA8XX_USB_INTR_SRC_CLEAR_REG 0x28
# define DA8XX_USB_INTR_MASK_REG 0x2c
# define DA8XX_USB_INTR_MASK_SET_REG 0x30
# define DA8XX_USB_INTR_MASK_CLEAR_REG 0x34
# define DA8XX_USB_INTR_SRC_MASKED_REG 0x38
# define DA8XX_USB_END_OF_INTR_REG 0x3c
# define DA8XX_USB_GENERIC_RNDIS_EP_SIZE_REG(n) (0x50 + (((n) - 1) << 2))
/* Control register bits */
# define DA8XX_SOFT_RESET_MASK 1
# define DA8XX_USB_TX_EP_MASK 0x1f /* EP0 + 4 Tx EPs */
# define DA8XX_USB_RX_EP_MASK 0x1e /* 4 Rx EPs */
/* USB interrupt register bits */
# define DA8XX_INTR_USB_SHIFT 16
# define DA8XX_INTR_USB_MASK (0x1ff << DA8XX_INTR_USB_SHIFT) /* 8 Mentor */
/* interrupts and DRVVBUS interrupt */
# define DA8XX_INTR_DRVVBUS 0x100
# define DA8XX_INTR_RX_SHIFT 8
# define DA8XX_INTR_RX_MASK (DA8XX_USB_RX_EP_MASK << DA8XX_INTR_RX_SHIFT)
# define DA8XX_INTR_TX_SHIFT 0
# define DA8XX_INTR_TX_MASK (DA8XX_USB_TX_EP_MASK << DA8XX_INTR_TX_SHIFT)
# define DA8XX_MENTOR_CORE_OFFSET 0x400
2010-12-02 10:40:34 +03:00
struct da8xx_glue {
struct device * dev ;
struct platform_device * musb ;
2016-09-13 05:48:34 +03:00
struct platform_device * usb_phy ;
2010-12-02 10:57:08 +03:00
struct clk * clk ;
2016-09-13 05:48:34 +03:00
struct phy * phy ;
2010-12-02 10:40:34 +03:00
} ;
2010-09-24 14:44:03 +04:00
/*
* Because we don ' t set CTRL . UINT , it ' s " important " to :
* - not read / write INTRUSB / INTRUSBE ( except during
* initial setup , as a workaround ) ;
* - use INTSET / INTCLR instead .
*/
/**
2010-12-01 14:22:05 +03:00
* da8xx_musb_enable - enable interrupts
2010-09-24 14:44:03 +04:00
*/
2010-12-01 14:22:05 +03:00
static void da8xx_musb_enable ( struct musb * musb )
2010-09-24 14:44:03 +04:00
{
void __iomem * reg_base = musb - > ctrl_base ;
u32 mask ;
/* Workaround: setup IRQs through both register sets. */
mask = ( ( musb - > epmask & DA8XX_USB_TX_EP_MASK ) < < DA8XX_INTR_TX_SHIFT ) |
( ( musb - > epmask & DA8XX_USB_RX_EP_MASK ) < < DA8XX_INTR_RX_SHIFT ) |
DA8XX_INTR_USB_MASK ;
musb_writel ( reg_base , DA8XX_USB_INTR_MASK_SET_REG , mask ) ;
/* Force the DRVVBUS IRQ so we can start polling for ID change. */
2011-11-24 17:46:26 +04:00
musb_writel ( reg_base , DA8XX_USB_INTR_SRC_SET_REG ,
DA8XX_INTR_DRVVBUS < < DA8XX_INTR_USB_SHIFT ) ;
2010-09-24 14:44:03 +04:00
}
/**
2010-12-01 14:22:05 +03:00
* da8xx_musb_disable - disable HDRC and flush interrupts
2010-09-24 14:44:03 +04:00
*/
2010-12-01 14:22:05 +03:00
static void da8xx_musb_disable ( struct musb * musb )
2010-09-24 14:44:03 +04:00
{
void __iomem * reg_base = musb - > ctrl_base ;
musb_writel ( reg_base , DA8XX_USB_INTR_MASK_CLEAR_REG ,
DA8XX_INTR_USB_MASK |
DA8XX_INTR_TX_MASK | DA8XX_INTR_RX_MASK ) ;
musb_writel ( reg_base , DA8XX_USB_END_OF_INTR_REG , 0 ) ;
}
2011-06-22 18:28:09 +04:00
# define portstate(stmt) stmt
2010-09-24 14:44:03 +04:00
2010-12-01 14:22:05 +03:00
static void da8xx_musb_set_vbus ( struct musb * musb , int is_on )
2010-09-24 14:44:03 +04:00
{
WARN_ON ( is_on & & is_peripheral_active ( musb ) ) ;
}
# define POLL_SECONDS 2
2017-10-24 13:08:35 +03:00
static void otg_timer ( struct timer_list * t )
2010-09-24 14:44:03 +04:00
{
2017-10-24 13:08:35 +03:00
struct musb * musb = from_timer ( musb , t , dev_timer ) ;
2010-09-24 14:44:03 +04: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 13:44:08 +04:00
dev_dbg ( musb - > controller , " Poll devctl %02x (%s) \n " , devctl ,
2014-10-30 20:41:13 +03:00
usb_otg_state_string ( musb - > xceiv - > otg - > state ) ) ;
2010-09-24 14:44:03 +04:00
spin_lock_irqsave ( & musb - > lock , flags ) ;
2014-10-30 20:41:13 +03:00
switch ( musb - > xceiv - > otg - > state ) {
2010-09-24 14:44:03 +04:00
case OTG_STATE_A_WAIT_BCON :
devctl & = ~ MUSB_DEVCTL_SESSION ;
musb_writeb ( musb - > mregs , MUSB_DEVCTL , devctl ) ;
devctl = musb_readb ( musb - > mregs , MUSB_DEVCTL ) ;
if ( devctl & MUSB_DEVCTL_BDEVICE ) {
2014-10-30 20:41:13 +03:00
musb - > xceiv - > otg - > state = OTG_STATE_B_IDLE ;
2010-09-24 14:44:03 +04:00
MUSB_DEV_MODE ( musb ) ;
} else {
2014-10-30 20:41:13 +03:00
musb - > xceiv - > otg - > state = OTG_STATE_A_IDLE ;
2010-09-24 14:44:03 +04:00
MUSB_HST_MODE ( musb ) ;
}
break ;
case OTG_STATE_A_WAIT_VFALL :
/*
* Wait till VBUS falls below SessionEnd ( ~ 0.2 V ) ; 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 13:08:35 +03:00
mod_timer ( & musb - > dev_timer , jiffies + POLL_SECONDS * HZ ) ;
2010-09-24 14:44:03 +04:00
break ;
}
2014-10-30 20:41:13 +03:00
musb - > xceiv - > otg - > state = OTG_STATE_A_WAIT_VRISE ;
2010-09-24 14:44:03 +04:00
musb_writel ( musb - > ctrl_base , DA8XX_USB_INTR_SRC_SET_REG ,
MUSB_INTR_VBUSERROR < < DA8XX_INTR_USB_SHIFT ) ;
break ;
case OTG_STATE_B_IDLE :
/*
* There ' s no ID - changed IRQ , so we have no good way to tell
* when to switch to the A - Default state machine ( by setting
* the DEVCTL . Session bit ) .
*
* 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 13:08:35 +03:00
mod_timer ( & musb - > dev_timer , jiffies + POLL_SECONDS * HZ ) ;
2010-09-24 14:44:03 +04:00
else
2014-10-30 20:41:13 +03:00
musb - > xceiv - > otg - > state = OTG_STATE_A_IDLE ;
2010-09-24 14:44:03 +04:00
break ;
default :
break ;
}
spin_unlock_irqrestore ( & musb - > lock , flags ) ;
}
2010-12-01 14:22:05 +03:00
static void da8xx_musb_try_idle ( struct musb * musb , unsigned long timeout )
2010-09-24 14:44:03 +04:00
{
static unsigned long last_timer ;
if ( timeout = = 0 )
timeout = jiffies + msecs_to_jiffies ( 3 ) ;
/* Never idle if active, or when VBUS timeout is not set as host */
if ( musb - > is_active | | ( musb - > a_wait_bcon = = 0 & &
2014-10-30 20:41:13 +03:00
musb - > xceiv - > otg - > state = = OTG_STATE_A_WAIT_BCON ) ) {
2011-05-11 13:44:08 +04:00
dev_dbg ( musb - > controller , " %s active, deleting timer \n " ,
2014-10-30 20:41:13 +03:00
usb_otg_state_string ( musb - > xceiv - > otg - > state ) ) ;
2017-10-24 13:08:35 +03:00
del_timer ( & musb - > dev_timer ) ;
2010-09-24 14:44:03 +04:00
last_timer = jiffies ;
return ;
}
2017-10-24 13:08:35 +03:00
if ( time_after ( last_timer , timeout ) & & timer_pending ( & musb - > dev_timer ) ) {
2011-05-11 13:44:08 +04:00
dev_dbg ( musb - > controller , " Longer idle timer already pending, ignoring... \n " ) ;
2010-09-24 14:44:03 +04:00
return ;
}
last_timer = timeout ;
2011-05-11 13:44:08 +04:00
dev_dbg ( musb - > controller , " %s inactive, starting idle timer for %u ms \n " ,
2014-10-30 20:41:13 +03:00
usb_otg_state_string ( musb - > xceiv - > otg - > state ) ,
2011-05-05 14:11:21 +04:00
jiffies_to_msecs ( timeout - jiffies ) ) ;
2017-10-24 13:08:35 +03:00
mod_timer ( & musb - > dev_timer , timeout ) ;
2010-09-24 14:44:03 +04:00
}
2010-12-01 14:22:05 +03:00
static irqreturn_t da8xx_musb_interrupt ( int irq , void * hci )
2010-09-24 14:44:03 +04:00
{
struct musb * musb = hci ;
void __iomem * reg_base = musb - > ctrl_base ;
unsigned long flags ;
irqreturn_t ret = IRQ_NONE ;
u32 status ;
spin_lock_irqsave ( & musb - > lock , flags ) ;
/*
* NOTE : DA8XX shadows the Mentor IRQs . Don ' t manage them through
* the Mentor registers ( except for setup ) , use the TI ones and EOI .
*/
/* Acknowledge and handle non-CPPI interrupts */
status = musb_readl ( reg_base , DA8XX_USB_INTR_SRC_MASKED_REG ) ;
if ( ! status )
goto eoi ;
musb_writel ( reg_base , DA8XX_USB_INTR_SRC_CLEAR_REG , status ) ;
2011-05-11 13:44:08 +04:00
dev_dbg ( musb - > controller , " USB IRQ %08x \n " , status ) ;
2010-09-24 14:44:03 +04:00
musb - > int_rx = ( status & DA8XX_INTR_RX_MASK ) > > DA8XX_INTR_RX_SHIFT ;
musb - > int_tx = ( status & DA8XX_INTR_TX_MASK ) > > DA8XX_INTR_TX_SHIFT ;
musb - > int_usb = ( status & DA8XX_INTR_USB_MASK ) > > DA8XX_INTR_USB_SHIFT ;
/*
* DRVVBUS IRQs are the only proxy we have ( a very poor one ! ) for
* DA8xx ' 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 that we know its
* value but DEVCTL . BDevice is invalid without DEVCTL . Session set .
* Also , DRVVBUS pulses for SRP ( but not at 5 V ) . . .
*/
if ( status & ( DA8XX_INTR_DRVVBUS < < DA8XX_INTR_USB_SHIFT ) ) {
int drvvbus = musb_readl ( reg_base , DA8XX_USB_STAT_REG ) ;
void __iomem * mregs = musb - > mregs ;
u8 devctl = musb_readb ( mregs , MUSB_DEVCTL ) ;
int err ;
2013-03-14 13:18:29 +04:00
err = musb - > int_usb & MUSB_INTR_VBUSERROR ;
2010-09-24 14:44:03 +04: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 for VBUS to stop registering in
* devctl .
*/
musb - > int_usb & = ~ MUSB_INTR_VBUSERROR ;
2014-10-30 20:41:13 +03:00
musb - > xceiv - > otg - > state = OTG_STATE_A_WAIT_VFALL ;
2017-10-24 13:08:35 +03:00
mod_timer ( & musb - > dev_timer , jiffies + POLL_SECONDS * HZ ) ;
2010-09-24 14:44:03 +04:00
WARNING ( " VBUS error workaround (delay coming) \n " ) ;
2011-11-24 17:46:26 +04:00
} else if ( drvvbus ) {
2010-09-24 14:44:03 +04:00
MUSB_HST_MODE ( musb ) ;
2014-10-30 20:41:13 +03:00
musb - > xceiv - > otg - > state = OTG_STATE_A_WAIT_VRISE ;
2010-09-24 14:44:03 +04:00
portstate ( musb - > port1_status | = USB_PORT_STAT_POWER ) ;
2017-10-24 13:08:35 +03:00
del_timer ( & musb - > dev_timer ) ;
2017-12-05 17:45:30 +03:00
} else if ( ! ( musb - > int_usb & MUSB_INTR_BABBLE ) ) {
/*
* When babble condition happens , drvvbus interrupt
* is also generated . Ignore this drvvbus interrupt
* and let babble interrupt handler recovers the
* controller ; otherwise , the host - mode flag is lost
* due to the MUSB_DEV_MODE ( ) call below and babble
* recovery logic will not be called .
*/
2010-09-24 14:44:03 +04:00
musb - > is_active = 0 ;
MUSB_DEV_MODE ( musb ) ;
2014-10-30 20:41:13 +03:00
musb - > xceiv - > otg - > state = OTG_STATE_B_IDLE ;
2010-09-24 14:44:03 +04:00
portstate ( musb - > port1_status & = ~ USB_PORT_STAT_POWER ) ;
}
2011-05-11 13:44:08 +04:00
dev_dbg ( musb - > controller , " VBUS %s (%s)%s, devctl %02x \n " ,
2010-09-24 14:44:03 +04:00
drvvbus ? " on " : " off " ,
2014-10-30 20:41:13 +03:00
usb_otg_state_string ( musb - > xceiv - > otg - > state ) ,
2010-09-24 14:44:03 +04:00
err ? " ERROR " : " " ,
devctl ) ;
ret = IRQ_HANDLED ;
}
if ( musb - > int_tx | | musb - > int_rx | | musb - > int_usb )
ret | = musb_interrupt ( musb ) ;
eoi :
/* EOI needs to be written for the IRQ to be re-asserted. */
if ( ret = = IRQ_HANDLED | | status )
musb_writel ( reg_base , DA8XX_USB_END_OF_INTR_REG , 0 ) ;
/* Poll for ID change */
2014-10-30 20:41:13 +03:00
if ( musb - > xceiv - > otg - > state = = OTG_STATE_B_IDLE )
2017-10-24 13:08:35 +03:00
mod_timer ( & musb - > dev_timer , jiffies + POLL_SECONDS * HZ ) ;
2010-09-24 14:44:03 +04:00
spin_unlock_irqrestore ( & musb - > lock , flags ) ;
return ret ;
}
2010-12-01 14:22:05 +03:00
static int da8xx_musb_set_mode ( struct musb * musb , u8 musb_mode )
2010-09-24 14:44:03 +04:00
{
2016-09-13 05:48:34 +03:00
struct da8xx_glue * glue = dev_get_drvdata ( musb - > controller - > parent ) ;
enum phy_mode phy_mode ;
2010-09-24 14:44:03 +04:00
2016-11-21 17:59:31 +03:00
/*
* The PHY has some issues when it is forced in device or host mode .
* Unless the user request another mode , configure the PHY in OTG mode .
*/
if ( ! musb - > is_initialized )
return phy_set_mode ( glue - > phy , PHY_MODE_USB_OTG ) ;
2010-09-24 14:44:03 +04:00
switch ( musb_mode ) {
case MUSB_HOST : /* Force VBUS valid, ID = 0 */
2016-09-13 05:48:34 +03:00
phy_mode = PHY_MODE_USB_HOST ;
2010-09-24 14:44:03 +04:00
break ;
case MUSB_PERIPHERAL : /* Force VBUS valid, ID = 1 */
2016-09-13 05:48:34 +03:00
phy_mode = PHY_MODE_USB_DEVICE ;
2010-09-24 14:44:03 +04:00
break ;
case MUSB_OTG : /* Don't override the VBUS/ID comparators */
2016-09-13 05:48:34 +03:00
phy_mode = PHY_MODE_USB_OTG ;
2010-09-24 14:44:03 +04:00
break ;
default :
2016-09-13 05:48:34 +03:00
return - EINVAL ;
2010-09-24 14:44:03 +04:00
}
2016-09-13 05:48:34 +03:00
return phy_set_mode ( glue - > phy , phy_mode ) ;
2010-09-24 14:44:03 +04:00
}
2010-12-01 14:22:05 +03:00
static int da8xx_musb_init ( struct musb * musb )
2010-09-24 14:44:03 +04:00
{
2016-09-13 05:48:34 +03:00
struct da8xx_glue * glue = dev_get_drvdata ( musb - > controller - > parent ) ;
2010-09-24 14:44:03 +04:00
void __iomem * reg_base = musb - > ctrl_base ;
u32 rev ;
2013-01-04 19:13:58 +04:00
int ret = - ENODEV ;
2010-09-24 14:44:03 +04:00
musb - > mregs + = DA8XX_MENTOR_CORE_OFFSET ;
2016-11-21 17:59:30 +03:00
ret = clk_prepare_enable ( glue - > clk ) ;
if ( ret ) {
dev_err ( glue - > dev , " failed to enable clock \n " ) ;
return ret ;
}
2010-09-24 14:44:03 +04:00
/* Returns zero if e.g. not clocked */
rev = musb_readl ( reg_base , DA8XX_USB_REVISION_REG ) ;
if ( ! rev )
goto fail ;
2012-06-22 15:32:46 +04:00
musb - > xceiv = usb_get_phy ( USB_PHY_TYPE_USB2 ) ;
2013-01-04 19:13:58 +04:00
if ( IS_ERR_OR_NULL ( musb - > xceiv ) ) {
ret = - EPROBE_DEFER ;
2010-09-24 14:44:03 +04:00
goto fail ;
2013-01-04 19:13:58 +04:00
}
2010-09-24 14:44:03 +04:00
2017-10-24 13:08:35 +03:00
timer_setup ( & musb - > dev_timer , otg_timer , 0 ) ;
2010-09-24 14:44:03 +04:00
/* Reset the controller */
musb_writel ( reg_base , DA8XX_USB_CTRL_REG , DA8XX_SOFT_RESET_MASK ) ;
/* Start the on-chip PHY and its PLL. */
2016-09-13 05:48:34 +03:00
ret = phy_init ( glue - > phy ) ;
if ( ret ) {
dev_err ( glue - > dev , " Failed to init phy. \n " ) ;
2016-11-21 17:59:30 +03:00
goto fail ;
2016-09-13 05:48:34 +03:00
}
ret = phy_power_on ( glue - > phy ) ;
if ( ret ) {
dev_err ( glue - > dev , " Failed to power on phy. \n " ) ;
goto err_phy_power_on ;
}
2010-09-24 14:44:03 +04:00
msleep ( 5 ) ;
/* NOTE: IRQs are in mixed mode, not bypass to pure MUSB */
2016-09-13 05:48:34 +03:00
pr_debug ( " DA8xx OTG revision %08x, control %02x \n " , rev ,
2010-09-24 14:44:03 +04:00
musb_readb ( reg_base , DA8XX_USB_CTRL_REG ) ) ;
2010-12-01 14:22:05 +03:00
musb - > isr = da8xx_musb_interrupt ;
2010-09-24 14:44:03 +04:00
return 0 ;
2016-09-13 05:48:34 +03:00
err_phy_power_on :
phy_exit ( glue - > phy ) ;
2010-09-24 14:44:03 +04:00
fail :
2016-11-21 17:59:30 +03:00
clk_disable_unprepare ( glue - > clk ) ;
2013-01-04 19:13:58 +04:00
return ret ;
2010-09-24 14:44:03 +04:00
}
2010-12-01 14:22:05 +03:00
static int da8xx_musb_exit ( struct musb * musb )
2010-09-24 14:44:03 +04:00
{
2016-09-13 05:48:34 +03:00
struct da8xx_glue * glue = dev_get_drvdata ( musb - > controller - > parent ) ;
2017-10-24 13:08:35 +03:00
del_timer_sync ( & musb - > dev_timer ) ;
2010-09-24 14:44:03 +04:00
2016-09-13 05:48:34 +03:00
phy_power_off ( glue - > phy ) ;
phy_exit ( glue - > phy ) ;
clk_disable_unprepare ( glue - > clk ) ;
2010-09-24 14:44:03 +04:00
2012-06-22 15:32:45 +04:00
usb_put_phy ( musb - > xceiv ) ;
2010-09-24 14:44:03 +04:00
return 0 ;
}
2010-12-01 14:22:05 +03:00
2016-11-21 17:59:29 +03:00
static inline u8 get_vbus_power ( struct device * dev )
{
struct regulator * vbus_supply ;
int current_uA ;
vbus_supply = regulator_get_optional ( dev , " vbus " ) ;
if ( IS_ERR ( vbus_supply ) )
return 255 ;
current_uA = regulator_get_current_limit ( vbus_supply ) ;
regulator_put ( vbus_supply ) ;
if ( current_uA < = 0 | | current_uA > 510000 )
return 255 ;
return current_uA / 1000 / 2 ;
}
2017-04-17 07:21:17 +03:00
# ifdef CONFIG_USB_TI_CPPI41_DMA
static void da8xx_dma_controller_callback ( struct dma_controller * c )
{
struct musb * musb = c - > musb ;
void __iomem * reg_base = musb - > ctrl_base ;
musb_writel ( reg_base , DA8XX_USB_END_OF_INTR_REG , 0 ) ;
}
static struct dma_controller *
da8xx_dma_controller_create ( struct musb * musb , void __iomem * base )
{
struct dma_controller * controller ;
controller = cppi41_dma_controller_create ( musb , base ) ;
if ( IS_ERR_OR_NULL ( controller ) )
return controller ;
controller - > dma_callback = da8xx_dma_controller_callback ;
return controller ;
}
# endif
2010-12-02 10:48:58 +03:00
static const struct musb_platform_ops da8xx_ops = {
2017-04-17 07:21:17 +03:00
. quirks = MUSB_INDEXED_EP | MUSB_PRESERVE_SESSION |
2017-04-17 07:21:18 +03:00
MUSB_DMA_CPPI41 | MUSB_DA8XX ,
2010-12-01 14:22:05 +03:00
. init = da8xx_musb_init ,
. exit = da8xx_musb_exit ,
2014-11-24 22:05:04 +03:00
. fifo_mode = 2 ,
2017-04-17 07:21:17 +03:00
# ifdef CONFIG_USB_TI_CPPI41_DMA
. dma_init = da8xx_dma_controller_create ,
. dma_exit = cppi41_dma_controller_destroy ,
# endif
2010-12-01 14:22:05 +03:00
. enable = da8xx_musb_enable ,
. disable = da8xx_musb_disable ,
. set_mode = da8xx_musb_set_mode ,
. try_idle = da8xx_musb_try_idle ,
. set_vbus = da8xx_musb_set_vbus ,
} ;
2010-12-02 10:19:35 +03:00
2013-09-20 03:14:38 +04:00
static const struct platform_device_info da8xx_dev_info = {
. name = " musb-hdrc " ,
. id = PLATFORM_DEVID_AUTO ,
. dma_mask = DMA_BIT_MASK ( 32 ) ,
} ;
2010-12-02 10:19:35 +03:00
2016-11-21 17:59:29 +03:00
static const struct musb_hdrc_config da8xx_config = {
. ram_bits = 10 ,
. num_eps = 5 ,
. multipoint = 1 ,
} ;
2017-04-25 23:04:53 +03:00
static struct of_dev_auxdata da8xx_auxdata_lookup [ ] = {
2017-04-17 07:21:17 +03:00
OF_DEV_AUXDATA ( " ti,da830-cppi41 " , 0x01e01000 , " cppi41-dmaengine " ,
NULL ) ,
{ }
} ;
2012-11-19 22:21:48 +04:00
static int da8xx_probe ( struct platform_device * pdev )
2010-12-02 10:19:35 +03:00
{
2013-04-24 18:21:42 +04:00
struct resource musb_resources [ 2 ] ;
2013-07-30 12:03:12 +04:00
struct musb_hdrc_platform_data * pdata = dev_get_platdata ( & pdev - > dev ) ;
2010-12-02 10:40:34 +03:00
struct da8xx_glue * glue ;
2013-09-20 03:14:38 +04:00
struct platform_device_info pinfo ;
2010-12-02 10:57:08 +03:00
struct clk * clk ;
2016-11-21 17:59:29 +03:00
struct device_node * np = pdev - > dev . of_node ;
2016-09-13 05:48:33 +03:00
int ret ;
2010-12-02 10:57:08 +03:00
2016-09-13 05:48:33 +03:00
glue = devm_kzalloc ( & pdev - > dev , sizeof ( * glue ) , GFP_KERNEL ) ;
2016-08-25 20:39:27 +03:00
if ( ! glue )
2016-09-13 05:48:33 +03:00
return - ENOMEM ;
2010-12-02 10:40:34 +03:00
2018-01-07 06:19:50 +03:00
clk = devm_clk_get ( & pdev - > dev , NULL ) ;
2010-12-02 10:57:08 +03:00
if ( IS_ERR ( clk ) ) {
dev_err ( & pdev - > dev , " failed to get clock \n " ) ;
2016-09-13 05:48:33 +03:00
return PTR_ERR ( clk ) ;
2010-12-02 10:57:08 +03:00
}
2016-09-13 05:48:34 +03:00
glue - > phy = devm_phy_get ( & pdev - > dev , " usb-phy " ) ;
if ( IS_ERR ( glue - > phy ) ) {
2016-11-01 23:47:04 +03:00
if ( PTR_ERR ( glue - > phy ) ! = - EPROBE_DEFER )
dev_err ( & pdev - > dev , " failed to get phy \n " ) ;
2016-09-13 05:48:34 +03:00
return PTR_ERR ( glue - > phy ) ;
2010-12-02 10:57:08 +03:00
}
2010-12-02 10:40:34 +03:00
glue - > dev = & pdev - > dev ;
2010-12-02 10:57:08 +03:00
glue - > clk = clk ;
2010-12-02 10:40:34 +03:00
2016-11-21 17:59:29 +03:00
if ( IS_ENABLED ( CONFIG_OF ) & & np ) {
pdata = devm_kzalloc ( & pdev - > dev , sizeof ( * pdata ) , GFP_KERNEL ) ;
if ( ! pdata )
return - ENOMEM ;
pdata - > config = & da8xx_config ;
pdata - > mode = musb_get_mode ( & pdev - > dev ) ;
pdata - > power = get_vbus_power ( & pdev - > dev ) ;
}
2010-12-02 10:48:58 +03:00
pdata - > platform_ops = & da8xx_ops ;
2016-09-13 05:48:34 +03:00
glue - > usb_phy = usb_phy_generic_register ( ) ;
2016-09-22 23:58:31 +03:00
ret = PTR_ERR_OR_ZERO ( glue - > usb_phy ) ;
if ( ret ) {
2016-09-13 05:48:34 +03:00
dev_err ( & pdev - > dev , " failed to register usb_phy \n " ) ;
2016-09-22 23:58:31 +03:00
return ret ;
2014-04-17 01:16:33 +04:00
}
2010-12-02 10:40:34 +03:00
platform_set_drvdata ( pdev , glue ) ;
2010-12-02 10:19:35 +03:00
2017-04-17 07:21:17 +03:00
ret = of_platform_populate ( pdev - > dev . of_node , NULL ,
da8xx_auxdata_lookup , & pdev - > dev ) ;
if ( ret )
return ret ;
2013-04-24 18:21:42 +04: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-20 03:14:38 +04:00
pinfo = da8xx_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 ) ;
2016-09-22 23:58:31 +03:00
glue - > musb = platform_device_register_full ( & pinfo ) ;
ret = PTR_ERR_OR_ZERO ( glue - > musb ) ;
if ( ret ) {
2013-09-20 03:14:38 +04:00
dev_err ( & pdev - > dev , " failed to register musb device: %d \n " , ret ) ;
2016-09-13 05:48:34 +03:00
usb_phy_generic_unregister ( glue - > usb_phy ) ;
2010-12-02 10:19:35 +03:00
}
2016-09-22 23:58:31 +03:00
return ret ;
2010-12-02 10:19:35 +03:00
}
2012-11-19 22:26:20 +04:00
static int da8xx_remove ( struct platform_device * pdev )
2010-12-02 10:19:35 +03:00
{
2010-12-02 10:40:34 +03:00
struct da8xx_glue * glue = platform_get_drvdata ( pdev ) ;
2010-12-02 10:19:35 +03:00
2012-10-23 09:26:15 +04:00
platform_device_unregister ( glue - > musb ) ;
2016-09-13 05:48:34 +03:00
usb_phy_generic_unregister ( glue - > usb_phy ) ;
2010-12-02 10:19:35 +03:00
return 0 ;
}
2017-02-02 06:30:18 +03:00
# ifdef CONFIG_PM_SLEEP
static int da8xx_suspend ( struct device * dev )
{
int ret ;
struct da8xx_glue * glue = dev_get_drvdata ( dev ) ;
ret = phy_power_off ( glue - > phy ) ;
if ( ret )
return ret ;
clk_disable_unprepare ( glue - > clk ) ;
return 0 ;
}
static int da8xx_resume ( struct device * dev )
{
int ret ;
struct da8xx_glue * glue = dev_get_drvdata ( dev ) ;
ret = clk_prepare_enable ( glue - > clk ) ;
if ( ret )
return ret ;
return phy_power_on ( glue - > phy ) ;
}
# endif
static SIMPLE_DEV_PM_OPS ( da8xx_pm_ops , da8xx_suspend , da8xx_resume ) ;
2016-11-21 17:59:29 +03:00
# ifdef CONFIG_OF
static const struct of_device_id da8xx_id_table [ ] = {
{
. compatible = " ti,da830-musb " ,
} ,
{ } ,
} ;
MODULE_DEVICE_TABLE ( of , da8xx_id_table ) ;
# endif
2010-12-02 10:19:35 +03:00
static struct platform_driver da8xx_driver = {
2012-01-26 14:40:23 +04:00
. probe = da8xx_probe ,
2012-11-19 22:21:08 +04:00
. remove = da8xx_remove ,
2010-12-02 10:19:35 +03:00
. driver = {
. name = " musb-da8xx " ,
2017-02-02 06:30:18 +03:00
. pm = & da8xx_pm_ops ,
2016-11-21 17:59:29 +03:00
. of_match_table = of_match_ptr ( da8xx_id_table ) ,
2010-12-02 10:19:35 +03:00
} ,
} ;
MODULE_DESCRIPTION ( " DA8xx/OMAP-L1x MUSB Glue Layer " ) ;
MODULE_AUTHOR ( " Sergei Shtylyov <sshtylyov@ru.mvista.com> " ) ;
MODULE_LICENSE ( " GPL v2 " ) ;
2012-10-10 22:36:59 +04:00
module_platform_driver ( da8xx_driver ) ;