xref: /openbmc/linux/drivers/usb/dwc3/core.c (revision b5a65c40)
172246da4SFelipe Balbi /**
272246da4SFelipe Balbi  * core.c - DesignWare USB3 DRD Controller Core file
372246da4SFelipe Balbi  *
472246da4SFelipe Balbi  * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
572246da4SFelipe Balbi  *
672246da4SFelipe Balbi  * Authors: Felipe Balbi <balbi@ti.com>,
772246da4SFelipe Balbi  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
872246da4SFelipe Balbi  *
95945f789SFelipe Balbi  * This program is free software: you can redistribute it and/or modify
105945f789SFelipe Balbi  * it under the terms of the GNU General Public License version 2  of
115945f789SFelipe Balbi  * the License as published by the Free Software Foundation.
1272246da4SFelipe Balbi  *
135945f789SFelipe Balbi  * This program is distributed in the hope that it will be useful,
145945f789SFelipe Balbi  * but WITHOUT ANY WARRANTY; without even the implied warranty of
155945f789SFelipe Balbi  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
165945f789SFelipe Balbi  * GNU General Public License for more details.
1772246da4SFelipe Balbi  *
185945f789SFelipe Balbi  * You should have received a copy of the GNU General Public License
195945f789SFelipe Balbi  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
2072246da4SFelipe Balbi  */
2172246da4SFelipe Balbi 
22fa0ea13eSFelipe Balbi #include <linux/version.h>
23a72e658bSFelipe Balbi #include <linux/module.h>
2472246da4SFelipe Balbi #include <linux/kernel.h>
2572246da4SFelipe Balbi #include <linux/slab.h>
2672246da4SFelipe Balbi #include <linux/spinlock.h>
2772246da4SFelipe Balbi #include <linux/platform_device.h>
2872246da4SFelipe Balbi #include <linux/pm_runtime.h>
2972246da4SFelipe Balbi #include <linux/interrupt.h>
3072246da4SFelipe Balbi #include <linux/ioport.h>
3172246da4SFelipe Balbi #include <linux/io.h>
3272246da4SFelipe Balbi #include <linux/list.h>
3372246da4SFelipe Balbi #include <linux/delay.h>
3472246da4SFelipe Balbi #include <linux/dma-mapping.h>
35457e84b6SFelipe Balbi #include <linux/of.h>
36404905a6SHeikki Krogerus #include <linux/acpi.h>
3772246da4SFelipe Balbi 
3872246da4SFelipe Balbi #include <linux/usb/ch9.h>
3972246da4SFelipe Balbi #include <linux/usb/gadget.h>
40f7e846f0SFelipe Balbi #include <linux/usb/of.h>
41a45c82b8SRuchika Kharwar #include <linux/usb/otg.h>
4272246da4SFelipe Balbi 
436462cbd5SFelipe Balbi #include "platform_data.h"
4472246da4SFelipe Balbi #include "core.h"
4572246da4SFelipe Balbi #include "gadget.h"
4672246da4SFelipe Balbi #include "io.h"
4772246da4SFelipe Balbi 
4872246da4SFelipe Balbi #include "debug.h"
4972246da4SFelipe Balbi 
508300dd23SFelipe Balbi /* -------------------------------------------------------------------------- */
518300dd23SFelipe Balbi 
523140e8cbSSebastian Andrzej Siewior void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
533140e8cbSSebastian Andrzej Siewior {
543140e8cbSSebastian Andrzej Siewior 	u32 reg;
553140e8cbSSebastian Andrzej Siewior 
563140e8cbSSebastian Andrzej Siewior 	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
573140e8cbSSebastian Andrzej Siewior 	reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
583140e8cbSSebastian Andrzej Siewior 	reg |= DWC3_GCTL_PRTCAPDIR(mode);
593140e8cbSSebastian Andrzej Siewior 	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
603140e8cbSSebastian Andrzej Siewior }
618300dd23SFelipe Balbi 
6272246da4SFelipe Balbi /**
6372246da4SFelipe Balbi  * dwc3_core_soft_reset - Issues core soft reset and PHY reset
6472246da4SFelipe Balbi  * @dwc: pointer to our context structure
6572246da4SFelipe Balbi  */
6657303488SKishon Vijay Abraham I static int dwc3_core_soft_reset(struct dwc3 *dwc)
6772246da4SFelipe Balbi {
6872246da4SFelipe Balbi 	u32		reg;
6957303488SKishon Vijay Abraham I 	int		ret;
7072246da4SFelipe Balbi 
7172246da4SFelipe Balbi 	/* Before Resetting PHY, put Core in Reset */
7272246da4SFelipe Balbi 	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
7372246da4SFelipe Balbi 	reg |= DWC3_GCTL_CORESOFTRESET;
7472246da4SFelipe Balbi 	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
7572246da4SFelipe Balbi 
7672246da4SFelipe Balbi 	/* Assert USB3 PHY reset */
7772246da4SFelipe Balbi 	reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
7872246da4SFelipe Balbi 	reg |= DWC3_GUSB3PIPECTL_PHYSOFTRST;
7972246da4SFelipe Balbi 	dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
8072246da4SFelipe Balbi 
8172246da4SFelipe Balbi 	/* Assert USB2 PHY reset */
8272246da4SFelipe Balbi 	reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
8372246da4SFelipe Balbi 	reg |= DWC3_GUSB2PHYCFG_PHYSOFTRST;
8472246da4SFelipe Balbi 	dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
8572246da4SFelipe Balbi 
8651e1e7bcSFelipe Balbi 	usb_phy_init(dwc->usb2_phy);
8751e1e7bcSFelipe Balbi 	usb_phy_init(dwc->usb3_phy);
8857303488SKishon Vijay Abraham I 	ret = phy_init(dwc->usb2_generic_phy);
8957303488SKishon Vijay Abraham I 	if (ret < 0)
9057303488SKishon Vijay Abraham I 		return ret;
9157303488SKishon Vijay Abraham I 
9257303488SKishon Vijay Abraham I 	ret = phy_init(dwc->usb3_generic_phy);
9357303488SKishon Vijay Abraham I 	if (ret < 0) {
9457303488SKishon Vijay Abraham I 		phy_exit(dwc->usb2_generic_phy);
9557303488SKishon Vijay Abraham I 		return ret;
9657303488SKishon Vijay Abraham I 	}
9772246da4SFelipe Balbi 	mdelay(100);
9872246da4SFelipe Balbi 
9972246da4SFelipe Balbi 	/* Clear USB3 PHY reset */
10072246da4SFelipe Balbi 	reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
10172246da4SFelipe Balbi 	reg &= ~DWC3_GUSB3PIPECTL_PHYSOFTRST;
10272246da4SFelipe Balbi 	dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
10372246da4SFelipe Balbi 
10472246da4SFelipe Balbi 	/* Clear USB2 PHY reset */
10572246da4SFelipe Balbi 	reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
10672246da4SFelipe Balbi 	reg &= ~DWC3_GUSB2PHYCFG_PHYSOFTRST;
10772246da4SFelipe Balbi 	dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
10872246da4SFelipe Balbi 
10945627ac6SPratyush Anand 	mdelay(100);
11045627ac6SPratyush Anand 
11172246da4SFelipe Balbi 	/* After PHYs are stable we can take Core out of reset state */
11272246da4SFelipe Balbi 	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
11372246da4SFelipe Balbi 	reg &= ~DWC3_GCTL_CORESOFTRESET;
11472246da4SFelipe Balbi 	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
11557303488SKishon Vijay Abraham I 
11657303488SKishon Vijay Abraham I 	return 0;
11772246da4SFelipe Balbi }
11872246da4SFelipe Balbi 
11972246da4SFelipe Balbi /**
12072246da4SFelipe Balbi  * dwc3_free_one_event_buffer - Frees one event buffer
12172246da4SFelipe Balbi  * @dwc: Pointer to our controller context structure
12272246da4SFelipe Balbi  * @evt: Pointer to event buffer to be freed
12372246da4SFelipe Balbi  */
12472246da4SFelipe Balbi static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
12572246da4SFelipe Balbi 		struct dwc3_event_buffer *evt)
12672246da4SFelipe Balbi {
12772246da4SFelipe Balbi 	dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma);
12872246da4SFelipe Balbi }
12972246da4SFelipe Balbi 
13072246da4SFelipe Balbi /**
1311d046793SPaul Zimmerman  * dwc3_alloc_one_event_buffer - Allocates one event buffer structure
13272246da4SFelipe Balbi  * @dwc: Pointer to our controller context structure
13372246da4SFelipe Balbi  * @length: size of the event buffer
13472246da4SFelipe Balbi  *
1351d046793SPaul Zimmerman  * Returns a pointer to the allocated event buffer structure on success
13672246da4SFelipe Balbi  * otherwise ERR_PTR(errno).
13772246da4SFelipe Balbi  */
13867d0b500SFelipe Balbi static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
13967d0b500SFelipe Balbi 		unsigned length)
14072246da4SFelipe Balbi {
14172246da4SFelipe Balbi 	struct dwc3_event_buffer	*evt;
14272246da4SFelipe Balbi 
143380f0d28SFelipe Balbi 	evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL);
14472246da4SFelipe Balbi 	if (!evt)
14572246da4SFelipe Balbi 		return ERR_PTR(-ENOMEM);
14672246da4SFelipe Balbi 
14772246da4SFelipe Balbi 	evt->dwc	= dwc;
14872246da4SFelipe Balbi 	evt->length	= length;
14972246da4SFelipe Balbi 	evt->buf	= dma_alloc_coherent(dwc->dev, length,
15072246da4SFelipe Balbi 			&evt->dma, GFP_KERNEL);
151e32672f0SFelipe Balbi 	if (!evt->buf)
15272246da4SFelipe Balbi 		return ERR_PTR(-ENOMEM);
15372246da4SFelipe Balbi 
15472246da4SFelipe Balbi 	return evt;
15572246da4SFelipe Balbi }
15672246da4SFelipe Balbi 
15772246da4SFelipe Balbi /**
15872246da4SFelipe Balbi  * dwc3_free_event_buffers - frees all allocated event buffers
15972246da4SFelipe Balbi  * @dwc: Pointer to our controller context structure
16072246da4SFelipe Balbi  */
16172246da4SFelipe Balbi static void dwc3_free_event_buffers(struct dwc3 *dwc)
16272246da4SFelipe Balbi {
16372246da4SFelipe Balbi 	struct dwc3_event_buffer	*evt;
16472246da4SFelipe Balbi 	int i;
16572246da4SFelipe Balbi 
1669f622b2aSFelipe Balbi 	for (i = 0; i < dwc->num_event_buffers; i++) {
16772246da4SFelipe Balbi 		evt = dwc->ev_buffs[i];
16864b6c8a7SAnton Tikhomirov 		if (evt)
16972246da4SFelipe Balbi 			dwc3_free_one_event_buffer(dwc, evt);
17072246da4SFelipe Balbi 	}
17172246da4SFelipe Balbi }
17272246da4SFelipe Balbi 
17372246da4SFelipe Balbi /**
17472246da4SFelipe Balbi  * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length
1751d046793SPaul Zimmerman  * @dwc: pointer to our controller context structure
17672246da4SFelipe Balbi  * @length: size of event buffer
17772246da4SFelipe Balbi  *
1781d046793SPaul Zimmerman  * Returns 0 on success otherwise negative errno. In the error case, dwc
17972246da4SFelipe Balbi  * may contain some buffers allocated but not all which were requested.
18072246da4SFelipe Balbi  */
18141ac7b3aSBill Pemberton static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
18272246da4SFelipe Balbi {
1839f622b2aSFelipe Balbi 	int			num;
18472246da4SFelipe Balbi 	int			i;
18572246da4SFelipe Balbi 
1869f622b2aSFelipe Balbi 	num = DWC3_NUM_INT(dwc->hwparams.hwparams1);
1879f622b2aSFelipe Balbi 	dwc->num_event_buffers = num;
1889f622b2aSFelipe Balbi 
189380f0d28SFelipe Balbi 	dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs) * num,
190380f0d28SFelipe Balbi 			GFP_KERNEL);
191734d5a53SJingoo Han 	if (!dwc->ev_buffs)
192457d3f21SFelipe Balbi 		return -ENOMEM;
193457d3f21SFelipe Balbi 
19472246da4SFelipe Balbi 	for (i = 0; i < num; i++) {
19572246da4SFelipe Balbi 		struct dwc3_event_buffer	*evt;
19672246da4SFelipe Balbi 
19772246da4SFelipe Balbi 		evt = dwc3_alloc_one_event_buffer(dwc, length);
19872246da4SFelipe Balbi 		if (IS_ERR(evt)) {
19972246da4SFelipe Balbi 			dev_err(dwc->dev, "can't allocate event buffer\n");
20072246da4SFelipe Balbi 			return PTR_ERR(evt);
20172246da4SFelipe Balbi 		}
20272246da4SFelipe Balbi 		dwc->ev_buffs[i] = evt;
20372246da4SFelipe Balbi 	}
20472246da4SFelipe Balbi 
20572246da4SFelipe Balbi 	return 0;
20672246da4SFelipe Balbi }
20772246da4SFelipe Balbi 
20872246da4SFelipe Balbi /**
20972246da4SFelipe Balbi  * dwc3_event_buffers_setup - setup our allocated event buffers
2101d046793SPaul Zimmerman  * @dwc: pointer to our controller context structure
21172246da4SFelipe Balbi  *
21272246da4SFelipe Balbi  * Returns 0 on success otherwise negative errno.
21372246da4SFelipe Balbi  */
2147acd85e0SPaul Zimmerman static int dwc3_event_buffers_setup(struct dwc3 *dwc)
21572246da4SFelipe Balbi {
21672246da4SFelipe Balbi 	struct dwc3_event_buffer	*evt;
21772246da4SFelipe Balbi 	int				n;
21872246da4SFelipe Balbi 
2199f622b2aSFelipe Balbi 	for (n = 0; n < dwc->num_event_buffers; n++) {
22072246da4SFelipe Balbi 		evt = dwc->ev_buffs[n];
22172246da4SFelipe Balbi 		dev_dbg(dwc->dev, "Event buf %p dma %08llx length %d\n",
22272246da4SFelipe Balbi 				evt->buf, (unsigned long long) evt->dma,
22372246da4SFelipe Balbi 				evt->length);
22472246da4SFelipe Balbi 
2257acd85e0SPaul Zimmerman 		evt->lpos = 0;
2267acd85e0SPaul Zimmerman 
22772246da4SFelipe Balbi 		dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n),
22872246da4SFelipe Balbi 				lower_32_bits(evt->dma));
22972246da4SFelipe Balbi 		dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n),
23072246da4SFelipe Balbi 				upper_32_bits(evt->dma));
23172246da4SFelipe Balbi 		dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n),
23268d6a01bSFelipe Balbi 				DWC3_GEVNTSIZ_SIZE(evt->length));
23372246da4SFelipe Balbi 		dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
23472246da4SFelipe Balbi 	}
23572246da4SFelipe Balbi 
23672246da4SFelipe Balbi 	return 0;
23772246da4SFelipe Balbi }
23872246da4SFelipe Balbi 
23972246da4SFelipe Balbi static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
24072246da4SFelipe Balbi {
24172246da4SFelipe Balbi 	struct dwc3_event_buffer	*evt;
24272246da4SFelipe Balbi 	int				n;
24372246da4SFelipe Balbi 
2449f622b2aSFelipe Balbi 	for (n = 0; n < dwc->num_event_buffers; n++) {
24572246da4SFelipe Balbi 		evt = dwc->ev_buffs[n];
2467acd85e0SPaul Zimmerman 
2477acd85e0SPaul Zimmerman 		evt->lpos = 0;
2487acd85e0SPaul Zimmerman 
24972246da4SFelipe Balbi 		dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0);
25072246da4SFelipe Balbi 		dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0);
25168d6a01bSFelipe Balbi 		dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), DWC3_GEVNTSIZ_INTMASK
25268d6a01bSFelipe Balbi 				| DWC3_GEVNTSIZ_SIZE(0));
25372246da4SFelipe Balbi 		dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
25472246da4SFelipe Balbi 	}
25572246da4SFelipe Balbi }
25672246da4SFelipe Balbi 
2570ffcaf37SFelipe Balbi static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc)
2580ffcaf37SFelipe Balbi {
2590ffcaf37SFelipe Balbi 	if (!dwc->has_hibernation)
2600ffcaf37SFelipe Balbi 		return 0;
2610ffcaf37SFelipe Balbi 
2620ffcaf37SFelipe Balbi 	if (!dwc->nr_scratch)
2630ffcaf37SFelipe Balbi 		return 0;
2640ffcaf37SFelipe Balbi 
2650ffcaf37SFelipe Balbi 	dwc->scratchbuf = kmalloc_array(dwc->nr_scratch,
2660ffcaf37SFelipe Balbi 			DWC3_SCRATCHBUF_SIZE, GFP_KERNEL);
2670ffcaf37SFelipe Balbi 	if (!dwc->scratchbuf)
2680ffcaf37SFelipe Balbi 		return -ENOMEM;
2690ffcaf37SFelipe Balbi 
2700ffcaf37SFelipe Balbi 	return 0;
2710ffcaf37SFelipe Balbi }
2720ffcaf37SFelipe Balbi 
2730ffcaf37SFelipe Balbi static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
2740ffcaf37SFelipe Balbi {
2750ffcaf37SFelipe Balbi 	dma_addr_t scratch_addr;
2760ffcaf37SFelipe Balbi 	u32 param;
2770ffcaf37SFelipe Balbi 	int ret;
2780ffcaf37SFelipe Balbi 
2790ffcaf37SFelipe Balbi 	if (!dwc->has_hibernation)
2800ffcaf37SFelipe Balbi 		return 0;
2810ffcaf37SFelipe Balbi 
2820ffcaf37SFelipe Balbi 	if (!dwc->nr_scratch)
2830ffcaf37SFelipe Balbi 		return 0;
2840ffcaf37SFelipe Balbi 
2850ffcaf37SFelipe Balbi 	 /* should never fall here */
2860ffcaf37SFelipe Balbi 	if (!WARN_ON(dwc->scratchbuf))
2870ffcaf37SFelipe Balbi 		return 0;
2880ffcaf37SFelipe Balbi 
2890ffcaf37SFelipe Balbi 	scratch_addr = dma_map_single(dwc->dev, dwc->scratchbuf,
2900ffcaf37SFelipe Balbi 			dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
2910ffcaf37SFelipe Balbi 			DMA_BIDIRECTIONAL);
2920ffcaf37SFelipe Balbi 	if (dma_mapping_error(dwc->dev, scratch_addr)) {
2930ffcaf37SFelipe Balbi 		dev_err(dwc->dev, "failed to map scratch buffer\n");
2940ffcaf37SFelipe Balbi 		ret = -EFAULT;
2950ffcaf37SFelipe Balbi 		goto err0;
2960ffcaf37SFelipe Balbi 	}
2970ffcaf37SFelipe Balbi 
2980ffcaf37SFelipe Balbi 	dwc->scratch_addr = scratch_addr;
2990ffcaf37SFelipe Balbi 
3000ffcaf37SFelipe Balbi 	param = lower_32_bits(scratch_addr);
3010ffcaf37SFelipe Balbi 
3020ffcaf37SFelipe Balbi 	ret = dwc3_send_gadget_generic_command(dwc,
3030ffcaf37SFelipe Balbi 			DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO, param);
3040ffcaf37SFelipe Balbi 	if (ret < 0)
3050ffcaf37SFelipe Balbi 		goto err1;
3060ffcaf37SFelipe Balbi 
3070ffcaf37SFelipe Balbi 	param = upper_32_bits(scratch_addr);
3080ffcaf37SFelipe Balbi 
3090ffcaf37SFelipe Balbi 	ret = dwc3_send_gadget_generic_command(dwc,
3100ffcaf37SFelipe Balbi 			DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI, param);
3110ffcaf37SFelipe Balbi 	if (ret < 0)
3120ffcaf37SFelipe Balbi 		goto err1;
3130ffcaf37SFelipe Balbi 
3140ffcaf37SFelipe Balbi 	return 0;
3150ffcaf37SFelipe Balbi 
3160ffcaf37SFelipe Balbi err1:
3170ffcaf37SFelipe Balbi 	dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
3180ffcaf37SFelipe Balbi 			DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
3190ffcaf37SFelipe Balbi 
3200ffcaf37SFelipe Balbi err0:
3210ffcaf37SFelipe Balbi 	return ret;
3220ffcaf37SFelipe Balbi }
3230ffcaf37SFelipe Balbi 
3240ffcaf37SFelipe Balbi static void dwc3_free_scratch_buffers(struct dwc3 *dwc)
3250ffcaf37SFelipe Balbi {
3260ffcaf37SFelipe Balbi 	if (!dwc->has_hibernation)
3270ffcaf37SFelipe Balbi 		return;
3280ffcaf37SFelipe Balbi 
3290ffcaf37SFelipe Balbi 	if (!dwc->nr_scratch)
3300ffcaf37SFelipe Balbi 		return;
3310ffcaf37SFelipe Balbi 
3320ffcaf37SFelipe Balbi 	 /* should never fall here */
3330ffcaf37SFelipe Balbi 	if (!WARN_ON(dwc->scratchbuf))
3340ffcaf37SFelipe Balbi 		return;
3350ffcaf37SFelipe Balbi 
3360ffcaf37SFelipe Balbi 	dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
3370ffcaf37SFelipe Balbi 			DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
3380ffcaf37SFelipe Balbi 	kfree(dwc->scratchbuf);
3390ffcaf37SFelipe Balbi }
3400ffcaf37SFelipe Balbi 
341789451f6SFelipe Balbi static void dwc3_core_num_eps(struct dwc3 *dwc)
342789451f6SFelipe Balbi {
343789451f6SFelipe Balbi 	struct dwc3_hwparams	*parms = &dwc->hwparams;
344789451f6SFelipe Balbi 
345789451f6SFelipe Balbi 	dwc->num_in_eps = DWC3_NUM_IN_EPS(parms);
346789451f6SFelipe Balbi 	dwc->num_out_eps = DWC3_NUM_EPS(parms) - dwc->num_in_eps;
347789451f6SFelipe Balbi 
348789451f6SFelipe Balbi 	dev_vdbg(dwc->dev, "found %d IN and %d OUT endpoints\n",
349789451f6SFelipe Balbi 			dwc->num_in_eps, dwc->num_out_eps);
350789451f6SFelipe Balbi }
351789451f6SFelipe Balbi 
35241ac7b3aSBill Pemberton static void dwc3_cache_hwparams(struct dwc3 *dwc)
35326ceca97SFelipe Balbi {
35426ceca97SFelipe Balbi 	struct dwc3_hwparams	*parms = &dwc->hwparams;
35526ceca97SFelipe Balbi 
35626ceca97SFelipe Balbi 	parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0);
35726ceca97SFelipe Balbi 	parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1);
35826ceca97SFelipe Balbi 	parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2);
35926ceca97SFelipe Balbi 	parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3);
36026ceca97SFelipe Balbi 	parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4);
36126ceca97SFelipe Balbi 	parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5);
36226ceca97SFelipe Balbi 	parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6);
36326ceca97SFelipe Balbi 	parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7);
36426ceca97SFelipe Balbi 	parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8);
36526ceca97SFelipe Balbi }
36626ceca97SFelipe Balbi 
36772246da4SFelipe Balbi /**
368b5a65c40SHuang Rui  * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core
369b5a65c40SHuang Rui  * @dwc: Pointer to our controller context structure
370b5a65c40SHuang Rui  */
371b5a65c40SHuang Rui static void dwc3_phy_setup(struct dwc3 *dwc)
372b5a65c40SHuang Rui {
373b5a65c40SHuang Rui 	u32 reg;
374b5a65c40SHuang Rui 
375b5a65c40SHuang Rui 	reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
376b5a65c40SHuang Rui 
377b5a65c40SHuang Rui 	if (dwc->u2ss_inp3_quirk)
378b5a65c40SHuang Rui 		reg |= DWC3_GUSB3PIPECTL_U2SSINP3OK;
379b5a65c40SHuang Rui 
380b5a65c40SHuang Rui 	dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
381b5a65c40SHuang Rui 
382b5a65c40SHuang Rui 	mdelay(100);
383b5a65c40SHuang Rui }
384b5a65c40SHuang Rui 
385b5a65c40SHuang Rui /**
38672246da4SFelipe Balbi  * dwc3_core_init - Low-level initialization of DWC3 Core
38772246da4SFelipe Balbi  * @dwc: Pointer to our controller context structure
38872246da4SFelipe Balbi  *
38972246da4SFelipe Balbi  * Returns 0 on success otherwise negative errno.
39072246da4SFelipe Balbi  */
39141ac7b3aSBill Pemberton static int dwc3_core_init(struct dwc3 *dwc)
39272246da4SFelipe Balbi {
39372246da4SFelipe Balbi 	unsigned long		timeout;
3940ffcaf37SFelipe Balbi 	u32			hwparams4 = dwc->hwparams.hwparams4;
39572246da4SFelipe Balbi 	u32			reg;
39672246da4SFelipe Balbi 	int			ret;
39772246da4SFelipe Balbi 
3987650bd74SSebastian Andrzej Siewior 	reg = dwc3_readl(dwc->regs, DWC3_GSNPSID);
3997650bd74SSebastian Andrzej Siewior 	/* This should read as U3 followed by revision number */
4007650bd74SSebastian Andrzej Siewior 	if ((reg & DWC3_GSNPSID_MASK) != 0x55330000) {
4017650bd74SSebastian Andrzej Siewior 		dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
4027650bd74SSebastian Andrzej Siewior 		ret = -ENODEV;
4037650bd74SSebastian Andrzej Siewior 		goto err0;
4047650bd74SSebastian Andrzej Siewior 	}
405248b122bSFelipe Balbi 	dwc->revision = reg;
4067650bd74SSebastian Andrzej Siewior 
407fa0ea13eSFelipe Balbi 	/*
408fa0ea13eSFelipe Balbi 	 * Write Linux Version Code to our GUID register so it's easy to figure
409fa0ea13eSFelipe Balbi 	 * out which kernel version a bug was found.
410fa0ea13eSFelipe Balbi 	 */
411fa0ea13eSFelipe Balbi 	dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE);
412fa0ea13eSFelipe Balbi 
4130e1e5c47SPaul Zimmerman 	/* Handle USB2.0-only core configuration */
4140e1e5c47SPaul Zimmerman 	if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
4150e1e5c47SPaul Zimmerman 			DWC3_GHWPARAMS3_SSPHY_IFC_DIS) {
4160e1e5c47SPaul Zimmerman 		if (dwc->maximum_speed == USB_SPEED_SUPER)
4170e1e5c47SPaul Zimmerman 			dwc->maximum_speed = USB_SPEED_HIGH;
4180e1e5c47SPaul Zimmerman 	}
4190e1e5c47SPaul Zimmerman 
42072246da4SFelipe Balbi 	/* issue device SoftReset too */
42172246da4SFelipe Balbi 	timeout = jiffies + msecs_to_jiffies(500);
42272246da4SFelipe Balbi 	dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
42372246da4SFelipe Balbi 	do {
42472246da4SFelipe Balbi 		reg = dwc3_readl(dwc->regs, DWC3_DCTL);
42572246da4SFelipe Balbi 		if (!(reg & DWC3_DCTL_CSFTRST))
42672246da4SFelipe Balbi 			break;
42772246da4SFelipe Balbi 
42872246da4SFelipe Balbi 		if (time_after(jiffies, timeout)) {
42972246da4SFelipe Balbi 			dev_err(dwc->dev, "Reset Timed Out\n");
43072246da4SFelipe Balbi 			ret = -ETIMEDOUT;
43172246da4SFelipe Balbi 			goto err0;
43272246da4SFelipe Balbi 		}
43372246da4SFelipe Balbi 
43472246da4SFelipe Balbi 		cpu_relax();
43572246da4SFelipe Balbi 	} while (true);
43672246da4SFelipe Balbi 
43757303488SKishon Vijay Abraham I 	ret = dwc3_core_soft_reset(dwc);
43857303488SKishon Vijay Abraham I 	if (ret)
43957303488SKishon Vijay Abraham I 		goto err0;
44058a0f23fSPratyush Anand 
4414878a028SSebastian Andrzej Siewior 	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
4423e87c42aSPaul Zimmerman 	reg &= ~DWC3_GCTL_SCALEDOWN_MASK;
4434878a028SSebastian Andrzej Siewior 
444164d7731SSebastian Andrzej Siewior 	switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) {
4454878a028SSebastian Andrzej Siewior 	case DWC3_GHWPARAMS1_EN_PWROPT_CLK:
44632a4a135SFelipe Balbi 		/**
44732a4a135SFelipe Balbi 		 * WORKAROUND: DWC3 revisions between 2.10a and 2.50a have an
44832a4a135SFelipe Balbi 		 * issue which would cause xHCI compliance tests to fail.
44932a4a135SFelipe Balbi 		 *
45032a4a135SFelipe Balbi 		 * Because of that we cannot enable clock gating on such
45132a4a135SFelipe Balbi 		 * configurations.
45232a4a135SFelipe Balbi 		 *
45332a4a135SFelipe Balbi 		 * Refers to:
45432a4a135SFelipe Balbi 		 *
45532a4a135SFelipe Balbi 		 * STAR#9000588375: Clock Gating, SOF Issues when ref_clk-Based
45632a4a135SFelipe Balbi 		 * SOF/ITP Mode Used
45732a4a135SFelipe Balbi 		 */
45832a4a135SFelipe Balbi 		if ((dwc->dr_mode == USB_DR_MODE_HOST ||
45932a4a135SFelipe Balbi 				dwc->dr_mode == USB_DR_MODE_OTG) &&
46032a4a135SFelipe Balbi 				(dwc->revision >= DWC3_REVISION_210A &&
46132a4a135SFelipe Balbi 				dwc->revision <= DWC3_REVISION_250A))
46232a4a135SFelipe Balbi 			reg |= DWC3_GCTL_DSBLCLKGTNG | DWC3_GCTL_SOFITPSYNC;
46332a4a135SFelipe Balbi 		else
4644878a028SSebastian Andrzej Siewior 			reg &= ~DWC3_GCTL_DSBLCLKGTNG;
4654878a028SSebastian Andrzej Siewior 		break;
4660ffcaf37SFelipe Balbi 	case DWC3_GHWPARAMS1_EN_PWROPT_HIB:
4670ffcaf37SFelipe Balbi 		/* enable hibernation here */
4680ffcaf37SFelipe Balbi 		dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4);
4692eac3992SHuang Rui 
4702eac3992SHuang Rui 		/*
4712eac3992SHuang Rui 		 * REVISIT Enabling this bit so that host-mode hibernation
4722eac3992SHuang Rui 		 * will work. Device-mode hibernation is not yet implemented.
4732eac3992SHuang Rui 		 */
4742eac3992SHuang Rui 		reg |= DWC3_GCTL_GBLHIBERNATIONEN;
4750ffcaf37SFelipe Balbi 		break;
4764878a028SSebastian Andrzej Siewior 	default:
4774878a028SSebastian Andrzej Siewior 		dev_dbg(dwc->dev, "No power optimization available\n");
4784878a028SSebastian Andrzej Siewior 	}
4794878a028SSebastian Andrzej Siewior 
480946bd579SHuang Rui 	/* check if current dwc3 is on simulation board */
481946bd579SHuang Rui 	if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) {
482946bd579SHuang Rui 		dev_dbg(dwc->dev, "it is on FPGA board\n");
483946bd579SHuang Rui 		dwc->is_fpga = true;
484946bd579SHuang Rui 	}
485946bd579SHuang Rui 
4863b81221aSHuang Rui 	WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga,
4873b81221aSHuang Rui 			"disable_scramble cannot be used on non-FPGA builds\n");
4883b81221aSHuang Rui 
4893b81221aSHuang Rui 	if (dwc->disable_scramble_quirk && dwc->is_fpga)
4903b81221aSHuang Rui 		reg |= DWC3_GCTL_DISSCRAMBLE;
4913b81221aSHuang Rui 	else
4923b81221aSHuang Rui 		reg &= ~DWC3_GCTL_DISSCRAMBLE;
4933b81221aSHuang Rui 
4949a5b2f31SHuang Rui 	if (dwc->u2exit_lfps_quirk)
4959a5b2f31SHuang Rui 		reg |= DWC3_GCTL_U2EXIT_LFPS;
4969a5b2f31SHuang Rui 
4974878a028SSebastian Andrzej Siewior 	/*
4984878a028SSebastian Andrzej Siewior 	 * WORKAROUND: DWC3 revisions <1.90a have a bug
4991d046793SPaul Zimmerman 	 * where the device can fail to connect at SuperSpeed
5004878a028SSebastian Andrzej Siewior 	 * and falls back to high-speed mode which causes
5011d046793SPaul Zimmerman 	 * the device to enter a Connect/Disconnect loop
5024878a028SSebastian Andrzej Siewior 	 */
5034878a028SSebastian Andrzej Siewior 	if (dwc->revision < DWC3_REVISION_190A)
5044878a028SSebastian Andrzej Siewior 		reg |= DWC3_GCTL_U2RSTECN;
5054878a028SSebastian Andrzej Siewior 
506789451f6SFelipe Balbi 	dwc3_core_num_eps(dwc);
507789451f6SFelipe Balbi 
5084878a028SSebastian Andrzej Siewior 	dwc3_writel(dwc->regs, DWC3_GCTL, reg);
5094878a028SSebastian Andrzej Siewior 
510b5a65c40SHuang Rui 	dwc3_phy_setup(dwc);
511b5a65c40SHuang Rui 
5120ffcaf37SFelipe Balbi 	ret = dwc3_alloc_scratch_buffers(dwc);
5130ffcaf37SFelipe Balbi 	if (ret)
5140ffcaf37SFelipe Balbi 		goto err1;
5150ffcaf37SFelipe Balbi 
5160ffcaf37SFelipe Balbi 	ret = dwc3_setup_scratch_buffers(dwc);
5170ffcaf37SFelipe Balbi 	if (ret)
5180ffcaf37SFelipe Balbi 		goto err2;
5190ffcaf37SFelipe Balbi 
52072246da4SFelipe Balbi 	return 0;
52172246da4SFelipe Balbi 
5220ffcaf37SFelipe Balbi err2:
5230ffcaf37SFelipe Balbi 	dwc3_free_scratch_buffers(dwc);
5240ffcaf37SFelipe Balbi 
5250ffcaf37SFelipe Balbi err1:
5260ffcaf37SFelipe Balbi 	usb_phy_shutdown(dwc->usb2_phy);
5270ffcaf37SFelipe Balbi 	usb_phy_shutdown(dwc->usb3_phy);
52857303488SKishon Vijay Abraham I 	phy_exit(dwc->usb2_generic_phy);
52957303488SKishon Vijay Abraham I 	phy_exit(dwc->usb3_generic_phy);
5300ffcaf37SFelipe Balbi 
53172246da4SFelipe Balbi err0:
53272246da4SFelipe Balbi 	return ret;
53372246da4SFelipe Balbi }
53472246da4SFelipe Balbi 
53572246da4SFelipe Balbi static void dwc3_core_exit(struct dwc3 *dwc)
53672246da4SFelipe Balbi {
5370ffcaf37SFelipe Balbi 	dwc3_free_scratch_buffers(dwc);
53801b8daf7SVivek Gautam 	usb_phy_shutdown(dwc->usb2_phy);
53901b8daf7SVivek Gautam 	usb_phy_shutdown(dwc->usb3_phy);
54057303488SKishon Vijay Abraham I 	phy_exit(dwc->usb2_generic_phy);
54157303488SKishon Vijay Abraham I 	phy_exit(dwc->usb3_generic_phy);
54272246da4SFelipe Balbi }
54372246da4SFelipe Balbi 
5443c9f94acSFelipe Balbi static int dwc3_core_get_phy(struct dwc3 *dwc)
54572246da4SFelipe Balbi {
5463c9f94acSFelipe Balbi 	struct device		*dev = dwc->dev;
547941ea361SFelipe Balbi 	struct device_node	*node = dev->of_node;
5483c9f94acSFelipe Balbi 	int ret;
54972246da4SFelipe Balbi 
5505088b6f5SKishon Vijay Abraham I 	if (node) {
5515088b6f5SKishon Vijay Abraham I 		dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
5525088b6f5SKishon Vijay Abraham I 		dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1);
553bb674907SFelipe Balbi 	} else {
554bb674907SFelipe Balbi 		dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
555bb674907SFelipe Balbi 		dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
5565088b6f5SKishon Vijay Abraham I 	}
5575088b6f5SKishon Vijay Abraham I 
558d105e7f8SFelipe Balbi 	if (IS_ERR(dwc->usb2_phy)) {
559d105e7f8SFelipe Balbi 		ret = PTR_ERR(dwc->usb2_phy);
560122f06e6SKishon Vijay Abraham I 		if (ret == -ENXIO || ret == -ENODEV) {
561122f06e6SKishon Vijay Abraham I 			dwc->usb2_phy = NULL;
562122f06e6SKishon Vijay Abraham I 		} else if (ret == -EPROBE_DEFER) {
563d105e7f8SFelipe Balbi 			return ret;
564122f06e6SKishon Vijay Abraham I 		} else {
56551e1e7bcSFelipe Balbi 			dev_err(dev, "no usb2 phy configured\n");
566122f06e6SKishon Vijay Abraham I 			return ret;
567122f06e6SKishon Vijay Abraham I 		}
56851e1e7bcSFelipe Balbi 	}
56951e1e7bcSFelipe Balbi 
570d105e7f8SFelipe Balbi 	if (IS_ERR(dwc->usb3_phy)) {
571315955d7SRuchika Kharwar 		ret = PTR_ERR(dwc->usb3_phy);
572122f06e6SKishon Vijay Abraham I 		if (ret == -ENXIO || ret == -ENODEV) {
573122f06e6SKishon Vijay Abraham I 			dwc->usb3_phy = NULL;
574122f06e6SKishon Vijay Abraham I 		} else if (ret == -EPROBE_DEFER) {
575d105e7f8SFelipe Balbi 			return ret;
576122f06e6SKishon Vijay Abraham I 		} else {
57751e1e7bcSFelipe Balbi 			dev_err(dev, "no usb3 phy configured\n");
578122f06e6SKishon Vijay Abraham I 			return ret;
579122f06e6SKishon Vijay Abraham I 		}
58051e1e7bcSFelipe Balbi 	}
58151e1e7bcSFelipe Balbi 
58257303488SKishon Vijay Abraham I 	dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy");
58357303488SKishon Vijay Abraham I 	if (IS_ERR(dwc->usb2_generic_phy)) {
58457303488SKishon Vijay Abraham I 		ret = PTR_ERR(dwc->usb2_generic_phy);
58557303488SKishon Vijay Abraham I 		if (ret == -ENOSYS || ret == -ENODEV) {
58657303488SKishon Vijay Abraham I 			dwc->usb2_generic_phy = NULL;
58757303488SKishon Vijay Abraham I 		} else if (ret == -EPROBE_DEFER) {
58857303488SKishon Vijay Abraham I 			return ret;
58957303488SKishon Vijay Abraham I 		} else {
59057303488SKishon Vijay Abraham I 			dev_err(dev, "no usb2 phy configured\n");
59157303488SKishon Vijay Abraham I 			return ret;
59257303488SKishon Vijay Abraham I 		}
59357303488SKishon Vijay Abraham I 	}
59457303488SKishon Vijay Abraham I 
59557303488SKishon Vijay Abraham I 	dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy");
59657303488SKishon Vijay Abraham I 	if (IS_ERR(dwc->usb3_generic_phy)) {
59757303488SKishon Vijay Abraham I 		ret = PTR_ERR(dwc->usb3_generic_phy);
59857303488SKishon Vijay Abraham I 		if (ret == -ENOSYS || ret == -ENODEV) {
59957303488SKishon Vijay Abraham I 			dwc->usb3_generic_phy = NULL;
60057303488SKishon Vijay Abraham I 		} else if (ret == -EPROBE_DEFER) {
60157303488SKishon Vijay Abraham I 			return ret;
60257303488SKishon Vijay Abraham I 		} else {
60357303488SKishon Vijay Abraham I 			dev_err(dev, "no usb3 phy configured\n");
60457303488SKishon Vijay Abraham I 			return ret;
60557303488SKishon Vijay Abraham I 		}
60657303488SKishon Vijay Abraham I 	}
60757303488SKishon Vijay Abraham I 
6083c9f94acSFelipe Balbi 	return 0;
6093c9f94acSFelipe Balbi }
6103c9f94acSFelipe Balbi 
6115f94adfeSFelipe Balbi static int dwc3_core_init_mode(struct dwc3 *dwc)
6125f94adfeSFelipe Balbi {
6135f94adfeSFelipe Balbi 	struct device *dev = dwc->dev;
6145f94adfeSFelipe Balbi 	int ret;
6155f94adfeSFelipe Balbi 
6165f94adfeSFelipe Balbi 	switch (dwc->dr_mode) {
6175f94adfeSFelipe Balbi 	case USB_DR_MODE_PERIPHERAL:
6185f94adfeSFelipe Balbi 		dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
6195f94adfeSFelipe Balbi 		ret = dwc3_gadget_init(dwc);
6205f94adfeSFelipe Balbi 		if (ret) {
6215f94adfeSFelipe Balbi 			dev_err(dev, "failed to initialize gadget\n");
6225f94adfeSFelipe Balbi 			return ret;
6235f94adfeSFelipe Balbi 		}
6245f94adfeSFelipe Balbi 		break;
6255f94adfeSFelipe Balbi 	case USB_DR_MODE_HOST:
6265f94adfeSFelipe Balbi 		dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
6275f94adfeSFelipe Balbi 		ret = dwc3_host_init(dwc);
6285f94adfeSFelipe Balbi 		if (ret) {
6295f94adfeSFelipe Balbi 			dev_err(dev, "failed to initialize host\n");
6305f94adfeSFelipe Balbi 			return ret;
6315f94adfeSFelipe Balbi 		}
6325f94adfeSFelipe Balbi 		break;
6335f94adfeSFelipe Balbi 	case USB_DR_MODE_OTG:
6345f94adfeSFelipe Balbi 		dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
6355f94adfeSFelipe Balbi 		ret = dwc3_host_init(dwc);
6365f94adfeSFelipe Balbi 		if (ret) {
6375f94adfeSFelipe Balbi 			dev_err(dev, "failed to initialize host\n");
6385f94adfeSFelipe Balbi 			return ret;
6395f94adfeSFelipe Balbi 		}
6405f94adfeSFelipe Balbi 
6415f94adfeSFelipe Balbi 		ret = dwc3_gadget_init(dwc);
6425f94adfeSFelipe Balbi 		if (ret) {
6435f94adfeSFelipe Balbi 			dev_err(dev, "failed to initialize gadget\n");
6445f94adfeSFelipe Balbi 			return ret;
6455f94adfeSFelipe Balbi 		}
6465f94adfeSFelipe Balbi 		break;
6475f94adfeSFelipe Balbi 	default:
6485f94adfeSFelipe Balbi 		dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode);
6495f94adfeSFelipe Balbi 		return -EINVAL;
6505f94adfeSFelipe Balbi 	}
6515f94adfeSFelipe Balbi 
6525f94adfeSFelipe Balbi 	return 0;
6535f94adfeSFelipe Balbi }
6545f94adfeSFelipe Balbi 
6555f94adfeSFelipe Balbi static void dwc3_core_exit_mode(struct dwc3 *dwc)
6565f94adfeSFelipe Balbi {
6575f94adfeSFelipe Balbi 	switch (dwc->dr_mode) {
6585f94adfeSFelipe Balbi 	case USB_DR_MODE_PERIPHERAL:
6595f94adfeSFelipe Balbi 		dwc3_gadget_exit(dwc);
6605f94adfeSFelipe Balbi 		break;
6615f94adfeSFelipe Balbi 	case USB_DR_MODE_HOST:
6625f94adfeSFelipe Balbi 		dwc3_host_exit(dwc);
6635f94adfeSFelipe Balbi 		break;
6645f94adfeSFelipe Balbi 	case USB_DR_MODE_OTG:
6655f94adfeSFelipe Balbi 		dwc3_host_exit(dwc);
6665f94adfeSFelipe Balbi 		dwc3_gadget_exit(dwc);
6675f94adfeSFelipe Balbi 		break;
6685f94adfeSFelipe Balbi 	default:
6695f94adfeSFelipe Balbi 		/* do nothing */
6705f94adfeSFelipe Balbi 		break;
6715f94adfeSFelipe Balbi 	}
6725f94adfeSFelipe Balbi }
6735f94adfeSFelipe Balbi 
6743c9f94acSFelipe Balbi #define DWC3_ALIGN_MASK		(16 - 1)
6753c9f94acSFelipe Balbi 
6763c9f94acSFelipe Balbi static int dwc3_probe(struct platform_device *pdev)
6773c9f94acSFelipe Balbi {
6783c9f94acSFelipe Balbi 	struct device		*dev = &pdev->dev;
6793c9f94acSFelipe Balbi 	struct dwc3_platform_data *pdata = dev_get_platdata(dev);
6803c9f94acSFelipe Balbi 	struct device_node	*node = dev->of_node;
6813c9f94acSFelipe Balbi 	struct resource		*res;
6823c9f94acSFelipe Balbi 	struct dwc3		*dwc;
68380caf7d2SHuang Rui 	u8			lpm_nyet_threshold;
6843c9f94acSFelipe Balbi 
685b09e99eeSAndy Shevchenko 	int			ret;
6863c9f94acSFelipe Balbi 
6873c9f94acSFelipe Balbi 	void __iomem		*regs;
6883c9f94acSFelipe Balbi 	void			*mem;
6893c9f94acSFelipe Balbi 
6903c9f94acSFelipe Balbi 	mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
691734d5a53SJingoo Han 	if (!mem)
6923c9f94acSFelipe Balbi 		return -ENOMEM;
693734d5a53SJingoo Han 
6943c9f94acSFelipe Balbi 	dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
6953c9f94acSFelipe Balbi 	dwc->mem = mem;
6963c9f94acSFelipe Balbi 	dwc->dev = dev;
6973c9f94acSFelipe Balbi 
6983c9f94acSFelipe Balbi 	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
6993c9f94acSFelipe Balbi 	if (!res) {
7003c9f94acSFelipe Balbi 		dev_err(dev, "missing IRQ\n");
7013c9f94acSFelipe Balbi 		return -ENODEV;
7023c9f94acSFelipe Balbi 	}
7033c9f94acSFelipe Balbi 	dwc->xhci_resources[1].start = res->start;
7043c9f94acSFelipe Balbi 	dwc->xhci_resources[1].end = res->end;
7053c9f94acSFelipe Balbi 	dwc->xhci_resources[1].flags = res->flags;
7063c9f94acSFelipe Balbi 	dwc->xhci_resources[1].name = res->name;
7073c9f94acSFelipe Balbi 
7083c9f94acSFelipe Balbi 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
7093c9f94acSFelipe Balbi 	if (!res) {
7103c9f94acSFelipe Balbi 		dev_err(dev, "missing memory resource\n");
7113c9f94acSFelipe Balbi 		return -ENODEV;
7123c9f94acSFelipe Balbi 	}
7133c9f94acSFelipe Balbi 
714f32a5e23SVivek Gautam 	dwc->xhci_resources[0].start = res->start;
715f32a5e23SVivek Gautam 	dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
716f32a5e23SVivek Gautam 					DWC3_XHCI_REGS_END;
717f32a5e23SVivek Gautam 	dwc->xhci_resources[0].flags = res->flags;
718f32a5e23SVivek Gautam 	dwc->xhci_resources[0].name = res->name;
719f32a5e23SVivek Gautam 
720f32a5e23SVivek Gautam 	res->start += DWC3_GLOBALS_REGS_START;
721f32a5e23SVivek Gautam 
722f32a5e23SVivek Gautam 	/*
723f32a5e23SVivek Gautam 	 * Request memory region but exclude xHCI regs,
724f32a5e23SVivek Gautam 	 * since it will be requested by the xhci-plat driver.
725f32a5e23SVivek Gautam 	 */
726f32a5e23SVivek Gautam 	regs = devm_ioremap_resource(dev, res);
727f32a5e23SVivek Gautam 	if (IS_ERR(regs))
728f32a5e23SVivek Gautam 		return PTR_ERR(regs);
729f32a5e23SVivek Gautam 
730f32a5e23SVivek Gautam 	dwc->regs	= regs;
731f32a5e23SVivek Gautam 	dwc->regs_size	= resource_size(res);
732f32a5e23SVivek Gautam 	/*
733f32a5e23SVivek Gautam 	 * restore res->start back to its original value so that,
734f32a5e23SVivek Gautam 	 * in case the probe is deferred, we don't end up getting error in
735f32a5e23SVivek Gautam 	 * request the memory region the next time probe is called.
736f32a5e23SVivek Gautam 	 */
737f32a5e23SVivek Gautam 	res->start -= DWC3_GLOBALS_REGS_START;
738f32a5e23SVivek Gautam 
73980caf7d2SHuang Rui 	/* default to highest possible threshold */
74080caf7d2SHuang Rui 	lpm_nyet_threshold = 0xff;
74180caf7d2SHuang Rui 
7423c9f94acSFelipe Balbi 	if (node) {
7433c9f94acSFelipe Balbi 		dwc->maximum_speed = of_usb_get_maximum_speed(node);
74480caf7d2SHuang Rui 		dwc->has_lpm_erratum = of_property_read_bool(node,
74580caf7d2SHuang Rui 				"snps,has-lpm-erratum");
74680caf7d2SHuang Rui 		of_property_read_u8(node, "snps,lpm-nyet-threshold",
74780caf7d2SHuang Rui 				&lpm_nyet_threshold);
7483c9f94acSFelipe Balbi 
74980caf7d2SHuang Rui 		dwc->needs_fifo_resize = of_property_read_bool(node,
75080caf7d2SHuang Rui 				"tx-fifo-resize");
7513c9f94acSFelipe Balbi 		dwc->dr_mode = of_usb_get_dr_mode(node);
7523b81221aSHuang Rui 
7533b81221aSHuang Rui 		dwc->disable_scramble_quirk = of_property_read_bool(node,
7543b81221aSHuang Rui 				"snps,disable_scramble_quirk");
7559a5b2f31SHuang Rui 		dwc->u2exit_lfps_quirk = of_property_read_bool(node,
7569a5b2f31SHuang Rui 				"snps,u2exit_lfps_quirk");
757b5a65c40SHuang Rui 		dwc->u2ss_inp3_quirk = of_property_read_bool(node,
758b5a65c40SHuang Rui 				"snps,u2ss_inp3_quirk");
7593c9f94acSFelipe Balbi 	} else if (pdata) {
7603c9f94acSFelipe Balbi 		dwc->maximum_speed = pdata->maximum_speed;
76180caf7d2SHuang Rui 		dwc->has_lpm_erratum = pdata->has_lpm_erratum;
76280caf7d2SHuang Rui 		if (pdata->lpm_nyet_threshold)
76380caf7d2SHuang Rui 			lpm_nyet_threshold = pdata->lpm_nyet_threshold;
7643c9f94acSFelipe Balbi 
7653c9f94acSFelipe Balbi 		dwc->needs_fifo_resize = pdata->tx_fifo_resize;
7663c9f94acSFelipe Balbi 		dwc->dr_mode = pdata->dr_mode;
7673b81221aSHuang Rui 
7683b81221aSHuang Rui 		dwc->disable_scramble_quirk = pdata->disable_scramble_quirk;
7699a5b2f31SHuang Rui 		dwc->u2exit_lfps_quirk = pdata->u2exit_lfps_quirk;
770b5a65c40SHuang Rui 		dwc->u2ss_inp3_quirk = pdata->u2ss_inp3_quirk;
7713c9f94acSFelipe Balbi 	}
7723c9f94acSFelipe Balbi 
7733c9f94acSFelipe Balbi 	/* default to superspeed if no maximum_speed passed */
7743c9f94acSFelipe Balbi 	if (dwc->maximum_speed == USB_SPEED_UNKNOWN)
7753c9f94acSFelipe Balbi 		dwc->maximum_speed = USB_SPEED_SUPER;
7763c9f94acSFelipe Balbi 
77780caf7d2SHuang Rui 	dwc->lpm_nyet_threshold = lpm_nyet_threshold;
77880caf7d2SHuang Rui 
7793c9f94acSFelipe Balbi 	ret = dwc3_core_get_phy(dwc);
7803c9f94acSFelipe Balbi 	if (ret)
7813c9f94acSFelipe Balbi 		return ret;
7823c9f94acSFelipe Balbi 
78372246da4SFelipe Balbi 	spin_lock_init(&dwc->lock);
78472246da4SFelipe Balbi 	platform_set_drvdata(pdev, dwc);
78572246da4SFelipe Balbi 
78619bacdc9SHeikki Krogerus 	if (!dev->dma_mask) {
787ddff14f1SKishon Vijay Abraham I 		dev->dma_mask = dev->parent->dma_mask;
788ddff14f1SKishon Vijay Abraham I 		dev->dma_parms = dev->parent->dma_parms;
789ddff14f1SKishon Vijay Abraham I 		dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask);
79019bacdc9SHeikki Krogerus 	}
791ddff14f1SKishon Vijay Abraham I 
792802ca850SChanho Park 	pm_runtime_enable(dev);
793802ca850SChanho Park 	pm_runtime_get_sync(dev);
794802ca850SChanho Park 	pm_runtime_forbid(dev);
79572246da4SFelipe Balbi 
7964fd24483SKishon Vijay Abraham I 	dwc3_cache_hwparams(dwc);
7974fd24483SKishon Vijay Abraham I 
7983921426bSFelipe Balbi 	ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
7993921426bSFelipe Balbi 	if (ret) {
8003921426bSFelipe Balbi 		dev_err(dwc->dev, "failed to allocate event buffers\n");
8013921426bSFelipe Balbi 		ret = -ENOMEM;
8023921426bSFelipe Balbi 		goto err0;
8033921426bSFelipe Balbi 	}
8043921426bSFelipe Balbi 
80532a4a135SFelipe Balbi 	if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
80632a4a135SFelipe Balbi 		dwc->dr_mode = USB_DR_MODE_HOST;
80732a4a135SFelipe Balbi 	else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
80832a4a135SFelipe Balbi 		dwc->dr_mode = USB_DR_MODE_PERIPHERAL;
80932a4a135SFelipe Balbi 
81032a4a135SFelipe Balbi 	if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
81132a4a135SFelipe Balbi 		dwc->dr_mode = USB_DR_MODE_OTG;
81232a4a135SFelipe Balbi 
81372246da4SFelipe Balbi 	ret = dwc3_core_init(dwc);
81472246da4SFelipe Balbi 	if (ret) {
815802ca850SChanho Park 		dev_err(dev, "failed to initialize core\n");
8163921426bSFelipe Balbi 		goto err0;
81772246da4SFelipe Balbi 	}
81872246da4SFelipe Balbi 
8193088f108SKishon Vijay Abraham I 	usb_phy_set_suspend(dwc->usb2_phy, 0);
8203088f108SKishon Vijay Abraham I 	usb_phy_set_suspend(dwc->usb3_phy, 0);
82157303488SKishon Vijay Abraham I 	ret = phy_power_on(dwc->usb2_generic_phy);
82257303488SKishon Vijay Abraham I 	if (ret < 0)
82357303488SKishon Vijay Abraham I 		goto err1;
82457303488SKishon Vijay Abraham I 
82557303488SKishon Vijay Abraham I 	ret = phy_power_on(dwc->usb3_generic_phy);
82657303488SKishon Vijay Abraham I 	if (ret < 0)
82757303488SKishon Vijay Abraham I 		goto err_usb2phy_power;
8283088f108SKishon Vijay Abraham I 
829f122d33eSFelipe Balbi 	ret = dwc3_event_buffers_setup(dwc);
830f122d33eSFelipe Balbi 	if (ret) {
831f122d33eSFelipe Balbi 		dev_err(dwc->dev, "failed to setup event buffers\n");
83257303488SKishon Vijay Abraham I 		goto err_usb3phy_power;
833f122d33eSFelipe Balbi 	}
834f122d33eSFelipe Balbi 
8355f94adfeSFelipe Balbi 	ret = dwc3_core_init_mode(dwc);
8365f94adfeSFelipe Balbi 	if (ret)
837f122d33eSFelipe Balbi 		goto err2;
83872246da4SFelipe Balbi 
83972246da4SFelipe Balbi 	ret = dwc3_debugfs_init(dwc);
84072246da4SFelipe Balbi 	if (ret) {
841802ca850SChanho Park 		dev_err(dev, "failed to initialize debugfs\n");
842f122d33eSFelipe Balbi 		goto err3;
84372246da4SFelipe Balbi 	}
84472246da4SFelipe Balbi 
845802ca850SChanho Park 	pm_runtime_allow(dev);
84672246da4SFelipe Balbi 
84772246da4SFelipe Balbi 	return 0;
84872246da4SFelipe Balbi 
849f122d33eSFelipe Balbi err3:
8505f94adfeSFelipe Balbi 	dwc3_core_exit_mode(dwc);
85172246da4SFelipe Balbi 
852f122d33eSFelipe Balbi err2:
853f122d33eSFelipe Balbi 	dwc3_event_buffers_cleanup(dwc);
854f122d33eSFelipe Balbi 
85557303488SKishon Vijay Abraham I err_usb3phy_power:
85657303488SKishon Vijay Abraham I 	phy_power_off(dwc->usb3_generic_phy);
85757303488SKishon Vijay Abraham I 
85857303488SKishon Vijay Abraham I err_usb2phy_power:
85957303488SKishon Vijay Abraham I 	phy_power_off(dwc->usb2_generic_phy);
86057303488SKishon Vijay Abraham I 
861802ca850SChanho Park err1:
862501fae51SKishon Vijay Abraham I 	usb_phy_set_suspend(dwc->usb2_phy, 1);
863501fae51SKishon Vijay Abraham I 	usb_phy_set_suspend(dwc->usb3_phy, 1);
86472246da4SFelipe Balbi 	dwc3_core_exit(dwc);
86572246da4SFelipe Balbi 
8663921426bSFelipe Balbi err0:
8673921426bSFelipe Balbi 	dwc3_free_event_buffers(dwc);
8683921426bSFelipe Balbi 
86972246da4SFelipe Balbi 	return ret;
87072246da4SFelipe Balbi }
87172246da4SFelipe Balbi 
872fb4e98abSBill Pemberton static int dwc3_remove(struct platform_device *pdev)
87372246da4SFelipe Balbi {
87472246da4SFelipe Balbi 	struct dwc3	*dwc = platform_get_drvdata(pdev);
87572246da4SFelipe Balbi 
876dc99f16fSFelipe Balbi 	dwc3_debugfs_exit(dwc);
877dc99f16fSFelipe Balbi 	dwc3_core_exit_mode(dwc);
878dc99f16fSFelipe Balbi 	dwc3_event_buffers_cleanup(dwc);
879dc99f16fSFelipe Balbi 	dwc3_free_event_buffers(dwc);
880dc99f16fSFelipe Balbi 
8818ba007a9SKishon Vijay Abraham I 	usb_phy_set_suspend(dwc->usb2_phy, 1);
8828ba007a9SKishon Vijay Abraham I 	usb_phy_set_suspend(dwc->usb3_phy, 1);
88357303488SKishon Vijay Abraham I 	phy_power_off(dwc->usb2_generic_phy);
88457303488SKishon Vijay Abraham I 	phy_power_off(dwc->usb3_generic_phy);
8858ba007a9SKishon Vijay Abraham I 
88672246da4SFelipe Balbi 	dwc3_core_exit(dwc);
88772246da4SFelipe Balbi 
8887415f17cSFelipe Balbi 	pm_runtime_put_sync(&pdev->dev);
8897415f17cSFelipe Balbi 	pm_runtime_disable(&pdev->dev);
8907415f17cSFelipe Balbi 
89172246da4SFelipe Balbi 	return 0;
89272246da4SFelipe Balbi }
89372246da4SFelipe Balbi 
8947415f17cSFelipe Balbi #ifdef CONFIG_PM_SLEEP
8957415f17cSFelipe Balbi static int dwc3_suspend(struct device *dev)
8967415f17cSFelipe Balbi {
8977415f17cSFelipe Balbi 	struct dwc3	*dwc = dev_get_drvdata(dev);
8987415f17cSFelipe Balbi 	unsigned long	flags;
8997415f17cSFelipe Balbi 
9007415f17cSFelipe Balbi 	spin_lock_irqsave(&dwc->lock, flags);
9017415f17cSFelipe Balbi 
902a45c82b8SRuchika Kharwar 	switch (dwc->dr_mode) {
903a45c82b8SRuchika Kharwar 	case USB_DR_MODE_PERIPHERAL:
904a45c82b8SRuchika Kharwar 	case USB_DR_MODE_OTG:
9057415f17cSFelipe Balbi 		dwc3_gadget_suspend(dwc);
9067415f17cSFelipe Balbi 		/* FALLTHROUGH */
907a45c82b8SRuchika Kharwar 	case USB_DR_MODE_HOST:
9087415f17cSFelipe Balbi 	default:
9090b0231aaSFelipe Balbi 		dwc3_event_buffers_cleanup(dwc);
9107415f17cSFelipe Balbi 		break;
9117415f17cSFelipe Balbi 	}
9127415f17cSFelipe Balbi 
9137415f17cSFelipe Balbi 	dwc->gctl = dwc3_readl(dwc->regs, DWC3_GCTL);
9147415f17cSFelipe Balbi 	spin_unlock_irqrestore(&dwc->lock, flags);
9157415f17cSFelipe Balbi 
9167415f17cSFelipe Balbi 	usb_phy_shutdown(dwc->usb3_phy);
9177415f17cSFelipe Balbi 	usb_phy_shutdown(dwc->usb2_phy);
91857303488SKishon Vijay Abraham I 	phy_exit(dwc->usb2_generic_phy);
91957303488SKishon Vijay Abraham I 	phy_exit(dwc->usb3_generic_phy);
9207415f17cSFelipe Balbi 
9217415f17cSFelipe Balbi 	return 0;
9227415f17cSFelipe Balbi }
9237415f17cSFelipe Balbi 
9247415f17cSFelipe Balbi static int dwc3_resume(struct device *dev)
9257415f17cSFelipe Balbi {
9267415f17cSFelipe Balbi 	struct dwc3	*dwc = dev_get_drvdata(dev);
9277415f17cSFelipe Balbi 	unsigned long	flags;
92857303488SKishon Vijay Abraham I 	int		ret;
9297415f17cSFelipe Balbi 
9307415f17cSFelipe Balbi 	usb_phy_init(dwc->usb3_phy);
9317415f17cSFelipe Balbi 	usb_phy_init(dwc->usb2_phy);
93257303488SKishon Vijay Abraham I 	ret = phy_init(dwc->usb2_generic_phy);
93357303488SKishon Vijay Abraham I 	if (ret < 0)
93457303488SKishon Vijay Abraham I 		return ret;
93557303488SKishon Vijay Abraham I 
93657303488SKishon Vijay Abraham I 	ret = phy_init(dwc->usb3_generic_phy);
93757303488SKishon Vijay Abraham I 	if (ret < 0)
93857303488SKishon Vijay Abraham I 		goto err_usb2phy_init;
9397415f17cSFelipe Balbi 
9407415f17cSFelipe Balbi 	spin_lock_irqsave(&dwc->lock, flags);
9417415f17cSFelipe Balbi 
9420b0231aaSFelipe Balbi 	dwc3_event_buffers_setup(dwc);
9437415f17cSFelipe Balbi 	dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl);
9447415f17cSFelipe Balbi 
945a45c82b8SRuchika Kharwar 	switch (dwc->dr_mode) {
946a45c82b8SRuchika Kharwar 	case USB_DR_MODE_PERIPHERAL:
947a45c82b8SRuchika Kharwar 	case USB_DR_MODE_OTG:
9487415f17cSFelipe Balbi 		dwc3_gadget_resume(dwc);
9497415f17cSFelipe Balbi 		/* FALLTHROUGH */
950a45c82b8SRuchika Kharwar 	case USB_DR_MODE_HOST:
9517415f17cSFelipe Balbi 	default:
9527415f17cSFelipe Balbi 		/* do nothing */
9537415f17cSFelipe Balbi 		break;
9547415f17cSFelipe Balbi 	}
9557415f17cSFelipe Balbi 
9567415f17cSFelipe Balbi 	spin_unlock_irqrestore(&dwc->lock, flags);
9577415f17cSFelipe Balbi 
9587415f17cSFelipe Balbi 	pm_runtime_disable(dev);
9597415f17cSFelipe Balbi 	pm_runtime_set_active(dev);
9607415f17cSFelipe Balbi 	pm_runtime_enable(dev);
9617415f17cSFelipe Balbi 
9627415f17cSFelipe Balbi 	return 0;
96357303488SKishon Vijay Abraham I 
96457303488SKishon Vijay Abraham I err_usb2phy_init:
96557303488SKishon Vijay Abraham I 	phy_exit(dwc->usb2_generic_phy);
96657303488SKishon Vijay Abraham I 
96757303488SKishon Vijay Abraham I 	return ret;
9687415f17cSFelipe Balbi }
9697415f17cSFelipe Balbi 
9707415f17cSFelipe Balbi static const struct dev_pm_ops dwc3_dev_pm_ops = {
9717415f17cSFelipe Balbi 	SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)
9727415f17cSFelipe Balbi };
9737415f17cSFelipe Balbi 
9747415f17cSFelipe Balbi #define DWC3_PM_OPS	&(dwc3_dev_pm_ops)
9757415f17cSFelipe Balbi #else
9767415f17cSFelipe Balbi #define DWC3_PM_OPS	NULL
9777415f17cSFelipe Balbi #endif
9787415f17cSFelipe Balbi 
9795088b6f5SKishon Vijay Abraham I #ifdef CONFIG_OF
9805088b6f5SKishon Vijay Abraham I static const struct of_device_id of_dwc3_match[] = {
9815088b6f5SKishon Vijay Abraham I 	{
98222a5aa17SFelipe Balbi 		.compatible = "snps,dwc3"
98322a5aa17SFelipe Balbi 	},
98422a5aa17SFelipe Balbi 	{
9855088b6f5SKishon Vijay Abraham I 		.compatible = "synopsys,dwc3"
9865088b6f5SKishon Vijay Abraham I 	},
9875088b6f5SKishon Vijay Abraham I 	{ },
9885088b6f5SKishon Vijay Abraham I };
9895088b6f5SKishon Vijay Abraham I MODULE_DEVICE_TABLE(of, of_dwc3_match);
9905088b6f5SKishon Vijay Abraham I #endif
9915088b6f5SKishon Vijay Abraham I 
992404905a6SHeikki Krogerus #ifdef CONFIG_ACPI
993404905a6SHeikki Krogerus 
994404905a6SHeikki Krogerus #define ACPI_ID_INTEL_BSW	"808622B7"
995404905a6SHeikki Krogerus 
996404905a6SHeikki Krogerus static const struct acpi_device_id dwc3_acpi_match[] = {
997404905a6SHeikki Krogerus 	{ ACPI_ID_INTEL_BSW, 0 },
998404905a6SHeikki Krogerus 	{ },
999404905a6SHeikki Krogerus };
1000404905a6SHeikki Krogerus MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match);
1001404905a6SHeikki Krogerus #endif
1002404905a6SHeikki Krogerus 
100372246da4SFelipe Balbi static struct platform_driver dwc3_driver = {
100472246da4SFelipe Balbi 	.probe		= dwc3_probe,
10057690417dSBill Pemberton 	.remove		= dwc3_remove,
100672246da4SFelipe Balbi 	.driver		= {
100772246da4SFelipe Balbi 		.name	= "dwc3",
10085088b6f5SKishon Vijay Abraham I 		.of_match_table	= of_match_ptr(of_dwc3_match),
1009404905a6SHeikki Krogerus 		.acpi_match_table = ACPI_PTR(dwc3_acpi_match),
10107415f17cSFelipe Balbi 		.pm	= DWC3_PM_OPS,
101172246da4SFelipe Balbi 	},
101272246da4SFelipe Balbi };
101372246da4SFelipe Balbi 
1014b1116dccSTobias Klauser module_platform_driver(dwc3_driver);
1015b1116dccSTobias Klauser 
10167ae4fc4dSSebastian Andrzej Siewior MODULE_ALIAS("platform:dwc3");
101772246da4SFelipe Balbi MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
10185945f789SFelipe Balbi MODULE_LICENSE("GPL v2");
101972246da4SFelipe Balbi MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");
1020