1 /* Copyright (C) 2007,2008 Freescale Semiconductor, Inc.
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation; either version 2 of the License, or (at your
6 * option) any later version.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 675 Mass Ave, Cambridge, MA 02139, USA.
18 #ifndef __LINUX_USB_OTG_FSM_H
19 #define __LINUX_USB_OTG_FSM_H
21 #include <linux/mutex.h>
22 #include <linux/errno.h>
27 #define VDBG(fmt, args...) pr_debug("[%s] " fmt , \
30 #define VDBG(stuff...) do {} while (0)
34 #define MPC_LOC printk("Current Location [%s]:[%d]\n", __FILE__, __LINE__)
36 #define MPC_LOC do {} while (0)
39 #define PROTO_UNDEF (0)
40 #define PROTO_HOST (1)
41 #define PROTO_GADGET (2)
43 #define OTG_STS_SELECTOR 0xF000 /* OTG status selector, according to
44 * OTG and EH 2.0 Chapter 6.2.3
48 #define HOST_REQUEST_FLAG 1 /* Host request flag, according to
49 * OTG and EH 2.0 Charpter 6.2.3
53 #define T_HOST_REQ_POLL (1500) /* 1500ms, HNP polling interval */
56 /* Standard OTG timers */
65 /* Auxiliary timers */
75 /* OTG state machine according to the OTG spec */
107 /* Internal variables */
113 /* Informative variables */
118 /* Auxilary informative variables */
119 int a_suspend_req_inf;
121 /* Timeout indicator for timers */
122 int a_wait_vrise_tmout;
123 int a_wait_vfall_tmout;
124 int a_wait_bcon_tmout;
125 int a_aidl_bdis_tmout;
126 int b_ase0_brst_tmout;
127 int a_bidl_adis_tmout;
129 struct otg_fsm_ops *ops;
132 /* Current usb protocol used: 0:undefine; 1:host; 2:client */
136 struct delayed_work hnp_polling_work;
140 void (*chrg_vbus)(struct otg_fsm *fsm, int on);
141 void (*drv_vbus)(struct otg_fsm *fsm, int on);
142 void (*loc_conn)(struct otg_fsm *fsm, int on);
143 void (*loc_sof)(struct otg_fsm *fsm, int on);
144 void (*start_pulse)(struct otg_fsm *fsm);
145 void (*start_adp_prb)(struct otg_fsm *fsm);
146 void (*start_adp_sns)(struct otg_fsm *fsm);
147 void (*add_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
148 void (*del_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
149 int (*start_host)(struct otg_fsm *fsm, int on);
150 int (*start_gadget)(struct otg_fsm *fsm, int on);
154 static inline int otg_chrg_vbus(struct otg_fsm *fsm, int on)
156 if (!fsm->ops->chrg_vbus)
158 fsm->ops->chrg_vbus(fsm, on);
162 static inline int otg_drv_vbus(struct otg_fsm *fsm, int on)
164 if (!fsm->ops->drv_vbus)
166 if (fsm->drv_vbus != on) {
168 fsm->ops->drv_vbus(fsm, on);
173 static inline int otg_loc_conn(struct otg_fsm *fsm, int on)
175 if (!fsm->ops->loc_conn)
177 if (fsm->loc_conn != on) {
179 fsm->ops->loc_conn(fsm, on);
184 static inline int otg_loc_sof(struct otg_fsm *fsm, int on)
186 if (!fsm->ops->loc_sof)
188 if (fsm->loc_sof != on) {
190 fsm->ops->loc_sof(fsm, on);
195 static inline int otg_start_pulse(struct otg_fsm *fsm)
197 if (!fsm->ops->start_pulse)
199 if (!fsm->data_pulse) {
201 fsm->ops->start_pulse(fsm);
206 static inline int otg_start_adp_prb(struct otg_fsm *fsm)
208 if (!fsm->ops->start_adp_prb)
213 fsm->ops->start_adp_prb(fsm);
218 static inline int otg_start_adp_sns(struct otg_fsm *fsm)
220 if (!fsm->ops->start_adp_sns)
224 fsm->ops->start_adp_sns(fsm);
229 static inline int otg_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
231 if (!fsm->ops->add_timer)
233 fsm->ops->add_timer(fsm, timer);
237 static inline int otg_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
239 if (!fsm->ops->del_timer)
241 fsm->ops->del_timer(fsm, timer);
245 static inline int otg_start_host(struct otg_fsm *fsm, int on)
247 if (!fsm->ops->start_host)
249 return fsm->ops->start_host(fsm, on);
252 static inline int otg_start_gadget(struct otg_fsm *fsm, int on)
254 if (!fsm->ops->start_gadget)
256 return fsm->ops->start_gadget(fsm, on);
259 int otg_statemachine(struct otg_fsm *fsm);
261 #endif /* __LINUX_USB_OTG_FSM_H */