Patchwork [U-Boot,RFC,v3,4/7] USB: dwc3: dwc3 code adaption for uBoot

login
register
mail settings
Submitter Dan Murphy
Date July 2, 2013, 3:15 p.m.
Message ID <1372778113-26053-5-git-send-email-dmurphy@ti.com>
Download mbox | patch
Permalink /patch/256452/
State RFC
Delegated to: Marek Vasut
Headers show

Comments

Dan Murphy - July 2, 2013, 3:15 p.m.
All code not applicable to uBoot is ifdef'd out with

ifndef __UBOOT__ as it is done in the musb-new directory.

This code has not been fully debuged or excersized.

Signed-off-by: Dan Murphy <dmurphy@ti.com>
---
 Makefile                      |    1 +
 drivers/usb/dwc3/Makefile     |   53 ++++++
 drivers/usb/dwc3/core.c       |   90 +++++++++-
 drivers/usb/dwc3/core.h       |   53 +++++-
 drivers/usb/dwc3/dwc3-omap.c  |   28 ++-
 drivers/usb/dwc3/dwc3-omap.h  |   41 +++++
 drivers/usb/dwc3/dwc3-uboot.c |  384 +++++++++++++++++++++++++++++++++++++++++
 drivers/usb/dwc3/ep0.c        |   31 +++-
 drivers/usb/dwc3/gadget.c     |   75 +++++++-
 drivers/usb/dwc3/gadget.h     |    2 +
 drivers/usb/dwc3/host.c       |   27 ++-
 drivers/usb/dwc3/io.h         |   15 ++
 12 files changed, 779 insertions(+), 21 deletions(-)
 create mode 100644 drivers/usb/dwc3/Makefile
 create mode 100644 drivers/usb/dwc3/dwc3-omap.h
 create mode 100644 drivers/usb/dwc3/dwc3-uboot.c

Patch

diff --git a/Makefile b/Makefile
index fdaddb9..e4a6264 100644
--- a/Makefile
+++ b/Makefile
@@ -327,6 +327,7 @@  LIBS-y += drivers/usb/gadget/libusb_gadget.o
 LIBS-y += drivers/usb/host/libusb_host.o
 LIBS-y += drivers/usb/musb/libusb_musb.o
 LIBS-y += drivers/usb/musb-new/libusb_musb-new.o
+LIBS-y += drivers/usb/dwc3/libusb_dwc3.o
 LIBS-y += drivers/usb/phy/libusb_phy.o
 LIBS-y += drivers/usb/ulpi/libusb_ulpi.o
 LIBS-y += drivers/video/libvideo.o
diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
new file mode 100644
index 0000000..0d589cc
--- /dev/null
+++ b/drivers/usb/dwc3/Makefile
@@ -0,0 +1,53 @@ 
+#
+# (C) Copyright 2013
+# Texas Instruments Incorporated.
+#
+# Author: Dan Murphy <dmurphy@ti.com>
+#
+# 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
+#
+
+include $(TOPDIR)/config.mk
+
+LIB	:= $(obj)libusb_dwc3.o
+
+COBJS-$(CONFIG_USB_DWC3) += core.o dwc3-uboot.o
+COBJS-$(CONFIG_USB_DWC3_GADGET) += gadget.o ep0.o
+COBJS-$(CONFIG_USB_DWC3_HOST) += host.o
+COBJS-$(CONFIG_USB_DWC3_OMAP) += dwc3-omap.o
+
+CFLAGS_NO_WARN := $(call cc-option,-Wno-unused-variable) \
+			$(call cc-option,-Wno-unused-label)
+CFLAGS += $(CFLAGS_NO_WARN)
+
+COBJS	:= $(COBJS-y)
+SRCS	:= $(COBJS:.o=.c)
+OBJS	:= $(addprefix $(obj),$(COBJS))
+
+all:	$(LIB)
+
+$(LIB):	$(obj).depend $(OBJS)
+	$(call cmd_link_o_target, $(OBJS))
+
+#########################################################################
+
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
+
+sinclude $(obj).depend
+
+#########################################################################
+
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index c35d49d..1bf1882 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -6,6 +6,8 @@ 
  * Authors: Felipe Balbi <balbi@ti.com>,
  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  *
+ * Back-ported by: Dan Murphy <dmurphy@ti.com>
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -36,6 +38,9 @@ 
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#define __UBOOT__
+#ifndef __UBOOT__
+
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/slab.h>
@@ -51,14 +56,28 @@ 
 #include <linux/of.h>
 
 #include <linux/usb/otg.h>
+
+#include <linux/usb/ch9.h>
+#include <linux/usb/gadget.h>
+
+#else
+#include <common.h>
+
+#include <linux/err.h>
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
+#include <linux/usb/linux-compat.h>
+
+#endif
 
 #include "core.h"
 #include "gadget.h"
 #include "io.h"
 
+#ifndef __UBOOT__
+/* TODO: Need to move over the debug files */
 #include "debug.h"
+#endif
 
 static char *maximum_speed = "super";
 module_param(maximum_speed, charp, 0);
@@ -98,9 +117,11 @@  static void dwc3_core_soft_reset(struct dwc3 *dwc)
 	reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
 	reg |= DWC3_GUSB2PHYCFG_PHYSOFTRST;
 	dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
-
+#ifndef __UBOOT__
+	/* FIX THIS DM */
 	usb_phy_init(dwc->usb2_phy);
 	usb_phy_init(dwc->usb3_phy);
+#endif
 	mdelay(100);
 
 	/* Clear USB3 PHY reset */
@@ -145,7 +166,11 @@  static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
 {
 	struct dwc3_event_buffer	*evt;
 
+#ifndef __UBOOT__
 	evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL);
+#else
+	evt = kzalloc(sizeof(*evt), GFP_KERNEL);
+#endif
 	if (!evt)
 		return ERR_PTR(-ENOMEM);
 
@@ -163,7 +188,11 @@  static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
  * dwc3_free_event_buffers - frees all allocated event buffers
  * @dwc: Pointer to our controller context structure
  */
+#ifndef __UBOOT__
 static void dwc3_free_event_buffers(struct dwc3 *dwc)
+#else
+void dwc3_free_event_buffers(struct dwc3 *dwc)
+#endif
 {
 	struct dwc3_event_buffer	*evt;
 	int i;
@@ -183,16 +212,23 @@  static void dwc3_free_event_buffers(struct dwc3 *dwc)
  * Returns 0 on success otherwise negative errno. In the error case, dwc
  * may contain some buffers allocated but not all which were requested.
  */
+#ifndef __UBOOT__
 static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
+#else
+int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
+#endif
 {
 	int			num;
 	int			i;
 
 	num = DWC3_NUM_INT(dwc->hwparams.hwparams1);
 	dwc->num_event_buffers = num;
-
+#ifndef __UBOOT__
 	dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs) * num,
 			GFP_KERNEL);
+#else
+	dwc->ev_buffs = kzalloc(sizeof(*dwc->ev_buffs) * num, GFP_KERNEL);
+#endif
 	if (!dwc->ev_buffs) {
 		dev_err(dwc->dev, "can't allocate event buffers array\n");
 		return -ENOMEM;
@@ -218,7 +254,11 @@  static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
  *
  * Returns 0 on success otherwise negative errno.
  */
+#ifndef __UBOOT__
 static int dwc3_event_buffers_setup(struct dwc3 *dwc)
+#else
+int dwc3_event_buffers_setup(struct dwc3 *dwc)
+#endif
 {
 	struct dwc3_event_buffer	*evt;
 	int				n;
@@ -242,8 +282,11 @@  static int dwc3_event_buffers_setup(struct dwc3 *dwc)
 
 	return 0;
 }
-
+#ifndef __UBOOT__
 static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
+#else
+void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
+#endif
 {
 	struct dwc3_event_buffer	*evt;
 	int				n;
@@ -270,8 +313,11 @@  static void dwc3_core_num_eps(struct dwc3 *dwc)
 	dev_vdbg(dwc->dev, "found %d IN and %d OUT endpoints\n",
 			dwc->num_in_eps, dwc->num_out_eps);
 }
-
+#ifndef __UBOOT__
 static void dwc3_cache_hwparams(struct dwc3 *dwc)
+#else
+void dwc3_cache_hwparams(struct dwc3 *dwc)
+#endif
 {
 	struct dwc3_hwparams	*parms = &dwc->hwparams;
 
@@ -292,7 +338,11 @@  static void dwc3_cache_hwparams(struct dwc3 *dwc)
  *
  * Returns 0 on success otherwise negative errno.
  */
+#ifndef __UBOOT__
 static int dwc3_core_init(struct dwc3 *dwc)
+#else
+int dwc3_core_init(struct dwc3 *dwc)
+#endif
 {
 	unsigned long		timeout;
 	u32			reg;
@@ -308,14 +358,25 @@  static int dwc3_core_init(struct dwc3 *dwc)
 	dwc->revision = reg;
 
 	/* issue device SoftReset too */
+#ifndef __UBOOT__
 	timeout = jiffies + msecs_to_jiffies(500);
+#else
+	timeout = 500;
+#endif
 	dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
 	do {
 		reg = dwc3_readl(dwc->regs, DWC3_DCTL);
 		if (!(reg & DWC3_DCTL_CSFTRST))
 			break;
 
+#ifndef __UBOOT__
 		if (time_after(jiffies, timeout)) {
+#else
+		mdelay(1);
+		timeout--;
+
+		if (!timeout) {
+#endif
 			dev_err(dwc->dev, "Reset Timed Out\n");
 			ret = -ETIMEDOUT;
 			goto err0;
@@ -356,13 +417,21 @@  static int dwc3_core_init(struct dwc3 *dwc)
 err0:
 	return ret;
 }
-
+#ifndef __UBOOT__
 static void dwc3_core_exit(struct dwc3 *dwc)
+#else
+void dwc3_core_exit(struct dwc3 *dwc)
+#endif
 {
+#ifndef __UBOOT__
+	/* FIX THIS DM */
 	usb_phy_shutdown(dwc->usb2_phy);
 	usb_phy_shutdown(dwc->usb3_phy);
+#endif
 }
 
+#ifndef __UBOOT__
+
 #define DWC3_ALIGN_MASK		(16 - 1)
 
 static int dwc3_probe(struct platform_device *pdev)
@@ -699,10 +768,11 @@  static int dwc3_suspend(struct device *dev)
 
 	dwc->gctl = dwc3_readl(dwc->regs, DWC3_GCTL);
 	spin_unlock_irqrestore(&dwc->lock, flags);
-
+#ifndef __UBOOT__
+	/* FIX THIS DM */
 	usb_phy_shutdown(dwc->usb3_phy);
 	usb_phy_shutdown(dwc->usb2_phy);
-
+#endif
 	return 0;
 }
 
@@ -710,9 +780,11 @@  static int dwc3_resume(struct device *dev)
 {
 	struct dwc3	*dwc = dev_get_drvdata(dev);
 	unsigned long	flags;
-
+#ifndef __UBOOT__
+	/* FIX THIS DM */
 	usb_phy_init(dwc->usb3_phy);
 	usb_phy_init(dwc->usb2_phy);
+#endif
 	msleep(100);
 
 	spin_lock_irqsave(&dwc->lock, flags);
@@ -773,6 +845,8 @@  static struct platform_driver dwc3_driver = {
 
 module_platform_driver(dwc3_driver);
 
+#endif /* __UBOOT__ */
+
 MODULE_ALIAS("platform:dwc3");
 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
 MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index b69d322..43e81f9 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -6,6 +6,8 @@ 
  * Authors: Felipe Balbi <balbi@ti.com>,
  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  *
+ * Back-ported by: Dan Murphy <dmurphy@ti.com>
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -39,6 +41,8 @@ 
 #ifndef __DRIVERS_USB_DWC3_CORE_H
 #define __DRIVERS_USB_DWC3_CORE_H
 
+#define __UBOOT__
+#ifndef __UBOOT__
 #include <linux/device.h>
 #include <linux/spinlock.h>
 #include <linux/ioport.h>
@@ -50,6 +54,15 @@ 
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 
+#else
+
+#include <linux/usb/ch9.h>
+#include <linux/usb/gadget.h>
+#include <linux/compiler.h>
+#include <linux/usb/linux-compat.h>
+
+#endif
+
 /* Global constants */
 #define DWC3_EP0_BOUNCE_SIZE	512
 #define DWC3_ENDPOINTS_NUM	32
@@ -676,7 +689,9 @@  struct dwc3 {
 	struct device		*dev;
 
 	struct platform_device	*xhci;
+#ifndef __UBOOT__
 	struct resource		xhci_resources[DWC3_XHCI_RESOURCES_NUM];
+#endif
 
 	struct dwc3_event_buffer **ev_buffs;
 	struct dwc3_ep		*eps[DWC3_ENDPOINTS_NUM];
@@ -889,7 +904,15 @@  union dwc3_event {
 void dwc3_set_mode(struct dwc3 *dwc, u32 mode);
 int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc);
 
+#ifndef __UBOOT__
+/* TODO rework this for uboot */
 #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
+#endif
+#endif /* __UBOOT__ */
+
+#if defined(CONFIG_USB_DWC3_HOST) || \
+	defined(CONFIG_USB_DWC3_DUAL_ROLE)
+
 int dwc3_host_init(struct dwc3 *dwc);
 void dwc3_host_exit(struct dwc3 *dwc);
 #else
@@ -899,7 +922,15 @@  static inline void dwc3_host_exit(struct dwc3 *dwc)
 { }
 #endif
 
+#ifndef __UBOOT__
+/* TODO rework this for uboot */
 #if IS_ENABLED(CONFIG_USB_DWC3_GADGET) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
+#endif
+#endif
+
+#if defined(CONFIG_USB_DWC3_GADGET) || \
+	defined(CONFIG_USB_DWC3_DUAL_ROLE)
+
 int dwc3_gadget_init(struct dwc3 *dwc);
 void dwc3_gadget_exit(struct dwc3 *dwc);
 #else
@@ -910,11 +941,20 @@  static inline void dwc3_gadget_exit(struct dwc3 *dwc)
 #endif
 
 /* power management interface */
+#ifndef __UBOOT__
+/* TODO rework this for uboot */
 #if !IS_ENABLED(CONFIG_USB_DWC3_HOST)
+#endif /* __UBOOT__ */
+#endif
+#if defined (CONFIG_USB_DWC3_HOST)
+
 int dwc3_gadget_prepare(struct dwc3 *dwc);
 void dwc3_gadget_complete(struct dwc3 *dwc);
 int dwc3_gadget_suspend(struct dwc3 *dwc);
 int dwc3_gadget_resume(struct dwc3 *dwc);
+
+#endif
+/*
 #else
 static inline int dwc3_gadget_prepare(struct dwc3 *dwc)
 {
@@ -934,6 +974,17 @@  static inline int dwc3_gadget_resume(struct dwc3 *dwc)
 {
 	return 0;
 }
-#endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */
+#endif */
+/* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */
+
+#ifdef __UBOOT__
+int dwc3_core_init(struct dwc3 *dwc);
+int dwc3_event_buffers_setup(struct dwc3 *dwc);
+void dwc3_core_exit(struct dwc3 *dwc);
+int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length);
+void dwc3_free_event_buffers(struct dwc3 *dwc);
+void dwc3_event_buffers_cleanup(struct dwc3 *dwc);
+void dwc3_cache_hwparams(struct dwc3 *dwc);
+#endif
 
 #endif /* __DRIVERS_USB_DWC3_CORE_H */
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index 34638b9..3dc31d2 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -6,6 +6,8 @@ 
  * Authors: Felipe Balbi <balbi@ti.com>,
  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  *
+ * Back-ported by: Dan Murphy <dmurphy@ti.com>
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -36,6 +38,9 @@ 
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#define __UBOOT__
+#ifndef __UBOOT__
+
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/slab.h>
@@ -53,6 +58,16 @@ 
 
 #include <linux/usb/otg.h>
 
+#else
+
+#include <linux/usb/linux-compat.h>
+#include <usb/lin_gadget_compat.h>
+
+#include "io.h"
+#include "dwc3-omap.h"
+
+#endif
+
 /*
  * All these registers belong to OMAP's Wrapper around the
  * DesignWare USB3 Core.
@@ -144,8 +159,11 @@  int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
 	struct dwc3_omap	*omap = _omap;
 
 	if (!omap)
+#ifndef __UBOOT__
 		return -EPROBE_DEFER;
-
+#else
+		return -EINVAL;
+#endif
 	switch (status) {
 	case OMAP_DWC3_ID_GROUND:
 		dev_dbg(omap->dev, "ID GND\n");
@@ -243,6 +261,7 @@  static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
 	return IRQ_HANDLED;
 }
 
+#ifndef __UBOOT__
 static int dwc3_omap_remove_core(struct device *dev, void *c)
 {
 	struct platform_device *pdev = to_platform_device(dev);
@@ -251,8 +270,13 @@  static int dwc3_omap_remove_core(struct device *dev, void *c)
 
 	return 0;
 }
+#endif
 
+#ifndef __UBOOT__
 static void dwc3_omap_enable_irqs(struct dwc3_omap *omap)
+#else
+void dwc3_omap_enable_irqs(struct dwc3_omap *omap)
+#endif
 {
 	u32			reg;
 
@@ -280,6 +304,7 @@  static void dwc3_omap_disable_irqs(struct dwc3_omap *omap)
 	dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, 0x00);
 }
 
+#ifndef __UBOOT__
 static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32);
 
 static int dwc3_omap_probe(struct platform_device *pdev)
@@ -474,6 +499,7 @@  static struct platform_driver dwc3_omap_driver = {
 };
 
 module_platform_driver(dwc3_omap_driver);
+#endif /* __UBOOT__ */
 
 MODULE_ALIAS("platform:omap-dwc3");
 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
diff --git a/drivers/usb/dwc3/dwc3-omap.h b/drivers/usb/dwc3/dwc3-omap.h
new file mode 100644
index 0000000..e80a89f
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-omap.h
@@ -0,0 +1,41 @@ 
+/*
+ * Copyright (C) 2013 by Texas Instruments
+ * *
+ * Back-ported by: Dan Murphy <dmurphy@ti.com>
+ *
+ * The Inventra Controller Driver for Linux 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.
+ */
+
+#ifndef __DWC3_OMAP_H__
+#define __DWC3_OMAP_H__
+
+enum omap_dwc3_vbus_id_status {
+	OMAP_DWC3_UNKNOWN = 0,
+	OMAP_DWC3_ID_GROUND,
+	OMAP_DWC3_ID_FLOAT,
+	OMAP_DWC3_VBUS_VALID,
+	OMAP_DWC3_VBUS_OFF,
+};
+
+enum dwc3_omap_utmi_mode {
+	DWC3_OMAP_UTMI_MODE_UNKNOWN = 0,
+	DWC3_OMAP_UTMI_MODE_HW,
+	DWC3_OMAP_UTMI_MODE_SW,
+};
+
+#if defined(CONFIG_USB_DWC3)
+extern int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status);
+#endif
+/*
+TODO need this override for non-USB_DWC3
+#else
+static inline int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
+{
+	return -ENODEV;
+}
+#endif
+*/
+#endif	/* __DWC3_OMAP_H__ */
diff --git a/drivers/usb/dwc3/dwc3-uboot.c b/drivers/usb/dwc3/dwc3-uboot.c
new file mode 100644
index 0000000..3732462
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-uboot.c
@@ -0,0 +1,384 @@ 
+/**
+ * dwc3-uboot.c - dwc3 uboot initialization
+ *
+ * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Authors: Dan Murphy <dmurphy@ti.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The names of the above-listed copyright holders may not be used
+ *    to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2, as published by the Free
+ * Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR
+ * CONTRIBUTORS 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.
+ */
+
+#include <usb.h>
+#include <linux/usb/linux-compat.h>
+#include <linux/usb/usb-compat.h>
+#include <usb_defs.h>
+
+#include "core.h"
+#include "io.h"
+#include "dwc3-omap.h"
+
+#define DWC3_ALIGN_MASK		(16 - 1)
+
+static char *maximum_speed = "super";
+
+
+#include <asm/omap_common.h>
+/* IRQS0 BITS */
+#define USBOTGSS_IRQO_COREIRQ_ST		(1 << 0)
+
+/* IRQ1 BITS */
+#define USBOTGSS_IRQ1_DMADISABLECLR		(1 << 17)
+#define USBOTGSS_IRQ1_OEVT			(1 << 16)
+#define USBOTGSS_IRQ1_DRVVBUS_RISE		(1 << 13)
+#define USBOTGSS_IRQ1_CHRGVBUS_RISE		(1 << 12)
+#define USBOTGSS_IRQ1_DISCHRGVBUS_RISE		(1 << 11)
+#define USBOTGSS_IRQ1_IDPULLUP_RISE		(1 << 8)
+#define USBOTGSS_IRQ1_DRVVBUS_FALL		(1 << 5)
+#define USBOTGSS_IRQ1_CHRGVBUS_FALL		(1 << 4)
+#define USBOTGSS_IRQ1_DISCHRGVBUS_FALL		(1 << 3)
+#define USBOTGSS_IRQ1_IDPULLUP_FALL		(1 << 0)
+
+#define USBOTGSS_IRQENABLE_SET_0	0x4A02002c
+#define USBOTGSS_IRQENABLE_SET_1	0x4A02003c
+#define USBOTGSS_SYSCONFIG		0x4A020010
+#define USBOTGSS_IRQSTATUS_0		0x4A020028
+#define USBOTGSS_IRQSTATUS_1		0x4A020038
+#define USBOTGSS_UTMI_OTG_STATUS 0x4A020084
+
+struct usb_dpll_params {
+	u16	m;
+	u8	n;
+	u8	freq:3;
+	u8	sd;
+	u32	mf;
+};
+
+static struct usb_dpll_params omap_usb3_dpll_params[6] = {
+	{1250, 5, 4, 20, 0},		/* 12 MHz */
+	{0, 0, 0, 0, 0},		/* for 13 MHz TBD   */
+	{3125, 20, 4, 20, 0},		/* 16.8 MHz */
+	{1172, 8, 4, 20, 65537},	/* 19.2 MHz */
+	{1250, 12, 4, 20, 0},		/* 26 MHz */
+	{3125, 47, 4, 20, 92843},	/* 38.4 MHz */
+};
+
+#define USB3_PHY_PLL_CONFIGURATION1	0x4A084C0C
+#define USB3_PHY_PLL_REGN_MASK		0xFE
+#define USB3_PHY_PLL_REGN_SHIFT		1
+#define USB3_PHY_PLL_REGM_MASK		0x1FFE00
+#define USB3_PHY_PLL_REGM_SHIFT		9
+#define USB3_PHY_PLL_CONFIGURATION2	0x4A084C10
+#define USB3_PHY_PLL_SELFREQDCO_MASK	0xE
+#define USB3_PHY_PLL_SELFREQDCO_SHIFT	1
+#define USB3_PHY_PLL_CONFIGURATION4     0x4A084C20
+#define USB3_PHY_PLL_REGM_F_MASK	0x3FFFF
+#define USB3_PHY_PLL_REGM_F_SHIFT	0
+#define USB3_PHY_PLL_CONFIGURATION3	0x4A084C14
+#define USB3_PHY_PLL_SD_MASK		0x3FC00
+#define USB3_PHY_PLL_SD_SHIFT		9
+#define USB3_PHY_CONTROL_PHY_POWER_USB	0x4A002370
+#define USB3_PWRCTL_CLK_CMD_MASK	0x3FE000
+#define USB3_PWRCTL_CLK_FREQ_MASK	0xFFC
+#define USB3_PHY_PARTIAL_RX_POWERON     (1<<6)
+#define USB3_PHY_TX_RX_POWERON		0x3
+#define USB3_PWRCTL_CLK_CMD_SHIFT	14
+#define USB3_PWRCTL_CLK_FREQ_SHIFT	22
+#define USB3_PHY_PLL_IDLE		1
+
+#define USB3_PHY_PLL_STATUS	0x4A084C04
+#define USB3_PHY_PLL_TICOPWDN   0x10000
+#define USB3_PHY_PLL_LOCK	0x2
+#define CONTROL_DEV_CONF	0x4A002300
+#define CONTROL_DEV_CONF_USBPHY_PD	1
+
+#define USB3_PHY_PLL_GO		0x4A084C08
+#define USB3_PHY_SET_PLL_GO	1
+
+void setup_usb(void)
+{
+	u32			val;
+	u32			retry;
+	u8 vali;
+	writel(0x118, 0x4A0029EC);
+	writel(0x1180000, 0x4A0029F0);
+	writel(0x118, 0x4A0029F4);
+	/* Turn on 32K AON clk */
+	writel(0x100, 0x4A008640);
+	/* Setting USBOTGSS_SYSCONFIG set to NO idle  */
+	val = readl(0x4A020010);
+	writel(0x10034, 0x4A020010);
+
+	/* Set the IRQ Enables */
+	/* Clear status */
+	val = readl(USBOTGSS_UTMI_OTG_STATUS);
+	writel(val, USBOTGSS_UTMI_OTG_STATUS);
+	/* Enable interrupts */
+	writel(0x1, USBOTGSS_IRQENABLE_SET_0);
+	writel(0x13939, USBOTGSS_IRQENABLE_SET_1);
+	/* Check for non zero status */
+	val = readl(USBOTGSS_IRQSTATUS_1);
+	writel(val, USBOTGSS_IRQSTATUS_1);
+	val = readl(USBOTGSS_IRQSTATUS_0);
+	writel(val, USBOTGSS_IRQSTATUS_0);
+}
+
+#ifdef CONFIG_USB_DWC3_HOST
+static struct musb *host;
+static struct usb_hcd hcd;
+static enum usb_device_speed host_speed;
+
+#define DWC_HOST_TIMEOUT	0x3ffffff
+
+static struct usb_host_endpoint hep;
+static struct urb urb;
+
+static void dwc3_host_complete_urb(struct urb *urb)
+{
+	urb->dev->status &= ~USB_ST_NOT_PROC;
+	urb->dev->act_len = urb->actual_length;
+
+	return;
+}
+
+static struct urb *construct_urb(struct usb_device *dev, int endpoint_type,
+				unsigned long pipe, void *buffer, int len,
+				struct devrequest *setup, int interval)
+{
+	int epnum = usb_pipeendpoint(pipe);
+	int is_in = usb_pipein(pipe);
+
+	memset(&urb, 0, sizeof(struct urb));
+	memset(&hep, 0, sizeof(struct usb_host_endpoint));
+
+	INIT_LIST_HEAD(&hep.urb_list);
+
+	INIT_LIST_HEAD(&urb.urb_list);
+	urb.ep = &hep;
+	urb.complete = dwc3_host_complete_urb;
+	urb.status = -EINPROGRESS;
+	urb.dev = dev;
+	urb.pipe = pipe;
+	urb.transfer_buffer = buffer;
+	urb.transfer_dma = (unsigned long)buffer;
+	urb.transfer_buffer_length = len;
+	urb.setup_packet = (unsigned char *)setup;
+
+	urb.ep->desc.wMaxPacketSize =
+		__cpu_to_le16(is_in ? dev->epmaxpacketin[epnum] :
+				dev->epmaxpacketout[epnum]);
+	urb.ep->desc.bmAttributes = endpoint_type;
+	urb.ep->desc.bEndpointAddress =
+		(is_in ? USB_DIR_IN : USB_DIR_OUT) | epnum;
+	urb.ep->desc.bInterval = interval;
+
+	return &urb;
+}
+
+static int submit_urb(struct usb_hcd *hcd, struct urb *urb)
+{
+	return NULL;
+}
+
+int submit_control_msg(struct usb_device *dev, unsigned long pipe,
+			void *buffer, int len, struct devrequest *setup)
+{
+	struct urb *urb = construct_urb(dev, USB_ENDPOINT_XFER_CONTROL, pipe,
+					buffer, len, setup, 0);
+
+	/* Fix speed for non hub-attached devices */
+	if (!dev->parent)
+		dev->speed = host_speed;
+
+	return submit_urb(&hcd, urb);
+}
+
+
+int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
+					void *buffer, int len)
+{
+	struct urb *urb = construct_urb(dev, USB_ENDPOINT_XFER_BULK, pipe,
+					buffer, len, NULL, 0);
+	return submit_urb(&hcd, urb);
+}
+
+int submit_int_msg(struct usb_device *dev, unsigned long pipe,
+				void *buffer, int len, int interval)
+{
+	struct urb *urb = construct_urb(dev, USB_ENDPOINT_XFER_INT, pipe,
+					buffer, len, NULL, interval);
+	return submit_urb(&hcd, urb);
+}
+
+/* The init sequence was abstracted from the core.c probe function */
+int usb_lowlevel_init(int index, void **controller)
+{
+	struct dwc3 *dwc;
+	int ret = -ENOMEM;
+	void *mem;
+	u8 mode;
+
+	mem = kzalloc(sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
+	if (!mem) {
+		dev_err(dev, "not enough memory\n");
+		return -ENOMEM;
+	}
+	dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
+	dwc->mem = mem;
+	dwc->regs = 0x4A030000;
+
+	if (!strncmp("super", maximum_speed, 5))
+		dwc->maximum_speed = DWC3_DCFG_SUPERSPEED;
+	else if (!strncmp("high", maximum_speed, 4))
+		dwc->maximum_speed = DWC3_DCFG_HIGHSPEED;
+	else if (!strncmp("full", maximum_speed, 4))
+		dwc->maximum_speed = DWC3_DCFG_FULLSPEED1;
+	else if (!strncmp("low", maximum_speed, 3))
+		dwc->maximum_speed = DWC3_DCFG_LOWSPEED;
+	else
+		dwc->maximum_speed = DWC3_DCFG_SUPERSPEED;
+
+	setup_usb();
+
+	dwc3_cache_hwparams(dwc);
+
+	ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
+	if (ret) {
+		dev_err(dwc->dev, "failed to allocate event buffers\n");
+		ret = -ENOMEM;
+		goto err0;
+	}
+
+	ret = dwc3_core_init(dwc);
+	if (ret) {
+		dev_err(dev, "failed to initialize core\n");
+		goto err0;
+	}
+
+	ret = dwc3_event_buffers_setup(dwc);
+	if (ret) {
+		dev_err(dwc->dev, "failed to setup event buffers\n");
+		goto err1;
+	}
+/* TODO: Figure out how to enable this
+	if (CONFIG_USB_DWC3_HOST)
+		mode = DWC3_MODE_HOST;
+	else if (CONFIG_USB_DWC3_GADGET)
+		mode = DWC3_MODE_DEVICE;
+	else
+		mode = DWC3_MODE_DRD;
+*/
+	mode = DWC3_MODE_HOST;
+	switch (mode) {
+	case DWC3_MODE_DEVICE:
+		dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
+		ret = dwc3_gadget_init(dwc);
+		if (ret) {
+			printf("failed to initialize gadget\n");
+			goto err2;
+		}
+		break;
+	case DWC3_MODE_HOST:
+		dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
+		ret = dwc3_host_init(dwc);
+		if (ret) {
+			printf("failed to initialize host\n");
+			goto err2;
+		}
+		break;
+	case DWC3_MODE_DRD:
+		dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
+		ret = dwc3_host_init(dwc);
+		if (ret) {
+			printf("failed to initialize host\n");
+			goto err2;
+		}
+
+		ret = dwc3_gadget_init(dwc);
+		if (ret) {
+			printf("failed to initialize gadget\n");
+			goto err2;
+		}
+		break;
+	default:
+		printf("Unsupported mode of operation %d\n", mode);
+		goto err2;
+	}
+	dwc->mode = mode;
+
+	return 0;
+
+err2:
+	dwc3_event_buffers_cleanup(dwc);
+
+err1:
+	dwc3_core_exit(dwc);
+
+err0:
+	dwc3_free_event_buffers(dwc);
+
+	return ret;
+}
+
+int usb_lowlevel_stop(int index)
+{
+	return 0;
+}
+#endif /* CONFIG_USB_DWC3_HOST */
+
+#ifdef CONFIG_USB_DWC3_GADGET
+int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
+{
+	return 0;
+}
+
+static struct dwc *gadget;
+int usb_gadget_register_driver(struct usb_gadget_driver *driver)
+{
+	int ret;
+
+	if (!driver || /* driver->speed < USB_SPEED_FULL ||*/ !driver->bind ||
+	    !driver->setup) {
+		printf("bad parameter.\n");
+		return -EINVAL;
+	}
+
+	if (!gadget) {
+		printf("Controller uninitialized\n");
+		return -ENXIO;
+	}
+
+	return 0;
+}
+
+int usb_gadget_handle_interrupts(void)
+{
+	return 0;
+}
+#endif /* CONFIG_USB_DWC3_GADGET */
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 5acbb94..423301e 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -6,6 +6,8 @@ 
  * Authors: Felipe Balbi <balbi@ti.com>,
  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  *
+ * Back-ported by: Dan Murphy <dmurphy@ti.com>
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -36,6 +38,9 @@ 
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#define __UBOOT__
+#ifndef __UBOOT__
+
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
@@ -50,6 +55,18 @@ 
 #include <linux/usb/gadget.h>
 #include <linux/usb/composite.h>
 
+#else
+
+#include <common.h>
+
+#include <linux/usb/ch9.h>
+#include <linux/usb/gadget.h>
+#include <linux/usb/composite.h>
+#include <linux/usb/linux-compat.h>
+#include <usb/lin_gadget_compat.h>
+
+#endif
+
 #include "core.h"
 #include "gadget.h"
 #include "io.h"
@@ -147,7 +164,12 @@  static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep,
 		direction = !!(dep->flags & DWC3_EP0_DIR_IN);
 
 		if (dwc->ep0state != EP0_DATA_PHASE) {
+
+#ifndef __UBOOT__
 			dev_WARN(dwc->dev, "Unexpected pending request\n");
+#else
+			printf("Unexpected pending request\n");
+#endif
 			return 0;
 		}
 
@@ -902,14 +924,15 @@  static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
 			&& (dep->number == 0)) {
 		u32	transfer_size;
 		u32	maxpacket;
-
+#ifndef __UBOOT__
+	/* FIX THIS DM */
 		ret = usb_gadget_map_request(&dwc->gadget, &req->request,
 				dep->number);
 		if (ret) {
 			dev_dbg(dwc->dev, "failed to map request\n");
 			return;
 		}
-
+#endif
 		WARN_ON(req->request.length > DWC3_EP0_BOUNCE_SIZE);
 
 		maxpacket = dep->endpoint.maxpacket;
@@ -926,13 +949,15 @@  static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
 				dwc->ep0_bounce_addr, transfer_size,
 				DWC3_TRBCTL_CONTROL_DATA);
 	} else {
+#ifndef __UBOOT__
+	/* FIX THIS DM */
 		ret = usb_gadget_map_request(&dwc->gadget, &req->request,
 				dep->number);
 		if (ret) {
 			dev_dbg(dwc->dev, "failed to map request\n");
 			return;
 		}
-
+#endif
 		ret = dwc3_ep0_start_trans(dwc, dep->number, req->request.dma,
 				req->request.length, DWC3_TRBCTL_CONTROL_DATA);
 	}
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 2b6e7e0..694762d 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -6,6 +6,8 @@ 
  * Authors: Felipe Balbi <balbi@ti.com>,
  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  *
+ * Back-ported by: Dan Murphy <dmurphy@ti.com>
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -36,6 +38,9 @@ 
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#define __UBOOT__
+#ifndef __UBOOT__
+
 #include <linux/kernel.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
@@ -50,6 +55,16 @@ 
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 
+#else
+
+#include <common.h>
+#include <linux/usb/ch9.h>
+#include <linux/usb/gadget.h>
+#include <linux/usb/linux-compat.h>
+#include <usb/lin_gadget_compat.h>
+
+#endif
+
 #include "core.h"
 #include "gadget.h"
 #include "io.h"
@@ -268,8 +283,12 @@  void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
 	if (dwc->ep0_bounced && dep->number == 0)
 		dwc->ep0_bounced = false;
 	else
+
+#ifndef __UBOOT__
+	/* FIX THIS DM */
 		usb_gadget_unmap_request(&dwc->gadget, &req->request,
 				req->direction);
+#endif
 
 	dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n",
 			req, dep->name, req->request.actual,
@@ -654,23 +673,44 @@  static int dwc3_gadget_ep_enable(struct usb_ep *ep,
 	dwc = dep->dwc;
 
 	if (dep->flags & DWC3_EP_ENABLED) {
+
+#ifndef __UBOOT__
 		dev_WARN_ONCE(dwc->dev, true, "%s is already enabled\n",
 				dep->name);
+#else
+		printf("%s is already enabled\n", dep->name);
+#endif
 		return 0;
 	}
 
 	switch (usb_endpoint_type(desc)) {
 	case USB_ENDPOINT_XFER_CONTROL:
+#ifndef __UBOOT__
 		strlcat(dep->name, "-control", sizeof(dep->name));
+#else
+		strcat(dep->name, "-control");
+#endif
 		break;
 	case USB_ENDPOINT_XFER_ISOC:
+#ifndef __UBOOT__
 		strlcat(dep->name, "-isoc", sizeof(dep->name));
+#else
+		strcat(dep->name, "-isoc");
+#endif
 		break;
 	case USB_ENDPOINT_XFER_BULK:
+#ifndef __UBOOT__
 		strlcat(dep->name, "-bulk", sizeof(dep->name));
+#else
+		strcat(dep->name, "-bulk");
+#endif
 		break;
 	case USB_ENDPOINT_XFER_INT:
+#ifndef __UBOOT__
 		strlcat(dep->name, "-int", sizeof(dep->name));
+#else
+		strcat(dep->name, "-int");
+#endif
 		break;
 	default:
 		dev_err(dwc->dev, "invalid endpoint transfer type\n");
@@ -701,8 +741,12 @@  static int dwc3_gadget_ep_disable(struct usb_ep *ep)
 	dwc = dep->dwc;
 
 	if (!(dep->flags & DWC3_EP_ENABLED)) {
+#ifndef __UBOOT__
 		dev_WARN_ONCE(dwc->dev, true, "%s is already disabled\n",
 				dep->name);
+#else
+		printf("%s is already disabled\n", dep->name);
+#endif
 		return 0;
 	}
 
@@ -896,6 +940,9 @@  static void dwc3_prepare_trbs(struct dwc3_ep *dep, bool starting)
 			struct scatterlist *s;
 			int		i;
 
+			printf("Fix this\n");
+#ifndef __UBOOT__
+	/* FIX THIS DM */
 			for_each_sg(sg, s, request->num_mapped_sgs, i) {
 				unsigned chain = true;
 
@@ -923,6 +970,7 @@  static void dwc3_prepare_trbs(struct dwc3_ep *dep, bool starting)
 				if (last_one)
 					break;
 			}
+#endif
 		} else {
 			dma = req->request.dma;
 			length = req->request.length;
@@ -1002,8 +1050,11 @@  static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep, u16 cmd_param,
 		 * here and stop, unmap, free and del each of the linked
 		 * requests instead of what we do now.
 		 */
+#ifndef __UBOOT__
+	/* FIX THIS DM */
 		usb_gadget_unmap_request(&dwc->gadget, &req->request,
 				req->direction);
+#endif
 		list_del(&req->list);
 		return ret;
 	}
@@ -1070,11 +1121,13 @@  static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req)
 	 * This will also avoid Host cancelling URBs due to too
 	 * many NAKs.
 	 */
+#ifndef __UBOOT__
+	/* FIX THIS DM */
 	ret = usb_gadget_map_request(&dwc->gadget, &req->request,
 			dep->direction);
 	if (ret)
 		return ret;
-
+#endif
 	list_add_tail(&req->list, &dep->request_list);
 
 	/*
@@ -1376,14 +1429,23 @@  static int dwc3_gadget_wakeup(struct usb_gadget *g)
 	}
 
 	/* poll until Link State changes to ON */
+#ifndef __UBOOT__
 	timeout = jiffies + msecs_to_jiffies(100);
-
 	while (!time_after(jiffies, timeout)) {
+#else
+	timeout = 100;
+	while (timeout != 0) {
+#endif
+
 		reg = dwc3_readl(dwc->regs, DWC3_DSTS);
 
 		/* in HS, means ON */
 		if (DWC3_DSTS_USBLNKST(reg) == DWC3_LINK_STATE_U0)
 			break;
+#ifdef __UBOOT__
+		mdelay(1);
+		timeout--;
+#endif
 	}
 
 	if (DWC3_DSTS_USBLNKST(reg) != DWC3_LINK_STATE_U0) {
@@ -1564,7 +1626,7 @@  static int dwc3_gadget_start(struct usb_gadget *g,
 	/* begin to receive SETUP packets */
 	dwc->ep0state = EP0_SETUP_PHASE;
 	dwc3_ep0_out_start(dwc);
-
+#ifndef __UBOOT__
 	irq = platform_get_irq(to_platform_device(dwc->dev), 0);
 	ret = request_threaded_irq(irq, dwc3_interrupt, dwc3_thread_interrupt,
 			IRQF_SHARED | IRQF_ONESHOT, "dwc3", dwc);
@@ -1573,7 +1635,7 @@  static int dwc3_gadget_start(struct usb_gadget *g,
 				irq, ret);
 		goto err1;
 	}
-
+#endif /* __UBOOT__ */
 	dwc3_gadget_enable_irq(dwc);
 
 	spin_unlock_irqrestore(&dwc->lock, flags);
@@ -1599,8 +1661,10 @@  static int dwc3_gadget_stop(struct usb_gadget *g,
 	spin_lock_irqsave(&dwc->lock, flags);
 
 	dwc3_gadget_disable_irq(dwc);
+#ifndef __UBOOT__
 	irq = platform_get_irq(to_platform_device(dwc->dev), 0);
 	free_irq(irq, dwc);
+#endif
 
 	__dwc3_gadget_ep_disable(dwc->eps[0]);
 	__dwc3_gadget_ep_disable(dwc->eps[1]);
@@ -2644,12 +2708,13 @@  int dwc3_gadget_init(struct dwc3 *dwc)
 		dwc3_gadget_usb3_phy_suspend(dwc, false);
 	}
 
+#ifndef __UBOOT__
 	ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget);
 	if (ret) {
 		dev_err(dwc->dev, "failed to register udc\n");
 		goto err5;
 	}
-
+#endif
 	return 0;
 
 err5:
diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h
index 99e6d72..23c57fe 100644
--- a/drivers/usb/dwc3/gadget.h
+++ b/drivers/usb/dwc3/gadget.h
@@ -6,6 +6,8 @@ 
  * Authors: Felipe Balbi <balbi@ti.com>,
  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  *
+ * Back-ported by: Dan Murphy <dmurphy@ti.com>
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
index 0fa1846..0171b6c 100644
--- a/drivers/usb/dwc3/host.c
+++ b/drivers/usb/dwc3/host.c
@@ -5,6 +5,8 @@ 
  *
  * Authors: Felipe Balbi <balbi@ti.com>,
  *
+ * Back-ported by: Dan Murphy <dmurphy@ti.com>
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -35,30 +37,44 @@ 
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#define __UBOOT__
+#ifndef __UBOOT__
 #include <linux/platform_device.h>
+#endif
 
 #include "core.h"
 
 int dwc3_host_init(struct dwc3 *dwc)
 {
+#ifndef __UBOOT__
 	struct platform_device	*xhci;
+#endif
+	void *xhci;
 	int			ret;
-
+#ifndef __UBOOT__
 	xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
 	if (!xhci) {
 		dev_err(dwc->dev, "couldn't allocate xHCI device\n");
 		ret = -ENOMEM;
 		goto err0;
 	}
-
 	dma_set_coherent_mask(&xhci->dev, dwc->dev->coherent_dma_mask);
 
 	xhci->dev.parent	= dwc->dev;
 	xhci->dev.dma_mask	= dwc->dev->dma_mask;
 	xhci->dev.dma_parms	= dwc->dev->dma_parms;
 
+#else
+	xhci = kzalloc(sizeof(*dwc), GFP_KERNEL);
+	if (!xhci) {
+		dev_err(dev, "not enough memory\n");
+		return -ENOMEM;
+	}
+#endif
+
 	dwc->xhci = xhci;
 
+#ifndef __UBOOT__
 	ret = platform_device_add_resources(xhci, dwc->xhci_resources,
 						DWC3_XHCI_RESOURCES_NUM);
 	if (ret) {
@@ -71,11 +87,14 @@  int dwc3_host_init(struct dwc3 *dwc)
 		dev_err(dwc->dev, "failed to register xHCI device\n");
 		goto err1;
 	}
-
+#endif
 	return 0;
 
 err1:
+#ifndef __UBOOT__
 	platform_device_put(xhci);
+#endif
+
 
 err0:
 	return ret;
@@ -83,5 +102,7 @@  err0:
 
 void dwc3_host_exit(struct dwc3 *dwc)
 {
+#ifndef __UBOOT__
 	platform_device_unregister(dwc->xhci);
+#endif
 }
diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h
index a50f76b..2b0895a 100644
--- a/drivers/usb/dwc3/io.h
+++ b/drivers/usb/dwc3/io.h
@@ -6,6 +6,8 @@ 
  * Authors: Felipe Balbi <balbi@ti.com>,
  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
  *
+ * Back-ported by: Dan Murphy <dmurphy@ti.com>
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -39,7 +41,12 @@ 
 #ifndef __DRIVERS_USB_DWC3_IO_H
 #define __DRIVERS_USB_DWC3_IO_H
 
+#define __UBOOT__
+#ifndef __UBOOT__
 #include <linux/io.h>
+#else
+#include <asm/io.h>
+#endif
 
 #include "core.h"
 
@@ -50,7 +57,11 @@  static inline u32 dwc3_readl(void __iomem *base, u32 offset)
 	 * space, see dwc3_probe in core.c.
 	 * However, the offsets are given starting from xHCI address space.
 	 */
+#ifndef __UBOOT__
 	return readl(base + (offset - DWC3_GLOBALS_REGS_START));
+#else
+	return readl(base + offset);
+#endif
 }
 
 static inline void dwc3_writel(void __iomem *base, u32 offset, u32 value)
@@ -60,7 +71,11 @@  static inline void dwc3_writel(void __iomem *base, u32 offset, u32 value)
 	 * space, see dwc3_probe in core.c.
 	 * However, the offsets are given starting from xHCI address space.
 	 */
+#ifndef __UBOOT__
 	writel(value, base + (offset - DWC3_GLOBALS_REGS_START));
+#else
+	writel(value, (base + offset));
+#endif
 }
 
 #endif /* __DRIVERS_USB_DWC3_IO_H */