blob: c9c683e28a1e7bfa11fd5f974fdf968d113d572b [file] [log] [blame]
Felipe Balbi72246da2011-08-19 18:10:58 +03001/**
2 * core.h - DesignWare USB3 DRD Core Header
3 *
4 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
Felipe Balbi72246da2011-08-19 18:10:58 +03005 *
6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The names of the above-listed copyright holders may not be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
21 *
22 * ALTERNATIVELY, this software may be distributed under the terms of the
23 * GNU General Public License ("GPL") version 2, as published by the Free
24 * Software Foundation.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
27 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#ifndef __DRIVERS_USB_DWC3_CORE_H
40#define __DRIVERS_USB_DWC3_CORE_H
41
42#include <linux/device.h>
43#include <linux/spinlock.h>
Felipe Balbid07e8812011-10-12 14:08:26 +030044#include <linux/ioport.h>
Felipe Balbi72246da2011-08-19 18:10:58 +030045#include <linux/list.h>
46#include <linux/dma-mapping.h>
47#include <linux/mm.h>
48#include <linux/debugfs.h>
49
50#include <linux/usb/ch9.h>
51#include <linux/usb/gadget.h>
52
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +020053#include "dwc3_otg.h"
54
Felipe Balbi72246da2011-08-19 18:10:58 +030055/* Global constants */
Felipe Balbib0791fb2012-05-04 12:58:14 +030056#define DWC3_EP0_BOUNCE_SIZE 512
Felipe Balbi72246da2011-08-19 18:10:58 +030057#define DWC3_ENDPOINTS_NUM 32
Ido Shayevitz4a187332012-04-23 14:53:37 +020058#define DWC3_XHCI_RESOURCES_NUM 2
Felipe Balbi72246da2011-08-19 18:10:58 +030059
Pavankumar Kondetid393e172012-06-12 16:07:29 +053060#define DWC3_EVENT_BUFFERS_SIZE (2 * PAGE_SIZE)
Felipe Balbi72246da2011-08-19 18:10:58 +030061#define DWC3_EVENT_TYPE_MASK 0xfe
62
63#define DWC3_EVENT_TYPE_DEV 0
64#define DWC3_EVENT_TYPE_CARKIT 3
65#define DWC3_EVENT_TYPE_I2C 4
66
67#define DWC3_DEVICE_EVENT_DISCONNECT 0
68#define DWC3_DEVICE_EVENT_RESET 1
69#define DWC3_DEVICE_EVENT_CONNECT_DONE 2
70#define DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE 3
71#define DWC3_DEVICE_EVENT_WAKEUP 4
Paul Zimmerman394c74f2012-02-15 18:56:58 -080072#define DWC3_DEVICE_EVENT_HIBER_REQ 5
Felipe Balbi72246da2011-08-19 18:10:58 +030073#define DWC3_DEVICE_EVENT_EOPF 6
74#define DWC3_DEVICE_EVENT_SOF 7
75#define DWC3_DEVICE_EVENT_ERRATIC_ERROR 9
76#define DWC3_DEVICE_EVENT_CMD_CMPL 10
77#define DWC3_DEVICE_EVENT_OVERFLOW 11
Pavankumar Kondeti33fe6f12012-06-12 16:21:46 +053078#define DWC3_DEVICE_EVENT_VENDOR_DEV_TEST_LMP 12
Felipe Balbi72246da2011-08-19 18:10:58 +030079
80#define DWC3_GEVNTCOUNT_MASK 0xfffc
81#define DWC3_GSNPSID_MASK 0xffff0000
82#define DWC3_GSNPSREV_MASK 0xffff
83
Ido Shayevitz4a187332012-04-23 14:53:37 +020084/* DWC3 registers memory space boundries */
85#define DWC3_XHCI_REGS_START 0x0
86#define DWC3_XHCI_REGS_END 0x7fff
87#define DWC3_GLOBALS_REGS_START 0xc100
88#define DWC3_GLOBALS_REGS_END 0xc6ff
89#define DWC3_DEVICE_REGS_START 0xc700
90#define DWC3_DEVICE_REGS_END 0xcbff
91#define DWC3_OTG_REGS_START 0xcc00
92#define DWC3_OTG_REGS_END 0xccff
93
Felipe Balbi72246da2011-08-19 18:10:58 +030094/* Global Registers */
95#define DWC3_GSBUSCFG0 0xc100
96#define DWC3_GSBUSCFG1 0xc104
97#define DWC3_GTXTHRCFG 0xc108
98#define DWC3_GRXTHRCFG 0xc10c
99#define DWC3_GCTL 0xc110
100#define DWC3_GEVTEN 0xc114
101#define DWC3_GSTS 0xc118
102#define DWC3_GSNPSID 0xc120
103#define DWC3_GGPIO 0xc124
104#define DWC3_GUID 0xc128
105#define DWC3_GUCTL 0xc12c
106#define DWC3_GBUSERRADDR0 0xc130
107#define DWC3_GBUSERRADDR1 0xc134
108#define DWC3_GPRTBIMAP0 0xc138
109#define DWC3_GPRTBIMAP1 0xc13c
110#define DWC3_GHWPARAMS0 0xc140
111#define DWC3_GHWPARAMS1 0xc144
112#define DWC3_GHWPARAMS2 0xc148
113#define DWC3_GHWPARAMS3 0xc14c
114#define DWC3_GHWPARAMS4 0xc150
115#define DWC3_GHWPARAMS5 0xc154
116#define DWC3_GHWPARAMS6 0xc158
117#define DWC3_GHWPARAMS7 0xc15c
118#define DWC3_GDBGFIFOSPACE 0xc160
119#define DWC3_GDBGLTSSM 0xc164
120#define DWC3_GPRTBIMAP_HS0 0xc180
121#define DWC3_GPRTBIMAP_HS1 0xc184
122#define DWC3_GPRTBIMAP_FS0 0xc188
123#define DWC3_GPRTBIMAP_FS1 0xc18c
124
125#define DWC3_GUSB2PHYCFG(n) (0xc200 + (n * 0x04))
126#define DWC3_GUSB2I2CCTL(n) (0xc240 + (n * 0x04))
127
128#define DWC3_GUSB2PHYACC(n) (0xc280 + (n * 0x04))
129
130#define DWC3_GUSB3PIPECTL(n) (0xc2c0 + (n * 0x04))
131
132#define DWC3_GTXFIFOSIZ(n) (0xc300 + (n * 0x04))
133#define DWC3_GRXFIFOSIZ(n) (0xc380 + (n * 0x04))
134
135#define DWC3_GEVNTADRLO(n) (0xc400 + (n * 0x10))
136#define DWC3_GEVNTADRHI(n) (0xc404 + (n * 0x10))
137#define DWC3_GEVNTSIZ(n) (0xc408 + (n * 0x10))
138#define DWC3_GEVNTCOUNT(n) (0xc40c + (n * 0x10))
139
140#define DWC3_GHWPARAMS8 0xc600
Jack Pham1b309192014-04-16 11:54:55 +0530141#define DWC3_GFLADJ 0xc630
Felipe Balbi72246da2011-08-19 18:10:58 +0300142
143/* Device Registers */
144#define DWC3_DCFG 0xc700
145#define DWC3_DCTL 0xc704
146#define DWC3_DEVTEN 0xc708
147#define DWC3_DSTS 0xc70c
148#define DWC3_DGCMDPAR 0xc710
149#define DWC3_DGCMD 0xc714
150#define DWC3_DALEPENA 0xc720
151#define DWC3_DEPCMDPAR2(n) (0xc800 + (n * 0x10))
152#define DWC3_DEPCMDPAR1(n) (0xc804 + (n * 0x10))
153#define DWC3_DEPCMDPAR0(n) (0xc808 + (n * 0x10))
154#define DWC3_DEPCMD(n) (0xc80c + (n * 0x10))
155
156/* OTG Registers */
157#define DWC3_OCFG 0xcc00
158#define DWC3_OCTL 0xcc04
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200159#define DWC3_OEVT 0xcc08
160#define DWC3_OEVTEN 0xcc0c
161#define DWC3_OSTS 0xcc10
Felipe Balbi72246da2011-08-19 18:10:58 +0300162
163/* Bit fields */
164
165/* Global Configuration Register */
Paul Zimmerman1d046792012-02-15 18:56:56 -0800166#define DWC3_GCTL_PWRDNSCALE(n) ((n) << 19)
Vijayavardhan Vennapusaba79f6b2013-07-30 13:39:52 +0530167#define DWC3_GCTL_PWRDNSCALEMASK (0xFFF80000)
Felipe Balbif4aadbe2011-09-08 17:39:59 +0300168#define DWC3_GCTL_U2RSTECN (1 << 16)
Vijayavardhan Vennapusaba79f6b2013-07-30 13:39:52 +0530169#define DWC3_GCTL_SOFITPSYNC (1 << 10)
170#define DWC3_GCTL_U2EXIT_LFPS (1 << 2)
Paul Zimmerman1d046792012-02-15 18:56:56 -0800171#define DWC3_GCTL_RAMCLKSEL(x) (((x) & DWC3_GCTL_CLK_MASK) << 6)
Felipe Balbi72246da2011-08-19 18:10:58 +0300172#define DWC3_GCTL_CLK_BUS (0)
173#define DWC3_GCTL_CLK_PIPE (1)
174#define DWC3_GCTL_CLK_PIPEHALF (2)
175#define DWC3_GCTL_CLK_MASK (3)
176
Felipe Balbi0b9fe322011-10-17 08:50:39 +0300177#define DWC3_GCTL_PRTCAP(n) (((n) & (3 << 12)) >> 12)
Paul Zimmerman1d046792012-02-15 18:56:56 -0800178#define DWC3_GCTL_PRTCAPDIR(n) ((n) << 12)
Felipe Balbi72246da2011-08-19 18:10:58 +0300179#define DWC3_GCTL_PRTCAP_HOST 1
180#define DWC3_GCTL_PRTCAP_DEVICE 2
181#define DWC3_GCTL_PRTCAP_OTG 3
182
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800183#define DWC3_GCTL_CORESOFTRESET (1 << 11)
184#define DWC3_GCTL_SCALEDOWN(n) ((n) << 4)
185#define DWC3_GCTL_SCALEDOWN_MASK DWC3_GCTL_SCALEDOWN(3)
186#define DWC3_GCTL_DISSCRAMBLE (1 << 3)
187#define DWC3_GCTL_GBLHIBERNATIONEN (1 << 1)
188#define DWC3_GCTL_DSBLCLKGTNG (1 << 0)
Felipe Balbi72246da2011-08-19 18:10:58 +0300189
Pavankumar Kondetic6e15aa2012-07-16 11:37:15 +0530190/* Global User Control Register */
191#define DWC3_GUCTL_REFCLKPER (0x3FF << 22)
192
Felipe Balbi72246da2011-08-19 18:10:58 +0300193/* Global USB2 PHY Configuration Register */
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800194#define DWC3_GUSB2PHYCFG_PHYSOFTRST (1 << 31)
195#define DWC3_GUSB2PHYCFG_SUSPHY (1 << 6)
Felipe Balbi72246da2011-08-19 18:10:58 +0300196
197/* Global USB3 PIPE Control Register */
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800198#define DWC3_GUSB3PIPECTL_PHYSOFTRST (1 << 31)
199#define DWC3_GUSB3PIPECTL_SUSPHY (1 << 17)
200#define DWC3_GUSB3PIPECTL_DELAY_P1P2P3 (7 << 19)
201#define DWC3_GUSB3PIPECTL_DIS_RXDET_U3_RXDET (1 << 22)
Vijayavardhan Vennapusad0136a72013-06-07 13:22:18 +0530202#define DWC3_GUSB3PIPECTL_ELASTIC_BUF_MODE (1 << 0)
Felipe Balbi72246da2011-08-19 18:10:58 +0300203
Felipe Balbi457e84b2012-01-18 18:04:09 +0200204/* Global TX Fifo Size Register */
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800205#define DWC3_GTXFIFOSIZ_TXFDEF(n) ((n) & 0xffff)
206#define DWC3_GTXFIFOSIZ_TXFSTADDR(n) ((n) & 0xffff0000)
Felipe Balbi457e84b2012-01-18 18:04:09 +0200207
Felipe Balbiaabb7072011-09-30 10:58:50 +0300208/* Global HWPARAMS1 Register */
Paul Zimmerman1d046792012-02-15 18:56:56 -0800209#define DWC3_GHWPARAMS1_EN_PWROPT(n) (((n) & (3 << 24)) >> 24)
Felipe Balbiaabb7072011-09-30 10:58:50 +0300210#define DWC3_GHWPARAMS1_EN_PWROPT_NO 0
211#define DWC3_GHWPARAMS1_EN_PWROPT_CLK 1
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800212#define DWC3_GHWPARAMS1_EN_PWROPT_HIB 2
213#define DWC3_GHWPARAMS1_PWROPT(n) ((n) << 24)
214#define DWC3_GHWPARAMS1_PWROPT_MASK DWC3_GHWPARAMS1_PWROPT(3)
215
216/* Global HWPARAMS4 Register */
217#define DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(n) (((n) & (0x0f << 13)) >> 13)
218#define DWC3_MAX_HIBER_SCRATCHBUFS 15
Felipe Balbiaabb7072011-09-30 10:58:50 +0300219
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200220/* Global HWPARAMS6 Register */
221#define DWC3_GHWPARAMS6_SRP_SUPPORT (1 << 10)
222
Jack Pham1b309192014-04-16 11:54:55 +0530223/* Global Frame Length Adjustment Register */
224#define DWC3_GFLADJ_REFCLK_240MHZDECR_PLS1 (1 << 31)
225#define DWC3_GFLADJ_REFCLK_240MHZ_DECR (0x7F << 24)
226#define DWC3_GFLADJ_REFCLK_LPM_SEL (1 << 23)
227#define DWC3_GFLADJ_REFCLK_FLADJ (0x3FFF << 8)
228
Felipe Balbi72246da2011-08-19 18:10:58 +0300229/* Device Configuration Register */
Sebastian Andrzej Siewiorbb8b8a32011-09-13 17:54:39 +0200230#define DWC3_DCFG_LPM_CAP (1 << 22)
Felipe Balbi72246da2011-08-19 18:10:58 +0300231#define DWC3_DCFG_DEVADDR(addr) ((addr) << 3)
232#define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f)
233
234#define DWC3_DCFG_SPEED_MASK (7 << 0)
235#define DWC3_DCFG_SUPERSPEED (4 << 0)
236#define DWC3_DCFG_HIGHSPEED (0 << 0)
237#define DWC3_DCFG_FULLSPEED2 (1 << 0)
238#define DWC3_DCFG_LOWSPEED (2 << 0)
239#define DWC3_DCFG_FULLSPEED1 (3 << 0)
240
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800241#define DWC3_DCFG_LPM_CAP (1 << 22)
242
Felipe Balbi72246da2011-08-19 18:10:58 +0300243/* Device Control Register */
244#define DWC3_DCTL_RUN_STOP (1 << 31)
245#define DWC3_DCTL_CSFTRST (1 << 30)
246#define DWC3_DCTL_LSFTRST (1 << 29)
247
248#define DWC3_DCTL_HIRD_THRES_MASK (0x1f << 24)
Pratyush Anandb403c112012-06-06 19:18:29 +0530249#define DWC3_DCTL_HIRD_THRES(n) ((n) << 24)
Felipe Balbi72246da2011-08-19 18:10:58 +0300250
251#define DWC3_DCTL_APPL1RES (1 << 23)
252
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800253/* These apply for core versions 1.87a and earlier */
254#define DWC3_DCTL_TRGTULST_MASK (0x0f << 17)
255#define DWC3_DCTL_TRGTULST(n) ((n) << 17)
256#define DWC3_DCTL_TRGTULST_U2 (DWC3_DCTL_TRGTULST(2))
257#define DWC3_DCTL_TRGTULST_U3 (DWC3_DCTL_TRGTULST(3))
258#define DWC3_DCTL_TRGTULST_SS_DIS (DWC3_DCTL_TRGTULST(4))
259#define DWC3_DCTL_TRGTULST_RX_DET (DWC3_DCTL_TRGTULST(5))
260#define DWC3_DCTL_TRGTULST_SS_INACT (DWC3_DCTL_TRGTULST(6))
Felipe Balbi8db7ed12012-01-18 18:32:29 +0200261
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800262/* These apply for core versions 1.94a and later */
263#define DWC3_DCTL_KEEP_CONNECT (1 << 19)
264#define DWC3_DCTL_L1_HIBER_EN (1 << 18)
265#define DWC3_DCTL_CRS (1 << 17)
266#define DWC3_DCTL_CSS (1 << 16)
Felipe Balbi8db7ed12012-01-18 18:32:29 +0200267
Felipe Balbi72246da2011-08-19 18:10:58 +0300268#define DWC3_DCTL_INITU2ENA (1 << 12)
269#define DWC3_DCTL_ACCEPTU2ENA (1 << 11)
270#define DWC3_DCTL_INITU1ENA (1 << 10)
271#define DWC3_DCTL_ACCEPTU1ENA (1 << 9)
272#define DWC3_DCTL_TSTCTRL_MASK (0xf << 1)
273
274#define DWC3_DCTL_ULSTCHNGREQ_MASK (0x0f << 5)
275#define DWC3_DCTL_ULSTCHNGREQ(n) (((n) << 5) & DWC3_DCTL_ULSTCHNGREQ_MASK)
276
277#define DWC3_DCTL_ULSTCHNG_NO_ACTION (DWC3_DCTL_ULSTCHNGREQ(0))
278#define DWC3_DCTL_ULSTCHNG_SS_DISABLED (DWC3_DCTL_ULSTCHNGREQ(4))
279#define DWC3_DCTL_ULSTCHNG_RX_DETECT (DWC3_DCTL_ULSTCHNGREQ(5))
280#define DWC3_DCTL_ULSTCHNG_SS_INACTIVE (DWC3_DCTL_ULSTCHNGREQ(6))
281#define DWC3_DCTL_ULSTCHNG_RECOVERY (DWC3_DCTL_ULSTCHNGREQ(8))
282#define DWC3_DCTL_ULSTCHNG_COMPLIANCE (DWC3_DCTL_ULSTCHNGREQ(10))
283#define DWC3_DCTL_ULSTCHNG_LOOPBACK (DWC3_DCTL_ULSTCHNGREQ(11))
284
285/* Device Event Enable Register */
286#define DWC3_DEVTEN_VNDRDEVTSTRCVEDEN (1 << 12)
287#define DWC3_DEVTEN_EVNTOVERFLOWEN (1 << 11)
288#define DWC3_DEVTEN_CMDCMPLTEN (1 << 10)
289#define DWC3_DEVTEN_ERRTICERREN (1 << 9)
290#define DWC3_DEVTEN_SOFEN (1 << 7)
291#define DWC3_DEVTEN_EOPFEN (1 << 6)
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800292#define DWC3_DEVTEN_HIBERNATIONREQEVTEN (1 << 5)
Felipe Balbi72246da2011-08-19 18:10:58 +0300293#define DWC3_DEVTEN_WKUPEVTEN (1 << 4)
294#define DWC3_DEVTEN_ULSTCNGEN (1 << 3)
295#define DWC3_DEVTEN_CONNECTDONEEN (1 << 2)
296#define DWC3_DEVTEN_USBRSTEN (1 << 1)
297#define DWC3_DEVTEN_DISCONNEVTEN (1 << 0)
298
299/* Device Status Register */
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800300#define DWC3_DSTS_DCNRD (1 << 29)
301
302/* This applies for core versions 1.87a and earlier */
Felipe Balbi72246da2011-08-19 18:10:58 +0300303#define DWC3_DSTS_PWRUPREQ (1 << 24)
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800304
305/* These apply for core versions 1.94a and later */
306#define DWC3_DSTS_RSS (1 << 25)
307#define DWC3_DSTS_SSS (1 << 24)
308
Felipe Balbi72246da2011-08-19 18:10:58 +0300309#define DWC3_DSTS_COREIDLE (1 << 23)
310#define DWC3_DSTS_DEVCTRLHLT (1 << 22)
311
312#define DWC3_DSTS_USBLNKST_MASK (0x0f << 18)
313#define DWC3_DSTS_USBLNKST(n) (((n) & DWC3_DSTS_USBLNKST_MASK) >> 18)
314
315#define DWC3_DSTS_RXFIFOEMPTY (1 << 17)
316
Pratyush Anande8478e62012-05-21 14:51:30 +0530317#define DWC3_DSTS_SOFFN_MASK (0x3fff << 3)
Felipe Balbi72246da2011-08-19 18:10:58 +0300318#define DWC3_DSTS_SOFFN(n) (((n) & DWC3_DSTS_SOFFN_MASK) >> 3)
319
320#define DWC3_DSTS_CONNECTSPD (7 << 0)
321
322#define DWC3_DSTS_SUPERSPEED (4 << 0)
323#define DWC3_DSTS_HIGHSPEED (0 << 0)
324#define DWC3_DSTS_FULLSPEED2 (1 << 0)
325#define DWC3_DSTS_LOWSPEED (2 << 0)
326#define DWC3_DSTS_FULLSPEED1 (3 << 0)
327
328/* Device Generic Command Register */
329#define DWC3_DGCMD_SET_LMP 0x01
330#define DWC3_DGCMD_SET_PERIODIC_PAR 0x02
331#define DWC3_DGCMD_XMIT_FUNCTION 0x03
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800332
333/* These apply for core versions 1.94a and later */
334#define DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO 0x04
335#define DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI 0x05
336
Felipe Balbi72246da2011-08-19 18:10:58 +0300337#define DWC3_DGCMD_SELECTED_FIFO_FLUSH 0x09
338#define DWC3_DGCMD_ALL_FIFO_FLUSH 0x0a
339#define DWC3_DGCMD_SET_ENDPOINT_NRDY 0x0c
340#define DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK 0x10
341
Felipe Balbi573c2762012-04-24 16:19:11 +0300342#define DWC3_DGCMD_STATUS(n) (((n) >> 15) & 1)
343#define DWC3_DGCMD_CMDACT (1 << 10)
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800344#define DWC3_DGCMD_CMDIOC (1 << 8)
345
346/* Device Generic Command Parameter Register */
347#define DWC3_DGCMDPAR_FORCE_LINKPM_ACCEPT (1 << 0)
348#define DWC3_DGCMDPAR_FIFO_NUM(n) ((n) << 0)
349#define DWC3_DGCMDPAR_RX_FIFO (0 << 5)
350#define DWC3_DGCMDPAR_TX_FIFO (1 << 5)
351#define DWC3_DGCMDPAR_LOOPBACK_DIS (0 << 0)
352#define DWC3_DGCMDPAR_LOOPBACK_ENA (1 << 0)
Felipe Balbi573c2762012-04-24 16:19:11 +0300353
Felipe Balbi72246da2011-08-19 18:10:58 +0300354/* Device Endpoint Command Register */
355#define DWC3_DEPCMD_PARAM_SHIFT 16
Paul Zimmerman1d046792012-02-15 18:56:56 -0800356#define DWC3_DEPCMD_PARAM(x) ((x) << DWC3_DEPCMD_PARAM_SHIFT)
357#define DWC3_DEPCMD_GET_RSC_IDX(x) (((x) >> DWC3_DEPCMD_PARAM_SHIFT) & 0x7f)
Felipe Balbi573c2762012-04-24 16:19:11 +0300358#define DWC3_DEPCMD_STATUS(x) (((x) >> 15) & 1)
Felipe Balbi72246da2011-08-19 18:10:58 +0300359#define DWC3_DEPCMD_HIPRI_FORCERM (1 << 11)
360#define DWC3_DEPCMD_CMDACT (1 << 10)
361#define DWC3_DEPCMD_CMDIOC (1 << 8)
362
363#define DWC3_DEPCMD_DEPSTARTCFG (0x09 << 0)
364#define DWC3_DEPCMD_ENDTRANSFER (0x08 << 0)
365#define DWC3_DEPCMD_UPDATETRANSFER (0x07 << 0)
366#define DWC3_DEPCMD_STARTTRANSFER (0x06 << 0)
367#define DWC3_DEPCMD_CLEARSTALL (0x05 << 0)
368#define DWC3_DEPCMD_SETSTALL (0x04 << 0)
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800369/* This applies for core versions 1.90a and earlier */
Felipe Balbi72246da2011-08-19 18:10:58 +0300370#define DWC3_DEPCMD_GETSEQNUMBER (0x03 << 0)
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800371/* This applies for core versions 1.94a and later */
372#define DWC3_DEPCMD_GETEPSTATE (0x03 << 0)
Felipe Balbi72246da2011-08-19 18:10:58 +0300373#define DWC3_DEPCMD_SETTRANSFRESOURCE (0x02 << 0)
374#define DWC3_DEPCMD_SETEPCONFIG (0x01 << 0)
375
376/* The EP number goes 0..31 so ep0 is always out and ep1 is always in */
377#define DWC3_DALEPENA_EP(n) (1 << n)
378
379#define DWC3_DEPCMD_TYPE_CONTROL 0
380#define DWC3_DEPCMD_TYPE_ISOC 1
381#define DWC3_DEPCMD_TYPE_BULK 2
382#define DWC3_DEPCMD_TYPE_INTR 3
383
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200384/* OTG Events Register */
385#define DWC3_OEVT_DEVICEMODE (1 << 31)
386#define DWC3_OEVTEN_OTGCONIDSTSCHNGEVNT (1 << 24)
387#define DWC3_OEVTEN_OTGADEVBHOSTENDEVNT (1 << 20)
388#define DWC3_OEVTEN_OTGADEVHOSTEVNT (1 << 19)
389#define DWC3_OEVTEN_OTGADEVHNPCHNGEVNT (1 << 18)
390#define DWC3_OEVTEN_OTGADEVSRPDETEVNT (1 << 17)
391#define DWC3_OEVTEN_OTGADEVSESSENDDETEVNT (1 << 16)
392#define DWC3_OEVTEN_OTGBDEVBHOSTENDEVNT (1 << 11)
393#define DWC3_OEVTEN_OTGBDEVHNPCHNGEVNT (1 << 10)
394#define DWC3_OEVTEN_OTGBDEVSESSVLDDETEVNT (1 << 9)
395#define DWC3_OEVTEN_OTGBDEVVBUSCHNGEVNT (1 << 8)
396
397/* OTG OSTS register */
398#define DWC3_OTG_OSTS_OTGSTATE_SHIFT (8)
399#define DWC3_OTG_OSTS_OTGSTATE (0xF << DWC3_OTG_OSTS_OTGSTATE_SHIFT)
400#define DWC3_OTG_OSTS_PERIPHERALSTATE (1 << 4)
401#define DWC3_OTG_OSTS_XHCIPRTPOWER (1 << 3)
402#define DWC3_OTG_OSTS_BSESVALID (1 << 2)
403#define DWC3_OTG_OSTS_VBUSVALID (1 << 1)
404#define DWC3_OTG_OSTS_CONIDSTS (1 << 0)
405
406/* OTG OSTS register */
407#define DWC3_OTG_OCTL_PERIMODE (1 << 6)
408#define DWC3_OTG_OCTL_PRTPWRCTL (1 << 5)
409#define DWC3_OTG_OCTL_HNPREQ (1 << 4)
410#define DWC3_OTG_OCTL_SESREQ (1 << 3)
411#define DWC3_OTG_OCTL_TERMSELDLPULSE (1 << 2)
412#define DWC3_OTG_OCTL_DEVSETHNPEN (1 << 1)
413#define DWC3_OTG_OCTL_HSTSETHNPEN (1 << 0)
414
Felipe Balbi72246da2011-08-19 18:10:58 +0300415/* Structures */
416
Felipe Balbif6bafc62012-02-06 11:04:53 +0200417struct dwc3_trb;
Felipe Balbi72246da2011-08-19 18:10:58 +0300418
419/**
420 * struct dwc3_event_buffer - Software event buffer representation
421 * @list: a list of event buffers
422 * @buf: _THE_ buffer
423 * @length: size of this buffer
424 * @dma: dma_addr_t
425 * @dwc: pointer to DWC controller
426 */
427struct dwc3_event_buffer {
428 void *buf;
429 unsigned length;
430 unsigned int lpos;
431
432 dma_addr_t dma;
433
434 struct dwc3 *dwc;
435};
436
437#define DWC3_EP_FLAG_STALLED (1 << 0)
438#define DWC3_EP_FLAG_WEDGED (1 << 1)
439
440#define DWC3_EP_DIRECTION_TX true
441#define DWC3_EP_DIRECTION_RX false
442
443#define DWC3_TRB_NUM 32
444#define DWC3_TRB_MASK (DWC3_TRB_NUM - 1)
445
446/**
447 * struct dwc3_ep - device side endpoint representation
448 * @endpoint: usb endpoint
449 * @request_list: list of requests for this endpoint
450 * @req_queued: list of requests on this ep which have TRBs setup
451 * @trb_pool: array of transaction buffers
452 * @trb_pool_dma: dma address of @trb_pool
453 * @free_slot: next slot which is going to be used
454 * @busy_slot: first slot which is owned by HW
455 * @desc: usb_endpoint_descriptor pointer
456 * @dwc: pointer to DWC controller
457 * @flags: endpoint flags (wedged, stalled, ...)
458 * @current_trb: index of current used trb
459 * @number: endpoint number (1 - 15)
460 * @type: set to bmAttributes & USB_ENDPOINT_XFERTYPE_MASK
Felipe Balbi4959cfc2012-06-06 12:04:13 +0300461 * @resource_index: Resource transfer index
Pratyush Anand73939b02012-05-25 18:54:56 +0530462 * @current_uf: Current uf received through last event parameter
Felipe Balbi72246da2011-08-19 18:10:58 +0300463 * @interval: the intervall on which the ISOC transfer is started
464 * @name: a human readable name e.g. ep1out-bulk
465 * @direction: true for TX, false for RX
Felipe Balbi879631a2011-09-30 10:58:47 +0300466 * @stream_capable: true when streams are enabled
Felipe Balbi72246da2011-08-19 18:10:58 +0300467 */
468struct dwc3_ep {
469 struct usb_ep endpoint;
470 struct list_head request_list;
471 struct list_head req_queued;
472
Felipe Balbif6bafc62012-02-06 11:04:53 +0200473 struct dwc3_trb *trb_pool;
Felipe Balbi72246da2011-08-19 18:10:58 +0300474 dma_addr_t trb_pool_dma;
475 u32 free_slot;
476 u32 busy_slot;
Felipe Balbic90bfae2011-11-29 13:11:21 +0200477 const struct usb_ss_ep_comp_descriptor *comp_desc;
Felipe Balbi72246da2011-08-19 18:10:58 +0300478 struct dwc3 *dwc;
479
480 unsigned flags;
481#define DWC3_EP_ENABLED (1 << 0)
482#define DWC3_EP_STALL (1 << 1)
483#define DWC3_EP_WEDGE (1 << 2)
484#define DWC3_EP_BUSY (1 << 4)
485#define DWC3_EP_PENDING_REQUEST (1 << 5)
Pratyush Anand73939b02012-05-25 18:54:56 +0530486#define DWC3_EP_MISSED_ISOC (1 << 6)
Felipe Balbi72246da2011-08-19 18:10:58 +0300487
Felipe Balbi984f66a2011-08-27 22:26:00 +0300488 /* This last one is specific to EP0 */
489#define DWC3_EP0_DIR_IN (1 << 31)
490
Felipe Balbi72246da2011-08-19 18:10:58 +0300491 unsigned current_trb;
492
493 u8 number;
494 u8 type;
Felipe Balbi4959cfc2012-06-06 12:04:13 +0300495 u8 resource_index;
Pratyush Anand73939b02012-05-25 18:54:56 +0530496 u16 current_uf;
Felipe Balbi72246da2011-08-19 18:10:58 +0300497 u32 interval;
498
499 char name[20];
500
501 unsigned direction:1;
Felipe Balbi879631a2011-09-30 10:58:47 +0300502 unsigned stream_capable:1;
Felipe Balbi72246da2011-08-19 18:10:58 +0300503};
504
505enum dwc3_phy {
506 DWC3_PHY_UNKNOWN = 0,
507 DWC3_PHY_USB3,
508 DWC3_PHY_USB2,
509};
510
Felipe Balbib53c7722011-08-30 15:50:40 +0300511enum dwc3_ep0_next {
512 DWC3_EP0_UNKNOWN = 0,
513 DWC3_EP0_COMPLETE,
Felipe Balbib53c7722011-08-30 15:50:40 +0300514 DWC3_EP0_NRDY_DATA,
515 DWC3_EP0_NRDY_STATUS,
516};
517
Felipe Balbi72246da2011-08-19 18:10:58 +0300518enum dwc3_ep0_state {
519 EP0_UNCONNECTED = 0,
Felipe Balbic7fcdeb2011-08-27 22:28:36 +0300520 EP0_SETUP_PHASE,
521 EP0_DATA_PHASE,
522 EP0_STATUS_PHASE,
Felipe Balbi72246da2011-08-19 18:10:58 +0300523};
524
525enum dwc3_link_state {
526 /* In SuperSpeed */
527 DWC3_LINK_STATE_U0 = 0x00, /* in HS, means ON */
528 DWC3_LINK_STATE_U1 = 0x01,
529 DWC3_LINK_STATE_U2 = 0x02, /* in HS, means SLEEP */
530 DWC3_LINK_STATE_U3 = 0x03, /* in HS, means SUSPEND */
531 DWC3_LINK_STATE_SS_DIS = 0x04,
532 DWC3_LINK_STATE_RX_DET = 0x05, /* in HS, means Early Suspend */
533 DWC3_LINK_STATE_SS_INACT = 0x06,
534 DWC3_LINK_STATE_POLL = 0x07,
535 DWC3_LINK_STATE_RECOV = 0x08,
536 DWC3_LINK_STATE_HRESET = 0x09,
537 DWC3_LINK_STATE_CMPLY = 0x0a,
538 DWC3_LINK_STATE_LPBK = 0x0b,
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800539 DWC3_LINK_STATE_RESET = 0x0e,
540 DWC3_LINK_STATE_RESUME = 0x0f,
Felipe Balbi72246da2011-08-19 18:10:58 +0300541 DWC3_LINK_STATE_MASK = 0x0f,
542};
543
544enum dwc3_device_state {
545 DWC3_DEFAULT_STATE,
546 DWC3_ADDRESS_STATE,
547 DWC3_CONFIGURED_STATE,
548};
549
Felipe Balbif6bafc62012-02-06 11:04:53 +0200550/* TRB Length, PCM and Status */
551#define DWC3_TRB_SIZE_MASK (0x00ffffff)
552#define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK)
553#define DWC3_TRB_SIZE_PCM1(n) (((n) & 0x03) << 24)
Pratyush Anand8379bef2012-05-21 12:46:26 +0530554#define DWC3_TRB_SIZE_TRBSTS(n) (((n) & (0x0f << 28)) >> 28)
Felipe Balbi72246da2011-08-19 18:10:58 +0300555
Felipe Balbif6bafc62012-02-06 11:04:53 +0200556#define DWC3_TRBSTS_OK 0
557#define DWC3_TRBSTS_MISSED_ISOC 1
558#define DWC3_TRBSTS_SETUP_PENDING 2
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800559#define DWC3_TRB_STS_XFER_IN_PROG 4
Felipe Balbi72246da2011-08-19 18:10:58 +0300560
Felipe Balbif6bafc62012-02-06 11:04:53 +0200561/* TRB Control */
562#define DWC3_TRB_CTRL_HWO (1 << 0)
563#define DWC3_TRB_CTRL_LST (1 << 1)
564#define DWC3_TRB_CTRL_CHN (1 << 2)
565#define DWC3_TRB_CTRL_CSP (1 << 3)
566#define DWC3_TRB_CTRL_TRBCTL(n) (((n) & 0x3f) << 4)
567#define DWC3_TRB_CTRL_ISP_IMI (1 << 10)
568#define DWC3_TRB_CTRL_IOC (1 << 11)
569#define DWC3_TRB_CTRL_SID_SOFN(n) (((n) & 0xffff) << 14)
570
571#define DWC3_TRBCTL_NORMAL DWC3_TRB_CTRL_TRBCTL(1)
572#define DWC3_TRBCTL_CONTROL_SETUP DWC3_TRB_CTRL_TRBCTL(2)
573#define DWC3_TRBCTL_CONTROL_STATUS2 DWC3_TRB_CTRL_TRBCTL(3)
574#define DWC3_TRBCTL_CONTROL_STATUS3 DWC3_TRB_CTRL_TRBCTL(4)
575#define DWC3_TRBCTL_CONTROL_DATA DWC3_TRB_CTRL_TRBCTL(5)
576#define DWC3_TRBCTL_ISOCHRONOUS_FIRST DWC3_TRB_CTRL_TRBCTL(6)
577#define DWC3_TRBCTL_ISOCHRONOUS DWC3_TRB_CTRL_TRBCTL(7)
578#define DWC3_TRBCTL_LINK_TRB DWC3_TRB_CTRL_TRBCTL(8)
Felipe Balbi72246da2011-08-19 18:10:58 +0300579
580/**
Felipe Balbif6bafc62012-02-06 11:04:53 +0200581 * struct dwc3_trb - transfer request block (hw format)
Felipe Balbi72246da2011-08-19 18:10:58 +0300582 * @bpl: DW0-3
583 * @bph: DW4-7
584 * @size: DW8-B
585 * @trl: DWC-F
586 */
Felipe Balbif6bafc62012-02-06 11:04:53 +0200587struct dwc3_trb {
588 u32 bpl;
589 u32 bph;
590 u32 size;
591 u32 ctrl;
Felipe Balbi72246da2011-08-19 18:10:58 +0300592} __packed;
593
Felipe Balbi72246da2011-08-19 18:10:58 +0300594/**
Felipe Balbia3299492011-09-30 10:58:48 +0300595 * dwc3_hwparams - copy of HWPARAMS registers
596 * @hwparams0 - GHWPARAMS0
597 * @hwparams1 - GHWPARAMS1
598 * @hwparams2 - GHWPARAMS2
599 * @hwparams3 - GHWPARAMS3
600 * @hwparams4 - GHWPARAMS4
601 * @hwparams5 - GHWPARAMS5
602 * @hwparams6 - GHWPARAMS6
603 * @hwparams7 - GHWPARAMS7
604 * @hwparams8 - GHWPARAMS8
605 */
606struct dwc3_hwparams {
607 u32 hwparams0;
608 u32 hwparams1;
609 u32 hwparams2;
610 u32 hwparams3;
611 u32 hwparams4;
612 u32 hwparams5;
613 u32 hwparams6;
614 u32 hwparams7;
615 u32 hwparams8;
616};
617
Felipe Balbi0949e992011-10-12 10:44:56 +0300618/* HWPARAMS0 */
619#define DWC3_MODE(n) ((n) & 0x7)
620
621#define DWC3_MODE_DEVICE 0
622#define DWC3_MODE_HOST 1
623#define DWC3_MODE_DRD 2
624#define DWC3_MODE_HUB 3
625
Felipe Balbi457e84b2012-01-18 18:04:09 +0200626#define DWC3_MDWIDTH(n) (((n) & 0xff00) >> 8)
627
Felipe Balbi0949e992011-10-12 10:44:56 +0300628/* HWPARAMS1 */
Felipe Balbi457e84b2012-01-18 18:04:09 +0200629#define DWC3_NUM_INT(n) (((n) & (0x3f << 15)) >> 15)
630
Arve Hjønnevåg6ef3aa42013-04-18 18:58:11 -0700631/* HWPARAMS3 */
632#define DWC3_NUM_IN_EPS_MASK (0x1f << 18)
633#define DWC3_NUM_EPS_MASK (0x3f << 12)
634#define DWC3_NUM_EPS(p) (((p)->hwparams3 & \
635 (DWC3_NUM_EPS_MASK)) >> 12)
636#define DWC3_NUM_IN_EPS(p) (((p)->hwparams3 & \
637 (DWC3_NUM_IN_EPS_MASK)) >> 18)
638
Felipe Balbi457e84b2012-01-18 18:04:09 +0200639/* HWPARAMS7 */
640#define DWC3_RAM1_DEPTH(n) ((n) & 0xffff)
Felipe Balbi9f622b22011-10-12 10:31:04 +0300641
Sebastian Andrzej Siewiore0ce0b02011-11-25 12:03:46 +0100642struct dwc3_request {
643 struct usb_request request;
644 struct list_head list;
645 struct dwc3_ep *dep;
646
647 u8 epnum;
Felipe Balbif6bafc62012-02-06 11:04:53 +0200648 struct dwc3_trb *trb;
Vijayavardhan Vennapusa5f5c3e62013-11-13 19:53:13 +0530649 struct dwc3_trb *ztrb;
Sebastian Andrzej Siewiore0ce0b02011-11-25 12:03:46 +0100650 dma_addr_t trb_dma;
651
652 unsigned direction:1;
653 unsigned mapped:1;
654 unsigned queued:1;
655};
656
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800657/*
658 * struct dwc3_scratchpad_array - hibernation scratchpad array
659 * (format defined by hw)
660 */
661struct dwc3_scratchpad_array {
662 __le64 dma_adr[DWC3_MAX_HIBER_SCRATCHBUFS];
663};
664
Vijayavardhan Vennapusa8a011c92013-07-29 09:06:48 +0530665#define DWC3_CONTROLLER_ERROR_EVENT 0
Vijayavardhan Vennapusaba79f6b2013-07-30 13:39:52 +0530666#define DWC3_CONTROLLER_RESET_EVENT 1
667#define DWC3_CONTROLLER_POST_RESET_EVENT 2
Vijayavardhan Vennapusada8d06c2013-10-22 19:19:57 +0530668#define DWC3_CONTROLLER_POST_INITIALIZATION_EVENT 3
Felipe Balbia3299492011-09-30 10:58:48 +0300669/**
Felipe Balbi72246da2011-08-19 18:10:58 +0300670 * struct dwc3 - representation of our controller
Felipe Balbi91db07d2011-08-27 01:40:52 +0300671 * @ctrl_req: usb control request which is used for ep0
672 * @ep0_trb: trb which is used for the ctrl_req
Felipe Balbi5812b1c2011-08-27 22:07:53 +0300673 * @ep0_bounce: bounce buffer for ep0
Felipe Balbi91db07d2011-08-27 01:40:52 +0300674 * @setup_buf: used while precessing STD USB requests
675 * @ctrl_req_addr: dma address of ctrl_req
676 * @ep0_trb: dma address of ep0_trb
677 * @ep0_usb_req: dummy req used while handling STD USB requests
Felipe Balbi5812b1c2011-08-27 22:07:53 +0300678 * @ep0_bounce_addr: dma address of ep0_bounce
Felipe Balbi72246da2011-08-19 18:10:58 +0300679 * @lock: for synchronizing
680 * @dev: pointer to our struct device
Felipe Balbid07e8812011-10-12 14:08:26 +0300681 * @xhci: pointer to our xHCI child
Felipe Balbi72246da2011-08-19 18:10:58 +0300682 * @event_buffer_list: a list of event buffers
683 * @gadget: device side representation of the peripheral controller
684 * @gadget_driver: pointer to the gadget driver
685 * @regs: base address for our registers
686 * @regs_size: address space size
687 * @irq: IRQ number
Felipe Balbi9f622b22011-10-12 10:31:04 +0300688 * @num_event_buffers: calculated number of event buffers
Felipe Balbifae2b902011-10-14 13:00:30 +0300689 * @u1u2: only used on revisions <1.83a for workaround
Felipe Balbi6c167fc2011-10-07 22:55:04 +0300690 * @maximum_speed: maximum speed requested (mainly for testing purposes)
Felipe Balbi72246da2011-08-19 18:10:58 +0300691 * @revision: revision register contents
Felipe Balbi0949e992011-10-12 10:44:56 +0300692 * @mode: mode of operation
Felipe Balbi72246da2011-08-19 18:10:58 +0300693 * @is_selfpowered: true when we are selfpowered
694 * @three_stage_setup: set if we perform a three phase setup
Felipe Balbi5812b1c2011-08-27 22:07:53 +0300695 * @ep0_bounced: true when we used bounce buffer
Felipe Balbi55f3fba2011-09-08 18:27:33 +0300696 * @ep0_expect_in: true when we expect a DATA IN transfer
Paul Zimmermanb23c8432011-09-30 10:58:42 +0300697 * @start_config_issued: true when StartConfig command has been issued
Felipe Balbidf62df52011-10-14 15:11:49 +0300698 * @setup_packet_pending: true when there's a Setup Packet in FIFO. Workaround
Felipe Balbi457e84b2012-01-18 18:04:09 +0200699 * @needs_fifo_resize: not all users might want fifo resizing, flag it
700 * @resize_fifos: tells us it's ok to reconfigure our TxFIFO sizes.
Felipe Balbi395c3492012-04-25 10:45:05 +0300701 * @isoch_delay: wValue from Set Isochronous Delay request;
Felipe Balbi9e788d62012-04-24 16:19:49 +0300702 * @u2sel: parameter from Set SEL request.
703 * @u2pel: parameter from Set SEL request.
704 * @u1sel: parameter from Set SEL request.
705 * @u1pel: parameter from Set SEL request.
Arve Hjønnevåg6ef3aa42013-04-18 18:58:11 -0700706 * @num_out_eps: number of out endpoints
707 * @num_in_eps: number of in endpoints
Felipe Balbib53c7722011-08-30 15:50:40 +0300708 * @ep0_next_event: hold the next expected event
Felipe Balbi72246da2011-08-19 18:10:58 +0300709 * @ep0state: state of endpoint zero
710 * @link_state: link state
711 * @speed: device speed (super, high, full, low)
712 * @mem: points to start of memory which is used for this struct.
Felipe Balbia3299492011-09-30 10:58:48 +0300713 * @hwparams: copy of hwparams registers
Felipe Balbi72246da2011-08-19 18:10:58 +0300714 * @root: debugfs root folder pointer
Vijayavardhan Vennapusafc3db602013-08-20 17:54:54 +0530715 * @tx_fifo_size: Available RAM size for TX fifo allocation
Manu Gautama10e7fb2015-04-21 16:13:43 +0530716 * @err_evt_seen: previous event in queue was erratic error
717 * @irq_cnt: total irq count
Felipe Balbi72246da2011-08-19 18:10:58 +0300718 */
719struct dwc3 {
720 struct usb_ctrlrequest *ctrl_req;
Felipe Balbif6bafc62012-02-06 11:04:53 +0200721 struct dwc3_trb *ep0_trb;
Felipe Balbi5812b1c2011-08-27 22:07:53 +0300722 void *ep0_bounce;
Felipe Balbi72246da2011-08-19 18:10:58 +0300723 u8 *setup_buf;
724 dma_addr_t ctrl_req_addr;
725 dma_addr_t ep0_trb_addr;
Felipe Balbi5812b1c2011-08-27 22:07:53 +0300726 dma_addr_t ep0_bounce_addr;
Sebastian Andrzej Siewiore0ce0b02011-11-25 12:03:46 +0100727 struct dwc3_request ep0_usb_req;
Arve Hjønnevåg6ef3aa42013-04-18 18:58:11 -0700728
Felipe Balbi72246da2011-08-19 18:10:58 +0300729 /* device lock */
730 spinlock_t lock;
Arve Hjønnevåg6ef3aa42013-04-18 18:58:11 -0700731
Felipe Balbi72246da2011-08-19 18:10:58 +0300732 struct device *dev;
733
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200734 struct dwc3_otg *dotg;
Felipe Balbid07e8812011-10-12 14:08:26 +0300735 struct platform_device *xhci;
Ido Shayevitz4a187332012-04-23 14:53:37 +0200736 struct resource xhci_resources[DWC3_XHCI_RESOURCES_NUM];
Felipe Balbid07e8812011-10-12 14:08:26 +0300737
Felipe Balbi457d3f22011-10-24 12:03:13 +0300738 struct dwc3_event_buffer **ev_buffs;
Felipe Balbi72246da2011-08-19 18:10:58 +0300739 struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM];
740
741 struct usb_gadget gadget;
742 struct usb_gadget_driver *gadget_driver;
743
744 void __iomem *regs;
745 size_t regs_size;
746
Felipe Balbi9f622b22011-10-12 10:31:04 +0300747 u32 num_event_buffers;
Felipe Balbifae2b902011-10-14 13:00:30 +0300748 u32 u1u2;
Felipe Balbi6c167fc2011-10-07 22:55:04 +0300749 u32 maximum_speed;
Felipe Balbi72246da2011-08-19 18:10:58 +0300750 u32 revision;
Felipe Balbi0949e992011-10-12 10:44:56 +0300751 u32 mode;
Felipe Balbi72246da2011-08-19 18:10:58 +0300752
753#define DWC3_REVISION_173A 0x5533173a
754#define DWC3_REVISION_175A 0x5533175a
755#define DWC3_REVISION_180A 0x5533180a
756#define DWC3_REVISION_183A 0x5533183a
757#define DWC3_REVISION_185A 0x5533185a
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800758#define DWC3_REVISION_187A 0x5533187a
Felipe Balbi72246da2011-08-19 18:10:58 +0300759#define DWC3_REVISION_188A 0x5533188a
760#define DWC3_REVISION_190A 0x5533190a
Paul Zimmerman394c74f2012-02-15 18:56:58 -0800761#define DWC3_REVISION_194A 0x5533194a
Felipe Balbic712cf82012-03-23 12:10:48 +0200762#define DWC3_REVISION_200A 0x5533200a
763#define DWC3_REVISION_202A 0x5533202a
764#define DWC3_REVISION_210A 0x5533210a
765#define DWC3_REVISION_220A 0x5533220a
Pavankumar Kondetife2c0632012-06-12 15:21:13 +0530766#define DWC3_REVISION_230A 0x5533230a
Jack Pham1b309192014-04-16 11:54:55 +0530767#define DWC3_REVISION_250A 0x5533250a
Felipe Balbi72246da2011-08-19 18:10:58 +0300768
769 unsigned is_selfpowered:1;
770 unsigned three_stage_setup:1;
Felipe Balbi5812b1c2011-08-27 22:07:53 +0300771 unsigned ep0_bounced:1;
Felipe Balbi55f3fba2011-09-08 18:27:33 +0300772 unsigned ep0_expect_in:1;
Paul Zimmermanb23c8432011-09-30 10:58:42 +0300773 unsigned start_config_issued:1;
Felipe Balbidf62df52011-10-14 15:11:49 +0300774 unsigned setup_packet_pending:1;
Sebastian Andrzej Siewior5bdb1dc2011-11-02 13:30:45 +0100775 unsigned delayed_status:1;
Felipe Balbi457e84b2012-01-18 18:04:09 +0200776 unsigned needs_fifo_resize:1;
777 unsigned resize_fifos:1;
Felipe Balbi72246da2011-08-19 18:10:58 +0300778
Felipe Balbib53c7722011-08-30 15:50:40 +0300779 enum dwc3_ep0_next ep0_next_event;
Felipe Balbi72246da2011-08-19 18:10:58 +0300780 enum dwc3_ep0_state ep0state;
781 enum dwc3_link_state link_state;
782 enum dwc3_device_state dev_state;
783
Felipe Balbi395c3492012-04-25 10:45:05 +0300784 u16 isoch_delay;
Felipe Balbi9e788d62012-04-24 16:19:49 +0300785 u16 u2sel;
786 u16 u2pel;
787 u8 u1sel;
788 u8 u1pel;
789
Felipe Balbi72246da2011-08-19 18:10:58 +0300790 u8 speed;
Felipe Balbi9e788d62012-04-24 16:19:49 +0300791
Arve Hjønnevåg6ef3aa42013-04-18 18:58:11 -0700792 u8 num_out_eps;
793 u8 num_in_eps;
794
Felipe Balbi72246da2011-08-19 18:10:58 +0300795 void *mem;
796
Felipe Balbia3299492011-09-30 10:58:48 +0300797 struct dwc3_hwparams hwparams;
Felipe Balbi72246da2011-08-19 18:10:58 +0300798 struct dentry *root;
Gerard Cauvy3b637362012-02-10 12:21:18 +0200799
800 u8 test_mode;
801 u8 test_mode_nr;
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200802
803 /* Indicate if the gadget was powered by the otg driver */
804 bool vbus_active;
805
806 /* Indicate if software connect was issued by the usb_gadget_driver */
807 bool softconnect;
Vijayavardhan Vennapusa8a011c92013-07-29 09:06:48 +0530808 void (*notify_event) (struct dwc3 *, unsigned);
Vijayavardhan Vennapusafc3db602013-08-20 17:54:54 +0530809 int tx_fifo_size;
Vijayavardhan Vennapusab77e1432013-10-03 18:17:50 +0530810 bool tx_fifo_reduced;
Manu Gautama10e7fb2015-04-21 16:13:43 +0530811 bool err_evt_seen;
812 unsigned long irq_cnt;
Felipe Balbi72246da2011-08-19 18:10:58 +0300813};
814
815/* -------------------------------------------------------------------------- */
816
Felipe Balbi72246da2011-08-19 18:10:58 +0300817/* -------------------------------------------------------------------------- */
818
819struct dwc3_event_type {
820 u32 is_devspec:1;
Huang Rui77d4e692013-06-27 01:08:11 +0800821 u32 type:7;
822 u32 reserved8_31:24;
Felipe Balbi72246da2011-08-19 18:10:58 +0300823} __packed;
824
825#define DWC3_DEPEVT_XFERCOMPLETE 0x01
826#define DWC3_DEPEVT_XFERINPROGRESS 0x02
827#define DWC3_DEPEVT_XFERNOTREADY 0x03
828#define DWC3_DEPEVT_RXTXFIFOEVT 0x04
829#define DWC3_DEPEVT_STREAMEVT 0x06
830#define DWC3_DEPEVT_EPCMDCMPLT 0x07
831
832/**
833 * struct dwc3_event_depvt - Device Endpoint Events
834 * @one_bit: indicates this is an endpoint event (not used)
835 * @endpoint_number: number of the endpoint
836 * @endpoint_event: The event we have:
837 * 0x00 - Reserved
838 * 0x01 - XferComplete
839 * 0x02 - XferInProgress
840 * 0x03 - XferNotReady
841 * 0x04 - RxTxFifoEvt (IN->Underrun, OUT->Overrun)
842 * 0x05 - Reserved
843 * 0x06 - StreamEvt
844 * 0x07 - EPCmdCmplt
845 * @reserved11_10: Reserved, don't use.
846 * @status: Indicates the status of the event. Refer to databook for
847 * more information.
848 * @parameters: Parameters of the current event. Refer to databook for
849 * more information.
850 */
851struct dwc3_event_depevt {
852 u32 one_bit:1;
853 u32 endpoint_number:5;
854 u32 endpoint_event:4;
855 u32 reserved11_10:2;
856 u32 status:4;
Felipe Balbi40aa41f2012-01-18 17:06:03 +0200857
858/* Within XferNotReady */
859#define DEPEVT_STATUS_TRANSFER_ACTIVE (1 << 3)
860
861/* Within XferComplete */
Paul Zimmerman1d046792012-02-15 18:56:56 -0800862#define DEPEVT_STATUS_BUSERR (1 << 0)
863#define DEPEVT_STATUS_SHORT (1 << 1)
864#define DEPEVT_STATUS_IOC (1 << 2)
Felipe Balbi72246da2011-08-19 18:10:58 +0300865#define DEPEVT_STATUS_LST (1 << 3)
Felipe Balbidc137f02011-08-27 22:04:32 +0300866
Felipe Balbi879631a2011-09-30 10:58:47 +0300867/* Stream event only */
868#define DEPEVT_STREAMEVT_FOUND 1
869#define DEPEVT_STREAMEVT_NOTFOUND 2
870
Felipe Balbidc137f02011-08-27 22:04:32 +0300871/* Control-only Status */
Felipe Balbidc137f02011-08-27 22:04:32 +0300872#define DEPEVT_STATUS_CONTROL_DATA 1
873#define DEPEVT_STATUS_CONTROL_STATUS 2
874
Felipe Balbi72246da2011-08-19 18:10:58 +0300875 u32 parameters:16;
876} __packed;
877
878/**
879 * struct dwc3_event_devt - Device Events
880 * @one_bit: indicates this is a non-endpoint event (not used)
881 * @device_event: indicates it's a device event. Should read as 0x00
882 * @type: indicates the type of device event.
883 * 0 - DisconnEvt
884 * 1 - USBRst
885 * 2 - ConnectDone
886 * 3 - ULStChng
887 * 4 - WkUpEvt
888 * 5 - Reserved
889 * 6 - EOPF
890 * 7 - SOF
891 * 8 - Reserved
892 * 9 - ErrticErr
893 * 10 - CmdCmplt
894 * 11 - EvntOverflow
895 * 12 - VndrDevTstRcved
896 * @reserved15_12: Reserved, not used
897 * @event_info: Information about this event
898 * @reserved31_24: Reserved, not used
899 */
900struct dwc3_event_devt {
901 u32 one_bit:1;
902 u32 device_event:7;
903 u32 type:4;
904 u32 reserved15_12:4;
905 u32 event_info:8;
906 u32 reserved31_24:8;
907} __packed;
908
909/**
910 * struct dwc3_event_gevt - Other Core Events
911 * @one_bit: indicates this is a non-endpoint event (not used)
912 * @device_event: indicates it's (0x03) Carkit or (0x04) I2C event.
913 * @phy_port_number: self-explanatory
914 * @reserved31_12: Reserved, not used.
915 */
916struct dwc3_event_gevt {
917 u32 one_bit:1;
918 u32 device_event:7;
919 u32 phy_port_number:4;
920 u32 reserved31_12:20;
921} __packed;
922
923/**
924 * union dwc3_event - representation of Event Buffer contents
925 * @raw: raw 32-bit event
926 * @type: the type of the event
927 * @depevt: Device Endpoint Event
928 * @devt: Device Event
929 * @gevt: Global Event
930 */
931union dwc3_event {
932 u32 raw;
933 struct dwc3_event_type type;
934 struct dwc3_event_depevt depevt;
935 struct dwc3_event_devt devt;
936 struct dwc3_event_gevt gevt;
937};
938
939/*
940 * DWC3 Features to be used as Driver Data
941 */
942
943#define DWC3_HAS_PERIPHERAL BIT(0)
944#define DWC3_HAS_XHCI BIT(1)
945#define DWC3_HAS_OTG BIT(3)
946
Felipe Balbid07e8812011-10-12 14:08:26 +0300947/* prototypes */
Sebastian Andrzej Siewior3140e8c2011-10-31 22:25:40 +0100948void dwc3_set_mode(struct dwc3 *dwc, u32 mode);
Felipe Balbi457e84b2012-01-18 18:04:09 +0200949int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc);
Sebastian Andrzej Siewior3140e8c2011-10-31 22:25:40 +0100950
Ido Shayevitzcdeef4c2012-05-29 13:17:41 +0200951int dwc3_otg_init(struct dwc3 *dwc);
952void dwc3_otg_exit(struct dwc3 *dwc);
953
Felipe Balbid07e8812011-10-12 14:08:26 +0300954int dwc3_host_init(struct dwc3 *dwc);
955void dwc3_host_exit(struct dwc3 *dwc);
956
Felipe Balbif80b45e2011-10-12 14:15:49 +0300957int dwc3_gadget_init(struct dwc3 *dwc);
958void dwc3_gadget_exit(struct dwc3 *dwc);
959
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530960void dwc3_gadget_restart(struct dwc3 *dwc);
961void dwc3_post_host_reset_core_init(struct dwc3 *dwc);
Wesley Cheng446ad8d2013-06-05 16:15:01 +0530962int dwc3_event_buffers_setup(struct dwc3 *dwc);
Manu Gautamf1fceddf2012-10-12 14:02:50 +0530963
Vijayavardhan Vennapusa8a011c92013-07-29 09:06:48 +0530964extern void dwc3_set_notifier(
965 void (*notify) (struct dwc3 *dwc3, unsigned event));
Manu Gautama10e7fb2015-04-21 16:13:43 +0530966extern int dwc3_notify_event(struct dwc3 *dwc3, unsigned event);
Felipe Balbi8300dd22011-10-18 13:54:01 +0300967extern int dwc3_get_device_id(void);
968extern void dwc3_put_device_id(int id);
969
Felipe Balbi72246da2011-08-19 18:10:58 +0300970#endif /* __DRIVERS_USB_DWC3_CORE_H */