2009-01-04 04:11:13 +00:00
|
|
|
/*
|
|
|
|
* TI's Davinci platform specific USB wrapper functions.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Texas Instruments
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Author: Thomas Abraham t-abraham@ti.com, Texas Instruments
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <asm/io.h>
|
2009-04-03 10:46:58 +00:00
|
|
|
#include "davinci.h"
|
2010-01-11 10:06:46 +00:00
|
|
|
#include <asm/arch/hardware.h>
|
2009-01-04 04:11:13 +00:00
|
|
|
|
2011-11-01 20:00:26 +00:00
|
|
|
#if !defined(CONFIG_DV_USBPHY_CTL)
|
|
|
|
#define CONFIG_DV_USBPHY_CTL (USBPHY_SESNDEN | USBPHY_VBDTCTEN)
|
|
|
|
#endif
|
|
|
|
|
2009-01-04 04:11:13 +00:00
|
|
|
/* MUSB platform configuration */
|
|
|
|
struct musb_config musb_cfg = {
|
2010-06-10 05:50:47 +00:00
|
|
|
.regs = (struct musb_regs *)MENTOR_USB0_BASE,
|
|
|
|
.timeout = DAVINCI_USB_TIMEOUT,
|
|
|
|
.musb_speed = 0,
|
2009-01-04 04:11:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* MUSB module register overlay */
|
|
|
|
struct davinci_usb_regs *dregs;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable the USB phy
|
|
|
|
*/
|
|
|
|
static u8 phy_on(void)
|
|
|
|
{
|
|
|
|
u32 timeout;
|
2010-01-11 10:06:46 +00:00
|
|
|
#ifdef DAVINCI_DM365EVM
|
|
|
|
u32 val;
|
|
|
|
#endif
|
2009-01-04 04:11:13 +00:00
|
|
|
/* Wait until the USB phy is turned on */
|
2010-01-11 10:06:46 +00:00
|
|
|
#ifdef DAVINCI_DM365EVM
|
|
|
|
writel(USBPHY_PHY24MHZ | USBPHY_SESNDEN |
|
|
|
|
USBPHY_VBDTCTEN, USBPHY_CTL_PADDR);
|
|
|
|
#else
|
2011-11-01 20:00:26 +00:00
|
|
|
writel(CONFIG_DV_USBPHY_CTL, USBPHY_CTL_PADDR);
|
2010-01-11 10:06:46 +00:00
|
|
|
#endif
|
2009-01-04 04:11:13 +00:00
|
|
|
timeout = musb_cfg.timeout;
|
2010-01-11 10:06:46 +00:00
|
|
|
|
|
|
|
#ifdef DAVINCI_DM365EVM
|
|
|
|
/* Set the ownership of GIO33 to USB */
|
|
|
|
val = readl(PINMUX4);
|
|
|
|
val &= ~(PINMUX4_USBDRVBUS_BITCLEAR);
|
|
|
|
val |= PINMUX4_USBDRVBUS_BITSET;
|
|
|
|
writel(val, PINMUX4);
|
|
|
|
#endif
|
2009-01-04 04:11:13 +00:00
|
|
|
while (timeout--)
|
|
|
|
if (readl(USBPHY_CTL_PADDR) & USBPHY_PHYCLKGD)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* USB phy was not turned on */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable the USB phy
|
|
|
|
*/
|
|
|
|
static void phy_off(void)
|
|
|
|
{
|
|
|
|
/* powerdown the on-chip PHY and its oscillator */
|
|
|
|
writel(USBPHY_OSCPDWN | USBPHY_PHYPDWN, USBPHY_CTL_PADDR);
|
|
|
|
}
|
|
|
|
|
2011-11-01 20:00:25 +00:00
|
|
|
void __enable_vbus(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* nothing to do, vbus is handled through the cpu.
|
|
|
|
* Define this function in board code, if it is
|
|
|
|
* different on your board.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
void enable_vbus(void)
|
|
|
|
__attribute__((weak, alias("__enable_vbus")));
|
|
|
|
|
2009-01-04 04:11:13 +00:00
|
|
|
/*
|
|
|
|
* This function performs Davinci platform specific initialization for usb0.
|
|
|
|
*/
|
|
|
|
int musb_platform_init(void)
|
|
|
|
{
|
|
|
|
u32 revision;
|
|
|
|
|
|
|
|
/* enable USB VBUS */
|
|
|
|
enable_vbus();
|
2011-11-01 20:00:25 +00:00
|
|
|
|
2009-01-04 04:11:13 +00:00
|
|
|
/* start the on-chip USB phy and its pll */
|
|
|
|
if (!phy_on())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* reset the controller */
|
|
|
|
dregs = (struct davinci_usb_regs *)DAVINCI_USB0_BASE;
|
|
|
|
writel(1, &dregs->ctrlr);
|
|
|
|
udelay(5000);
|
|
|
|
|
|
|
|
/* Returns zero if e.g. not clocked */
|
|
|
|
revision = readl(&dregs->version);
|
|
|
|
if (!revision)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Disable all interrupts */
|
|
|
|
writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_RXINT_MASK |
|
|
|
|
DAVINCI_USB_TXINT_MASK , &dregs->intmsksetr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function performs Davinci platform specific deinitialization for usb0.
|
|
|
|
*/
|
|
|
|
void musb_platform_deinit(void)
|
|
|
|
{
|
|
|
|
/* Turn of the phy */
|
|
|
|
phy_off();
|
|
|
|
|
|
|
|
/* flush any interrupts */
|
|
|
|
writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_TXINT_MASK |
|
|
|
|
DAVINCI_USB_RXINT_MASK , &dregs->intclrr);
|
|
|
|
}
|