18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * core.h - DesignWare USB3 DRD Core Header
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2010-2011 Texas Instruments Incorporated - https://www.ti.com
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Authors: Felipe Balbi <balbi@ti.com>,
88c2ecf20Sopenharmony_ci *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef __DRIVERS_USB_DWC3_CORE_H
128c2ecf20Sopenharmony_ci#define __DRIVERS_USB_DWC3_CORE_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/device.h>
158c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
168c2ecf20Sopenharmony_ci#include <linux/mutex.h>
178c2ecf20Sopenharmony_ci#include <linux/ioport.h>
188c2ecf20Sopenharmony_ci#include <linux/list.h>
198c2ecf20Sopenharmony_ci#include <linux/bitops.h>
208c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h>
218c2ecf20Sopenharmony_ci#include <linux/mm.h>
228c2ecf20Sopenharmony_ci#include <linux/debugfs.h>
238c2ecf20Sopenharmony_ci#include <linux/wait.h>
248c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#include <linux/usb/ch9.h>
278c2ecf20Sopenharmony_ci#include <linux/usb/gadget.h>
288c2ecf20Sopenharmony_ci#include <linux/usb/otg.h>
298c2ecf20Sopenharmony_ci#include <linux/usb/role.h>
308c2ecf20Sopenharmony_ci#include <linux/ulpi/interface.h>
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#include <linux/phy/phy.h>
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define DWC3_MSG_MAX	500
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/* Global constants */
378c2ecf20Sopenharmony_ci#define DWC3_PULL_UP_TIMEOUT	500	/* ms */
388c2ecf20Sopenharmony_ci#define DWC3_BOUNCE_SIZE	1024	/* size of a superspeed bulk */
398c2ecf20Sopenharmony_ci#define DWC3_EP0_SETUP_SIZE	512
408c2ecf20Sopenharmony_ci#define DWC3_ENDPOINTS_NUM	32
418c2ecf20Sopenharmony_ci#define DWC3_XHCI_RESOURCES_NUM	2
428c2ecf20Sopenharmony_ci#define DWC3_ISOC_MAX_RETRIES	5
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define DWC3_SCRATCHBUF_SIZE	4096	/* each buffer is assumed to be 4KiB */
458c2ecf20Sopenharmony_ci#define DWC3_EVENT_BUFFERS_SIZE	4096
468c2ecf20Sopenharmony_ci#define DWC3_EVENT_TYPE_MASK	0xfe
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define DWC3_EVENT_TYPE_DEV	0
498c2ecf20Sopenharmony_ci#define DWC3_EVENT_TYPE_CARKIT	3
508c2ecf20Sopenharmony_ci#define DWC3_EVENT_TYPE_I2C	4
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define DWC3_DEVICE_EVENT_DISCONNECT		0
538c2ecf20Sopenharmony_ci#define DWC3_DEVICE_EVENT_RESET			1
548c2ecf20Sopenharmony_ci#define DWC3_DEVICE_EVENT_CONNECT_DONE		2
558c2ecf20Sopenharmony_ci#define DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE	3
568c2ecf20Sopenharmony_ci#define DWC3_DEVICE_EVENT_WAKEUP		4
578c2ecf20Sopenharmony_ci#define DWC3_DEVICE_EVENT_HIBER_REQ		5
588c2ecf20Sopenharmony_ci#define DWC3_DEVICE_EVENT_EOPF			6
598c2ecf20Sopenharmony_ci#define DWC3_DEVICE_EVENT_SOF			7
608c2ecf20Sopenharmony_ci#define DWC3_DEVICE_EVENT_ERRATIC_ERROR		9
618c2ecf20Sopenharmony_ci#define DWC3_DEVICE_EVENT_CMD_CMPL		10
628c2ecf20Sopenharmony_ci#define DWC3_DEVICE_EVENT_OVERFLOW		11
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/* Controller's role while using the OTG block */
658c2ecf20Sopenharmony_ci#define DWC3_OTG_ROLE_IDLE	0
668c2ecf20Sopenharmony_ci#define DWC3_OTG_ROLE_HOST	1
678c2ecf20Sopenharmony_ci#define DWC3_OTG_ROLE_DEVICE	2
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#define DWC3_GEVNTCOUNT_MASK	0xfffc
708c2ecf20Sopenharmony_ci#define DWC3_GEVNTCOUNT_EHB	BIT(31)
718c2ecf20Sopenharmony_ci#define DWC3_GSNPSID_MASK	0xffff0000
728c2ecf20Sopenharmony_ci#define DWC3_GSNPSREV_MASK	0xffff
738c2ecf20Sopenharmony_ci#define DWC3_GSNPS_ID(p)	(((p) & DWC3_GSNPSID_MASK) >> 16)
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/* DWC3 registers memory space boundries */
768c2ecf20Sopenharmony_ci#define DWC3_XHCI_REGS_START		0x0
778c2ecf20Sopenharmony_ci#define DWC3_XHCI_REGS_END		0x7fff
788c2ecf20Sopenharmony_ci#define DWC3_GLOBALS_REGS_START		0xc100
798c2ecf20Sopenharmony_ci#define DWC3_GLOBALS_REGS_END		0xc6ff
808c2ecf20Sopenharmony_ci#define DWC3_DEVICE_REGS_START		0xc700
818c2ecf20Sopenharmony_ci#define DWC3_DEVICE_REGS_END		0xcbff
828c2ecf20Sopenharmony_ci#define DWC3_OTG_REGS_START		0xcc00
838c2ecf20Sopenharmony_ci#define DWC3_OTG_REGS_END		0xccff
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/* Global Registers */
868c2ecf20Sopenharmony_ci#define DWC3_GSBUSCFG0		0xc100
878c2ecf20Sopenharmony_ci#define DWC3_GSBUSCFG1		0xc104
888c2ecf20Sopenharmony_ci#define DWC3_GTXTHRCFG		0xc108
898c2ecf20Sopenharmony_ci#define DWC3_GRXTHRCFG		0xc10c
908c2ecf20Sopenharmony_ci#define DWC3_GCTL		0xc110
918c2ecf20Sopenharmony_ci#define DWC3_GEVTEN		0xc114
928c2ecf20Sopenharmony_ci#define DWC3_GSTS		0xc118
938c2ecf20Sopenharmony_ci#define DWC3_GUCTL1		0xc11c
948c2ecf20Sopenharmony_ci#define DWC3_GSNPSID		0xc120
958c2ecf20Sopenharmony_ci#define DWC3_GGPIO		0xc124
968c2ecf20Sopenharmony_ci#define DWC3_GUID		0xc128
978c2ecf20Sopenharmony_ci#define DWC3_GUCTL		0xc12c
988c2ecf20Sopenharmony_ci#define DWC3_GBUSERRADDR0	0xc130
998c2ecf20Sopenharmony_ci#define DWC3_GBUSERRADDR1	0xc134
1008c2ecf20Sopenharmony_ci#define DWC3_GPRTBIMAP0		0xc138
1018c2ecf20Sopenharmony_ci#define DWC3_GPRTBIMAP1		0xc13c
1028c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS0		0xc140
1038c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS1		0xc144
1048c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS2		0xc148
1058c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS3		0xc14c
1068c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS4		0xc150
1078c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS5		0xc154
1088c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS6		0xc158
1098c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS7		0xc15c
1108c2ecf20Sopenharmony_ci#define DWC3_GDBGFIFOSPACE	0xc160
1118c2ecf20Sopenharmony_ci#define DWC3_GDBGLTSSM		0xc164
1128c2ecf20Sopenharmony_ci#define DWC3_GDBGBMU		0xc16c
1138c2ecf20Sopenharmony_ci#define DWC3_GDBGLSPMUX		0xc170
1148c2ecf20Sopenharmony_ci#define DWC3_GDBGLSP		0xc174
1158c2ecf20Sopenharmony_ci#define DWC3_GDBGEPINFO0	0xc178
1168c2ecf20Sopenharmony_ci#define DWC3_GDBGEPINFO1	0xc17c
1178c2ecf20Sopenharmony_ci#define DWC3_GPRTBIMAP_HS0	0xc180
1188c2ecf20Sopenharmony_ci#define DWC3_GPRTBIMAP_HS1	0xc184
1198c2ecf20Sopenharmony_ci#define DWC3_GPRTBIMAP_FS0	0xc188
1208c2ecf20Sopenharmony_ci#define DWC3_GPRTBIMAP_FS1	0xc18c
1218c2ecf20Sopenharmony_ci#define DWC3_GUCTL2		0xc19c
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#define DWC3_VER_NUMBER		0xc1a0
1248c2ecf20Sopenharmony_ci#define DWC3_VER_TYPE		0xc1a4
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYCFG(n)	(0xc200 + ((n) * 0x04))
1278c2ecf20Sopenharmony_ci#define DWC3_GUSB2I2CCTL(n)	(0xc240 + ((n) * 0x04))
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYACC(n)	(0xc280 + ((n) * 0x04))
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci#define DWC3_GUSB3PIPECTL(n)	(0xc2c0 + ((n) * 0x04))
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci#define DWC3_GTXFIFOSIZ(n)	(0xc300 + ((n) * 0x04))
1348c2ecf20Sopenharmony_ci#define DWC3_GRXFIFOSIZ(n)	(0xc380 + ((n) * 0x04))
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci#define DWC3_GEVNTADRLO(n)	(0xc400 + ((n) * 0x10))
1378c2ecf20Sopenharmony_ci#define DWC3_GEVNTADRHI(n)	(0xc404 + ((n) * 0x10))
1388c2ecf20Sopenharmony_ci#define DWC3_GEVNTSIZ(n)	(0xc408 + ((n) * 0x10))
1398c2ecf20Sopenharmony_ci#define DWC3_GEVNTCOUNT(n)	(0xc40c + ((n) * 0x10))
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS8		0xc600
1428c2ecf20Sopenharmony_ci#define DWC3_GUCTL3		0xc60c
1438c2ecf20Sopenharmony_ci#define DWC3_GFLADJ		0xc630
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci/* Device Registers */
1468c2ecf20Sopenharmony_ci#define DWC3_DCFG		0xc700
1478c2ecf20Sopenharmony_ci#define DWC3_DCTL		0xc704
1488c2ecf20Sopenharmony_ci#define DWC3_DEVTEN		0xc708
1498c2ecf20Sopenharmony_ci#define DWC3_DSTS		0xc70c
1508c2ecf20Sopenharmony_ci#define DWC3_DGCMDPAR		0xc710
1518c2ecf20Sopenharmony_ci#define DWC3_DGCMD		0xc714
1528c2ecf20Sopenharmony_ci#define DWC3_DALEPENA		0xc720
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci#define DWC3_DEP_BASE(n)	(0xc800 + ((n) * 0x10))
1558c2ecf20Sopenharmony_ci#define DWC3_DEPCMDPAR2		0x00
1568c2ecf20Sopenharmony_ci#define DWC3_DEPCMDPAR1		0x04
1578c2ecf20Sopenharmony_ci#define DWC3_DEPCMDPAR0		0x08
1588c2ecf20Sopenharmony_ci#define DWC3_DEPCMD		0x0c
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci#define DWC3_DEV_IMOD(n)	(0xca00 + ((n) * 0x4))
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci/* OTG Registers */
1638c2ecf20Sopenharmony_ci#define DWC3_OCFG		0xcc00
1648c2ecf20Sopenharmony_ci#define DWC3_OCTL		0xcc04
1658c2ecf20Sopenharmony_ci#define DWC3_OEVT		0xcc08
1668c2ecf20Sopenharmony_ci#define DWC3_OEVTEN		0xcc0C
1678c2ecf20Sopenharmony_ci#define DWC3_OSTS		0xcc10
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci/* Bit fields */
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci/* Global SoC Bus Configuration INCRx Register 0 */
1728c2ecf20Sopenharmony_ci#define DWC3_GSBUSCFG0_INCR256BRSTENA	(1 << 7) /* INCR256 burst */
1738c2ecf20Sopenharmony_ci#define DWC3_GSBUSCFG0_INCR128BRSTENA	(1 << 6) /* INCR128 burst */
1748c2ecf20Sopenharmony_ci#define DWC3_GSBUSCFG0_INCR64BRSTENA	(1 << 5) /* INCR64 burst */
1758c2ecf20Sopenharmony_ci#define DWC3_GSBUSCFG0_INCR32BRSTENA	(1 << 4) /* INCR32 burst */
1768c2ecf20Sopenharmony_ci#define DWC3_GSBUSCFG0_INCR16BRSTENA	(1 << 3) /* INCR16 burst */
1778c2ecf20Sopenharmony_ci#define DWC3_GSBUSCFG0_INCR8BRSTENA	(1 << 2) /* INCR8 burst */
1788c2ecf20Sopenharmony_ci#define DWC3_GSBUSCFG0_INCR4BRSTENA	(1 << 1) /* INCR4 burst */
1798c2ecf20Sopenharmony_ci#define DWC3_GSBUSCFG0_INCRBRSTENA	(1 << 0) /* undefined length enable */
1808c2ecf20Sopenharmony_ci#define DWC3_GSBUSCFG0_INCRBRST_MASK	0xff
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci/* Global Debug LSP MUX Select */
1838c2ecf20Sopenharmony_ci#define DWC3_GDBGLSPMUX_ENDBC		BIT(15)	/* Host only */
1848c2ecf20Sopenharmony_ci#define DWC3_GDBGLSPMUX_HOSTSELECT(n)	((n) & 0x3fff)
1858c2ecf20Sopenharmony_ci#define DWC3_GDBGLSPMUX_DEVSELECT(n)	(((n) & 0xf) << 4)
1868c2ecf20Sopenharmony_ci#define DWC3_GDBGLSPMUX_EPSELECT(n)	((n) & 0xf)
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci/* Global Debug Queue/FIFO Space Available Register */
1898c2ecf20Sopenharmony_ci#define DWC3_GDBGFIFOSPACE_NUM(n)	((n) & 0x1f)
1908c2ecf20Sopenharmony_ci#define DWC3_GDBGFIFOSPACE_TYPE(n)	(((n) << 5) & 0x1e0)
1918c2ecf20Sopenharmony_ci#define DWC3_GDBGFIFOSPACE_SPACE_AVAILABLE(n) (((n) >> 16) & 0xffff)
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci#define DWC3_TXFIFO		0
1948c2ecf20Sopenharmony_ci#define DWC3_RXFIFO		1
1958c2ecf20Sopenharmony_ci#define DWC3_TXREQQ		2
1968c2ecf20Sopenharmony_ci#define DWC3_RXREQQ		3
1978c2ecf20Sopenharmony_ci#define DWC3_RXINFOQ		4
1988c2ecf20Sopenharmony_ci#define DWC3_PSTATQ		5
1998c2ecf20Sopenharmony_ci#define DWC3_DESCFETCHQ		6
2008c2ecf20Sopenharmony_ci#define DWC3_EVENTQ		7
2018c2ecf20Sopenharmony_ci#define DWC3_AUXEVENTQ		8
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci/* Global RX Threshold Configuration Register */
2048c2ecf20Sopenharmony_ci#define DWC3_GRXTHRCFG_MAXRXBURSTSIZE(n) (((n) & 0x1f) << 19)
2058c2ecf20Sopenharmony_ci#define DWC3_GRXTHRCFG_RXPKTCNT(n) (((n) & 0xf) << 24)
2068c2ecf20Sopenharmony_ci#define DWC3_GRXTHRCFG_PKTCNTSEL BIT(29)
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci/* Global RX Threshold Configuration Register for DWC_usb31 only */
2098c2ecf20Sopenharmony_ci#define DWC31_GRXTHRCFG_MAXRXBURSTSIZE(n)	(((n) & 0x1f) << 16)
2108c2ecf20Sopenharmony_ci#define DWC31_GRXTHRCFG_RXPKTCNT(n)		(((n) & 0x1f) << 21)
2118c2ecf20Sopenharmony_ci#define DWC31_GRXTHRCFG_PKTCNTSEL		BIT(26)
2128c2ecf20Sopenharmony_ci#define DWC31_RXTHRNUMPKTSEL_HS_PRD		BIT(15)
2138c2ecf20Sopenharmony_ci#define DWC31_RXTHRNUMPKT_HS_PRD(n)		(((n) & 0x3) << 13)
2148c2ecf20Sopenharmony_ci#define DWC31_RXTHRNUMPKTSEL_PRD		BIT(10)
2158c2ecf20Sopenharmony_ci#define DWC31_RXTHRNUMPKT_PRD(n)		(((n) & 0x1f) << 5)
2168c2ecf20Sopenharmony_ci#define DWC31_MAXRXBURSTSIZE_PRD(n)		((n) & 0x1f)
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci/* Global TX Threshold Configuration Register for DWC_usb31 only */
2198c2ecf20Sopenharmony_ci#define DWC31_GTXTHRCFG_MAXTXBURSTSIZE(n)	(((n) & 0x1f) << 16)
2208c2ecf20Sopenharmony_ci#define DWC31_GTXTHRCFG_TXPKTCNT(n)		(((n) & 0x1f) << 21)
2218c2ecf20Sopenharmony_ci#define DWC31_GTXTHRCFG_PKTCNTSEL		BIT(26)
2228c2ecf20Sopenharmony_ci#define DWC31_TXTHRNUMPKTSEL_HS_PRD		BIT(15)
2238c2ecf20Sopenharmony_ci#define DWC31_TXTHRNUMPKT_HS_PRD(n)		(((n) & 0x3) << 13)
2248c2ecf20Sopenharmony_ci#define DWC31_TXTHRNUMPKTSEL_PRD		BIT(10)
2258c2ecf20Sopenharmony_ci#define DWC31_TXTHRNUMPKT_PRD(n)		(((n) & 0x1f) << 5)
2268c2ecf20Sopenharmony_ci#define DWC31_MAXTXBURSTSIZE_PRD(n)		((n) & 0x1f)
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci/* Global Configuration Register */
2298c2ecf20Sopenharmony_ci#define DWC3_GCTL_PWRDNSCALE(n)	((n) << 19)
2308c2ecf20Sopenharmony_ci#define DWC3_GCTL_U2RSTECN	BIT(16)
2318c2ecf20Sopenharmony_ci#define DWC3_GCTL_RAMCLKSEL(x)	(((x) & DWC3_GCTL_CLK_MASK) << 6)
2328c2ecf20Sopenharmony_ci#define DWC3_GCTL_CLK_BUS	(0)
2338c2ecf20Sopenharmony_ci#define DWC3_GCTL_CLK_PIPE	(1)
2348c2ecf20Sopenharmony_ci#define DWC3_GCTL_CLK_PIPEHALF	(2)
2358c2ecf20Sopenharmony_ci#define DWC3_GCTL_CLK_MASK	(3)
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci#define DWC3_GCTL_PRTCAP(n)	(((n) & (3 << 12)) >> 12)
2388c2ecf20Sopenharmony_ci#define DWC3_GCTL_PRTCAPDIR(n)	((n) << 12)
2398c2ecf20Sopenharmony_ci#define DWC3_GCTL_PRTCAP_HOST	1
2408c2ecf20Sopenharmony_ci#define DWC3_GCTL_PRTCAP_DEVICE	2
2418c2ecf20Sopenharmony_ci#define DWC3_GCTL_PRTCAP_OTG	3
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci#define DWC3_GCTL_CORESOFTRESET		BIT(11)
2448c2ecf20Sopenharmony_ci#define DWC3_GCTL_SOFITPSYNC		BIT(10)
2458c2ecf20Sopenharmony_ci#define DWC3_GCTL_SCALEDOWN(n)		((n) << 4)
2468c2ecf20Sopenharmony_ci#define DWC3_GCTL_SCALEDOWN_MASK	DWC3_GCTL_SCALEDOWN(3)
2478c2ecf20Sopenharmony_ci#define DWC3_GCTL_DISSCRAMBLE		BIT(3)
2488c2ecf20Sopenharmony_ci#define DWC3_GCTL_U2EXIT_LFPS		BIT(2)
2498c2ecf20Sopenharmony_ci#define DWC3_GCTL_GBLHIBERNATIONEN	BIT(1)
2508c2ecf20Sopenharmony_ci#define DWC3_GCTL_DSBLCLKGTNG		BIT(0)
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci/* Global User Control 1 Register */
2538c2ecf20Sopenharmony_ci#define DWC3_GUCTL1_PARKMODE_DISABLE_SS	BIT(17)
2548c2ecf20Sopenharmony_ci#define DWC3_GUCTL1_TX_IPGAP_LINECHECK_DIS	BIT(28)
2558c2ecf20Sopenharmony_ci#define DWC3_GUCTL1_DEV_L1_EXIT_BY_HW	BIT(24)
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci/* Global Status Register */
2588c2ecf20Sopenharmony_ci#define DWC3_GSTS_OTG_IP	BIT(10)
2598c2ecf20Sopenharmony_ci#define DWC3_GSTS_BC_IP		BIT(9)
2608c2ecf20Sopenharmony_ci#define DWC3_GSTS_ADP_IP	BIT(8)
2618c2ecf20Sopenharmony_ci#define DWC3_GSTS_HOST_IP	BIT(7)
2628c2ecf20Sopenharmony_ci#define DWC3_GSTS_DEVICE_IP	BIT(6)
2638c2ecf20Sopenharmony_ci#define DWC3_GSTS_CSR_TIMEOUT	BIT(5)
2648c2ecf20Sopenharmony_ci#define DWC3_GSTS_BUS_ERR_ADDR_VLD	BIT(4)
2658c2ecf20Sopenharmony_ci#define DWC3_GSTS_CURMOD(n)	((n) & 0x3)
2668c2ecf20Sopenharmony_ci#define DWC3_GSTS_CURMOD_DEVICE	0
2678c2ecf20Sopenharmony_ci#define DWC3_GSTS_CURMOD_HOST	1
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci/* Global USB2 PHY Configuration Register */
2708c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYCFG_PHYSOFTRST	BIT(31)
2718c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS	BIT(30)
2728c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYCFG_SUSPHY		BIT(6)
2738c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYCFG_ULPI_UTMI	BIT(4)
2748c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYCFG_ENBLSLPM	BIT(8)
2758c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYCFG_PHYIF(n)	(n << 3)
2768c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYCFG_PHYIF_MASK	DWC3_GUSB2PHYCFG_PHYIF(1)
2778c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYCFG_USBTRDTIM(n)	(n << 10)
2788c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYCFG_USBTRDTIM_MASK	DWC3_GUSB2PHYCFG_USBTRDTIM(0xf)
2798c2ecf20Sopenharmony_ci#define USBTRDTIM_UTMI_8_BIT		9
2808c2ecf20Sopenharmony_ci#define USBTRDTIM_UTMI_16_BIT		5
2818c2ecf20Sopenharmony_ci#define UTMI_PHYIF_16_BIT		1
2828c2ecf20Sopenharmony_ci#define UTMI_PHYIF_8_BIT		0
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ci/* Global USB2 PHY Vendor Control Register */
2858c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYACC_NEWREGREQ	BIT(25)
2868c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYACC_DONE		BIT(24)
2878c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYACC_BUSY		BIT(23)
2888c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYACC_WRITE		BIT(22)
2898c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYACC_ADDR(n)	(n << 16)
2908c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYACC_EXTEND_ADDR(n)	(n << 8)
2918c2ecf20Sopenharmony_ci#define DWC3_GUSB2PHYACC_DATA(n)	(n & 0xff)
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci/* Global USB3 PIPE Control Register */
2948c2ecf20Sopenharmony_ci#define DWC3_GUSB3PIPECTL_PHYSOFTRST	BIT(31)
2958c2ecf20Sopenharmony_ci#define DWC3_GUSB3PIPECTL_U2SSINP3OK	BIT(29)
2968c2ecf20Sopenharmony_ci#define DWC3_GUSB3PIPECTL_DISRXDETINP3	BIT(28)
2978c2ecf20Sopenharmony_ci#define DWC3_GUSB3PIPECTL_UX_EXIT_PX	BIT(27)
2988c2ecf20Sopenharmony_ci#define DWC3_GUSB3PIPECTL_REQP1P2P3	BIT(24)
2998c2ecf20Sopenharmony_ci#define DWC3_GUSB3PIPECTL_DEP1P2P3(n)	((n) << 19)
3008c2ecf20Sopenharmony_ci#define DWC3_GUSB3PIPECTL_DEP1P2P3_MASK	DWC3_GUSB3PIPECTL_DEP1P2P3(7)
3018c2ecf20Sopenharmony_ci#define DWC3_GUSB3PIPECTL_DEP1P2P3_EN	DWC3_GUSB3PIPECTL_DEP1P2P3(1)
3028c2ecf20Sopenharmony_ci#define DWC3_GUSB3PIPECTL_DEPOCHANGE	BIT(18)
3038c2ecf20Sopenharmony_ci#define DWC3_GUSB3PIPECTL_SUSPHY	BIT(17)
3048c2ecf20Sopenharmony_ci#define DWC3_GUSB3PIPECTL_LFPSFILT	BIT(9)
3058c2ecf20Sopenharmony_ci#define DWC3_GUSB3PIPECTL_RX_DETOPOLL	BIT(8)
3068c2ecf20Sopenharmony_ci#define DWC3_GUSB3PIPECTL_TX_DEEPH_MASK	DWC3_GUSB3PIPECTL_TX_DEEPH(3)
3078c2ecf20Sopenharmony_ci#define DWC3_GUSB3PIPECTL_TX_DEEPH(n)	((n) << 1)
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci/* Global TX Fifo Size Register */
3108c2ecf20Sopenharmony_ci#define DWC31_GTXFIFOSIZ_TXFRAMNUM	BIT(15)		/* DWC_usb31 only */
3118c2ecf20Sopenharmony_ci#define DWC31_GTXFIFOSIZ_TXFDEP(n)	((n) & 0x7fff)	/* DWC_usb31 only */
3128c2ecf20Sopenharmony_ci#define DWC3_GTXFIFOSIZ_TXFDEP(n)	((n) & 0xffff)
3138c2ecf20Sopenharmony_ci#define DWC3_GTXFIFOSIZ_TXFSTADDR(n)	((n) & 0xffff0000)
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci/* Global RX Fifo Size Register */
3168c2ecf20Sopenharmony_ci#define DWC31_GRXFIFOSIZ_RXFDEP(n)	((n) & 0x7fff)	/* DWC_usb31 only */
3178c2ecf20Sopenharmony_ci#define DWC3_GRXFIFOSIZ_RXFDEP(n)	((n) & 0xffff)
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci/* Global Event Size Registers */
3208c2ecf20Sopenharmony_ci#define DWC3_GEVNTSIZ_INTMASK		BIT(31)
3218c2ecf20Sopenharmony_ci#define DWC3_GEVNTSIZ_SIZE(n)		((n) & 0xffff)
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci/* Global HWPARAMS0 Register */
3248c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS0_MODE(n)		((n) & 0x3)
3258c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS0_MODE_GADGET	0
3268c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS0_MODE_HOST	1
3278c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS0_MODE_DRD	2
3288c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS0_MBUS_TYPE(n)	(((n) >> 3) & 0x7)
3298c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS0_SBUS_TYPE(n)	(((n) >> 6) & 0x3)
3308c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS0_MDWIDTH(n)	(((n) >> 8) & 0xff)
3318c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS0_SDWIDTH(n)	(((n) >> 16) & 0xff)
3328c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS0_AWIDTH(n)	(((n) >> 24) & 0xff)
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci/* Global HWPARAMS1 Register */
3358c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS1_EN_PWROPT(n)	(((n) & (3 << 24)) >> 24)
3368c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS1_EN_PWROPT_NO	0
3378c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS1_EN_PWROPT_CLK	1
3388c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS1_EN_PWROPT_HIB	2
3398c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS1_PWROPT(n)	((n) << 24)
3408c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS1_PWROPT_MASK	DWC3_GHWPARAMS1_PWROPT(3)
3418c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS1_ENDBC		BIT(31)
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci/* Global HWPARAMS3 Register */
3448c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS3_SSPHY_IFC(n)		((n) & 3)
3458c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS3_SSPHY_IFC_DIS		0
3468c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS3_SSPHY_IFC_GEN1		1
3478c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS3_SSPHY_IFC_GEN2		2 /* DWC_usb31 only */
3488c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS3_HSPHY_IFC(n)		(((n) & (3 << 2)) >> 2)
3498c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS3_HSPHY_IFC_DIS		0
3508c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS3_HSPHY_IFC_UTMI		1
3518c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS3_HSPHY_IFC_ULPI		2
3528c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI	3
3538c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS3_FSPHY_IFC(n)		(((n) & (3 << 4)) >> 4)
3548c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS3_FSPHY_IFC_DIS		0
3558c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS3_FSPHY_IFC_ENA		1
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci/* Global HWPARAMS4 Register */
3588c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(n)	(((n) & (0x0f << 13)) >> 13)
3598c2ecf20Sopenharmony_ci#define DWC3_MAX_HIBER_SCRATCHBUFS		15
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci/* Global HWPARAMS6 Register */
3628c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS6_BCSUPPORT		BIT(14)
3638c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS6_OTG3SUPPORT		BIT(13)
3648c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS6_ADPSUPPORT		BIT(12)
3658c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS6_HNPSUPPORT		BIT(11)
3668c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS6_SRPSUPPORT		BIT(10)
3678c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS6_EN_FPGA			BIT(7)
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_ci/* DWC_usb32 only */
3708c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS6_MDWIDTH(n)		((n) & (0x3 << 8))
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_ci/* Global HWPARAMS7 Register */
3738c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS7_RAM1_DEPTH(n)	((n) & 0xffff)
3748c2ecf20Sopenharmony_ci#define DWC3_GHWPARAMS7_RAM2_DEPTH(n)	(((n) >> 16) & 0xffff)
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci/* Global Frame Length Adjustment Register */
3778c2ecf20Sopenharmony_ci#define DWC3_GFLADJ_30MHZ_SDBND_SEL		BIT(7)
3788c2ecf20Sopenharmony_ci#define DWC3_GFLADJ_30MHZ_MASK			0x3f
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci/* Global User Control Register 2 */
3818c2ecf20Sopenharmony_ci#define DWC3_GUCTL2_RST_ACTBITLATER		BIT(14)
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci/* Global User Control Register 3 */
3848c2ecf20Sopenharmony_ci#define DWC3_GUCTL3_SPLITDISABLE		BIT(14)
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci/* Device Configuration Register */
3878c2ecf20Sopenharmony_ci#define DWC3_DCFG_DEVADDR(addr)	((addr) << 3)
3888c2ecf20Sopenharmony_ci#define DWC3_DCFG_DEVADDR_MASK	DWC3_DCFG_DEVADDR(0x7f)
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci#define DWC3_DCFG_SPEED_MASK	(7 << 0)
3918c2ecf20Sopenharmony_ci#define DWC3_DCFG_SUPERSPEED_PLUS (5 << 0)  /* DWC_usb31 only */
3928c2ecf20Sopenharmony_ci#define DWC3_DCFG_SUPERSPEED	(4 << 0)
3938c2ecf20Sopenharmony_ci#define DWC3_DCFG_HIGHSPEED	(0 << 0)
3948c2ecf20Sopenharmony_ci#define DWC3_DCFG_FULLSPEED	BIT(0)
3958c2ecf20Sopenharmony_ci#define DWC3_DCFG_LOWSPEED	(2 << 0)
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci#define DWC3_DCFG_NUMP_SHIFT	17
3988c2ecf20Sopenharmony_ci#define DWC3_DCFG_NUMP(n)	(((n) >> DWC3_DCFG_NUMP_SHIFT) & 0x1f)
3998c2ecf20Sopenharmony_ci#define DWC3_DCFG_NUMP_MASK	(0x1f << DWC3_DCFG_NUMP_SHIFT)
4008c2ecf20Sopenharmony_ci#define DWC3_DCFG_LPM_CAP	BIT(22)
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ci/* Device Control Register */
4038c2ecf20Sopenharmony_ci#define DWC3_DCTL_RUN_STOP	BIT(31)
4048c2ecf20Sopenharmony_ci#define DWC3_DCTL_CSFTRST	BIT(30)
4058c2ecf20Sopenharmony_ci#define DWC3_DCTL_LSFTRST	BIT(29)
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_ci#define DWC3_DCTL_HIRD_THRES_MASK	(0x1f << 24)
4088c2ecf20Sopenharmony_ci#define DWC3_DCTL_HIRD_THRES(n)	((n) << 24)
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci#define DWC3_DCTL_APPL1RES	BIT(23)
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci/* These apply for core versions 1.87a and earlier */
4138c2ecf20Sopenharmony_ci#define DWC3_DCTL_TRGTULST_MASK		(0x0f << 17)
4148c2ecf20Sopenharmony_ci#define DWC3_DCTL_TRGTULST(n)		((n) << 17)
4158c2ecf20Sopenharmony_ci#define DWC3_DCTL_TRGTULST_U2		(DWC3_DCTL_TRGTULST(2))
4168c2ecf20Sopenharmony_ci#define DWC3_DCTL_TRGTULST_U3		(DWC3_DCTL_TRGTULST(3))
4178c2ecf20Sopenharmony_ci#define DWC3_DCTL_TRGTULST_SS_DIS	(DWC3_DCTL_TRGTULST(4))
4188c2ecf20Sopenharmony_ci#define DWC3_DCTL_TRGTULST_RX_DET	(DWC3_DCTL_TRGTULST(5))
4198c2ecf20Sopenharmony_ci#define DWC3_DCTL_TRGTULST_SS_INACT	(DWC3_DCTL_TRGTULST(6))
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci/* These apply for core versions 1.94a and later */
4228c2ecf20Sopenharmony_ci#define DWC3_DCTL_NYET_THRES(n)		(((n) & 0xf) << 20)
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci#define DWC3_DCTL_KEEP_CONNECT		BIT(19)
4258c2ecf20Sopenharmony_ci#define DWC3_DCTL_L1_HIBER_EN		BIT(18)
4268c2ecf20Sopenharmony_ci#define DWC3_DCTL_CRS			BIT(17)
4278c2ecf20Sopenharmony_ci#define DWC3_DCTL_CSS			BIT(16)
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ci#define DWC3_DCTL_INITU2ENA		BIT(12)
4308c2ecf20Sopenharmony_ci#define DWC3_DCTL_ACCEPTU2ENA		BIT(11)
4318c2ecf20Sopenharmony_ci#define DWC3_DCTL_INITU1ENA		BIT(10)
4328c2ecf20Sopenharmony_ci#define DWC3_DCTL_ACCEPTU1ENA		BIT(9)
4338c2ecf20Sopenharmony_ci#define DWC3_DCTL_TSTCTRL_MASK		(0xf << 1)
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci#define DWC3_DCTL_ULSTCHNGREQ_MASK	(0x0f << 5)
4368c2ecf20Sopenharmony_ci#define DWC3_DCTL_ULSTCHNGREQ(n) (((n) << 5) & DWC3_DCTL_ULSTCHNGREQ_MASK)
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci#define DWC3_DCTL_ULSTCHNG_NO_ACTION	(DWC3_DCTL_ULSTCHNGREQ(0))
4398c2ecf20Sopenharmony_ci#define DWC3_DCTL_ULSTCHNG_SS_DISABLED	(DWC3_DCTL_ULSTCHNGREQ(4))
4408c2ecf20Sopenharmony_ci#define DWC3_DCTL_ULSTCHNG_RX_DETECT	(DWC3_DCTL_ULSTCHNGREQ(5))
4418c2ecf20Sopenharmony_ci#define DWC3_DCTL_ULSTCHNG_SS_INACTIVE	(DWC3_DCTL_ULSTCHNGREQ(6))
4428c2ecf20Sopenharmony_ci#define DWC3_DCTL_ULSTCHNG_RECOVERY	(DWC3_DCTL_ULSTCHNGREQ(8))
4438c2ecf20Sopenharmony_ci#define DWC3_DCTL_ULSTCHNG_COMPLIANCE	(DWC3_DCTL_ULSTCHNGREQ(10))
4448c2ecf20Sopenharmony_ci#define DWC3_DCTL_ULSTCHNG_LOOPBACK	(DWC3_DCTL_ULSTCHNGREQ(11))
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci/* Device Event Enable Register */
4478c2ecf20Sopenharmony_ci#define DWC3_DEVTEN_VNDRDEVTSTRCVEDEN	BIT(12)
4488c2ecf20Sopenharmony_ci#define DWC3_DEVTEN_EVNTOVERFLOWEN	BIT(11)
4498c2ecf20Sopenharmony_ci#define DWC3_DEVTEN_CMDCMPLTEN		BIT(10)
4508c2ecf20Sopenharmony_ci#define DWC3_DEVTEN_ERRTICERREN		BIT(9)
4518c2ecf20Sopenharmony_ci#define DWC3_DEVTEN_SOFEN		BIT(7)
4528c2ecf20Sopenharmony_ci#define DWC3_DEVTEN_EOPFEN		BIT(6)
4538c2ecf20Sopenharmony_ci#define DWC3_DEVTEN_HIBERNATIONREQEVTEN	BIT(5)
4548c2ecf20Sopenharmony_ci#define DWC3_DEVTEN_WKUPEVTEN		BIT(4)
4558c2ecf20Sopenharmony_ci#define DWC3_DEVTEN_ULSTCNGEN		BIT(3)
4568c2ecf20Sopenharmony_ci#define DWC3_DEVTEN_CONNECTDONEEN	BIT(2)
4578c2ecf20Sopenharmony_ci#define DWC3_DEVTEN_USBRSTEN		BIT(1)
4588c2ecf20Sopenharmony_ci#define DWC3_DEVTEN_DISCONNEVTEN	BIT(0)
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci/* Device Status Register */
4618c2ecf20Sopenharmony_ci#define DWC3_DSTS_DCNRD			BIT(29)
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ci/* This applies for core versions 1.87a and earlier */
4648c2ecf20Sopenharmony_ci#define DWC3_DSTS_PWRUPREQ		BIT(24)
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_ci/* These apply for core versions 1.94a and later */
4678c2ecf20Sopenharmony_ci#define DWC3_DSTS_RSS			BIT(25)
4688c2ecf20Sopenharmony_ci#define DWC3_DSTS_SSS			BIT(24)
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_ci#define DWC3_DSTS_COREIDLE		BIT(23)
4718c2ecf20Sopenharmony_ci#define DWC3_DSTS_DEVCTRLHLT		BIT(22)
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci#define DWC3_DSTS_USBLNKST_MASK		(0x0f << 18)
4748c2ecf20Sopenharmony_ci#define DWC3_DSTS_USBLNKST(n)		(((n) & DWC3_DSTS_USBLNKST_MASK) >> 18)
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci#define DWC3_DSTS_RXFIFOEMPTY		BIT(17)
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_ci#define DWC3_DSTS_SOFFN_MASK		(0x3fff << 3)
4798c2ecf20Sopenharmony_ci#define DWC3_DSTS_SOFFN(n)		(((n) & DWC3_DSTS_SOFFN_MASK) >> 3)
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ci#define DWC3_DSTS_CONNECTSPD		(7 << 0)
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci#define DWC3_DSTS_SUPERSPEED_PLUS	(5 << 0) /* DWC_usb31 only */
4848c2ecf20Sopenharmony_ci#define DWC3_DSTS_SUPERSPEED		(4 << 0)
4858c2ecf20Sopenharmony_ci#define DWC3_DSTS_HIGHSPEED		(0 << 0)
4868c2ecf20Sopenharmony_ci#define DWC3_DSTS_FULLSPEED		BIT(0)
4878c2ecf20Sopenharmony_ci#define DWC3_DSTS_LOWSPEED		(2 << 0)
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci/* Device Generic Command Register */
4908c2ecf20Sopenharmony_ci#define DWC3_DGCMD_SET_LMP		0x01
4918c2ecf20Sopenharmony_ci#define DWC3_DGCMD_SET_PERIODIC_PAR	0x02
4928c2ecf20Sopenharmony_ci#define DWC3_DGCMD_XMIT_FUNCTION	0x03
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci/* These apply for core versions 1.94a and later */
4958c2ecf20Sopenharmony_ci#define DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO	0x04
4968c2ecf20Sopenharmony_ci#define DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI	0x05
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ci#define DWC3_DGCMD_SELECTED_FIFO_FLUSH	0x09
4998c2ecf20Sopenharmony_ci#define DWC3_DGCMD_ALL_FIFO_FLUSH	0x0a
5008c2ecf20Sopenharmony_ci#define DWC3_DGCMD_SET_ENDPOINT_NRDY	0x0c
5018c2ecf20Sopenharmony_ci#define DWC3_DGCMD_SET_ENDPOINT_PRIME	0x0d
5028c2ecf20Sopenharmony_ci#define DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK	0x10
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_ci#define DWC3_DGCMD_STATUS(n)		(((n) >> 12) & 0x0F)
5058c2ecf20Sopenharmony_ci#define DWC3_DGCMD_CMDACT		BIT(10)
5068c2ecf20Sopenharmony_ci#define DWC3_DGCMD_CMDIOC		BIT(8)
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_ci/* Device Generic Command Parameter Register */
5098c2ecf20Sopenharmony_ci#define DWC3_DGCMDPAR_FORCE_LINKPM_ACCEPT	BIT(0)
5108c2ecf20Sopenharmony_ci#define DWC3_DGCMDPAR_FIFO_NUM(n)		((n) << 0)
5118c2ecf20Sopenharmony_ci#define DWC3_DGCMDPAR_RX_FIFO			(0 << 5)
5128c2ecf20Sopenharmony_ci#define DWC3_DGCMDPAR_TX_FIFO			BIT(5)
5138c2ecf20Sopenharmony_ci#define DWC3_DGCMDPAR_LOOPBACK_DIS		(0 << 0)
5148c2ecf20Sopenharmony_ci#define DWC3_DGCMDPAR_LOOPBACK_ENA		BIT(0)
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci/* Device Endpoint Command Register */
5178c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_PARAM_SHIFT		16
5188c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_PARAM(x)		((x) << DWC3_DEPCMD_PARAM_SHIFT)
5198c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_GET_RSC_IDX(x)	(((x) >> DWC3_DEPCMD_PARAM_SHIFT) & 0x7f)
5208c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_STATUS(x)		(((x) >> 12) & 0x0F)
5218c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_HIPRI_FORCERM	BIT(11)
5228c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_CLEARPENDIN		BIT(11)
5238c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_CMDACT		BIT(10)
5248c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_CMDIOC		BIT(8)
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_DEPSTARTCFG		(0x09 << 0)
5278c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_ENDTRANSFER		(0x08 << 0)
5288c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_UPDATETRANSFER	(0x07 << 0)
5298c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_STARTTRANSFER	(0x06 << 0)
5308c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_CLEARSTALL		(0x05 << 0)
5318c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_SETSTALL		(0x04 << 0)
5328c2ecf20Sopenharmony_ci/* This applies for core versions 1.90a and earlier */
5338c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_GETSEQNUMBER	(0x03 << 0)
5348c2ecf20Sopenharmony_ci/* This applies for core versions 1.94a and later */
5358c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_GETEPSTATE		(0x03 << 0)
5368c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_SETTRANSFRESOURCE	(0x02 << 0)
5378c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_SETEPCONFIG		(0x01 << 0)
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_CMD(x)		((x) & 0xf)
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_ci/* The EP number goes 0..31 so ep0 is always out and ep1 is always in */
5428c2ecf20Sopenharmony_ci#define DWC3_DALEPENA_EP(n)		BIT(n)
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_TYPE_CONTROL	0
5458c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_TYPE_ISOC		1
5468c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_TYPE_BULK		2
5478c2ecf20Sopenharmony_ci#define DWC3_DEPCMD_TYPE_INTR		3
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_ci#define DWC3_DEV_IMOD_COUNT_SHIFT	16
5508c2ecf20Sopenharmony_ci#define DWC3_DEV_IMOD_COUNT_MASK	(0xffff << 16)
5518c2ecf20Sopenharmony_ci#define DWC3_DEV_IMOD_INTERVAL_SHIFT	0
5528c2ecf20Sopenharmony_ci#define DWC3_DEV_IMOD_INTERVAL_MASK	(0xffff << 0)
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_ci/* OTG Configuration Register */
5558c2ecf20Sopenharmony_ci#define DWC3_OCFG_DISPWRCUTTOFF		BIT(5)
5568c2ecf20Sopenharmony_ci#define DWC3_OCFG_HIBDISMASK		BIT(4)
5578c2ecf20Sopenharmony_ci#define DWC3_OCFG_SFTRSTMASK		BIT(3)
5588c2ecf20Sopenharmony_ci#define DWC3_OCFG_OTGVERSION		BIT(2)
5598c2ecf20Sopenharmony_ci#define DWC3_OCFG_HNPCAP		BIT(1)
5608c2ecf20Sopenharmony_ci#define DWC3_OCFG_SRPCAP		BIT(0)
5618c2ecf20Sopenharmony_ci
5628c2ecf20Sopenharmony_ci/* OTG CTL Register */
5638c2ecf20Sopenharmony_ci#define DWC3_OCTL_OTG3GOERR		BIT(7)
5648c2ecf20Sopenharmony_ci#define DWC3_OCTL_PERIMODE		BIT(6)
5658c2ecf20Sopenharmony_ci#define DWC3_OCTL_PRTPWRCTL		BIT(5)
5668c2ecf20Sopenharmony_ci#define DWC3_OCTL_HNPREQ		BIT(4)
5678c2ecf20Sopenharmony_ci#define DWC3_OCTL_SESREQ		BIT(3)
5688c2ecf20Sopenharmony_ci#define DWC3_OCTL_TERMSELIDPULSE	BIT(2)
5698c2ecf20Sopenharmony_ci#define DWC3_OCTL_DEVSETHNPEN		BIT(1)
5708c2ecf20Sopenharmony_ci#define DWC3_OCTL_HSTSETHNPEN		BIT(0)
5718c2ecf20Sopenharmony_ci
5728c2ecf20Sopenharmony_ci/* OTG Event Register */
5738c2ecf20Sopenharmony_ci#define DWC3_OEVT_DEVICEMODE		BIT(31)
5748c2ecf20Sopenharmony_ci#define DWC3_OEVT_XHCIRUNSTPSET		BIT(27)
5758c2ecf20Sopenharmony_ci#define DWC3_OEVT_DEVRUNSTPSET		BIT(26)
5768c2ecf20Sopenharmony_ci#define DWC3_OEVT_HIBENTRY		BIT(25)
5778c2ecf20Sopenharmony_ci#define DWC3_OEVT_CONIDSTSCHNG		BIT(24)
5788c2ecf20Sopenharmony_ci#define DWC3_OEVT_HRRCONFNOTIF		BIT(23)
5798c2ecf20Sopenharmony_ci#define DWC3_OEVT_HRRINITNOTIF		BIT(22)
5808c2ecf20Sopenharmony_ci#define DWC3_OEVT_ADEVIDLE		BIT(21)
5818c2ecf20Sopenharmony_ci#define DWC3_OEVT_ADEVBHOSTEND		BIT(20)
5828c2ecf20Sopenharmony_ci#define DWC3_OEVT_ADEVHOST		BIT(19)
5838c2ecf20Sopenharmony_ci#define DWC3_OEVT_ADEVHNPCHNG		BIT(18)
5848c2ecf20Sopenharmony_ci#define DWC3_OEVT_ADEVSRPDET		BIT(17)
5858c2ecf20Sopenharmony_ci#define DWC3_OEVT_ADEVSESSENDDET	BIT(16)
5868c2ecf20Sopenharmony_ci#define DWC3_OEVT_BDEVBHOSTEND		BIT(11)
5878c2ecf20Sopenharmony_ci#define DWC3_OEVT_BDEVHNPCHNG		BIT(10)
5888c2ecf20Sopenharmony_ci#define DWC3_OEVT_BDEVSESSVLDDET	BIT(9)
5898c2ecf20Sopenharmony_ci#define DWC3_OEVT_BDEVVBUSCHNG		BIT(8)
5908c2ecf20Sopenharmony_ci#define DWC3_OEVT_BSESSVLD		BIT(3)
5918c2ecf20Sopenharmony_ci#define DWC3_OEVT_HSTNEGSTS		BIT(2)
5928c2ecf20Sopenharmony_ci#define DWC3_OEVT_SESREQSTS		BIT(1)
5938c2ecf20Sopenharmony_ci#define DWC3_OEVT_ERROR			BIT(0)
5948c2ecf20Sopenharmony_ci
5958c2ecf20Sopenharmony_ci/* OTG Event Enable Register */
5968c2ecf20Sopenharmony_ci#define DWC3_OEVTEN_XHCIRUNSTPSETEN	BIT(27)
5978c2ecf20Sopenharmony_ci#define DWC3_OEVTEN_DEVRUNSTPSETEN	BIT(26)
5988c2ecf20Sopenharmony_ci#define DWC3_OEVTEN_HIBENTRYEN		BIT(25)
5998c2ecf20Sopenharmony_ci#define DWC3_OEVTEN_CONIDSTSCHNGEN	BIT(24)
6008c2ecf20Sopenharmony_ci#define DWC3_OEVTEN_HRRCONFNOTIFEN	BIT(23)
6018c2ecf20Sopenharmony_ci#define DWC3_OEVTEN_HRRINITNOTIFEN	BIT(22)
6028c2ecf20Sopenharmony_ci#define DWC3_OEVTEN_ADEVIDLEEN		BIT(21)
6038c2ecf20Sopenharmony_ci#define DWC3_OEVTEN_ADEVBHOSTENDEN	BIT(20)
6048c2ecf20Sopenharmony_ci#define DWC3_OEVTEN_ADEVHOSTEN		BIT(19)
6058c2ecf20Sopenharmony_ci#define DWC3_OEVTEN_ADEVHNPCHNGEN	BIT(18)
6068c2ecf20Sopenharmony_ci#define DWC3_OEVTEN_ADEVSRPDETEN	BIT(17)
6078c2ecf20Sopenharmony_ci#define DWC3_OEVTEN_ADEVSESSENDDETEN	BIT(16)
6088c2ecf20Sopenharmony_ci#define DWC3_OEVTEN_BDEVBHOSTENDEN	BIT(11)
6098c2ecf20Sopenharmony_ci#define DWC3_OEVTEN_BDEVHNPCHNGEN	BIT(10)
6108c2ecf20Sopenharmony_ci#define DWC3_OEVTEN_BDEVSESSVLDDETEN	BIT(9)
6118c2ecf20Sopenharmony_ci#define DWC3_OEVTEN_BDEVVBUSCHNGEN	BIT(8)
6128c2ecf20Sopenharmony_ci
6138c2ecf20Sopenharmony_ci/* OTG Status Register */
6148c2ecf20Sopenharmony_ci#define DWC3_OSTS_DEVRUNSTP		BIT(13)
6158c2ecf20Sopenharmony_ci#define DWC3_OSTS_XHCIRUNSTP		BIT(12)
6168c2ecf20Sopenharmony_ci#define DWC3_OSTS_PERIPHERALSTATE	BIT(4)
6178c2ecf20Sopenharmony_ci#define DWC3_OSTS_XHCIPRTPOWER		BIT(3)
6188c2ecf20Sopenharmony_ci#define DWC3_OSTS_BSESVLD		BIT(2)
6198c2ecf20Sopenharmony_ci#define DWC3_OSTS_VBUSVLD		BIT(1)
6208c2ecf20Sopenharmony_ci#define DWC3_OSTS_CONIDSTS		BIT(0)
6218c2ecf20Sopenharmony_ci
6228c2ecf20Sopenharmony_ci/* Structures */
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_cistruct dwc3_trb;
6258c2ecf20Sopenharmony_ci
6268c2ecf20Sopenharmony_ci/**
6278c2ecf20Sopenharmony_ci * struct dwc3_event_buffer - Software event buffer representation
6288c2ecf20Sopenharmony_ci * @buf: _THE_ buffer
6298c2ecf20Sopenharmony_ci * @cache: The buffer cache used in the threaded interrupt
6308c2ecf20Sopenharmony_ci * @length: size of this buffer
6318c2ecf20Sopenharmony_ci * @lpos: event offset
6328c2ecf20Sopenharmony_ci * @count: cache of last read event count register
6338c2ecf20Sopenharmony_ci * @flags: flags related to this event buffer
6348c2ecf20Sopenharmony_ci * @dma: dma_addr_t
6358c2ecf20Sopenharmony_ci * @dwc: pointer to DWC controller
6368c2ecf20Sopenharmony_ci */
6378c2ecf20Sopenharmony_cistruct dwc3_event_buffer {
6388c2ecf20Sopenharmony_ci	void			*buf;
6398c2ecf20Sopenharmony_ci	void			*cache;
6408c2ecf20Sopenharmony_ci	unsigned int		length;
6418c2ecf20Sopenharmony_ci	unsigned int		lpos;
6428c2ecf20Sopenharmony_ci	unsigned int		count;
6438c2ecf20Sopenharmony_ci	unsigned int		flags;
6448c2ecf20Sopenharmony_ci
6458c2ecf20Sopenharmony_ci#define DWC3_EVENT_PENDING	BIT(0)
6468c2ecf20Sopenharmony_ci
6478c2ecf20Sopenharmony_ci	dma_addr_t		dma;
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_ci	struct dwc3		*dwc;
6508c2ecf20Sopenharmony_ci};
6518c2ecf20Sopenharmony_ci
6528c2ecf20Sopenharmony_ci#define DWC3_EP_FLAG_STALLED	BIT(0)
6538c2ecf20Sopenharmony_ci#define DWC3_EP_FLAG_WEDGED	BIT(1)
6548c2ecf20Sopenharmony_ci
6558c2ecf20Sopenharmony_ci#define DWC3_EP_DIRECTION_TX	true
6568c2ecf20Sopenharmony_ci#define DWC3_EP_DIRECTION_RX	false
6578c2ecf20Sopenharmony_ci
6588c2ecf20Sopenharmony_ci#define DWC3_TRB_NUM		256
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_ci/**
6618c2ecf20Sopenharmony_ci * struct dwc3_ep - device side endpoint representation
6628c2ecf20Sopenharmony_ci * @endpoint: usb endpoint
6638c2ecf20Sopenharmony_ci * @cancelled_list: list of cancelled requests for this endpoint
6648c2ecf20Sopenharmony_ci * @pending_list: list of pending requests for this endpoint
6658c2ecf20Sopenharmony_ci * @started_list: list of started requests on this endpoint
6668c2ecf20Sopenharmony_ci * @regs: pointer to first endpoint register
6678c2ecf20Sopenharmony_ci * @trb_pool: array of transaction buffers
6688c2ecf20Sopenharmony_ci * @trb_pool_dma: dma address of @trb_pool
6698c2ecf20Sopenharmony_ci * @trb_enqueue: enqueue 'pointer' into TRB array
6708c2ecf20Sopenharmony_ci * @trb_dequeue: dequeue 'pointer' into TRB array
6718c2ecf20Sopenharmony_ci * @dwc: pointer to DWC controller
6728c2ecf20Sopenharmony_ci * @saved_state: ep state saved during hibernation
6738c2ecf20Sopenharmony_ci * @flags: endpoint flags (wedged, stalled, ...)
6748c2ecf20Sopenharmony_ci * @number: endpoint number (1 - 15)
6758c2ecf20Sopenharmony_ci * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK
6768c2ecf20Sopenharmony_ci * @resource_index: Resource transfer index
6778c2ecf20Sopenharmony_ci * @frame_number: set to the frame number we want this transfer to start (ISOC)
6788c2ecf20Sopenharmony_ci * @interval: the interval on which the ISOC transfer is started
6798c2ecf20Sopenharmony_ci * @name: a human readable name e.g. ep1out-bulk
6808c2ecf20Sopenharmony_ci * @direction: true for TX, false for RX
6818c2ecf20Sopenharmony_ci * @stream_capable: true when streams are enabled
6828c2ecf20Sopenharmony_ci * @combo_num: the test combination BIT[15:14] of the frame number to test
6838c2ecf20Sopenharmony_ci *		isochronous START TRANSFER command failure workaround
6848c2ecf20Sopenharmony_ci * @start_cmd_status: the status of testing START TRANSFER command with
6858c2ecf20Sopenharmony_ci *		combo_num = 'b00
6868c2ecf20Sopenharmony_ci */
6878c2ecf20Sopenharmony_cistruct dwc3_ep {
6888c2ecf20Sopenharmony_ci	struct usb_ep		endpoint;
6898c2ecf20Sopenharmony_ci	struct list_head	cancelled_list;
6908c2ecf20Sopenharmony_ci	struct list_head	pending_list;
6918c2ecf20Sopenharmony_ci	struct list_head	started_list;
6928c2ecf20Sopenharmony_ci
6938c2ecf20Sopenharmony_ci	void __iomem		*regs;
6948c2ecf20Sopenharmony_ci
6958c2ecf20Sopenharmony_ci	struct dwc3_trb		*trb_pool;
6968c2ecf20Sopenharmony_ci	dma_addr_t		trb_pool_dma;
6978c2ecf20Sopenharmony_ci	struct dwc3		*dwc;
6988c2ecf20Sopenharmony_ci
6998c2ecf20Sopenharmony_ci	u32			saved_state;
7008c2ecf20Sopenharmony_ci	unsigned int		flags;
7018c2ecf20Sopenharmony_ci#define DWC3_EP_ENABLED		BIT(0)
7028c2ecf20Sopenharmony_ci#define DWC3_EP_STALL		BIT(1)
7038c2ecf20Sopenharmony_ci#define DWC3_EP_WEDGE		BIT(2)
7048c2ecf20Sopenharmony_ci#define DWC3_EP_TRANSFER_STARTED BIT(3)
7058c2ecf20Sopenharmony_ci#define DWC3_EP_END_TRANSFER_PENDING BIT(4)
7068c2ecf20Sopenharmony_ci#define DWC3_EP_PENDING_REQUEST	BIT(5)
7078c2ecf20Sopenharmony_ci#define DWC3_EP_DELAY_START	BIT(6)
7088c2ecf20Sopenharmony_ci#define DWC3_EP_WAIT_TRANSFER_COMPLETE	BIT(7)
7098c2ecf20Sopenharmony_ci#define DWC3_EP_IGNORE_NEXT_NOSTREAM	BIT(8)
7108c2ecf20Sopenharmony_ci#define DWC3_EP_FORCE_RESTART_STREAM	BIT(9)
7118c2ecf20Sopenharmony_ci#define DWC3_EP_FIRST_STREAM_PRIMED	BIT(10)
7128c2ecf20Sopenharmony_ci#define DWC3_EP_PENDING_CLEAR_STALL	BIT(11)
7138c2ecf20Sopenharmony_ci
7148c2ecf20Sopenharmony_ci	/* This last one is specific to EP0 */
7158c2ecf20Sopenharmony_ci#define DWC3_EP0_DIR_IN		BIT(31)
7168c2ecf20Sopenharmony_ci
7178c2ecf20Sopenharmony_ci	/*
7188c2ecf20Sopenharmony_ci	 * IMPORTANT: we *know* we have 256 TRBs in our @trb_pool, so we will
7198c2ecf20Sopenharmony_ci	 * use a u8 type here. If anybody decides to increase number of TRBs to
7208c2ecf20Sopenharmony_ci	 * anything larger than 256 - I can't see why people would want to do
7218c2ecf20Sopenharmony_ci	 * this though - then this type needs to be changed.
7228c2ecf20Sopenharmony_ci	 *
7238c2ecf20Sopenharmony_ci	 * By using u8 types we ensure that our % operator when incrementing
7248c2ecf20Sopenharmony_ci	 * enqueue and dequeue get optimized away by the compiler.
7258c2ecf20Sopenharmony_ci	 */
7268c2ecf20Sopenharmony_ci	u8			trb_enqueue;
7278c2ecf20Sopenharmony_ci	u8			trb_dequeue;
7288c2ecf20Sopenharmony_ci
7298c2ecf20Sopenharmony_ci	u8			number;
7308c2ecf20Sopenharmony_ci	u8			type;
7318c2ecf20Sopenharmony_ci	u8			resource_index;
7328c2ecf20Sopenharmony_ci	u32			frame_number;
7338c2ecf20Sopenharmony_ci	u32			interval;
7348c2ecf20Sopenharmony_ci
7358c2ecf20Sopenharmony_ci	char			name[20];
7368c2ecf20Sopenharmony_ci
7378c2ecf20Sopenharmony_ci	unsigned		direction:1;
7388c2ecf20Sopenharmony_ci	unsigned		stream_capable:1;
7398c2ecf20Sopenharmony_ci
7408c2ecf20Sopenharmony_ci	/* For isochronous START TRANSFER workaround only */
7418c2ecf20Sopenharmony_ci	u8			combo_num;
7428c2ecf20Sopenharmony_ci	int			start_cmd_status;
7438c2ecf20Sopenharmony_ci};
7448c2ecf20Sopenharmony_ci
7458c2ecf20Sopenharmony_cienum dwc3_phy {
7468c2ecf20Sopenharmony_ci	DWC3_PHY_UNKNOWN = 0,
7478c2ecf20Sopenharmony_ci	DWC3_PHY_USB3,
7488c2ecf20Sopenharmony_ci	DWC3_PHY_USB2,
7498c2ecf20Sopenharmony_ci};
7508c2ecf20Sopenharmony_ci
7518c2ecf20Sopenharmony_cienum dwc3_ep0_next {
7528c2ecf20Sopenharmony_ci	DWC3_EP0_UNKNOWN = 0,
7538c2ecf20Sopenharmony_ci	DWC3_EP0_COMPLETE,
7548c2ecf20Sopenharmony_ci	DWC3_EP0_NRDY_DATA,
7558c2ecf20Sopenharmony_ci	DWC3_EP0_NRDY_STATUS,
7568c2ecf20Sopenharmony_ci};
7578c2ecf20Sopenharmony_ci
7588c2ecf20Sopenharmony_cienum dwc3_ep0_state {
7598c2ecf20Sopenharmony_ci	EP0_UNCONNECTED		= 0,
7608c2ecf20Sopenharmony_ci	EP0_SETUP_PHASE,
7618c2ecf20Sopenharmony_ci	EP0_DATA_PHASE,
7628c2ecf20Sopenharmony_ci	EP0_STATUS_PHASE,
7638c2ecf20Sopenharmony_ci};
7648c2ecf20Sopenharmony_ci
7658c2ecf20Sopenharmony_cienum dwc3_link_state {
7668c2ecf20Sopenharmony_ci	/* In SuperSpeed */
7678c2ecf20Sopenharmony_ci	DWC3_LINK_STATE_U0		= 0x00, /* in HS, means ON */
7688c2ecf20Sopenharmony_ci	DWC3_LINK_STATE_U1		= 0x01,
7698c2ecf20Sopenharmony_ci	DWC3_LINK_STATE_U2		= 0x02, /* in HS, means SLEEP */
7708c2ecf20Sopenharmony_ci	DWC3_LINK_STATE_U3		= 0x03, /* in HS, means SUSPEND */
7718c2ecf20Sopenharmony_ci	DWC3_LINK_STATE_SS_DIS		= 0x04,
7728c2ecf20Sopenharmony_ci	DWC3_LINK_STATE_RX_DET		= 0x05, /* in HS, means Early Suspend */
7738c2ecf20Sopenharmony_ci	DWC3_LINK_STATE_SS_INACT	= 0x06,
7748c2ecf20Sopenharmony_ci	DWC3_LINK_STATE_POLL		= 0x07,
7758c2ecf20Sopenharmony_ci	DWC3_LINK_STATE_RECOV		= 0x08,
7768c2ecf20Sopenharmony_ci	DWC3_LINK_STATE_HRESET		= 0x09,
7778c2ecf20Sopenharmony_ci	DWC3_LINK_STATE_CMPLY		= 0x0a,
7788c2ecf20Sopenharmony_ci	DWC3_LINK_STATE_LPBK		= 0x0b,
7798c2ecf20Sopenharmony_ci	DWC3_LINK_STATE_RESET		= 0x0e,
7808c2ecf20Sopenharmony_ci	DWC3_LINK_STATE_RESUME		= 0x0f,
7818c2ecf20Sopenharmony_ci	DWC3_LINK_STATE_MASK		= 0x0f,
7828c2ecf20Sopenharmony_ci};
7838c2ecf20Sopenharmony_ci
7848c2ecf20Sopenharmony_ci/* TRB Length, PCM and Status */
7858c2ecf20Sopenharmony_ci#define DWC3_TRB_SIZE_MASK	(0x00ffffff)
7868c2ecf20Sopenharmony_ci#define DWC3_TRB_SIZE_LENGTH(n)	((n) & DWC3_TRB_SIZE_MASK)
7878c2ecf20Sopenharmony_ci#define DWC3_TRB_SIZE_PCM1(n)	(((n) & 0x03) << 24)
7888c2ecf20Sopenharmony_ci#define DWC3_TRB_SIZE_TRBSTS(n)	(((n) & (0x0f << 28)) >> 28)
7898c2ecf20Sopenharmony_ci
7908c2ecf20Sopenharmony_ci#define DWC3_TRBSTS_OK			0
7918c2ecf20Sopenharmony_ci#define DWC3_TRBSTS_MISSED_ISOC		1
7928c2ecf20Sopenharmony_ci#define DWC3_TRBSTS_SETUP_PENDING	2
7938c2ecf20Sopenharmony_ci#define DWC3_TRB_STS_XFER_IN_PROG	4
7948c2ecf20Sopenharmony_ci
7958c2ecf20Sopenharmony_ci/* TRB Control */
7968c2ecf20Sopenharmony_ci#define DWC3_TRB_CTRL_HWO		BIT(0)
7978c2ecf20Sopenharmony_ci#define DWC3_TRB_CTRL_LST		BIT(1)
7988c2ecf20Sopenharmony_ci#define DWC3_TRB_CTRL_CHN		BIT(2)
7998c2ecf20Sopenharmony_ci#define DWC3_TRB_CTRL_CSP		BIT(3)
8008c2ecf20Sopenharmony_ci#define DWC3_TRB_CTRL_TRBCTL(n)		(((n) & 0x3f) << 4)
8018c2ecf20Sopenharmony_ci#define DWC3_TRB_CTRL_ISP_IMI		BIT(10)
8028c2ecf20Sopenharmony_ci#define DWC3_TRB_CTRL_IOC		BIT(11)
8038c2ecf20Sopenharmony_ci#define DWC3_TRB_CTRL_SID_SOFN(n)	(((n) & 0xffff) << 14)
8048c2ecf20Sopenharmony_ci#define DWC3_TRB_CTRL_GET_SID_SOFN(n)	(((n) & (0xffff << 14)) >> 14)
8058c2ecf20Sopenharmony_ci
8068c2ecf20Sopenharmony_ci#define DWC3_TRBCTL_TYPE(n)		((n) & (0x3f << 4))
8078c2ecf20Sopenharmony_ci#define DWC3_TRBCTL_NORMAL		DWC3_TRB_CTRL_TRBCTL(1)
8088c2ecf20Sopenharmony_ci#define DWC3_TRBCTL_CONTROL_SETUP	DWC3_TRB_CTRL_TRBCTL(2)
8098c2ecf20Sopenharmony_ci#define DWC3_TRBCTL_CONTROL_STATUS2	DWC3_TRB_CTRL_TRBCTL(3)
8108c2ecf20Sopenharmony_ci#define DWC3_TRBCTL_CONTROL_STATUS3	DWC3_TRB_CTRL_TRBCTL(4)
8118c2ecf20Sopenharmony_ci#define DWC3_TRBCTL_CONTROL_DATA	DWC3_TRB_CTRL_TRBCTL(5)
8128c2ecf20Sopenharmony_ci#define DWC3_TRBCTL_ISOCHRONOUS_FIRST	DWC3_TRB_CTRL_TRBCTL(6)
8138c2ecf20Sopenharmony_ci#define DWC3_TRBCTL_ISOCHRONOUS		DWC3_TRB_CTRL_TRBCTL(7)
8148c2ecf20Sopenharmony_ci#define DWC3_TRBCTL_LINK_TRB		DWC3_TRB_CTRL_TRBCTL(8)
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci/**
8178c2ecf20Sopenharmony_ci * struct dwc3_trb - transfer request block (hw format)
8188c2ecf20Sopenharmony_ci * @bpl: DW0-3
8198c2ecf20Sopenharmony_ci * @bph: DW4-7
8208c2ecf20Sopenharmony_ci * @size: DW8-B
8218c2ecf20Sopenharmony_ci * @ctrl: DWC-F
8228c2ecf20Sopenharmony_ci */
8238c2ecf20Sopenharmony_cistruct dwc3_trb {
8248c2ecf20Sopenharmony_ci	u32		bpl;
8258c2ecf20Sopenharmony_ci	u32		bph;
8268c2ecf20Sopenharmony_ci	u32		size;
8278c2ecf20Sopenharmony_ci	u32		ctrl;
8288c2ecf20Sopenharmony_ci} __packed;
8298c2ecf20Sopenharmony_ci
8308c2ecf20Sopenharmony_ci/**
8318c2ecf20Sopenharmony_ci * struct dwc3_hwparams - copy of HWPARAMS registers
8328c2ecf20Sopenharmony_ci * @hwparams0: GHWPARAMS0
8338c2ecf20Sopenharmony_ci * @hwparams1: GHWPARAMS1
8348c2ecf20Sopenharmony_ci * @hwparams2: GHWPARAMS2
8358c2ecf20Sopenharmony_ci * @hwparams3: GHWPARAMS3
8368c2ecf20Sopenharmony_ci * @hwparams4: GHWPARAMS4
8378c2ecf20Sopenharmony_ci * @hwparams5: GHWPARAMS5
8388c2ecf20Sopenharmony_ci * @hwparams6: GHWPARAMS6
8398c2ecf20Sopenharmony_ci * @hwparams7: GHWPARAMS7
8408c2ecf20Sopenharmony_ci * @hwparams8: GHWPARAMS8
8418c2ecf20Sopenharmony_ci */
8428c2ecf20Sopenharmony_cistruct dwc3_hwparams {
8438c2ecf20Sopenharmony_ci	u32	hwparams0;
8448c2ecf20Sopenharmony_ci	u32	hwparams1;
8458c2ecf20Sopenharmony_ci	u32	hwparams2;
8468c2ecf20Sopenharmony_ci	u32	hwparams3;
8478c2ecf20Sopenharmony_ci	u32	hwparams4;
8488c2ecf20Sopenharmony_ci	u32	hwparams5;
8498c2ecf20Sopenharmony_ci	u32	hwparams6;
8508c2ecf20Sopenharmony_ci	u32	hwparams7;
8518c2ecf20Sopenharmony_ci	u32	hwparams8;
8528c2ecf20Sopenharmony_ci};
8538c2ecf20Sopenharmony_ci
8548c2ecf20Sopenharmony_ci/* HWPARAMS0 */
8558c2ecf20Sopenharmony_ci#define DWC3_MODE(n)		((n) & 0x7)
8568c2ecf20Sopenharmony_ci
8578c2ecf20Sopenharmony_ci#define DWC3_MDWIDTH(n)		(((n) & 0xff00) >> 8)
8588c2ecf20Sopenharmony_ci
8598c2ecf20Sopenharmony_ci/* HWPARAMS1 */
8608c2ecf20Sopenharmony_ci#define DWC3_NUM_INT(n)		(((n) & (0x3f << 15)) >> 15)
8618c2ecf20Sopenharmony_ci
8628c2ecf20Sopenharmony_ci/* HWPARAMS3 */
8638c2ecf20Sopenharmony_ci#define DWC3_NUM_IN_EPS_MASK	(0x1f << 18)
8648c2ecf20Sopenharmony_ci#define DWC3_NUM_EPS_MASK	(0x3f << 12)
8658c2ecf20Sopenharmony_ci#define DWC3_NUM_EPS(p)		(((p)->hwparams3 &		\
8668c2ecf20Sopenharmony_ci			(DWC3_NUM_EPS_MASK)) >> 12)
8678c2ecf20Sopenharmony_ci#define DWC3_NUM_IN_EPS(p)	(((p)->hwparams3 &		\
8688c2ecf20Sopenharmony_ci			(DWC3_NUM_IN_EPS_MASK)) >> 18)
8698c2ecf20Sopenharmony_ci
8708c2ecf20Sopenharmony_ci/* HWPARAMS7 */
8718c2ecf20Sopenharmony_ci#define DWC3_RAM1_DEPTH(n)	((n) & 0xffff)
8728c2ecf20Sopenharmony_ci
8738c2ecf20Sopenharmony_ci/**
8748c2ecf20Sopenharmony_ci * struct dwc3_request - representation of a transfer request
8758c2ecf20Sopenharmony_ci * @request: struct usb_request to be transferred
8768c2ecf20Sopenharmony_ci * @list: a list_head used for request queueing
8778c2ecf20Sopenharmony_ci * @dep: struct dwc3_ep owning this request
8788c2ecf20Sopenharmony_ci * @sg: pointer to first incomplete sg
8798c2ecf20Sopenharmony_ci * @start_sg: pointer to the sg which should be queued next
8808c2ecf20Sopenharmony_ci * @num_pending_sgs: counter to pending sgs
8818c2ecf20Sopenharmony_ci * @num_queued_sgs: counter to the number of sgs which already got queued
8828c2ecf20Sopenharmony_ci * @remaining: amount of data remaining
8838c2ecf20Sopenharmony_ci * @status: internal dwc3 request status tracking
8848c2ecf20Sopenharmony_ci * @epnum: endpoint number to which this request refers
8858c2ecf20Sopenharmony_ci * @trb: pointer to struct dwc3_trb
8868c2ecf20Sopenharmony_ci * @trb_dma: DMA address of @trb
8878c2ecf20Sopenharmony_ci * @num_trbs: number of TRBs used by this request
8888c2ecf20Sopenharmony_ci * @needs_extra_trb: true when request needs one extra TRB (either due to ZLP
8898c2ecf20Sopenharmony_ci *	or unaligned OUT)
8908c2ecf20Sopenharmony_ci * @direction: IN or OUT direction flag
8918c2ecf20Sopenharmony_ci * @mapped: true when request has been dma-mapped
8928c2ecf20Sopenharmony_ci */
8938c2ecf20Sopenharmony_cistruct dwc3_request {
8948c2ecf20Sopenharmony_ci	struct usb_request	request;
8958c2ecf20Sopenharmony_ci	struct list_head	list;
8968c2ecf20Sopenharmony_ci	struct dwc3_ep		*dep;
8978c2ecf20Sopenharmony_ci	struct scatterlist	*sg;
8988c2ecf20Sopenharmony_ci	struct scatterlist	*start_sg;
8998c2ecf20Sopenharmony_ci
9008c2ecf20Sopenharmony_ci	unsigned int		num_pending_sgs;
9018c2ecf20Sopenharmony_ci	unsigned int		num_queued_sgs;
9028c2ecf20Sopenharmony_ci	unsigned int		remaining;
9038c2ecf20Sopenharmony_ci
9048c2ecf20Sopenharmony_ci	unsigned int		status;
9058c2ecf20Sopenharmony_ci#define DWC3_REQUEST_STATUS_QUEUED	0
9068c2ecf20Sopenharmony_ci#define DWC3_REQUEST_STATUS_STARTED	1
9078c2ecf20Sopenharmony_ci#define DWC3_REQUEST_STATUS_CANCELLED	2
9088c2ecf20Sopenharmony_ci#define DWC3_REQUEST_STATUS_COMPLETED	3
9098c2ecf20Sopenharmony_ci#define DWC3_REQUEST_STATUS_UNKNOWN	-1
9108c2ecf20Sopenharmony_ci
9118c2ecf20Sopenharmony_ci	u8			epnum;
9128c2ecf20Sopenharmony_ci	struct dwc3_trb		*trb;
9138c2ecf20Sopenharmony_ci	dma_addr_t		trb_dma;
9148c2ecf20Sopenharmony_ci
9158c2ecf20Sopenharmony_ci	unsigned int		num_trbs;
9168c2ecf20Sopenharmony_ci
9178c2ecf20Sopenharmony_ci	unsigned int		needs_extra_trb:1;
9188c2ecf20Sopenharmony_ci	unsigned int		direction:1;
9198c2ecf20Sopenharmony_ci	unsigned int		mapped:1;
9208c2ecf20Sopenharmony_ci};
9218c2ecf20Sopenharmony_ci
9228c2ecf20Sopenharmony_ci/*
9238c2ecf20Sopenharmony_ci * struct dwc3_scratchpad_array - hibernation scratchpad array
9248c2ecf20Sopenharmony_ci * (format defined by hw)
9258c2ecf20Sopenharmony_ci */
9268c2ecf20Sopenharmony_cistruct dwc3_scratchpad_array {
9278c2ecf20Sopenharmony_ci	__le64	dma_adr[DWC3_MAX_HIBER_SCRATCHBUFS];
9288c2ecf20Sopenharmony_ci};
9298c2ecf20Sopenharmony_ci
9308c2ecf20Sopenharmony_ci/**
9318c2ecf20Sopenharmony_ci * struct dwc3 - representation of our controller
9328c2ecf20Sopenharmony_ci * @drd_work: workqueue used for role swapping
9338c2ecf20Sopenharmony_ci * @ep0_trb: trb which is used for the ctrl_req
9348c2ecf20Sopenharmony_ci * @bounce: address of bounce buffer
9358c2ecf20Sopenharmony_ci * @scratchbuf: address of scratch buffer
9368c2ecf20Sopenharmony_ci * @setup_buf: used while precessing STD USB requests
9378c2ecf20Sopenharmony_ci * @ep0_trb_addr: dma address of @ep0_trb
9388c2ecf20Sopenharmony_ci * @bounce_addr: dma address of @bounce
9398c2ecf20Sopenharmony_ci * @ep0_usb_req: dummy req used while handling STD USB requests
9408c2ecf20Sopenharmony_ci * @scratch_addr: dma address of scratchbuf
9418c2ecf20Sopenharmony_ci * @ep0_in_setup: one control transfer is completed and enter setup phase
9428c2ecf20Sopenharmony_ci * @lock: for synchronizing
9438c2ecf20Sopenharmony_ci * @mutex: for mode switching
9448c2ecf20Sopenharmony_ci * @dev: pointer to our struct device
9458c2ecf20Sopenharmony_ci * @sysdev: pointer to the DMA-capable device
9468c2ecf20Sopenharmony_ci * @xhci: pointer to our xHCI child
9478c2ecf20Sopenharmony_ci * @xhci_resources: struct resources for our @xhci child
9488c2ecf20Sopenharmony_ci * @ev_buf: struct dwc3_event_buffer pointer
9498c2ecf20Sopenharmony_ci * @eps: endpoint array
9508c2ecf20Sopenharmony_ci * @gadget: device side representation of the peripheral controller
9518c2ecf20Sopenharmony_ci * @gadget_driver: pointer to the gadget driver
9528c2ecf20Sopenharmony_ci * @clks: array of clocks
9538c2ecf20Sopenharmony_ci * @num_clks: number of clocks
9548c2ecf20Sopenharmony_ci * @reset: reset control
9558c2ecf20Sopenharmony_ci * @regs: base address for our registers
9568c2ecf20Sopenharmony_ci * @regs_size: address space size
9578c2ecf20Sopenharmony_ci * @fladj: frame length adjustment
9588c2ecf20Sopenharmony_ci * @irq_gadget: peripheral controller's IRQ number
9598c2ecf20Sopenharmony_ci * @otg_irq: IRQ number for OTG IRQs
9608c2ecf20Sopenharmony_ci * @current_otg_role: current role of operation while using the OTG block
9618c2ecf20Sopenharmony_ci * @desired_otg_role: desired role of operation while using the OTG block
9628c2ecf20Sopenharmony_ci * @otg_restart_host: flag that OTG controller needs to restart host
9638c2ecf20Sopenharmony_ci * @nr_scratch: number of scratch buffers
9648c2ecf20Sopenharmony_ci * @u1u2: only used on revisions <1.83a for workaround
9658c2ecf20Sopenharmony_ci * @maximum_speed: maximum speed requested (mainly for testing purposes)
9668c2ecf20Sopenharmony_ci * @ip: controller's ID
9678c2ecf20Sopenharmony_ci * @revision: controller's version of an IP
9688c2ecf20Sopenharmony_ci * @version_type: VERSIONTYPE register contents, a sub release of a revision
9698c2ecf20Sopenharmony_ci * @dr_mode: requested mode of operation
9708c2ecf20Sopenharmony_ci * @current_dr_role: current role of operation when in dual-role mode
9718c2ecf20Sopenharmony_ci * @desired_dr_role: desired role of operation when in dual-role mode
9728c2ecf20Sopenharmony_ci * @edev: extcon handle
9738c2ecf20Sopenharmony_ci * @edev_nb: extcon notifier
9748c2ecf20Sopenharmony_ci * @hsphy_mode: UTMI phy mode, one of following:
9758c2ecf20Sopenharmony_ci *		- USBPHY_INTERFACE_MODE_UTMI
9768c2ecf20Sopenharmony_ci *		- USBPHY_INTERFACE_MODE_UTMIW
9778c2ecf20Sopenharmony_ci * @role_sw: usb_role_switch handle
9788c2ecf20Sopenharmony_ci * @role_switch_default_mode: default operation mode of controller while
9798c2ecf20Sopenharmony_ci *			usb role is USB_ROLE_NONE.
9808c2ecf20Sopenharmony_ci * @usb2_phy: pointer to USB2 PHY
9818c2ecf20Sopenharmony_ci * @usb3_phy: pointer to USB3 PHY
9828c2ecf20Sopenharmony_ci * @usb2_generic_phy: pointer to USB2 PHY
9838c2ecf20Sopenharmony_ci * @usb3_generic_phy: pointer to USB3 PHY
9848c2ecf20Sopenharmony_ci * @phys_ready: flag to indicate that PHYs are ready
9858c2ecf20Sopenharmony_ci * @ulpi: pointer to ulpi interface
9868c2ecf20Sopenharmony_ci * @ulpi_ready: flag to indicate that ULPI is initialized
9878c2ecf20Sopenharmony_ci * @u2sel: parameter from Set SEL request.
9888c2ecf20Sopenharmony_ci * @u2pel: parameter from Set SEL request.
9898c2ecf20Sopenharmony_ci * @u1sel: parameter from Set SEL request.
9908c2ecf20Sopenharmony_ci * @u1pel: parameter from Set SEL request.
9918c2ecf20Sopenharmony_ci * @num_eps: number of endpoints
9928c2ecf20Sopenharmony_ci * @ep0_next_event: hold the next expected event
9938c2ecf20Sopenharmony_ci * @ep0state: state of endpoint zero
9948c2ecf20Sopenharmony_ci * @link_state: link state
9958c2ecf20Sopenharmony_ci * @speed: device speed (super, high, full, low)
9968c2ecf20Sopenharmony_ci * @hwparams: copy of hwparams registers
9978c2ecf20Sopenharmony_ci * @root: debugfs root folder pointer
9988c2ecf20Sopenharmony_ci * @regset: debugfs pointer to regdump file
9998c2ecf20Sopenharmony_ci * @dbg_lsp_select: current debug lsp mux register selection
10008c2ecf20Sopenharmony_ci * @test_mode: true when we're entering a USB test mode
10018c2ecf20Sopenharmony_ci * @test_mode_nr: test feature selector
10028c2ecf20Sopenharmony_ci * @lpm_nyet_threshold: LPM NYET response threshold
10038c2ecf20Sopenharmony_ci * @hird_threshold: HIRD threshold
10048c2ecf20Sopenharmony_ci * @rx_thr_num_pkt_prd: periodic ESS receive packet count
10058c2ecf20Sopenharmony_ci * @rx_max_burst_prd: max periodic ESS receive burst size
10068c2ecf20Sopenharmony_ci * @tx_thr_num_pkt_prd: periodic ESS transmit packet count
10078c2ecf20Sopenharmony_ci * @tx_max_burst_prd: max periodic ESS transmit burst size
10088c2ecf20Sopenharmony_ci * @hsphy_interface: "utmi" or "ulpi"
10098c2ecf20Sopenharmony_ci * @connected: true when we're connected to a host, false otherwise
10108c2ecf20Sopenharmony_ci * @softconnect: true when gadget connect is called, false when disconnect runs
10118c2ecf20Sopenharmony_ci * @delayed_status: true when gadget driver asks for delayed status
10128c2ecf20Sopenharmony_ci * @ep0_bounced: true when we used bounce buffer
10138c2ecf20Sopenharmony_ci * @ep0_expect_in: true when we expect a DATA IN transfer
10148c2ecf20Sopenharmony_ci * @has_hibernation: true when dwc3 was configured with Hibernation
10158c2ecf20Sopenharmony_ci * @sysdev_is_parent: true when dwc3 device has a parent driver
10168c2ecf20Sopenharmony_ci * @has_lpm_erratum: true when core was configured with LPM Erratum. Note that
10178c2ecf20Sopenharmony_ci *			there's now way for software to detect this in runtime.
10188c2ecf20Sopenharmony_ci * @is_utmi_l1_suspend: the core asserts output signal
10198c2ecf20Sopenharmony_ci *	0	- utmi_sleep_n
10208c2ecf20Sopenharmony_ci *	1	- utmi_l1_suspend_n
10218c2ecf20Sopenharmony_ci * @is_fpga: true when we are using the FPGA board
10228c2ecf20Sopenharmony_ci * @pending_events: true when we have pending IRQs to be handled
10238c2ecf20Sopenharmony_ci * @pullups_connected: true when Run/Stop bit is set
10248c2ecf20Sopenharmony_ci * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround
10258c2ecf20Sopenharmony_ci * @three_stage_setup: set if we perform a three phase setup
10268c2ecf20Sopenharmony_ci * @dis_start_transfer_quirk: set if start_transfer failure SW workaround is
10278c2ecf20Sopenharmony_ci *			not needed for DWC_usb31 version 1.70a-ea06 and below
10288c2ecf20Sopenharmony_ci * @usb3_lpm_capable: set if hadrware supports Link Power Management
10298c2ecf20Sopenharmony_ci * @usb2_lpm_disable: set to disable usb2 lpm for host
10308c2ecf20Sopenharmony_ci * @usb2_gadget_lpm_disable: set to disable usb2 lpm for gadget
10318c2ecf20Sopenharmony_ci * @disable_scramble_quirk: set if we enable the disable scramble quirk
10328c2ecf20Sopenharmony_ci * @u2exit_lfps_quirk: set if we enable u2exit lfps quirk
10338c2ecf20Sopenharmony_ci * @u2ss_inp3_quirk: set if we enable P3 OK for U2/SS Inactive quirk
10348c2ecf20Sopenharmony_ci * @req_p1p2p3_quirk: set if we enable request p1p2p3 quirk
10358c2ecf20Sopenharmony_ci * @del_p1p2p3_quirk: set if we enable delay p1p2p3 quirk
10368c2ecf20Sopenharmony_ci * @del_phy_power_chg_quirk: set if we enable delay phy power change quirk
10378c2ecf20Sopenharmony_ci * @lfps_filter_quirk: set if we enable LFPS filter quirk
10388c2ecf20Sopenharmony_ci * @rx_detect_poll_quirk: set if we enable rx_detect to polling lfps quirk
10398c2ecf20Sopenharmony_ci * @dis_u3_susphy_quirk: set if we disable usb3 suspend phy
10408c2ecf20Sopenharmony_ci * @dis_u2_susphy_quirk: set if we disable usb2 suspend phy
10418c2ecf20Sopenharmony_ci * @dis_enblslpm_quirk: set if we clear enblslpm in GUSB2PHYCFG,
10428c2ecf20Sopenharmony_ci *                      disabling the suspend signal to the PHY.
10438c2ecf20Sopenharmony_ci * @dis_u1_entry_quirk: set if link entering into U1 state needs to be disabled.
10448c2ecf20Sopenharmony_ci * @dis_u2_entry_quirk: set if link entering into U2 state needs to be disabled.
10458c2ecf20Sopenharmony_ci * @dis_rxdet_inp3_quirk: set if we disable Rx.Detect in P3
10468c2ecf20Sopenharmony_ci * @dis_u2_freeclk_exists_quirk : set if we clear u2_freeclk_exists
10478c2ecf20Sopenharmony_ci *			in GUSB2PHYCFG, specify that USB2 PHY doesn't
10488c2ecf20Sopenharmony_ci *			provide a free-running PHY clock.
10498c2ecf20Sopenharmony_ci * @dis_del_phy_power_chg_quirk: set if we disable delay phy power
10508c2ecf20Sopenharmony_ci *			change quirk.
10518c2ecf20Sopenharmony_ci * @dis_tx_ipgap_linecheck_quirk: set if we disable u2mac linestate
10528c2ecf20Sopenharmony_ci *			check during HS transmit.
10538c2ecf20Sopenharmony_ci * @parkmode_disable_ss_quirk: set if we need to disable all SuperSpeed
10548c2ecf20Sopenharmony_ci *			instances in park mode.
10558c2ecf20Sopenharmony_ci * @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk
10568c2ecf20Sopenharmony_ci * @tx_de_emphasis: Tx de-emphasis value
10578c2ecf20Sopenharmony_ci *	0	- -6dB de-emphasis
10588c2ecf20Sopenharmony_ci *	1	- -3.5dB de-emphasis
10598c2ecf20Sopenharmony_ci *	2	- No de-emphasis
10608c2ecf20Sopenharmony_ci *	3	- Reserved
10618c2ecf20Sopenharmony_ci * @dis_metastability_quirk: set to disable metastability quirk.
10628c2ecf20Sopenharmony_ci * @dis_split_quirk: set to disable split boundary.
10638c2ecf20Sopenharmony_ci * @imod_interval: set the interrupt moderation interval in 250ns
10648c2ecf20Sopenharmony_ci *			increments or 0 to disable.
10658c2ecf20Sopenharmony_ci */
10668c2ecf20Sopenharmony_cistruct dwc3 {
10678c2ecf20Sopenharmony_ci	struct work_struct	drd_work;
10688c2ecf20Sopenharmony_ci	struct dwc3_trb		*ep0_trb;
10698c2ecf20Sopenharmony_ci	void			*bounce;
10708c2ecf20Sopenharmony_ci	void			*scratchbuf;
10718c2ecf20Sopenharmony_ci	u8			*setup_buf;
10728c2ecf20Sopenharmony_ci	dma_addr_t		ep0_trb_addr;
10738c2ecf20Sopenharmony_ci	dma_addr_t		bounce_addr;
10748c2ecf20Sopenharmony_ci	dma_addr_t		scratch_addr;
10758c2ecf20Sopenharmony_ci	struct dwc3_request	ep0_usb_req;
10768c2ecf20Sopenharmony_ci	struct completion	ep0_in_setup;
10778c2ecf20Sopenharmony_ci
10788c2ecf20Sopenharmony_ci	/* device lock */
10798c2ecf20Sopenharmony_ci	spinlock_t		lock;
10808c2ecf20Sopenharmony_ci
10818c2ecf20Sopenharmony_ci	/* mode switching lock */
10828c2ecf20Sopenharmony_ci	struct mutex		mutex;
10838c2ecf20Sopenharmony_ci
10848c2ecf20Sopenharmony_ci	struct device		*dev;
10858c2ecf20Sopenharmony_ci	struct device		*sysdev;
10868c2ecf20Sopenharmony_ci
10878c2ecf20Sopenharmony_ci	struct platform_device	*xhci;
10888c2ecf20Sopenharmony_ci	struct resource		xhci_resources[DWC3_XHCI_RESOURCES_NUM];
10898c2ecf20Sopenharmony_ci
10908c2ecf20Sopenharmony_ci	struct dwc3_event_buffer *ev_buf;
10918c2ecf20Sopenharmony_ci	struct dwc3_ep		*eps[DWC3_ENDPOINTS_NUM];
10928c2ecf20Sopenharmony_ci
10938c2ecf20Sopenharmony_ci	struct usb_gadget	*gadget;
10948c2ecf20Sopenharmony_ci	struct usb_gadget_driver *gadget_driver;
10958c2ecf20Sopenharmony_ci
10968c2ecf20Sopenharmony_ci	struct clk_bulk_data	*clks;
10978c2ecf20Sopenharmony_ci	int			num_clks;
10988c2ecf20Sopenharmony_ci
10998c2ecf20Sopenharmony_ci	struct reset_control	*reset;
11008c2ecf20Sopenharmony_ci
11018c2ecf20Sopenharmony_ci	struct usb_phy		*usb2_phy;
11028c2ecf20Sopenharmony_ci	struct usb_phy		*usb3_phy;
11038c2ecf20Sopenharmony_ci
11048c2ecf20Sopenharmony_ci	struct phy		*usb2_generic_phy;
11058c2ecf20Sopenharmony_ci	struct phy		*usb3_generic_phy;
11068c2ecf20Sopenharmony_ci
11078c2ecf20Sopenharmony_ci	bool			phys_ready;
11088c2ecf20Sopenharmony_ci
11098c2ecf20Sopenharmony_ci	struct ulpi		*ulpi;
11108c2ecf20Sopenharmony_ci	bool			ulpi_ready;
11118c2ecf20Sopenharmony_ci
11128c2ecf20Sopenharmony_ci	void __iomem		*regs;
11138c2ecf20Sopenharmony_ci	size_t			regs_size;
11148c2ecf20Sopenharmony_ci
11158c2ecf20Sopenharmony_ci	enum usb_dr_mode	dr_mode;
11168c2ecf20Sopenharmony_ci	u32			current_dr_role;
11178c2ecf20Sopenharmony_ci	u32			desired_dr_role;
11188c2ecf20Sopenharmony_ci	struct extcon_dev	*edev;
11198c2ecf20Sopenharmony_ci	struct notifier_block	edev_nb;
11208c2ecf20Sopenharmony_ci	enum usb_phy_interface	hsphy_mode;
11218c2ecf20Sopenharmony_ci	struct usb_role_switch	*role_sw;
11228c2ecf20Sopenharmony_ci	enum usb_dr_mode	role_switch_default_mode;
11238c2ecf20Sopenharmony_ci
11248c2ecf20Sopenharmony_ci	u32			fladj;
11258c2ecf20Sopenharmony_ci	u32			irq_gadget;
11268c2ecf20Sopenharmony_ci	u32			otg_irq;
11278c2ecf20Sopenharmony_ci	u32			current_otg_role;
11288c2ecf20Sopenharmony_ci	u32			desired_otg_role;
11298c2ecf20Sopenharmony_ci	bool			otg_restart_host;
11308c2ecf20Sopenharmony_ci	u32			nr_scratch;
11318c2ecf20Sopenharmony_ci	u32			u1u2;
11328c2ecf20Sopenharmony_ci	u32			maximum_speed;
11338c2ecf20Sopenharmony_ci
11348c2ecf20Sopenharmony_ci	u32			ip;
11358c2ecf20Sopenharmony_ci
11368c2ecf20Sopenharmony_ci#define DWC3_IP			0x5533
11378c2ecf20Sopenharmony_ci#define DWC31_IP		0x3331
11388c2ecf20Sopenharmony_ci#define DWC32_IP		0x3332
11398c2ecf20Sopenharmony_ci
11408c2ecf20Sopenharmony_ci	u32			revision;
11418c2ecf20Sopenharmony_ci
11428c2ecf20Sopenharmony_ci#define DWC3_REVISION_ANY	0x0
11438c2ecf20Sopenharmony_ci#define DWC3_REVISION_173A	0x5533173a
11448c2ecf20Sopenharmony_ci#define DWC3_REVISION_175A	0x5533175a
11458c2ecf20Sopenharmony_ci#define DWC3_REVISION_180A	0x5533180a
11468c2ecf20Sopenharmony_ci#define DWC3_REVISION_183A	0x5533183a
11478c2ecf20Sopenharmony_ci#define DWC3_REVISION_185A	0x5533185a
11488c2ecf20Sopenharmony_ci#define DWC3_REVISION_187A	0x5533187a
11498c2ecf20Sopenharmony_ci#define DWC3_REVISION_188A	0x5533188a
11508c2ecf20Sopenharmony_ci#define DWC3_REVISION_190A	0x5533190a
11518c2ecf20Sopenharmony_ci#define DWC3_REVISION_194A	0x5533194a
11528c2ecf20Sopenharmony_ci#define DWC3_REVISION_200A	0x5533200a
11538c2ecf20Sopenharmony_ci#define DWC3_REVISION_202A	0x5533202a
11548c2ecf20Sopenharmony_ci#define DWC3_REVISION_210A	0x5533210a
11558c2ecf20Sopenharmony_ci#define DWC3_REVISION_220A	0x5533220a
11568c2ecf20Sopenharmony_ci#define DWC3_REVISION_230A	0x5533230a
11578c2ecf20Sopenharmony_ci#define DWC3_REVISION_240A	0x5533240a
11588c2ecf20Sopenharmony_ci#define DWC3_REVISION_250A	0x5533250a
11598c2ecf20Sopenharmony_ci#define DWC3_REVISION_260A	0x5533260a
11608c2ecf20Sopenharmony_ci#define DWC3_REVISION_270A	0x5533270a
11618c2ecf20Sopenharmony_ci#define DWC3_REVISION_280A	0x5533280a
11628c2ecf20Sopenharmony_ci#define DWC3_REVISION_290A	0x5533290a
11638c2ecf20Sopenharmony_ci#define DWC3_REVISION_300A	0x5533300a
11648c2ecf20Sopenharmony_ci#define DWC3_REVISION_310A	0x5533310a
11658c2ecf20Sopenharmony_ci#define DWC3_REVISION_330A	0x5533330a
11668c2ecf20Sopenharmony_ci
11678c2ecf20Sopenharmony_ci#define DWC31_REVISION_ANY	0x0
11688c2ecf20Sopenharmony_ci#define DWC31_REVISION_110A	0x3131302a
11698c2ecf20Sopenharmony_ci#define DWC31_REVISION_120A	0x3132302a
11708c2ecf20Sopenharmony_ci#define DWC31_REVISION_160A	0x3136302a
11718c2ecf20Sopenharmony_ci#define DWC31_REVISION_170A	0x3137302a
11728c2ecf20Sopenharmony_ci#define DWC31_REVISION_180A	0x3138302a
11738c2ecf20Sopenharmony_ci#define DWC31_REVISION_190A	0x3139302a
11748c2ecf20Sopenharmony_ci
11758c2ecf20Sopenharmony_ci#define DWC32_REVISION_ANY	0x0
11768c2ecf20Sopenharmony_ci#define DWC32_REVISION_100A	0x3130302a
11778c2ecf20Sopenharmony_ci
11788c2ecf20Sopenharmony_ci	u32			version_type;
11798c2ecf20Sopenharmony_ci
11808c2ecf20Sopenharmony_ci#define DWC31_VERSIONTYPE_ANY		0x0
11818c2ecf20Sopenharmony_ci#define DWC31_VERSIONTYPE_EA01		0x65613031
11828c2ecf20Sopenharmony_ci#define DWC31_VERSIONTYPE_EA02		0x65613032
11838c2ecf20Sopenharmony_ci#define DWC31_VERSIONTYPE_EA03		0x65613033
11848c2ecf20Sopenharmony_ci#define DWC31_VERSIONTYPE_EA04		0x65613034
11858c2ecf20Sopenharmony_ci#define DWC31_VERSIONTYPE_EA05		0x65613035
11868c2ecf20Sopenharmony_ci#define DWC31_VERSIONTYPE_EA06		0x65613036
11878c2ecf20Sopenharmony_ci
11888c2ecf20Sopenharmony_ci	enum dwc3_ep0_next	ep0_next_event;
11898c2ecf20Sopenharmony_ci	enum dwc3_ep0_state	ep0state;
11908c2ecf20Sopenharmony_ci	enum dwc3_link_state	link_state;
11918c2ecf20Sopenharmony_ci
11928c2ecf20Sopenharmony_ci	u16			u2sel;
11938c2ecf20Sopenharmony_ci	u16			u2pel;
11948c2ecf20Sopenharmony_ci	u8			u1sel;
11958c2ecf20Sopenharmony_ci	u8			u1pel;
11968c2ecf20Sopenharmony_ci
11978c2ecf20Sopenharmony_ci	u8			speed;
11988c2ecf20Sopenharmony_ci
11998c2ecf20Sopenharmony_ci	u8			num_eps;
12008c2ecf20Sopenharmony_ci
12018c2ecf20Sopenharmony_ci	struct dwc3_hwparams	hwparams;
12028c2ecf20Sopenharmony_ci	struct dentry		*root;
12038c2ecf20Sopenharmony_ci	struct debugfs_regset32	*regset;
12048c2ecf20Sopenharmony_ci
12058c2ecf20Sopenharmony_ci	u32			dbg_lsp_select;
12068c2ecf20Sopenharmony_ci
12078c2ecf20Sopenharmony_ci	u8			test_mode;
12088c2ecf20Sopenharmony_ci	u8			test_mode_nr;
12098c2ecf20Sopenharmony_ci	u8			lpm_nyet_threshold;
12108c2ecf20Sopenharmony_ci	u8			hird_threshold;
12118c2ecf20Sopenharmony_ci	u8			rx_thr_num_pkt_prd;
12128c2ecf20Sopenharmony_ci	u8			rx_max_burst_prd;
12138c2ecf20Sopenharmony_ci	u8			tx_thr_num_pkt_prd;
12148c2ecf20Sopenharmony_ci	u8			tx_max_burst_prd;
12158c2ecf20Sopenharmony_ci
12168c2ecf20Sopenharmony_ci	const char		*hsphy_interface;
12178c2ecf20Sopenharmony_ci
12188c2ecf20Sopenharmony_ci	unsigned		connected:1;
12198c2ecf20Sopenharmony_ci	unsigned		softconnect:1;
12208c2ecf20Sopenharmony_ci	unsigned		delayed_status:1;
12218c2ecf20Sopenharmony_ci	unsigned		ep0_bounced:1;
12228c2ecf20Sopenharmony_ci	unsigned		ep0_expect_in:1;
12238c2ecf20Sopenharmony_ci	unsigned		has_hibernation:1;
12248c2ecf20Sopenharmony_ci	unsigned		sysdev_is_parent:1;
12258c2ecf20Sopenharmony_ci	unsigned		has_lpm_erratum:1;
12268c2ecf20Sopenharmony_ci	unsigned		is_utmi_l1_suspend:1;
12278c2ecf20Sopenharmony_ci	unsigned		is_fpga:1;
12288c2ecf20Sopenharmony_ci	unsigned		pending_events:1;
12298c2ecf20Sopenharmony_ci	unsigned		pullups_connected:1;
12308c2ecf20Sopenharmony_ci	unsigned		setup_packet_pending:1;
12318c2ecf20Sopenharmony_ci	unsigned		three_stage_setup:1;
12328c2ecf20Sopenharmony_ci	unsigned		dis_start_transfer_quirk:1;
12338c2ecf20Sopenharmony_ci	unsigned		usb3_lpm_capable:1;
12348c2ecf20Sopenharmony_ci	unsigned		usb2_lpm_disable:1;
12358c2ecf20Sopenharmony_ci	unsigned		usb2_gadget_lpm_disable:1;
12368c2ecf20Sopenharmony_ci
12378c2ecf20Sopenharmony_ci	unsigned		disable_scramble_quirk:1;
12388c2ecf20Sopenharmony_ci	unsigned		u2exit_lfps_quirk:1;
12398c2ecf20Sopenharmony_ci	unsigned		u2ss_inp3_quirk:1;
12408c2ecf20Sopenharmony_ci	unsigned		req_p1p2p3_quirk:1;
12418c2ecf20Sopenharmony_ci	unsigned                del_p1p2p3_quirk:1;
12428c2ecf20Sopenharmony_ci	unsigned		del_phy_power_chg_quirk:1;
12438c2ecf20Sopenharmony_ci	unsigned		lfps_filter_quirk:1;
12448c2ecf20Sopenharmony_ci	unsigned		rx_detect_poll_quirk:1;
12458c2ecf20Sopenharmony_ci	unsigned		dis_u3_susphy_quirk:1;
12468c2ecf20Sopenharmony_ci	unsigned		dis_u2_susphy_quirk:1;
12478c2ecf20Sopenharmony_ci	unsigned		dis_enblslpm_quirk:1;
12488c2ecf20Sopenharmony_ci	unsigned		dis_u1_entry_quirk:1;
12498c2ecf20Sopenharmony_ci	unsigned		dis_u2_entry_quirk:1;
12508c2ecf20Sopenharmony_ci	unsigned		dis_rxdet_inp3_quirk:1;
12518c2ecf20Sopenharmony_ci	unsigned		dis_u2_freeclk_exists_quirk:1;
12528c2ecf20Sopenharmony_ci	unsigned		dis_del_phy_power_chg_quirk:1;
12538c2ecf20Sopenharmony_ci	unsigned		dis_tx_ipgap_linecheck_quirk:1;
12548c2ecf20Sopenharmony_ci	unsigned		parkmode_disable_ss_quirk:1;
12558c2ecf20Sopenharmony_ci
12568c2ecf20Sopenharmony_ci	unsigned		tx_de_emphasis_quirk:1;
12578c2ecf20Sopenharmony_ci	unsigned		tx_de_emphasis:2;
12588c2ecf20Sopenharmony_ci
12598c2ecf20Sopenharmony_ci	unsigned		dis_metastability_quirk:1;
12608c2ecf20Sopenharmony_ci
12618c2ecf20Sopenharmony_ci	unsigned		dis_split_quirk:1;
12628c2ecf20Sopenharmony_ci
12638c2ecf20Sopenharmony_ci	u16			imod_interval;
12648c2ecf20Sopenharmony_ci};
12658c2ecf20Sopenharmony_ci
12668c2ecf20Sopenharmony_ci#define INCRX_BURST_MODE 0
12678c2ecf20Sopenharmony_ci#define INCRX_UNDEF_LENGTH_BURST_MODE 1
12688c2ecf20Sopenharmony_ci
12698c2ecf20Sopenharmony_ci#define work_to_dwc(w)		(container_of((w), struct dwc3, drd_work))
12708c2ecf20Sopenharmony_ci
12718c2ecf20Sopenharmony_ci/* -------------------------------------------------------------------------- */
12728c2ecf20Sopenharmony_ci
12738c2ecf20Sopenharmony_cistruct dwc3_event_type {
12748c2ecf20Sopenharmony_ci	u32	is_devspec:1;
12758c2ecf20Sopenharmony_ci	u32	type:7;
12768c2ecf20Sopenharmony_ci	u32	reserved8_31:24;
12778c2ecf20Sopenharmony_ci} __packed;
12788c2ecf20Sopenharmony_ci
12798c2ecf20Sopenharmony_ci#define DWC3_DEPEVT_XFERCOMPLETE	0x01
12808c2ecf20Sopenharmony_ci#define DWC3_DEPEVT_XFERINPROGRESS	0x02
12818c2ecf20Sopenharmony_ci#define DWC3_DEPEVT_XFERNOTREADY	0x03
12828c2ecf20Sopenharmony_ci#define DWC3_DEPEVT_RXTXFIFOEVT		0x04
12838c2ecf20Sopenharmony_ci#define DWC3_DEPEVT_STREAMEVT		0x06
12848c2ecf20Sopenharmony_ci#define DWC3_DEPEVT_EPCMDCMPLT		0x07
12858c2ecf20Sopenharmony_ci
12868c2ecf20Sopenharmony_ci/**
12878c2ecf20Sopenharmony_ci * struct dwc3_event_depevt - Device Endpoint Events
12888c2ecf20Sopenharmony_ci * @one_bit: indicates this is an endpoint event (not used)
12898c2ecf20Sopenharmony_ci * @endpoint_number: number of the endpoint
12908c2ecf20Sopenharmony_ci * @endpoint_event: The event we have:
12918c2ecf20Sopenharmony_ci *	0x00	- Reserved
12928c2ecf20Sopenharmony_ci *	0x01	- XferComplete
12938c2ecf20Sopenharmony_ci *	0x02	- XferInProgress
12948c2ecf20Sopenharmony_ci *	0x03	- XferNotReady
12958c2ecf20Sopenharmony_ci *	0x04	- RxTxFifoEvt (IN->Underrun, OUT->Overrun)
12968c2ecf20Sopenharmony_ci *	0x05	- Reserved
12978c2ecf20Sopenharmony_ci *	0x06	- StreamEvt
12988c2ecf20Sopenharmony_ci *	0x07	- EPCmdCmplt
12998c2ecf20Sopenharmony_ci * @reserved11_10: Reserved, don't use.
13008c2ecf20Sopenharmony_ci * @status: Indicates the status of the event. Refer to databook for
13018c2ecf20Sopenharmony_ci *	more information.
13028c2ecf20Sopenharmony_ci * @parameters: Parameters of the current event. Refer to databook for
13038c2ecf20Sopenharmony_ci *	more information.
13048c2ecf20Sopenharmony_ci */
13058c2ecf20Sopenharmony_cistruct dwc3_event_depevt {
13068c2ecf20Sopenharmony_ci	u32	one_bit:1;
13078c2ecf20Sopenharmony_ci	u32	endpoint_number:5;
13088c2ecf20Sopenharmony_ci	u32	endpoint_event:4;
13098c2ecf20Sopenharmony_ci	u32	reserved11_10:2;
13108c2ecf20Sopenharmony_ci	u32	status:4;
13118c2ecf20Sopenharmony_ci
13128c2ecf20Sopenharmony_ci/* Within XferNotReady */
13138c2ecf20Sopenharmony_ci#define DEPEVT_STATUS_TRANSFER_ACTIVE	BIT(3)
13148c2ecf20Sopenharmony_ci
13158c2ecf20Sopenharmony_ci/* Within XferComplete or XferInProgress */
13168c2ecf20Sopenharmony_ci#define DEPEVT_STATUS_BUSERR	BIT(0)
13178c2ecf20Sopenharmony_ci#define DEPEVT_STATUS_SHORT	BIT(1)
13188c2ecf20Sopenharmony_ci#define DEPEVT_STATUS_IOC	BIT(2)
13198c2ecf20Sopenharmony_ci#define DEPEVT_STATUS_LST	BIT(3) /* XferComplete */
13208c2ecf20Sopenharmony_ci#define DEPEVT_STATUS_MISSED_ISOC BIT(3) /* XferInProgress */
13218c2ecf20Sopenharmony_ci
13228c2ecf20Sopenharmony_ci/* Stream event only */
13238c2ecf20Sopenharmony_ci#define DEPEVT_STREAMEVT_FOUND		1
13248c2ecf20Sopenharmony_ci#define DEPEVT_STREAMEVT_NOTFOUND	2
13258c2ecf20Sopenharmony_ci
13268c2ecf20Sopenharmony_ci/* Stream event parameter */
13278c2ecf20Sopenharmony_ci#define DEPEVT_STREAM_PRIME		0xfffe
13288c2ecf20Sopenharmony_ci#define DEPEVT_STREAM_NOSTREAM		0x0
13298c2ecf20Sopenharmony_ci
13308c2ecf20Sopenharmony_ci/* Control-only Status */
13318c2ecf20Sopenharmony_ci#define DEPEVT_STATUS_CONTROL_DATA	1
13328c2ecf20Sopenharmony_ci#define DEPEVT_STATUS_CONTROL_STATUS	2
13338c2ecf20Sopenharmony_ci#define DEPEVT_STATUS_CONTROL_PHASE(n)	((n) & 3)
13348c2ecf20Sopenharmony_ci
13358c2ecf20Sopenharmony_ci/* In response to Start Transfer */
13368c2ecf20Sopenharmony_ci#define DEPEVT_TRANSFER_NO_RESOURCE	1
13378c2ecf20Sopenharmony_ci#define DEPEVT_TRANSFER_BUS_EXPIRY	2
13388c2ecf20Sopenharmony_ci
13398c2ecf20Sopenharmony_ci	u32	parameters:16;
13408c2ecf20Sopenharmony_ci
13418c2ecf20Sopenharmony_ci/* For Command Complete Events */
13428c2ecf20Sopenharmony_ci#define DEPEVT_PARAMETER_CMD(n)	(((n) & (0xf << 8)) >> 8)
13438c2ecf20Sopenharmony_ci} __packed;
13448c2ecf20Sopenharmony_ci
13458c2ecf20Sopenharmony_ci/**
13468c2ecf20Sopenharmony_ci * struct dwc3_event_devt - Device Events
13478c2ecf20Sopenharmony_ci * @one_bit: indicates this is a non-endpoint event (not used)
13488c2ecf20Sopenharmony_ci * @device_event: indicates it's a device event. Should read as 0x00
13498c2ecf20Sopenharmony_ci * @type: indicates the type of device event.
13508c2ecf20Sopenharmony_ci *	0	- DisconnEvt
13518c2ecf20Sopenharmony_ci *	1	- USBRst
13528c2ecf20Sopenharmony_ci *	2	- ConnectDone
13538c2ecf20Sopenharmony_ci *	3	- ULStChng
13548c2ecf20Sopenharmony_ci *	4	- WkUpEvt
13558c2ecf20Sopenharmony_ci *	5	- Reserved
13568c2ecf20Sopenharmony_ci *	6	- EOPF
13578c2ecf20Sopenharmony_ci *	7	- SOF
13588c2ecf20Sopenharmony_ci *	8	- Reserved
13598c2ecf20Sopenharmony_ci *	9	- ErrticErr
13608c2ecf20Sopenharmony_ci *	10	- CmdCmplt
13618c2ecf20Sopenharmony_ci *	11	- EvntOverflow
13628c2ecf20Sopenharmony_ci *	12	- VndrDevTstRcved
13638c2ecf20Sopenharmony_ci * @reserved15_12: Reserved, not used
13648c2ecf20Sopenharmony_ci * @event_info: Information about this event
13658c2ecf20Sopenharmony_ci * @reserved31_25: Reserved, not used
13668c2ecf20Sopenharmony_ci */
13678c2ecf20Sopenharmony_cistruct dwc3_event_devt {
13688c2ecf20Sopenharmony_ci	u32	one_bit:1;
13698c2ecf20Sopenharmony_ci	u32	device_event:7;
13708c2ecf20Sopenharmony_ci	u32	type:4;
13718c2ecf20Sopenharmony_ci	u32	reserved15_12:4;
13728c2ecf20Sopenharmony_ci	u32	event_info:9;
13738c2ecf20Sopenharmony_ci	u32	reserved31_25:7;
13748c2ecf20Sopenharmony_ci} __packed;
13758c2ecf20Sopenharmony_ci
13768c2ecf20Sopenharmony_ci/**
13778c2ecf20Sopenharmony_ci * struct dwc3_event_gevt - Other Core Events
13788c2ecf20Sopenharmony_ci * @one_bit: indicates this is a non-endpoint event (not used)
13798c2ecf20Sopenharmony_ci * @device_event: indicates it's (0x03) Carkit or (0x04) I2C event.
13808c2ecf20Sopenharmony_ci * @phy_port_number: self-explanatory
13818c2ecf20Sopenharmony_ci * @reserved31_12: Reserved, not used.
13828c2ecf20Sopenharmony_ci */
13838c2ecf20Sopenharmony_cistruct dwc3_event_gevt {
13848c2ecf20Sopenharmony_ci	u32	one_bit:1;
13858c2ecf20Sopenharmony_ci	u32	device_event:7;
13868c2ecf20Sopenharmony_ci	u32	phy_port_number:4;
13878c2ecf20Sopenharmony_ci	u32	reserved31_12:20;
13888c2ecf20Sopenharmony_ci} __packed;
13898c2ecf20Sopenharmony_ci
13908c2ecf20Sopenharmony_ci/**
13918c2ecf20Sopenharmony_ci * union dwc3_event - representation of Event Buffer contents
13928c2ecf20Sopenharmony_ci * @raw: raw 32-bit event
13938c2ecf20Sopenharmony_ci * @type: the type of the event
13948c2ecf20Sopenharmony_ci * @depevt: Device Endpoint Event
13958c2ecf20Sopenharmony_ci * @devt: Device Event
13968c2ecf20Sopenharmony_ci * @gevt: Global Event
13978c2ecf20Sopenharmony_ci */
13988c2ecf20Sopenharmony_ciunion dwc3_event {
13998c2ecf20Sopenharmony_ci	u32				raw;
14008c2ecf20Sopenharmony_ci	struct dwc3_event_type		type;
14018c2ecf20Sopenharmony_ci	struct dwc3_event_depevt	depevt;
14028c2ecf20Sopenharmony_ci	struct dwc3_event_devt		devt;
14038c2ecf20Sopenharmony_ci	struct dwc3_event_gevt		gevt;
14048c2ecf20Sopenharmony_ci};
14058c2ecf20Sopenharmony_ci
14068c2ecf20Sopenharmony_ci/**
14078c2ecf20Sopenharmony_ci * struct dwc3_gadget_ep_cmd_params - representation of endpoint command
14088c2ecf20Sopenharmony_ci * parameters
14098c2ecf20Sopenharmony_ci * @param2: third parameter
14108c2ecf20Sopenharmony_ci * @param1: second parameter
14118c2ecf20Sopenharmony_ci * @param0: first parameter
14128c2ecf20Sopenharmony_ci */
14138c2ecf20Sopenharmony_cistruct dwc3_gadget_ep_cmd_params {
14148c2ecf20Sopenharmony_ci	u32	param2;
14158c2ecf20Sopenharmony_ci	u32	param1;
14168c2ecf20Sopenharmony_ci	u32	param0;
14178c2ecf20Sopenharmony_ci};
14188c2ecf20Sopenharmony_ci
14198c2ecf20Sopenharmony_ci/*
14208c2ecf20Sopenharmony_ci * DWC3 Features to be used as Driver Data
14218c2ecf20Sopenharmony_ci */
14228c2ecf20Sopenharmony_ci
14238c2ecf20Sopenharmony_ci#define DWC3_HAS_PERIPHERAL		BIT(0)
14248c2ecf20Sopenharmony_ci#define DWC3_HAS_XHCI			BIT(1)
14258c2ecf20Sopenharmony_ci#define DWC3_HAS_OTG			BIT(3)
14268c2ecf20Sopenharmony_ci
14278c2ecf20Sopenharmony_ci/* prototypes */
14288c2ecf20Sopenharmony_civoid dwc3_set_prtcap(struct dwc3 *dwc, u32 mode);
14298c2ecf20Sopenharmony_civoid dwc3_set_mode(struct dwc3 *dwc, u32 mode);
14308c2ecf20Sopenharmony_ciu32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type);
14318c2ecf20Sopenharmony_ci
14328c2ecf20Sopenharmony_ci#define DWC3_IP_IS(_ip)							\
14338c2ecf20Sopenharmony_ci	(dwc->ip == _ip##_IP)
14348c2ecf20Sopenharmony_ci
14358c2ecf20Sopenharmony_ci#define DWC3_VER_IS(_ip, _ver)						\
14368c2ecf20Sopenharmony_ci	(DWC3_IP_IS(_ip) && dwc->revision == _ip##_REVISION_##_ver)
14378c2ecf20Sopenharmony_ci
14388c2ecf20Sopenharmony_ci#define DWC3_VER_IS_PRIOR(_ip, _ver)					\
14398c2ecf20Sopenharmony_ci	(DWC3_IP_IS(_ip) && dwc->revision < _ip##_REVISION_##_ver)
14408c2ecf20Sopenharmony_ci
14418c2ecf20Sopenharmony_ci#define DWC3_VER_IS_WITHIN(_ip, _from, _to)				\
14428c2ecf20Sopenharmony_ci	(DWC3_IP_IS(_ip) &&						\
14438c2ecf20Sopenharmony_ci	 dwc->revision >= _ip##_REVISION_##_from &&			\
14448c2ecf20Sopenharmony_ci	 (!(_ip##_REVISION_##_to) ||					\
14458c2ecf20Sopenharmony_ci	  dwc->revision <= _ip##_REVISION_##_to))
14468c2ecf20Sopenharmony_ci
14478c2ecf20Sopenharmony_ci#define DWC3_VER_TYPE_IS_WITHIN(_ip, _ver, _from, _to)			\
14488c2ecf20Sopenharmony_ci	(DWC3_VER_IS(_ip, _ver) &&					\
14498c2ecf20Sopenharmony_ci	 dwc->version_type >= _ip##_VERSIONTYPE_##_from &&		\
14508c2ecf20Sopenharmony_ci	 (!(_ip##_VERSIONTYPE_##_to) ||					\
14518c2ecf20Sopenharmony_ci	  dwc->version_type <= _ip##_VERSIONTYPE_##_to))
14528c2ecf20Sopenharmony_ci
14538c2ecf20Sopenharmony_cibool dwc3_has_imod(struct dwc3 *dwc);
14548c2ecf20Sopenharmony_ci
14558c2ecf20Sopenharmony_ciint dwc3_event_buffers_setup(struct dwc3 *dwc);
14568c2ecf20Sopenharmony_civoid dwc3_event_buffers_cleanup(struct dwc3 *dwc);
14578c2ecf20Sopenharmony_ci
14588c2ecf20Sopenharmony_ciint dwc3_core_soft_reset(struct dwc3 *dwc);
14598c2ecf20Sopenharmony_ci
14608c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
14618c2ecf20Sopenharmony_ciint dwc3_host_init(struct dwc3 *dwc);
14628c2ecf20Sopenharmony_civoid dwc3_host_exit(struct dwc3 *dwc);
14638c2ecf20Sopenharmony_ci#else
14648c2ecf20Sopenharmony_cistatic inline int dwc3_host_init(struct dwc3 *dwc)
14658c2ecf20Sopenharmony_ci{ return 0; }
14668c2ecf20Sopenharmony_cistatic inline void dwc3_host_exit(struct dwc3 *dwc)
14678c2ecf20Sopenharmony_ci{ }
14688c2ecf20Sopenharmony_ci#endif
14698c2ecf20Sopenharmony_ci
14708c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_USB_DWC3_GADGET) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
14718c2ecf20Sopenharmony_ciint dwc3_gadget_init(struct dwc3 *dwc);
14728c2ecf20Sopenharmony_civoid dwc3_gadget_exit(struct dwc3 *dwc);
14738c2ecf20Sopenharmony_ciint dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode);
14748c2ecf20Sopenharmony_ciint dwc3_gadget_get_link_state(struct dwc3 *dwc);
14758c2ecf20Sopenharmony_ciint dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state);
14768c2ecf20Sopenharmony_ciint dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned int cmd,
14778c2ecf20Sopenharmony_ci		struct dwc3_gadget_ep_cmd_params *params);
14788c2ecf20Sopenharmony_ciint dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned int cmd,
14798c2ecf20Sopenharmony_ci		u32 param);
14808c2ecf20Sopenharmony_ci#else
14818c2ecf20Sopenharmony_cistatic inline int dwc3_gadget_init(struct dwc3 *dwc)
14828c2ecf20Sopenharmony_ci{ return 0; }
14838c2ecf20Sopenharmony_cistatic inline void dwc3_gadget_exit(struct dwc3 *dwc)
14848c2ecf20Sopenharmony_ci{ }
14858c2ecf20Sopenharmony_cistatic inline int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode)
14868c2ecf20Sopenharmony_ci{ return 0; }
14878c2ecf20Sopenharmony_cistatic inline int dwc3_gadget_get_link_state(struct dwc3 *dwc)
14888c2ecf20Sopenharmony_ci{ return 0; }
14898c2ecf20Sopenharmony_cistatic inline int dwc3_gadget_set_link_state(struct dwc3 *dwc,
14908c2ecf20Sopenharmony_ci		enum dwc3_link_state state)
14918c2ecf20Sopenharmony_ci{ return 0; }
14928c2ecf20Sopenharmony_ci
14938c2ecf20Sopenharmony_cistatic inline int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned int cmd,
14948c2ecf20Sopenharmony_ci		struct dwc3_gadget_ep_cmd_params *params)
14958c2ecf20Sopenharmony_ci{ return 0; }
14968c2ecf20Sopenharmony_cistatic inline int dwc3_send_gadget_generic_command(struct dwc3 *dwc,
14978c2ecf20Sopenharmony_ci		int cmd, u32 param)
14988c2ecf20Sopenharmony_ci{ return 0; }
14998c2ecf20Sopenharmony_ci#endif
15008c2ecf20Sopenharmony_ci
15018c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
15028c2ecf20Sopenharmony_ciint dwc3_drd_init(struct dwc3 *dwc);
15038c2ecf20Sopenharmony_civoid dwc3_drd_exit(struct dwc3 *dwc);
15048c2ecf20Sopenharmony_civoid dwc3_otg_init(struct dwc3 *dwc);
15058c2ecf20Sopenharmony_civoid dwc3_otg_exit(struct dwc3 *dwc);
15068c2ecf20Sopenharmony_civoid dwc3_otg_update(struct dwc3 *dwc, bool ignore_idstatus);
15078c2ecf20Sopenharmony_civoid dwc3_otg_host_init(struct dwc3 *dwc);
15088c2ecf20Sopenharmony_ci#else
15098c2ecf20Sopenharmony_cistatic inline int dwc3_drd_init(struct dwc3 *dwc)
15108c2ecf20Sopenharmony_ci{ return 0; }
15118c2ecf20Sopenharmony_cistatic inline void dwc3_drd_exit(struct dwc3 *dwc)
15128c2ecf20Sopenharmony_ci{ }
15138c2ecf20Sopenharmony_cistatic inline void dwc3_otg_init(struct dwc3 *dwc)
15148c2ecf20Sopenharmony_ci{ }
15158c2ecf20Sopenharmony_cistatic inline void dwc3_otg_exit(struct dwc3 *dwc)
15168c2ecf20Sopenharmony_ci{ }
15178c2ecf20Sopenharmony_cistatic inline void dwc3_otg_update(struct dwc3 *dwc, bool ignore_idstatus)
15188c2ecf20Sopenharmony_ci{ }
15198c2ecf20Sopenharmony_cistatic inline void dwc3_otg_host_init(struct dwc3 *dwc)
15208c2ecf20Sopenharmony_ci{ }
15218c2ecf20Sopenharmony_ci#endif
15228c2ecf20Sopenharmony_ci
15238c2ecf20Sopenharmony_ci/* power management interface */
15248c2ecf20Sopenharmony_ci#if !IS_ENABLED(CONFIG_USB_DWC3_HOST)
15258c2ecf20Sopenharmony_ciint dwc3_gadget_suspend(struct dwc3 *dwc);
15268c2ecf20Sopenharmony_ciint dwc3_gadget_resume(struct dwc3 *dwc);
15278c2ecf20Sopenharmony_civoid dwc3_gadget_process_pending_events(struct dwc3 *dwc);
15288c2ecf20Sopenharmony_ci#else
15298c2ecf20Sopenharmony_cistatic inline int dwc3_gadget_suspend(struct dwc3 *dwc)
15308c2ecf20Sopenharmony_ci{
15318c2ecf20Sopenharmony_ci	return 0;
15328c2ecf20Sopenharmony_ci}
15338c2ecf20Sopenharmony_ci
15348c2ecf20Sopenharmony_cistatic inline int dwc3_gadget_resume(struct dwc3 *dwc)
15358c2ecf20Sopenharmony_ci{
15368c2ecf20Sopenharmony_ci	return 0;
15378c2ecf20Sopenharmony_ci}
15388c2ecf20Sopenharmony_ci
15398c2ecf20Sopenharmony_cistatic inline void dwc3_gadget_process_pending_events(struct dwc3 *dwc)
15408c2ecf20Sopenharmony_ci{
15418c2ecf20Sopenharmony_ci}
15428c2ecf20Sopenharmony_ci#endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */
15438c2ecf20Sopenharmony_ci
15448c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_USB_DWC3_ULPI)
15458c2ecf20Sopenharmony_ciint dwc3_ulpi_init(struct dwc3 *dwc);
15468c2ecf20Sopenharmony_civoid dwc3_ulpi_exit(struct dwc3 *dwc);
15478c2ecf20Sopenharmony_ci#else
15488c2ecf20Sopenharmony_cistatic inline int dwc3_ulpi_init(struct dwc3 *dwc)
15498c2ecf20Sopenharmony_ci{ return 0; }
15508c2ecf20Sopenharmony_cistatic inline void dwc3_ulpi_exit(struct dwc3 *dwc)
15518c2ecf20Sopenharmony_ci{ }
15528c2ecf20Sopenharmony_ci#endif
15538c2ecf20Sopenharmony_ci
15548c2ecf20Sopenharmony_ci#endif /* __DRIVERS_USB_DWC3_CORE_H */
1555