diff mbox

[v2,1/5] usb: dwc3: Add Keystone specific glue layer

Message ID 1386187811-9596-2-git-send-email-w-kwok2@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

WingMan Kwok Dec. 4, 2013, 8:10 p.m. UTC
Add Keystone platform specific glue layer to support
USB3 Host mode.

Cc: Santosh Shilimkar <santosh.shilimkar@ti.com>
Cc: Felipe Balbi <balbi@ti.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: WingMan Kwok <w-kwok2@ti.com>
---
 drivers/usb/dwc3/Kconfig         |    7 ++
 drivers/usb/dwc3/Makefile        |    1 +
 drivers/usb/dwc3/dwc3-keystone.c |  210 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 218 insertions(+)
 create mode 100644 drivers/usb/dwc3/dwc3-keystone.c

Comments

Felipe Balbi Dec. 6, 2013, 8:28 p.m. UTC | #1
Hi,

On Wed, Dec 04, 2013 at 03:10:07PM -0500, WingMan Kwok wrote:
> Add Keystone platform specific glue layer to support
> USB3 Host mode.
> 
> Cc: Santosh Shilimkar <santosh.shilimkar@ti.com>
> Cc: Felipe Balbi <balbi@ti.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: WingMan Kwok <w-kwok2@ti.com>
> ---
>  drivers/usb/dwc3/Kconfig         |    7 ++
>  drivers/usb/dwc3/Makefile        |    1 +
>  drivers/usb/dwc3/dwc3-keystone.c |  210 ++++++++++++++++++++++++++++++++++++++
>  3 files changed, 218 insertions(+)
>  create mode 100644 drivers/usb/dwc3/dwc3-keystone.c
> 
> diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
> index 70fc430..e2c730f 100644
> --- a/drivers/usb/dwc3/Kconfig
> +++ b/drivers/usb/dwc3/Kconfig
> @@ -70,6 +70,13 @@ config USB_DWC3_PCI
>  	  One such PCIe-based platform is Synopsys' PCIe HAPS model of
>  	  this IP.
>  
> +config USB_DWC3_KEYSTONE
> +	tristate "Texas Instruments Keystone2 Platforms"
> +	default USB_DWC3
> +	help
> +	  Support of USB2/3 functionality in TI Keystone2 platforms.
> +	  Say 'Y' or 'M' here if you have one such device
> +
>  comment "Debugging features"
>  
>  config USB_DWC3_DEBUG
> diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
> index dd17601..10ac3e7 100644
> --- a/drivers/usb/dwc3/Makefile
> +++ b/drivers/usb/dwc3/Makefile
> @@ -32,3 +32,4 @@ endif
>  obj-$(CONFIG_USB_DWC3_OMAP)		+= dwc3-omap.o
>  obj-$(CONFIG_USB_DWC3_EXYNOS)		+= dwc3-exynos.o
>  obj-$(CONFIG_USB_DWC3_PCI)		+= dwc3-pci.o
> +obj-$(CONFIG_USB_DWC3_KEYSTONE)		+= dwc3-keystone.o
> diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c
> new file mode 100644
> index 0000000..d3c0dc5
> --- /dev/null
> +++ b/drivers/usb/dwc3/dwc3-keystone.c
> @@ -0,0 +1,210 @@
> +/**
> + * dwc3-keystone.c - Keystone Specific Glue layer
> + *
> + * Copyright (C) 2010-2013 Texas Instruments Incorporated - http://www.ti.com
> + *
> + * Author: WingMan Kwok <w-kwok2@ti.com>
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2  of
> + * the License as published by the Free Software Foundation.
> + *
> + * 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.
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/module.h>
> +#include <linux/kernel.h>
> +#include <linux/interrupt.h>
> +#include <linux/spinlock.h>
> +#include <linux/platform_device.h>
> +#include <linux/dma-mapping.h>
> +#include <linux/io.h>
> +#include <linux/of_platform.h>
> +
> +/* USBSS register offsets */
> +#define USBSS_REVISION		0x0000
> +#define USBSS_SYSCONFIG		0x0010
> +#define USBSS_IRQ_EOI		0x0018
> +#define USBSS_IRQSTATUS_RAW_0	0x0020
> +#define USBSS_IRQSTATUS_0	0x0024
> +#define USBSS_IRQENABLE_SET_0	0x0028
> +#define USBSS_IRQENABLE_CLR_0	0x002c
> +
> +/* IRQ register bits */
> +#define USBSS_IRQ_EOI_LINE(n)	BIT(n)
> +#define USBSS_IRQ_EVENT_ST	BIT(0)
> +#define USBSS_IRQ_COREIRQ_EN	BIT(0)
> +#define USBSS_IRQ_COREIRQ_CLR	BIT(0)
> +
> +static u64 kdwc3_dma_mask;
> +
> +struct dwc3_keystone {
> +	spinlock_t			lock;
> +	struct device			*dev;
> +	struct clk			*clk;
> +	void __iomem			*usbss;
> +};
> +
> +static inline u32 kdwc3_readl(void __iomem *base, u32 offset)
> +{
> +	return readl(base + offset);
> +}
> +
> +static inline void kdwc3_writel(void __iomem *base, u32 offset, u32 value)
> +{
> +	writel(value, base + offset);
> +}
> +
> +static void kdwc3_enable_irqs(struct dwc3_keystone *kdwc)
> +{
> +	u32 val;
> +
> +	val = kdwc3_readl(kdwc->usbss, USBSS_IRQENABLE_SET_0);
> +	val = USBSS_IRQ_COREIRQ_EN;
> +	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, val);
> +}
> +
> +static void kdwc3_disable_irqs(struct dwc3_keystone *kdwc)
> +{
> +	u32 val;
> +
> +	val = kdwc3_readl(kdwc->usbss, USBSS_IRQENABLE_SET_0);
> +	val &= ~USBSS_IRQ_COREIRQ_EN;
> +	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, val);
> +}
> +
> +static irqreturn_t dwc3_keystone_interrupt(int irq, void *_kdwc)
> +{
> +	struct dwc3_keystone	*kdwc = _kdwc;
> +
> +	spin_lock(&kdwc->lock);

Isn't this lock unnecessary ? This handler will run with IRQs disabled
anyway.

> +	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_CLR_0, USBSS_IRQ_COREIRQ_CLR);
> +	kdwc3_writel(kdwc->usbss, USBSS_IRQSTATUS_0, USBSS_IRQ_EVENT_ST);
> +	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, USBSS_IRQ_COREIRQ_EN);
> +	kdwc3_writel(kdwc->usbss, USBSS_IRQ_EOI, USBSS_IRQ_EOI_LINE(0));
> +	spin_unlock(&kdwc->lock);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static int kdwc3_probe(struct platform_device *pdev)
> +{
> +	struct device_node	*node = pdev->dev.of_node;
> +	struct device		*dev = &pdev->dev;

if you invert these lines, it'll look a little nicer:

	struct device		*dev = &pdev->dev;
	struct device_node	*node = dev->of_node;

everything else looks pretty good, thanks
Santosh Shilimkar Dec. 6, 2013, 9:39 p.m. UTC | #2
On Friday 06 December 2013 03:28 PM, Felipe Balbi wrote:
> Hi,
> 
> On Wed, Dec 04, 2013 at 03:10:07PM -0500, WingMan Kwok wrote:
>> Add Keystone platform specific glue layer to support
>> USB3 Host mode.
>>
>> Cc: Santosh Shilimkar <santosh.shilimkar@ti.com>
>> Cc: Felipe Balbi <balbi@ti.com>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Signed-off-by: WingMan Kwok <w-kwok2@ti.com>
>> ---
>>  drivers/usb/dwc3/Kconfig         |    7 ++
>>  drivers/usb/dwc3/Makefile        |    1 +
>>  drivers/usb/dwc3/dwc3-keystone.c |  210 ++++++++++++++++++++++++++++++++++++++
>>  3 files changed, 218 insertions(+)
>>  create mode 100644 drivers/usb/dwc3/dwc3-keystone.c

[..]

>> +static irqreturn_t dwc3_keystone_interrupt(int irq, void *_kdwc)
>> +{
>> +	struct dwc3_keystone	*kdwc = _kdwc;
>> +
>> +	spin_lock(&kdwc->lock);
> 
> Isn't this lock unnecessary ? This handler will run with IRQs disabled
> anyway.
> 
Indeed.

>> +	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_CLR_0, USBSS_IRQ_COREIRQ_CLR);
>> +	kdwc3_writel(kdwc->usbss, USBSS_IRQSTATUS_0, USBSS_IRQ_EVENT_ST);
>> +	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, USBSS_IRQ_COREIRQ_EN);
>> +	kdwc3_writel(kdwc->usbss, USBSS_IRQ_EOI, USBSS_IRQ_EOI_LINE(0));
>> +	spin_unlock(&kdwc->lock);
>> +
>> +	return IRQ_HANDLED;
>> +}
>> +
>> +static int kdwc3_probe(struct platform_device *pdev)
>> +{
>> +	struct device_node	*node = pdev->dev.of_node;
>> +	struct device		*dev = &pdev->dev;
> 
> if you invert these lines, it'll look a little nicer:
> 
> 	struct device		*dev = &pdev->dev;
> 	struct device_node	*node = dev->of_node;
> 
> everything else looks pretty good, thanks
> 
Looks good to me as well. With above update, 
Acked-by: Santosh Shilimkar <santosh.shilimkar@ti.com>
Paul Zimmerman Dec. 6, 2013, 10:23 p.m. UTC | #3
> From: linux-usb-owner@vger.kernel.org [mailto:linux-usb-owner@vger.kernel.org] On Behalf Of Santosh Shilimkar
> Sent: Friday, December 06, 2013 1:40 PM
> 
> On Friday 06 December 2013 03:28 PM, Felipe Balbi wrote:
> > Hi,
> >
> > On Wed, Dec 04, 2013 at 03:10:07PM -0500, WingMan Kwok wrote:
> >> Add Keystone platform specific glue layer to support
> >> USB3 Host mode.
> >>
> >> Cc: Santosh Shilimkar <santosh.shilimkar@ti.com>
> >> Cc: Felipe Balbi <balbi@ti.com>
> >> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >> Signed-off-by: WingMan Kwok <w-kwok2@ti.com>
> >> ---
> >>  drivers/usb/dwc3/Kconfig         |    7 ++
> >>  drivers/usb/dwc3/Makefile        |    1 +
> >>  drivers/usb/dwc3/dwc3-keystone.c |  210 ++++++++++++++++++++++++++++++++++++++
> >>  3 files changed, 218 insertions(+)
> >>  create mode 100644 drivers/usb/dwc3/dwc3-keystone.c
> 
> [..]
> 
> >> +static irqreturn_t dwc3_keystone_interrupt(int irq, void *_kdwc)
> >> +{
> >> +	struct dwc3_keystone	*kdwc = _kdwc;
> >> +
> >> +	spin_lock(&kdwc->lock);
> >
> > Isn't this lock unnecessary ? This handler will run with IRQs disabled
> > anyway.
> >
> Indeed.

Say what? AFAIK it's necessary to take the driver lock inside the interrupt
handler, because of SMP. Here is the equivalent routine from dwc3-omap.c:

static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
{
        struct dwc3_omap        *omap = _omap;
        u32                     reg;

        spin_lock(&omap->lock);

        ...
}

Has this now become unnecessary?
Santosh Shilimkar Dec. 7, 2013, 5:25 a.m. UTC | #4
(sorry for html reply)
Paul Zimmerman Dec. 7, 2013, 6:25 a.m. UTC | #5
> From: Shilimkar, Santosh [mailto:santosh.shilimkar@ti.com]
> Sent: Friday, December 06, 2013 9:25 PM
> 
>> From: Paul Zimmerman [Paul.Zimmerman@synopsys.com]
>> Sent: Friday, December 06, 2013 5:23 PM
>> 
>> > From: linux-usb-owner@vger.kernel.org [mailto:linux-usb-owner@vger.kernel.org] On Behalf Of Santosh Shilimkar
>> > Sent: Friday, December 06, 2013 1:40 PM
>> >
>> > On Friday 06 December 2013 03:28 PM, Felipe Balbi wrote:
>> > > Hi,
>> > >
>> > > On Wed, Dec 04, 2013 at 03:10:07PM -0500, WingMan Kwok wrote:
>> > >> Add Keystone platform specific glue layer to support
>> > >> USB3 Host mode.
>> > >>
>> > >> Cc: Santosh Shilimkar <santosh.shilimkar@ti.com>
>> > >> Cc: Felipe Balbi <balbi@ti.com>
>> > >> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> > >> Signed-off-by: WingMan Kwok <w-kwok2@ti.com>
>> > >> ---
>> > >>  drivers/usb/dwc3/Kconfig         |    7 ++
>> > >>  drivers/usb/dwc3/Makefile        |    1 +
>> > >>  drivers/usb/dwc3/dwc3-keystone.c |  210 ++++++++++++++++++++++++++++++++++++++
>> > >>  3 files changed, 218 insertions(+)
>> > >>  create mode 100644 drivers/usb/dwc3/dwc3-keystone.c
>> >
>> > [..]
>> >
>> > >> +static irqreturn_t dwc3_keystone_interrupt(int irq, void *_kdwc)
>> > >> +{
>> > >> +  struct dwc3_keystone    *kdwc = _kdwc;
>> > >> +
>> > >> +  spin_lock(&kdwc->lock);
>> > >
>> > > Isn't this lock unnecessary ? This handler will run with IRQs disabled
>> > > anyway.
>> > >
>> > Indeed.
>>
>> Say what? AFAIK it's necessary to take the driver lock inside the interrupt
>> handler, because of SMP. Here is the equivalent routine from dwc3-omap.c:
>> 
>> static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
>> {
>>         struct dwc3_omap        *omap = _omap;
>>         u32                     reg;
>> 
>>         spin_lock(&omap->lock);
>> 
>>         ...
>> }
>> 
>> Has this now become unnecessary?
> 
> [Santosh] Not sure if i am missing your point, but this lock is not
> needed IMHO. The register update which is protected by the lock
> happens only in ISR where the source of the irq is disabled, so
> even on SMP machines there is no race possible which needs to
> be protected.
> 
> I would have agreed to you if there was some additional code outside
> isr  and the code in ISR were both needed lock and that would have been
> issue on SMP machine without spin lock.
> 
> On  OMAP code as well the lock is not needed but I let Felipe comment
> about it.

Yes sorry, I see now the lock is only taken in the ISR.

So you should probably get rid of the lock altogether, no?
Felipe Balbi Dec. 7, 2013, 5:53 p.m. UTC | #6
On Fri, Dec 06, 2013 at 11:25:24PM -0600, Shilimkar, Santosh wrote:
> (sorry for html reply)
> ________________________________________
> From: Paul Zimmerman [Paul.Zimmerman@synopsys.com]
> Sent: Friday, December 06, 2013 5:23 PM
> To: Shilimkar, Santosh; Balbi, Felipe; Kwok, WingMan
> Cc: linux-arm-kernel@lists.infradead.org; linux-usb@vger.kernel.org; Greg Kroah-Hartman
> Subject: RE: [PATCH v2 1/5] usb: dwc3: Add Keystone specific glue layer
> 
> > From: linux-usb-owner@vger.kernel.org [mailto:linux-usb-owner@vger.kernel.org] On Behalf Of Santosh Shilimkar
> > Sent: Friday, December 06, 2013 1:40 PM
> >
> > On Friday 06 December 2013 03:28 PM, Felipe Balbi wrote:
> > > Hi,
> > >
> > > On Wed, Dec 04, 2013 at 03:10:07PM -0500, WingMan Kwok wrote:
> > >> Add Keystone platform specific glue layer to support
> > >> USB3 Host mode.
> > >>
> > >> Cc: Santosh Shilimkar <santosh.shilimkar@ti.com>
> > >> Cc: Felipe Balbi <balbi@ti.com>
> > >> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > >> Signed-off-by: WingMan Kwok <w-kwok2@ti.com>
> > >> ---
> > >>  drivers/usb/dwc3/Kconfig         |    7 ++
> > >>  drivers/usb/dwc3/Makefile        |    1 +
> > >>  drivers/usb/dwc3/dwc3-keystone.c |  210 ++++++++++++++++++++++++++++++++++++++
> > >>  3 files changed, 218 insertions(+)
> > >>  create mode 100644 drivers/usb/dwc3/dwc3-keystone.c
> >
> > [..]
> >
> > >> +static irqreturn_t dwc3_keystone_interrupt(int irq, void *_kdwc)
> > >> +{
> > >> +  struct dwc3_keystone    *kdwc = _kdwc;
> > >> +
> > >> +  spin_lock(&kdwc->lock);
> > >
> > > Isn't this lock unnecessary ? This handler will run with IRQs disabled
> > > anyway.
> > >
> > Indeed.
> -------------------------------
> Say what? AFAIK it's necessary to take the driver lock inside the interrupt
> handler, because of SMP. Here is the equivalent routine from dwc3-omap.c:
> 
> static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
> {
>         struct dwc3_omap        *omap = _omap;
>         u32                     reg;
> 
>         spin_lock(&omap->lock);
> 
>         ...--
> Paul
> 
> 
> }
> 
> Has this now become unnecessary?
> ----------------
> 
> [Santosh] Not sure if i am missing your point, but this lock is not
> needed IMHO. The register update which is protected by the lock
> happens only in ISR where the source of the irq is disabled, so
> even on SMP machines there is no race possible which needs to
> be protected.
> 
> I would have agreed to you if there was some additional code outside
> isr  and the code in ISR were both needed lock and that would have been
> issue on SMP machine without spin lock.
> 
> On  OMAP code as well the lock is not needed but I let Felipe comment
> about it.

correct, I'll patch that up for v3.14 :-)
diff mbox

Patch

diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index 70fc430..e2c730f 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -70,6 +70,13 @@  config USB_DWC3_PCI
 	  One such PCIe-based platform is Synopsys' PCIe HAPS model of
 	  this IP.
 
+config USB_DWC3_KEYSTONE
+	tristate "Texas Instruments Keystone2 Platforms"
+	default USB_DWC3
+	help
+	  Support of USB2/3 functionality in TI Keystone2 platforms.
+	  Say 'Y' or 'M' here if you have one such device
+
 comment "Debugging features"
 
 config USB_DWC3_DEBUG
diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
index dd17601..10ac3e7 100644
--- a/drivers/usb/dwc3/Makefile
+++ b/drivers/usb/dwc3/Makefile
@@ -32,3 +32,4 @@  endif
 obj-$(CONFIG_USB_DWC3_OMAP)		+= dwc3-omap.o
 obj-$(CONFIG_USB_DWC3_EXYNOS)		+= dwc3-exynos.o
 obj-$(CONFIG_USB_DWC3_PCI)		+= dwc3-pci.o
+obj-$(CONFIG_USB_DWC3_KEYSTONE)		+= dwc3-keystone.o
diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c
new file mode 100644
index 0000000..d3c0dc5
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-keystone.c
@@ -0,0 +1,210 @@ 
+/**
+ * dwc3-keystone.c - Keystone Specific Glue layer
+ *
+ * Copyright (C) 2010-2013 Texas Instruments Incorporated - http://www.ti.com
+ *
+ * Author: WingMan Kwok <w-kwok2@ti.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#include <linux/clk.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/interrupt.h>
+#include <linux/spinlock.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/io.h>
+#include <linux/of_platform.h>
+
+/* USBSS register offsets */
+#define USBSS_REVISION		0x0000
+#define USBSS_SYSCONFIG		0x0010
+#define USBSS_IRQ_EOI		0x0018
+#define USBSS_IRQSTATUS_RAW_0	0x0020
+#define USBSS_IRQSTATUS_0	0x0024
+#define USBSS_IRQENABLE_SET_0	0x0028
+#define USBSS_IRQENABLE_CLR_0	0x002c
+
+/* IRQ register bits */
+#define USBSS_IRQ_EOI_LINE(n)	BIT(n)
+#define USBSS_IRQ_EVENT_ST	BIT(0)
+#define USBSS_IRQ_COREIRQ_EN	BIT(0)
+#define USBSS_IRQ_COREIRQ_CLR	BIT(0)
+
+static u64 kdwc3_dma_mask;
+
+struct dwc3_keystone {
+	spinlock_t			lock;
+	struct device			*dev;
+	struct clk			*clk;
+	void __iomem			*usbss;
+};
+
+static inline u32 kdwc3_readl(void __iomem *base, u32 offset)
+{
+	return readl(base + offset);
+}
+
+static inline void kdwc3_writel(void __iomem *base, u32 offset, u32 value)
+{
+	writel(value, base + offset);
+}
+
+static void kdwc3_enable_irqs(struct dwc3_keystone *kdwc)
+{
+	u32 val;
+
+	val = kdwc3_readl(kdwc->usbss, USBSS_IRQENABLE_SET_0);
+	val = USBSS_IRQ_COREIRQ_EN;
+	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, val);
+}
+
+static void kdwc3_disable_irqs(struct dwc3_keystone *kdwc)
+{
+	u32 val;
+
+	val = kdwc3_readl(kdwc->usbss, USBSS_IRQENABLE_SET_0);
+	val &= ~USBSS_IRQ_COREIRQ_EN;
+	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, val);
+}
+
+static irqreturn_t dwc3_keystone_interrupt(int irq, void *_kdwc)
+{
+	struct dwc3_keystone	*kdwc = _kdwc;
+
+	spin_lock(&kdwc->lock);
+	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_CLR_0, USBSS_IRQ_COREIRQ_CLR);
+	kdwc3_writel(kdwc->usbss, USBSS_IRQSTATUS_0, USBSS_IRQ_EVENT_ST);
+	kdwc3_writel(kdwc->usbss, USBSS_IRQENABLE_SET_0, USBSS_IRQ_COREIRQ_EN);
+	kdwc3_writel(kdwc->usbss, USBSS_IRQ_EOI, USBSS_IRQ_EOI_LINE(0));
+	spin_unlock(&kdwc->lock);
+
+	return IRQ_HANDLED;
+}
+
+static int kdwc3_probe(struct platform_device *pdev)
+{
+	struct device_node	*node = pdev->dev.of_node;
+	struct device		*dev = &pdev->dev;
+	struct dwc3_keystone	*kdwc;
+	struct resource		*res;
+	int			error, irq;
+
+	kdwc = devm_kzalloc(dev, sizeof(*kdwc), GFP_KERNEL);
+	if (!kdwc)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, kdwc);
+
+	spin_lock_init(&kdwc->lock);
+	kdwc->dev = dev;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "missing usbss resource\n");
+		return -EINVAL;
+	}
+
+	kdwc->usbss = devm_ioremap_resource(dev, res);
+	if (IS_ERR(kdwc->usbss))
+		return PTR_ERR(kdwc->usbss);
+
+	kdwc3_dma_mask = dma_get_mask(dev);
+	dev->dma_mask = &kdwc3_dma_mask;
+
+	kdwc->clk = devm_clk_get(kdwc->dev, "usb");
+	if (IS_ERR_OR_NULL(kdwc->clk)) {
+		dev_err(kdwc->dev, "unable to get kdwc usb clock\n");
+		return -ENODEV;
+	}
+
+	error = clk_prepare_enable(kdwc->clk);
+	if (error < 0) {
+		dev_dbg(kdwc->dev, "unable to enable usb clock, err %d\n",
+			error);
+		return error;
+	}
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "missing irq\n");
+		goto err_irq;
+	}
+
+	error = devm_request_irq(dev, irq, dwc3_keystone_interrupt, IRQF_SHARED,
+			dev_name(dev), kdwc);
+	if (error) {
+		dev_err(dev, "failed to request IRQ #%d --> %d\n",
+				irq, error);
+		goto err_irq;
+	}
+
+	kdwc3_enable_irqs(kdwc);
+
+	error = of_platform_populate(node, NULL, NULL, dev);
+	if (error) {
+		dev_err(&pdev->dev, "failed to create dwc3 core\n");
+		goto err_core;
+	}
+
+	return 0;
+
+err_core:
+	kdwc3_disable_irqs(kdwc);
+err_irq:
+	clk_disable_unprepare(kdwc->clk);
+
+	return error;
+}
+
+static int kdwc3_remove_core(struct device *dev, void *c)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+
+	platform_device_unregister(pdev);
+
+	return 0;
+}
+
+static int kdwc3_remove(struct platform_device *pdev)
+{
+	struct dwc3_keystone *kdwc = platform_get_drvdata(pdev);
+
+	kdwc3_disable_irqs(kdwc);
+	clk_disable_unprepare(kdwc->clk);
+	device_for_each_child(&pdev->dev, NULL, kdwc3_remove_core);
+	platform_set_drvdata(pdev, NULL);
+	return 0;
+}
+
+static const struct of_device_id kdwc3_of_match[] = {
+	{ .compatible = "ti,keystone-dwc3", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, kdwc3_of_match);
+
+static struct platform_driver kdwc3_driver = {
+	.probe		= kdwc3_probe,
+	.remove		= kdwc3_remove,
+	.driver		= {
+		.name	= "keystone-dwc3",
+		.owner	        = THIS_MODULE,
+		.of_match_table	= kdwc3_of_match,
+	},
+};
+
+module_platform_driver(kdwc3_driver);
+
+MODULE_ALIAS("platform:keystone-dwc3");
+MODULE_AUTHOR("WingMan Kwok <w-kwok2@ti.com>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("DesignWare USB3 KEYSTONE Glue Layer");