This source file includes following definitions.
- otg_chrg_vbus
- otg_drv_vbus
- otg_loc_conn
- otg_loc_sof
- otg_start_pulse
- otg_start_adp_prb
- otg_start_adp_sns
- otg_add_timer
- otg_del_timer
- otg_start_host
- otg_start_gadget
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #ifndef __LINUX_USB_OTG_FSM_H
20 #define __LINUX_USB_OTG_FSM_H
21
22 #include <linux/mutex.h>
23 #include <linux/errno.h>
24
25 #define PROTO_UNDEF (0)
26 #define PROTO_HOST (1)
27 #define PROTO_GADGET (2)
28
29 #define OTG_STS_SELECTOR 0xF000
30
31
32
33
34 #define HOST_REQUEST_FLAG 1
35
36
37
38
39 #define T_HOST_REQ_POLL (1500)
40
41 enum otg_fsm_timer {
42
43 A_WAIT_VRISE,
44 A_WAIT_VFALL,
45 A_WAIT_BCON,
46 A_AIDL_BDIS,
47 B_ASE0_BRST,
48 A_BIDL_ADIS,
49 B_AIDL_BDIS,
50
51
52 B_SE0_SRP,
53 B_SRP_FAIL,
54 A_WAIT_ENUM,
55 B_DATA_PLS,
56 B_SSEND_SRP,
57
58 NUM_OTG_FSM_TIMERS,
59 };
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137 struct otg_fsm {
138
139 int id;
140 int adp_change;
141 int power_up;
142 int a_srp_det;
143 int a_vbus_vld;
144 int b_conn;
145 int a_bus_resume;
146 int a_bus_suspend;
147 int a_conn;
148 int b_se0_srp;
149 int b_ssend_srp;
150 int b_sess_vld;
151 int test_device;
152 int a_bus_drop;
153 int a_bus_req;
154 int b_bus_req;
155
156
157 int a_sess_vld;
158 int b_bus_resume;
159 int b_bus_suspend;
160
161
162 int drv_vbus;
163 int loc_conn;
164 int loc_sof;
165 int adp_prb;
166 int adp_sns;
167 int data_pulse;
168
169
170 int a_set_b_hnp_en;
171 int b_srp_done;
172 int b_hnp_enable;
173 int a_clr_err;
174
175
176 int a_bus_drop_inf;
177 int a_bus_req_inf;
178 int a_clr_err_inf;
179 int b_bus_req_inf;
180
181 int a_suspend_req_inf;
182
183
184 int a_wait_vrise_tmout;
185 int a_wait_vfall_tmout;
186 int a_wait_bcon_tmout;
187 int a_aidl_bdis_tmout;
188 int b_ase0_brst_tmout;
189 int a_bidl_adis_tmout;
190
191 struct otg_fsm_ops *ops;
192 struct usb_otg *otg;
193
194
195 int protocol;
196 struct mutex lock;
197 u8 *host_req_flag;
198 struct delayed_work hnp_polling_work;
199 bool state_changed;
200 };
201
202 struct otg_fsm_ops {
203 void (*chrg_vbus)(struct otg_fsm *fsm, int on);
204 void (*drv_vbus)(struct otg_fsm *fsm, int on);
205 void (*loc_conn)(struct otg_fsm *fsm, int on);
206 void (*loc_sof)(struct otg_fsm *fsm, int on);
207 void (*start_pulse)(struct otg_fsm *fsm);
208 void (*start_adp_prb)(struct otg_fsm *fsm);
209 void (*start_adp_sns)(struct otg_fsm *fsm);
210 void (*add_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
211 void (*del_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
212 int (*start_host)(struct otg_fsm *fsm, int on);
213 int (*start_gadget)(struct otg_fsm *fsm, int on);
214 };
215
216
217 static inline int otg_chrg_vbus(struct otg_fsm *fsm, int on)
218 {
219 if (!fsm->ops->chrg_vbus)
220 return -EOPNOTSUPP;
221 fsm->ops->chrg_vbus(fsm, on);
222 return 0;
223 }
224
225 static inline int otg_drv_vbus(struct otg_fsm *fsm, int on)
226 {
227 if (!fsm->ops->drv_vbus)
228 return -EOPNOTSUPP;
229 if (fsm->drv_vbus != on) {
230 fsm->drv_vbus = on;
231 fsm->ops->drv_vbus(fsm, on);
232 }
233 return 0;
234 }
235
236 static inline int otg_loc_conn(struct otg_fsm *fsm, int on)
237 {
238 if (!fsm->ops->loc_conn)
239 return -EOPNOTSUPP;
240 if (fsm->loc_conn != on) {
241 fsm->loc_conn = on;
242 fsm->ops->loc_conn(fsm, on);
243 }
244 return 0;
245 }
246
247 static inline int otg_loc_sof(struct otg_fsm *fsm, int on)
248 {
249 if (!fsm->ops->loc_sof)
250 return -EOPNOTSUPP;
251 if (fsm->loc_sof != on) {
252 fsm->loc_sof = on;
253 fsm->ops->loc_sof(fsm, on);
254 }
255 return 0;
256 }
257
258 static inline int otg_start_pulse(struct otg_fsm *fsm)
259 {
260 if (!fsm->ops->start_pulse)
261 return -EOPNOTSUPP;
262 if (!fsm->data_pulse) {
263 fsm->data_pulse = 1;
264 fsm->ops->start_pulse(fsm);
265 }
266 return 0;
267 }
268
269 static inline int otg_start_adp_prb(struct otg_fsm *fsm)
270 {
271 if (!fsm->ops->start_adp_prb)
272 return -EOPNOTSUPP;
273 if (!fsm->adp_prb) {
274 fsm->adp_sns = 0;
275 fsm->adp_prb = 1;
276 fsm->ops->start_adp_prb(fsm);
277 }
278 return 0;
279 }
280
281 static inline int otg_start_adp_sns(struct otg_fsm *fsm)
282 {
283 if (!fsm->ops->start_adp_sns)
284 return -EOPNOTSUPP;
285 if (!fsm->adp_sns) {
286 fsm->adp_sns = 1;
287 fsm->ops->start_adp_sns(fsm);
288 }
289 return 0;
290 }
291
292 static inline int otg_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
293 {
294 if (!fsm->ops->add_timer)
295 return -EOPNOTSUPP;
296 fsm->ops->add_timer(fsm, timer);
297 return 0;
298 }
299
300 static inline int otg_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
301 {
302 if (!fsm->ops->del_timer)
303 return -EOPNOTSUPP;
304 fsm->ops->del_timer(fsm, timer);
305 return 0;
306 }
307
308 static inline int otg_start_host(struct otg_fsm *fsm, int on)
309 {
310 if (!fsm->ops->start_host)
311 return -EOPNOTSUPP;
312 return fsm->ops->start_host(fsm, on);
313 }
314
315 static inline int otg_start_gadget(struct otg_fsm *fsm, int on)
316 {
317 if (!fsm->ops->start_gadget)
318 return -EOPNOTSUPP;
319 return fsm->ops->start_gadget(fsm, on);
320 }
321
322 int otg_statemachine(struct otg_fsm *fsm);
323
324 #endif