1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#define otg_dbg(d, fmt, args...) dev_dbg((d)->dev, "%s(): " fmt,\
20 __func__, ## args)
21#define otg_vdbg(d, fmt, args...) dev_vdbg((d)->dev, "%s(): " fmt,\
22 __func__, ## args)
23#define otg_err(d, fmt, args...) dev_err((d)->dev, "%s(): ERROR: " fmt,\
24 __func__, ## args)
25#define otg_warn(d, fmt, args...) dev_warn((d)->dev, "%s(): WARN: " fmt,\
26 __func__, ## args)
27#define otg_info(d, fmt, args...) dev_info((d)->dev, "%s(): INFO: " fmt,\
28 __func__, ## args)
29
30#ifdef VERBOSE_DEBUG
31#define otg_write(o, reg, val) do { \
32 otg_vdbg(o, "OTG_WRITE: reg=0x%05x, val=0x%08x\n", reg, val); \
33 writel(val, ((void *)((o)->regs)) + reg); \
34 } while (0)
35
36#define otg_read(o, reg) ({ \
37 u32 __r = readl(((void *)((o)->regs)) + reg); \
38 otg_vdbg(o, "OTG_READ: reg=0x%05x, val=0x%08x\n", reg, __r); \
39 __r; \
40 })
41#else
42#define otg_write(o, reg, val) writel(val, ((void *)((o)->regs)) + reg)
43#define otg_read(o, reg) readl(((void *)((o)->regs)) + reg)
44#endif
45
46#define sleep_main_thread_until_condition_timeout(otg, condition, msecs) ({ \
47 int __timeout = msecs; \
48 while (!(condition)) { \
49 otg_dbg(otg, " ... sleeping for %d\n", __timeout); \
50 __timeout = sleep_main_thread_timeout(otg, __timeout); \
51 if (__timeout <= 0) { \
52 break; \
53 } \
54 } \
55 __timeout; \
56 })
57
58#define sleep_main_thread_until_condition(otg, condition) ({ \
59 int __rc; \
60 do { \
61 __rc = sleep_main_thread_until_condition_timeout(otg, \
62 condition, 50000); \
63 } while (__rc == 0); \
64 __rc; \
65 })
66
67#define GHWPARAMS6 0xc158
68#define GHWPARAMS6_SRP_SUPPORT_ENABLED 0x0400
69#define GHWPARAMS6_HNP_SUPPORT_ENABLED 0x0800
70
71#define GCTL 0xc110
72#define GCTL_PRT_CAP_DIR 0x3000
73#define GCTL_PRT_CAP_DIR_SHIFT 12
74#define GCTL_PRT_CAP_DIR_HOST 1
75#define GCTL_PRT_CAP_DIR_DEV 2
76#define GCTL_PRT_CAP_DIR_OTG 3
77#define GCTL_GBL_HIBERNATION_EN 0x2
78
79#define OCFG 0xcc00
80#define OCFG_SRP_CAP 0x01
81#define OCFG_SRP_CAP_SHIFT 0
82#define OCFG_HNP_CAP 0x02
83#define OCFG_HNP_CAP_SHIFT 1
84#define OCFG_OTG_VERSION 0x04
85#define OCFG_OTG_VERSION_SHIFT 2
86
87#define OCTL 0xcc04
88#define OCTL_HST_SET_HNP_EN 0x01
89#define OCTL_HST_SET_HNP_EN_SHIFT 0
90#define OCTL_DEV_SET_HNP_EN 0x02
91#define OCTL_DEV_SET_HNP_EN_SHIFT 1
92#define OCTL_TERM_SEL_DL_PULSE 0x04
93#define OCTL_TERM_SEL_DL_PULSE_SHIFT 2
94#define OCTL_SES_REQ 0x08
95#define OCTL_SES_REQ_SHIFT 3
96#define OCTL_HNP_REQ 0x10
97#define OCTL_HNP_REQ_SHIFT 4
98#define OCTL_PRT_PWR_CTL 0x20
99#define OCTL_PRT_PWR_CTL_SHIFT 5
100#define OCTL_PERI_MODE 0x40
101#define OCTL_PERI_MODE_SHIFT 6
102
103#define OEVT 0xcc08
104#define OEVT_ERR 0x00000001
105#define OEVT_ERR_SHIFT 0
106#define OEVT_SES_REQ_SCS 0x00000002
107#define OEVT_SES_REQ_SCS_SHIFT 1
108#define OEVT_HST_NEG_SCS 0x00000004
109#define OEVT_HST_NEG_SCS_SHIFT 2
110#define OEVT_B_SES_VLD_EVT 0x00000008
111#define OEVT_B_SES_VLD_EVT_SHIFT 3
112#define OEVT_B_DEV_VBUS_CHNG_EVNT 0x00000100
113#define OEVT_B_DEV_VBUS_CHNG_EVNT_SHIFT 8
114#define OEVT_B_DEV_SES_VLD_DET_EVNT 0x00000200
115#define OEVT_B_DEV_SES_VLD_DET_EVNT_SHIFT 9
116#define OEVT_B_DEV_HNP_CHNG_EVNT 0x00000400
117#define OEVT_B_DEV_HNP_CHNG_EVNT_SHIFT 10
118#define OEVT_B_DEV_B_HOST_END_EVNT 0x00000800
119#define OEVT_B_DEV_B_HOST_END_EVNT_SHIFT 11
120#define OEVT_A_DEV_SESS_END_DET_EVNT 0x00010000
121#define OEVT_A_DEV_SESS_END_DET_EVNT_SHIFT 16
122#define OEVT_A_DEV_SRP_DET_EVNT 0x00020000
123#define OEVT_A_DEV_SRP_DET_EVNT_SHIFT 17
124#define OEVT_A_DEV_HNP_CHNG_EVNT 0x00040000
125#define OEVT_A_DEV_HNP_CHNG_EVNT_SHIFT 18
126#define OEVT_A_DEV_HOST_EVNT 0x00080000
127#define OEVT_A_DEV_HOST_EVNT_SHIFT 19
128#define OEVT_A_DEV_B_DEV_HOST_END_EVNT 0x00100000
129#define OEVT_A_DEV_B_DEV_HOST_END_EVNT_SHIFT 20
130#define OEVT_A_DEV_IDLE_EVNT 0x00200000
131#define OEVT_A_DEV_IDLE_EVNT_SHIFT 21
132#define OEVT_HOST_ROLE_REQ_INIT_EVNT 0x00400000
133#define OEVT_HOST_ROLE_REQ_INIT_EVNT_SHIFT 22
134#define OEVT_HOST_ROLE_REQ_CONFIRM_EVNT 0x00800000
135#define OEVT_HOST_ROLE_REQ_CONFIRM_EVNT_SHIFT 23
136#define OEVT_CONN_ID_STS_CHNG_EVNT 0x01000000
137#define OEVT_CONN_ID_STS_CHNG_EVNT_SHIFT 24
138#define OEVT_DEV_MOD_EVNT 0x80000000
139#define OEVT_DEV_MOD_EVNT_SHIFT 31
140
141#define OEVTEN 0xcc0c
142
143#define OEVT_ALL (OEVT_CONN_ID_STS_CHNG_EVNT | \
144 OEVT_HOST_ROLE_REQ_INIT_EVNT | \
145 OEVT_HOST_ROLE_REQ_CONFIRM_EVNT | \
146 OEVT_A_DEV_B_DEV_HOST_END_EVNT | \
147 OEVT_A_DEV_HOST_EVNT | \
148 OEVT_A_DEV_HNP_CHNG_EVNT | \
149 OEVT_A_DEV_SRP_DET_EVNT | \
150 OEVT_A_DEV_SESS_END_DET_EVNT | \
151 OEVT_B_DEV_B_HOST_END_EVNT | \
152 OEVT_B_DEV_HNP_CHNG_EVNT | \
153 OEVT_B_DEV_SES_VLD_DET_EVNT | \
154 OEVT_B_DEV_VBUS_CHNG_EVNT)
155
156#define OSTS 0xcc10
157#define OSTS_CONN_ID_STS 0x0001
158#define OSTS_CONN_ID_STS_SHIFT 0
159#define OSTS_A_SES_VLD 0x0002
160#define OSTS_A_SES_VLD_SHIFT 1
161#define OSTS_B_SES_VLD 0x0004
162#define OSTS_B_SES_VLD_SHIFT 2
163#define OSTS_XHCI_PRT_PWR 0x0008
164#define OSTS_XHCI_PRT_PWR_SHIFT 3
165#define OSTS_PERIP_MODE 0x0010
166#define OSTS_PERIP_MODE_SHIFT 4
167#define OSTS_OTG_STATES 0x0f00
168#define OSTS_OTG_STATE_SHIFT 8
169
170#define DCTL 0xc704
171#define DCTL_RUN_STOP 0x80000000
172
173#define OTG_STATE_INVALID -1
174#define OTG_STATE_EXIT 14
175#define OTG_STATE_TERMINATED 15
176
177#define PERI_MODE_HOST 0
178#define PERI_MODE_PERIPHERAL 1
179
180
181struct dwc3_otg {
182
183
184 struct usb_otg otg;
185 struct device *dev;
186 struct dwc3 *dwc;
187
188 void __iomem *regs;
189
190 int main_wakeup_needed;
191 struct task_struct *main_thread;
192 wait_queue_head_t main_wq;
193
194 spinlock_t lock;
195
196 int otg_srp_reqd;
197
198
199 u32 otg_events;
200
201 u32 user_events;
202
203
204
205
206
207
208
209
210
211
212#define USER_SRP_EVENT 0x1
213
214#define USER_HNP_EVENT 0x2
215
216#define USER_END_SESSION 0x4
217
218
219
220
221#define USER_VBUS_ON 0x8
222
223#define USER_RSP_EVENT 0x10
224
225#define PCD_RECEIVED_HOST_RELEASE_EVENT 0x20
226
227#define INITIAL_SRP 0x40
228
229#define USER_A_CONN_EVENT 0x80
230
231
232
233
234#define USER_HNP_END_SESSION 0x100
235
236
237 enum usb_otg_state prev;
238 enum usb_otg_state state;
239
240 u32 hwparams6;
241 int hcd_irq;
242 int irq;
243 int host_started;
244 int peripheral_started;
245 int dev_enum;
246
247 struct delayed_work hp_work;
248
249};
250
251extern int usb_port_suspend(struct usb_device *udev, pm_message_t msg);
252extern void usb_kick_hub_wq(struct usb_device *dev);
253