[U-Boot] [PATCH v2 4/6] usb : musb : Adding DM6446 (TI DaVinci) platform specific USB support

Thomas Abraham t-abraham at ti.com
Thu Dec 18 00:10:54 CET 2008


Adding DM6446 (TI DaVinci) platform specific USB functionality for
USB Phy and VBUS initialization.

Signed-off-by: Ravi Babu <ravibabu at ti.com>
Signed-off-by: Swaminathan S <swami.iyer at ti.com>
Signed-off-by: Thomas Abraham <t-abraham at ti.com>
Signed-off-by: Ajay Kumar Gupta <ajay.gupta at ti.com>
---
 drivers/usb/Makefile      |    1 +
 drivers/usb/davinci_usb.c |  139 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/davinci_usb.h |   98 +++++++++++++++++++++++++++++++
 3 files changed, 238 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/davinci_usb.c
 create mode 100644 drivers/usb/davinci_usb.h

diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 94eea70..3a2706d 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -36,6 +36,7 @@ COBJS-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
 COBJS-$(CONFIG_USB_SL811HS) += sl811_usb.o
 COBJS-$(CONFIG_USB_EHCI_FSL) += usb_ehci_fsl.o
 COBJS-$(CONFIG_MUSB_HCD) += musb_hcd.o musb_core.o
+COBJS-$(CONFIG_USB_DAVINCI) += davinci_usb.o
 
 # device
 ifdef CONFIG_USB_DEVICE
diff --git a/drivers/usb/davinci_usb.c b/drivers/usb/davinci_usb.c
new file mode 100644
index 0000000..9c50606
--- /dev/null
+++ b/drivers/usb/davinci_usb.c
@@ -0,0 +1,139 @@
+/*
+ * 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 at ti.com, Texas Instruments
+ */
+
+#include <common.h>
+
+#ifdef CONFIG_USB_DAVINCI
+#include <asm/io.h>
+#include "davinci_usb.h"
+
+/* This function writes to a 32-bit register of platform usb wrapper */
+inline void pusb_writel(u32 offset, u32 value)
+{
+	writel(value, DAVINCI_USB0_BASE + offset);
+}
+
+/* This function reads a 32-bit register of platform usb wrapper */
+inline u32 pusb_readl(u32 offset)
+{
+	return readl(DAVINCI_USB0_BASE + offset);
+}
+
+/* This function writes to a 16-bit register of platform musb core */
+inline void musb_writew(u32 offset, u16 value)
+{
+	writew(value, MENTOR_USB0_BASE + offset);
+}
+
+/* This function writes to a 8-bit register of platform musb core */
+inline void musb_writeb(u32 offset, u8 value)
+{
+	writeb(value, MENTOR_USB0_BASE + offset);
+}
+
+/* This function reads a 16-bit register of platform usb wrapper */
+inline u16 musb_readw(u32 offset)
+{
+	return readw(MENTOR_USB0_BASE + offset);
+}
+
+/* This function reads a 8-bit register of platform usb wrapper */
+inline u8 musb_readb(u32 offset)
+{
+	return readb(MENTOR_USB0_BASE + offset);
+}
+
+/*
+ * Enable the usb phy
+ */
+static u8 phy_on(void)
+{
+	u32 timeout;
+
+	/* Wait until the usb phy is turned on */
+	writel(USBPHY_SESNDEN | USBPHY_VBDTCTEN, USBPHY_CTL_PADDR);
+	timeout = DAVINCI_USB_TIMEOUT;
+	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);
+}
+
+
+/*
+ * This function performs Davinci platform specific initialization for usb0.
+ */
+int musb_platform_init(void)
+{
+	u32  revision;
+
+	/* enable usb vbus */
+	enable_vbus();
+
+	/* start the on-chip usb phy and its pll */
+	if (!phy_on())
+		return -1;
+
+	/* reset the controller */
+	pusb_writel(DAVINCI_USB_CTRL_REG, 1);
+	udelay(5000);
+
+	/* Returns zero if e.g. not clocked */
+	revision = pusb_readl(DAVINCI_USB_VERSION_REG);
+	if (!revision)
+		return -1;
+
+	/* Disable all interrupts */
+	pusb_writel(DAVINCI_USB_INT_MASK_SET_REG, DAVINCI_USB_USBINT_MASK |
+			DAVINCI_USB_RXINT_MASK | DAVINCI_USB_TXINT_MASK);
+	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 */
+	pusb_writel(DAVINCI_USB_INT_MASK_CLR_REG, DAVINCI_USB_USBINT_MASK |
+			DAVINCI_USB_TXINT_MASK | DAVINCI_USB_RXINT_MASK);
+	pusb_writel(DAVINCI_USB_EOI_REG, 0);
+}
+
+#endif /* CONFIG_USB_DAVINCI */
+
diff --git a/drivers/usb/davinci_usb.h b/drivers/usb/davinci_usb.h
new file mode 100644
index 0000000..c0b618f
--- /dev/null
+++ b/drivers/usb/davinci_usb.h
@@ -0,0 +1,98 @@
+/*
+ * 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 at ti.com, Texas Instruments
+ */
+
+#ifndef __DAVINCI_USB_H__
+#define __DAVINCI_USB_H__
+
+#include <asm/arch/hardware.h>
+
+/* Base address of DAVINCI usb0 wrapper */
+#define DAVINCI_USB0_BASE 0x01C64000
+
+/* Base address of DAVINCI musb core */
+#define MENTOR_USB0_BASE (DAVINCI_USB0_BASE+0x400)
+
+/* Include usb OTG module registers here */
+#define DAVINCI_USB_VERSION_REG		0x00
+#define DAVINCI_USB_CTRL_REG		0x04
+#define DAVINCI_USB_STAT_REG		0x08
+#define DAVINCI_MODE_TGCR_REG		0x10
+#define DAVINCI_AUTOREQ_REG 		0x14
+#define DAVINCI_SRP_FIXTIME_REG 	0x18
+#define DAVINCI_TEARDOWN_REG		0x1C
+#define DAVINCI_USB_INT_SOURCE_REG	0x20
+#define DAVINCI_USB_INT_SET_REG 	0x24
+#define DAVINCI_USB_INT_SRC_CLR_REG 	0x28
+#define DAVINCI_USB_INT_MASK_REG	0x2c
+#define DAVINCI_USB_INT_MASK_SET_REG	0x30
+#define DAVINCI_USB_INT_MASK_CLR_REG	0x34
+#define DAVINCI_USB_INT_SRC_MASKED_REG	0x38
+#define DAVINCI_USB_EOI_REG 		0x3c
+#define DAVINCI_USB_EOI_INTVEC		0x40
+#define DAVINCI_GRNDIS_EP1SIZE_REG	0x50
+#define DAVINCI_GRNDIS_EP2SIZE_REG	0x54
+#define DAVINCI_GRNDIS_EP3SIZE_REG	0x58
+#define DAVINCI_GRNDIS_EP4SIZE_REG	0x5C
+
+#define DAVINCI_USB_TX_ENDPTS_MASK	0x1f /* ep0 + 4 tx */
+#define DAVINCI_USB_RX_ENDPTS_MASK	0x1e /* 4 rx */
+
+#define DAVINCI_USB_USBINT_SHIFT	16
+#define DAVINCI_USB_TXINT_SHIFT 	0
+#define DAVINCI_USB_RXINT_SHIFT 	8
+
+#define DAVINCI_INTR_DRVVBUS		0x0100
+
+#define DAVINCI_USB_USBINT_MASK 	0x01ff0000	/* 8 Mentor, DRVVBUS */
+#define DAVINCI_USB_TXINT_MASK \
+		(DAVINCI_USB_TX_ENDPTS_MASK << DAVINCI_USB_TXINT_SHIFT)
+#define DAVINCI_USB_RXINT_MASK \
+		(DAVINCI_USB_RX_ENDPTS_MASK << DAVINCI_USB_RXINT_SHIFT)
+
+#define MGC_BUSCTL_OFFSET(_bEnd, _bOffset) \
+		(0x80 + (8*(_bEnd)) + (_bOffset))
+
+/* Integrated highspeed/otg PHY */
+#define USBPHY_CTL_PADDR	(DAVINCI_SYSTEM_MODULE_BASE + 0x34)
+#define USBPHY_PHYCLKGD 	(1 << 8)
+#define USBPHY_SESNDEN		(1 << 7)	/* v(sess_end) comparator */
+#define USBPHY_VBDTCTEN 	(1 << 6)	/* v(bus) comparator */
+#define USBPHY_PHYPLLON 	(1 << 4)	/* override pll suspend */
+#define USBPHY_CLKO1SEL 	(1 << 3)
+#define USBPHY_OSCPDWN		(1 << 2)
+#define USBPHY_PHYPDWN		(1 << 0)
+
+/* Timeout for Davinci usb module */
+#define DAVINCI_USB_TIMEOUT 0x3FFFF
+
+/* IO Expander I2C address and VBUS enable mask */
+#define IOEXP_I2C_ADDR 0x3A
+#define IOEXP_VBUSEN_MASK 1
+
+/* extern functions */
+extern void lpsc_on(unsigned int id);
+extern int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len);
+extern int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len);
+extern void enable_vbus(void);
+#endif	/* __DAVINCI_USB_H__ */
+
-- 
1.5.6



More information about the U-Boot mailing list